forked from syndesisio/syndesis
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(ENTESB-18466): Flag operator as non-upgradeable
* When operator is installed via OLM, a separate OperatorCondition CR is created which can be updated with an "upgradeable" condition flagging whether the OLM can upgrade the operator * Turn off upgradeable state when * operator is initializing * operator is upgrading * Turn on upgradeable state when * operator has started * operator has completed an upgrade * Finds the OperatorCondition using the deployment name, deployment owner (CSV) and the CSV name (OperatorCondition has same name as the CSV). * Adds conditions tests but cannot completely implement due to operator-framework/operator-lib#103
- Loading branch information
1 parent
53d5231
commit 78a983e
Showing
14 changed files
with
460 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
install/operator/config/dev/operator/patch-image-pull-policy-always.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# --------------------------------------------------------------------------- | ||
# Licensed to the Apache Software Foundation (ASF) under one or more | ||
# contributor license agreements. See the NOTICE file distributed with | ||
# this work for additional information regarding copyright ownership. | ||
# The ASF licenses this file to You under the Apache License, Version 2.0 | ||
# (the "License"); you may not use this file except in compliance with | ||
# the License. You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# --------------------------------------------------------------------------- | ||
|
||
apiVersion: apps/v1 | ||
kind: Deployment | ||
metadata: | ||
name: syndesis-operator | ||
spec: | ||
template: | ||
spec: | ||
containers: | ||
- name: syndesis-operator | ||
imagePullPolicy: Always |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
147 changes: 147 additions & 0 deletions
147
install/operator/pkg/syndesis/olm/operator_conditions.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,147 @@ | ||
/* | ||
* Copyright (C) 2020 Red Hat, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package olm | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"os" | ||
|
||
olmapiv2 "github.com/operator-framework/api/pkg/operators/v2" | ||
conditions "github.com/operator-framework/operator-lib/conditions" | ||
errs "github.com/pkg/errors" | ||
synpkg "github.com/syndesisio/syndesis/install/operator/pkg" | ||
"github.com/syndesisio/syndesis/install/operator/pkg/syndesis/capabilities" | ||
"github.com/syndesisio/syndesis/install/operator/pkg/syndesis/clienttools" | ||
"github.com/syndesisio/syndesis/install/operator/pkg/syndesis/configuration" | ||
appsv1 "k8s.io/api/apps/v1" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"k8s.io/apimachinery/pkg/types" | ||
logf "sigs.k8s.io/controller-runtime/pkg/log" | ||
) | ||
|
||
var opCondLog = logf.Log.WithName("operator-condition-log") | ||
|
||
type ConditionState struct { | ||
// The value of the condition, either metav1.ConditionTrue or metav1.ConditionFalse | ||
Status metav1.ConditionStatus | ||
// The single word reason for the condition setting | ||
// Must start with a letter | ||
// Rest of the world can include letters, numbers, commas and colons | ||
// Cannot end with comma or colon | ||
Reason string | ||
// The description of the reason for the condition change. | ||
Message string | ||
} | ||
|
||
func GetConditionName(ctx context.Context, clientTools *clienttools.ClientTools, namespace string) (string, error) { | ||
opCondLog.V(synpkg.DEBUG_LOGGING_LVL).Info("Finding OLM Operator Condition") | ||
|
||
apiSpec, err := capabilities.ApiCapabilities(clientTools) | ||
if err != nil { | ||
return "", err | ||
} | ||
|
||
if !apiSpec.OlmSupport { | ||
// | ||
// This cluster does not support OLM so nothing to do | ||
// | ||
opCondLog.V(synpkg.DEBUG_LOGGING_LVL).Info("No OLM support ... aborting Operation Condition Search") | ||
return "", nil | ||
} | ||
|
||
rtClient, err := clientTools.RuntimeClient() | ||
if err != nil { | ||
return "", errs.Wrap(err, "Failed to initialise runtime client") | ||
} | ||
|
||
// | ||
// Find the operator condition associated with this operator | ||
// | ||
// deployment -> owned by CSV -> operator condition has the same name | ||
// | ||
configName, err := configuration.GetProductName(configuration.TemplateConfig) | ||
if err != nil { | ||
return "", errs.Wrap(err, "Failed to determine product name") | ||
} | ||
deploymentName := configName + "-operator" | ||
|
||
opCondLog.V(synpkg.DEBUG_LOGGING_LVL).Info("Finding Operator Deployment", "name", deploymentName) | ||
deployment := &appsv1.Deployment{} | ||
if err = rtClient.Get(ctx, types.NamespacedName{Namespace: namespace, Name: deploymentName}, deployment); err != nil { | ||
return "", err // Should find the deployment of this operator | ||
} | ||
|
||
opCondLog.V(synpkg.DEBUG_LOGGING_LVL).Info("Operator Deployment found", "name", deploymentName) | ||
ownerRefs := deployment.GetOwnerReferences() | ||
if len(ownerRefs) > 1 || len(ownerRefs) == 0 { | ||
// No operator condition as this is not owned by a CSV | ||
return "", nil | ||
} | ||
|
||
if ownerRefs[0].Kind != "ClusterServiceVersion" { | ||
// No operator condition as this is not owned by a CSV | ||
return "", nil | ||
} | ||
|
||
opCondLog.V(synpkg.DEBUG_LOGGING_LVL).Info("CSV Owned Deployment", "name", deploymentName, "owner", ownerRefs[0].Name) | ||
return ownerRefs[0].Name, nil | ||
} | ||
|
||
// | ||
// Creates the condition if it does not already exist | ||
// | ||
func SetUpgradeCondition(ctx context.Context, clientTools *clienttools.ClientTools, namespace string, state ConditionState) error { | ||
|
||
conditionName, err := GetConditionName(ctx, clientTools, namespace) | ||
if err != nil { | ||
return err | ||
} else if conditionName == "" { | ||
return nil | ||
} | ||
|
||
rtClient, err := clientTools.RuntimeClient() | ||
if err != nil { | ||
return errs.Wrap(err, "Failed to initialise runtime client") | ||
} | ||
|
||
clusterFactory := conditions.InClusterFactory{rtClient} | ||
err = os.Setenv("OPERATOR_CONDITION_NAME", conditionName) | ||
if err != nil { | ||
return err | ||
} | ||
fmt.Println("XXX Set env var") | ||
uc, err := clusterFactory.NewCondition(olmapiv2.ConditionType(olmapiv2.Upgradeable)) | ||
if err != nil { | ||
fmt.Println("XXX error") | ||
return err | ||
} | ||
|
||
fmt.Println("XXX Setting Condition") | ||
err = uc.Set(ctx, | ||
state.Status, | ||
conditions.WithReason(state.Reason), | ||
conditions.WithMessage(state.Message)) | ||
if err != nil { | ||
fmt.Println("XXX Failed on the last lap") | ||
fmt.Println(err) | ||
return err | ||
} | ||
|
||
fmt.Println("XXX State set") | ||
return nil | ||
} |
Oops, something went wrong.