From 1d0762bd070b1cd06bc7da4b739d53c78888e29b Mon Sep 17 00:00:00 2001 From: phantomjinx Date: Thu, 21 Apr 2022 22:21:43 +0100 Subject: [PATCH 1/2] chore: Reduces size of binaries by removing debug symbols * Adds compile flags for removal of debug symbols from binaries reducing the size by ~15% --- install/operator/build.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/install/operator/build.sh b/install/operator/build.sh index 456fa7e17f1..d3e012cd71e 100755 --- a/install/operator/build.sh +++ b/install/operator/build.sh @@ -45,7 +45,8 @@ fi BUILD_TIME=$(date +%Y-%m-%dT%H:%M:%S%z) if [ $OPERATOR_BUILD_MODE != "skip" ] ; then - LD_FLAGS=$(echo "-X github.com/syndesisio/syndesis/install/operator/pkg.DefaultOperatorImage=${OPERATOR_IMAGE_NAME}" \ + LD_FLAGS=$(echo "-s -w " \ + "-X github.com/syndesisio/syndesis/install/operator/pkg.DefaultOperatorImage=${OPERATOR_IMAGE_NAME}" \ "-X github.com/syndesisio/syndesis/install/operator/pkg.DefaultOperatorTag=${OPERATOR_IMAGE_TAG}" \ "-X github.com/syndesisio/syndesis/install/operator/pkg.BuildDateTime=${BUILD_TIME}") echo "LD_FLAGS: ${LD_FLAGS}" From 754964fa2da1b410553675bfa818bde92aa21155 Mon Sep 17 00:00:00 2001 From: phantomjinx Date: Thu, 21 Apr 2022 22:35:13 +0100 Subject: [PATCH 2/2] Fix(ENTESB-18466): Handles double upgrade of operator * A double upgrade (7.10 -> 7.11.0 -> 7.11.1) does not get to the point of running 7.11.0's Reconcile function before OLM kicks in upgrade to 7.11.1 so need to get the OLM operatorcondition applied before the pod has succeeded * Adds an init-container operator-init to the operator deployment * Objective is find the CSV operatorcondition and disable upgrading * container runs the operator image but has command operator-init instead of operator binary * Operator-init binary compiled in addition to syndesis-operator * Adds ProductName var to deployment template as required for finding the operatorcondition * syndesis_controller.go * Adds in disable states to start of Reconcile function to handle non-resource use-cases * .../action/... * To allow for operator-init binary to use operatorcondition API, have the productName passed in as a parameter --- install/operator/.lib.sh | 13 ++- install/operator/build/Dockerfile | 2 + install/operator/cmd/operator-init/main.go | 110 ++++++++++++++++++ install/operator/config/manager/Makefile | 6 + .../pkg/cmd/internal/install/install.go | 8 ++ .../syndesis/syndesis_controller.go | 60 +++++++++- .../install/operator_deployment.yml.tmpl | 11 ++ .../operator/pkg/syndesis/action/action.go | 2 +- .../operator/pkg/syndesis/action/backup.go | 2 +- .../pkg/syndesis/action/checkupdates.go | 8 +- .../pkg/syndesis/action/initialize.go | 4 +- .../operator/pkg/syndesis/action/install.go | 2 +- .../pkg/syndesis/action/pod_scheduling.go | 2 +- .../operator/pkg/syndesis/action/startup.go | 4 +- .../operator/pkg/syndesis/action/upgrade.go | 8 +- .../pkg/syndesis/action/upgradebackoff.go | 2 +- install/operator/pkg/syndesis/olm/csv.go | 6 + .../pkg/syndesis/olm/operator_conditions.go | 13 +-- .../syndesis/olm/operator_conditions_test.go | 6 +- 19 files changed, 235 insertions(+), 34 deletions(-) create mode 100644 install/operator/cmd/operator-init/main.go diff --git a/install/operator/.lib.sh b/install/operator/.lib.sh index 2351be3ca3e..1f03a9c2d09 100644 --- a/install/operator/.lib.sh +++ b/install/operator/.lib.sh @@ -136,6 +136,11 @@ build_operator() go build -o ./dist/${GOOS}-${GOARCH}/platform-detect \ -gcflags all=-trimpath=${GOPATH} -asmflags all=-trimpath=${GOPATH} -mod=vendor \ ./cmd/detect + + echo building ./dist/${GOOS}-${GOARCH}/operator-init executable + go build -o ./dist/${GOOS}-${GOARCH}/operator-init \ + -gcflags all=-trimpath=${GOPATH} -asmflags all=-trimpath=${GOPATH} -ldflags "-s -w" -mod=vendor \ + ./cmd/operator-init done done mkdir -p ./build/_output/bin @@ -168,8 +173,11 @@ COPY . . RUN go generate ./pkg/... RUN go test -test.short -mod=vendor ./cmd/... ./pkg/... RUN GOOS=linux GOARCH=amd64 go build $OPTS -o /dist/linux-amd64/syndesis-operator -gcflags all=-trimpath=\${GOPATH} -asmflags all=-trimpath=\${GOPATH} -mod=vendor github.com/syndesisio/syndesis/install/operator/cmd/manager +RUN GOOS=linux GOARCH=amd64 go build $OPTS -o /dist/linux-amd64/operator-init -gcflags all=-trimpath=\${GOPATH} -asmflags all=-trimpath=\${GOPATH} -mod=vendor github.com/syndesisio/syndesis/install/operator/cmd/operator-init RUN GOOS=darwin GOARCH=amd64 go build $OPTS -o /dist/darwin-amd64/syndesis-operator -gcflags all=-trimpath=\${GOPATH} -asmflags all=-trimpath=\${GOPATH} -mod=vendor github.com/syndesisio/syndesis/install/operator/cmd/manager +RUN GOOS=darwin GOARCH=amd64 go build $OPTS -o /dist/darwin-amd64/operator-init -gcflags all=-trimpath=\${GOPATH} -asmflags all=-trimpath=\${GOPATH} -mod=vendor github.com/syndesisio/syndesis/install/operator/cmd/operator-init RUN GOOS=windows GOARCH=amd64 go build $OPTS -o /dist/windows-amd64/syndesis-operator -gcflags all=-trimpath=\${GOPATH} -asmflags all=-trimpath=\${GOPATH} -mod=vendor github.com/syndesisio/syndesis/install/operator/cmd/manager +RUN GOOS=windows GOARCH=amd64 go build $OPTS -o /dist/windows-amd64/operator-init -gcflags all=-trimpath=\${GOPATH} -asmflags all=-trimpath=\${GOPATH} -mod=vendor github.com/syndesisio/syndesis/install/operator/cmd/operator-init EODockerfile docker build -t "${BUILDER_IMAGE_NAME}" . -f "${BUILDER_IMAGE_NAME}.tmp" @@ -179,14 +187,17 @@ EODockerfile for GOARCH in amd64 ; do for GOOS in linux darwin windows ; do - echo extracting executable to ./dist/${GOOS}-${GOARCH}/syndesis-operator + echo extracting executables to ./dist/${GOOS}-${GOARCH} mkdir -p ./dist/${GOOS}-${GOARCH} docker run "${BUILDER_IMAGE_NAME}" cat /dist/${GOOS}-${GOARCH}/syndesis-operator > ./dist/${GOOS}-${GOARCH}/syndesis-operator + docker run "${BUILDER_IMAGE_NAME}" cat /dist/${GOOS}-${GOARCH}/operator-init > ./dist/${GOOS}-${GOARCH}/operator-init done done chmod a+x ./dist/*/syndesis-operator + chmod a+x ./dist/*/operator-init mkdir -p ./build/_output/bin cp ./dist/linux-amd64/syndesis-operator ./build/_output/bin/syndesis-operator + cp ./dist/linux-amd64/operator-init ./build/_output/bin/operator-init ;; *) echo invalid build strategy: $strategy diff --git a/install/operator/build/Dockerfile b/install/operator/build/Dockerfile index 29ab8cb6eae..3190c3bd23e 100644 --- a/install/operator/build/Dockerfile +++ b/install/operator/build/Dockerfile @@ -1,11 +1,13 @@ FROM registry.access.redhat.com/ubi7/ubi-minimal:latest ENV OPERATOR=/usr/local/bin/syndesis-operator \ + OPINIT=/usr/local/bin/operator-init \ USER_UID=1001 \ USER_NAME=operator # install operator binary COPY build/_output/bin/syndesis-operator ${OPERATOR} +COPY build/_output/bin/operator-init ${OPINIT} COPY build/bin /usr/local/bin RUN /usr/local/bin/user_setup USER ${USER_UID} diff --git a/install/operator/cmd/operator-init/main.go b/install/operator/cmd/operator-init/main.go new file mode 100644 index 00000000000..f8b38a92719 --- /dev/null +++ b/install/operator/cmd/operator-init/main.go @@ -0,0 +1,110 @@ +/* + * Copyright (C) 2019 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 main + +import ( + "context" + "fmt" + "os" + + gerrors "github.com/pkg/errors" + synapis "github.com/syndesisio/syndesis/install/operator/pkg/apis" + synapi "github.com/syndesisio/syndesis/install/operator/pkg/apis/syndesis/v1beta3" + "github.com/syndesisio/syndesis/install/operator/pkg/syndesis/clienttools" + "github.com/syndesisio/syndesis/install/operator/pkg/syndesis/olm" + kerrors "k8s.io/apimachinery/pkg/api/errors" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "sigs.k8s.io/controller-runtime/pkg/client" +) + +func main() { + clientTools := &clienttools.ClientTools{} + + // + // Ensure runtime client knows about syndesis apis + // + scheme := clientTools.GetScheme() + if err := synapis.AddToScheme(scheme); err != nil { + fmt.Println(err, "Error occurred") + os.Exit(1) + } + + ctx := context.TODO() + + nm, found := os.LookupEnv("POD_NAMESPACE") + if !found { + fmt.Println("Error: No POD_NAMESPACE has been set") + os.Exit(1) + } else { + fmt.Println("Info: Using POD_NAMESPACE: ", nm) + } + + prodName, found := os.LookupEnv("PRODUCT_NAME") + if !found { + fmt.Println("Error: No PRODUCT_NAME has been set") + os.Exit(1) + } else { + fmt.Println("Info: Using PRODUCT_NAME: ", prodName) + } + + if err := setUpgradeCondition(ctx, clientTools, nm, prodName); err != nil { + fmt.Println(err, "Error occurred") + os.Exit(1) + } +} + +func setUpgradeCondition(ctx context.Context, clientTools *clienttools.ClientTools, nm string, prodName string) error { + found, err := hasSyndesis(ctx, clientTools, nm) + if err != nil { + return gerrors.Wrap(err, "Failed to get Syndesis resource") + } else if !found { + fmt.Println("Info: No Syndesis Custom Resource. Upgrade disablement not required") + return nil + } + + // + // Disable the upgrade until enabled + // + state := olm.ConditionState{ + Status: metav1.ConditionFalse, + Reason: "NotReady", + Message: "Disable any operator upgrade until reconciliation allows it", + } + if upgErr := olm.SetUpgradeCondition(ctx, clientTools, nm, prodName, state); upgErr != nil { + return gerrors.Wrap(upgErr, "Failed to set the upgrade condition on the operator") + } + + return nil +} + +func hasSyndesis(ctx context.Context, clientTools *clienttools.ClientTools, nm string) (bool, error) { + synList := synapi.SyndesisList{} + rtclient, err := clientTools.RuntimeClient() + if err != nil { + return false, err + } + + err = rtclient.List(ctx, &synList, &client.ListOptions{Namespace: nm}) + if err != nil { + if kerrors.IsNotFound(err) { + return false, nil + } + return false, err + } + + return len(synList.Items) > 0, nil +} diff --git a/install/operator/config/manager/Makefile b/install/operator/config/manager/Makefile index 1ba4a444754..09772876eae 100644 --- a/install/operator/config/manager/Makefile +++ b/install/operator/config/manager/Makefile @@ -6,6 +6,8 @@ USER_VAR := {KUBE_USER} TAG_VAR := {TAG} IMAGE_VAR := {IMAGE} DB_IMAGE_VAR := {DB_IMAGE} +VERSION_VAR := {VERSION} +PRODUCT_NAME_VAR := {PRODUCT_NAME} ROLENAME := syndesis-operator MANAGER_RESOURCE := ./manager.gen @@ -42,6 +44,8 @@ sync: sed -i 's/{{.Tag}}/$(TAG_VAR)/' $(MANAGER_RESOURCE).$(TMPL) sed -i 's/{{.Image}}/$(IMAGE_VAR)/' $(MANAGER_RESOURCE).$(TMPL) sed -i 's/{{.DatabaseImage}}/$(DB_IMAGE_VAR)/' $(MANAGER_RESOURCE).$(TMPL) + sed -i 's/{{.Version}}/$(VERSION_VAR)/' $(MANAGER_RESOURCE).$(TMPL) + sed -i 's/{{.ProductName}}/$(PRODUCT_NAME_VAR)/' $(MANAGER_RESOURCE).$(TMPL) sed -i '/{{- \|{{else}}\|{{end}}\|^$$/d' $(MANAGER_RESOURCE).$(TMPL) # end-sync @@ -52,4 +56,6 @@ init: sync sed -i 's/$(TAG_VAR)/$(TAG)/' $${resource}.$(YAML); \ sed -i 's~$(IMAGE_VAR)~$(IMAGE)~' $${resource}.$(YAML); \ sed -i 's~$(DB_IMAGE_VAR)~$(DB_IMAGE)~' $${resource}.$(YAML); \ + sed -i 's~$(VERSION_VAR)~$(VERSION:.0=)~' $${resource}.$(YAML); \ + sed -i 's~$(PRODUCT_NAME_VAR)~$(PACKAGE:.0=)~' $${resource}.$(YAML); \ done diff --git a/install/operator/pkg/cmd/internal/install/install.go b/install/operator/pkg/cmd/internal/install/install.go index f05406daaaf..e16c423ead7 100644 --- a/install/operator/pkg/cmd/internal/install/install.go +++ b/install/operator/pkg/cmd/internal/install/install.go @@ -46,6 +46,7 @@ type Install struct { eject string image string tag string + version string addons string customResource string devSupport bool @@ -53,6 +54,7 @@ type Install struct { apiServer capabilities.ApiServerSpec databaseImage string templateName string + productName string // processing state ejectedResources []unstructured.Unstructured @@ -165,6 +167,8 @@ func (o *Install) before(_ *cobra.Command, args []string) (err error) { config, err := configuration.GetProperties(o.Context, configuration.TemplateConfig, o.ClientTools(), &synapi.Syndesis{}) if err == nil { o.databaseImage = config.Syndesis.Components.Database.Image + o.version = config.Version + o.productName = config.ProductName } return nil @@ -210,7 +214,9 @@ type RenderScope struct { Role string Kind string EnabledAddons []string + Version string DatabaseImage string + ProductName string } func (o *Install) install(action string, resources []unstructured.Unstructured) error { @@ -270,6 +276,8 @@ func (o *Install) render(fromFile string) ([]unstructured.Unstructured, error) { Kind: "Role", EnabledAddons: addons, DatabaseImage: o.databaseImage, + Version: o.version, + ProductName: o.productName, }) return resources, err } diff --git a/install/operator/pkg/controller/syndesis/syndesis_controller.go b/install/operator/pkg/controller/syndesis/syndesis_controller.go index ddbe3a615cc..faec5d8759e 100644 --- a/install/operator/pkg/controller/syndesis/syndesis_controller.go +++ b/install/operator/pkg/controller/syndesis/syndesis_controller.go @@ -19,6 +19,9 @@ import ( synapi "github.com/syndesisio/syndesis/install/operator/pkg/apis/syndesis/v1beta3" "github.com/syndesisio/syndesis/install/operator/pkg/syndesis/action" "github.com/syndesisio/syndesis/install/operator/pkg/syndesis/clienttools" + "github.com/syndesisio/syndesis/install/operator/pkg/syndesis/configuration" + "github.com/syndesisio/syndesis/install/operator/pkg/syndesis/olm" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) var log = logf.Log.WithName("controller") @@ -88,25 +91,76 @@ func (r *ReconcileSyndesis) Reconcile(ctx context.Context, request reconcile.Req // Fetch the Syndesis syndesis syndesis := &synapi.Syndesis{} - client, _ := r.clientTools.RuntimeClient() + productName, err := configuration.GetProductName(configuration.TemplateConfig) + if err != nil { + log.Error(err, "Failed to determine product name") + } - err := client.Get(ctx, request.NamespacedName, syndesis) + err = client.Get(ctx, request.NamespacedName, syndesis) if err != nil { if errors.IsNotFound(err) { + + // + // Allow the operator to be upgradeable if no syndesis resource is installed + // + state := olm.ConditionState{ + Status: metav1.ConditionTrue, + Reason: "Ready", + Message: "No Syndesis Resource installed so operator can be upgraded", + } + if upgErr := olm.SetUpgradeCondition(ctx, r.clientTools, request.Namespace, productName, state); upgErr != nil { + log.Error(upgErr, "Failed to set the upgrade condition on the operator") + } + // Request object not found, could have been deleted after reconcile request. // Owned objects are automatically garbage collected. For additional cleanup logic use finalizers. // Return and don't requeue return reconcile.Result{}, nil } + // Error reading the object - requeue the request. log.Error(err, "Cannot read object", request.NamespacedName) + + // + // Stop the operator being upgradeable until a state can be read + // + state := olm.ConditionState{ + Status: metav1.ConditionFalse, + Reason: "NotReady", + Message: "Read error detecting syndesis resource", + } + if upgErr := olm.SetUpgradeCondition(ctx, r.clientTools, request.Namespace, productName, state); upgErr != nil { + log.Error(upgErr, "Failed to set the upgrade condition on the operator") + } + return reconcile.Result{ Requeue: true, RequeueAfter: 10 * time.Second, }, err } + // + // Check the syndesis resource allows for upgrades. Otherwise disable + // + stateMsg := "" + if syndesis.Status.Version != synpkg.DefaultOperatorTag { + stateMsg = "Not upgradeable due to version mismatch of operator and Syndesis Resource" + } else if syndesis.Status.Phase != synapi.SyndesisPhaseInstalled { + stateMsg = "Not upgradeable due to Syndesis Resource phase not reaching 'Installed'" + } + + if len(stateMsg) > 0 { + state := olm.ConditionState{ + Status: metav1.ConditionFalse, + Reason: "NotReady", + Message: stateMsg, + } + if upgErr := olm.SetUpgradeCondition(ctx, r.clientTools, request.Namespace, productName, state); upgErr != nil { + log.Error(upgErr, "Failed to set the upgrade condition on the operator") + } + } + for _, a := range actions { // Don't want to do anything if the syndesis resource has been updated in the meantime // This happens when a processing takes more tha the resync period @@ -120,7 +174,7 @@ func (r *ReconcileSyndesis) Reconcile(ctx context.Context, request reconcile.Req if a.CanExecute(syndesis) { log.V(synpkg.DEBUG_LOGGING_LVL).Info("Running action", "action", reflect.TypeOf(a)) - if err := a.Execute(ctx, syndesis, request.Namespace); err != nil { + if err := a.Execute(ctx, syndesis, request.Namespace, productName); err != nil { log.Error(err, "Error reconciling", "action", reflect.TypeOf(a), "phase", syndesis.Status.Phase) return reconcile.Result{ Requeue: true, diff --git a/install/operator/pkg/generator/assets/install/operator_deployment.yml.tmpl b/install/operator/pkg/generator/assets/install/operator_deployment.yml.tmpl index 3b1532fe4ec..488c7387ee7 100644 --- a/install/operator/pkg/generator/assets/install/operator_deployment.yml.tmpl +++ b/install/operator/pkg/generator/assets/install/operator_deployment.yml.tmpl @@ -74,6 +74,17 @@ spec: - name: syndesis-operator-data mountPath: /data initContainers: + - name: operator-init + image: {{.Image}}:{{.Tag}} + imagePullPolicy: Always + command: ["/usr/local/bin/operator-init"] + env: + - name: POD_NAMESPACE + valueFrom: + fieldRef: + fieldPath: metadata.namespace + - name: PRODUCT_NAME + value: {{.ProductName}} - command: - bash - -c diff --git a/install/operator/pkg/syndesis/action/action.go b/install/operator/pkg/syndesis/action/action.go index 0d5ab45fb21..1b398f2871e 100644 --- a/install/operator/pkg/syndesis/action/action.go +++ b/install/operator/pkg/syndesis/action/action.go @@ -36,7 +36,7 @@ var actionLog = logf.Log.WithName("action") type SyndesisOperatorAction interface { CanExecute(syndesis *synapi.Syndesis) bool - Execute(ctx context.Context, syndesis *synapi.Syndesis, operatorNamespace string) error + Execute(ctx context.Context, syndesis *synapi.Syndesis, operatorNamespace string, productName string) error } // NewOperatorActions gives the default set of actions operator will perform diff --git a/install/operator/pkg/syndesis/action/backup.go b/install/operator/pkg/syndesis/action/backup.go index 3bb75621e32..d6ff00e1a86 100644 --- a/install/operator/pkg/syndesis/action/backup.go +++ b/install/operator/pkg/syndesis/action/backup.go @@ -49,7 +49,7 @@ func (a *backupAction) CanExecute(syndesis *synapi.Syndesis) bool { } // Schedule a cronjob for systematic backups -func (a *backupAction) Execute(ctx context.Context, syndesis *synapi.Syndesis, operatorNamespace string) error { +func (a *backupAction) Execute(ctx context.Context, syndesis *synapi.Syndesis, operatorNamespace string, productName string) error { entries := c.Entries() if s := syndesis.Spec.Backup.Schedule; s != "" { diff --git a/install/operator/pkg/syndesis/action/checkupdates.go b/install/operator/pkg/syndesis/action/checkupdates.go index 52768d40650..23118abe642 100644 --- a/install/operator/pkg/syndesis/action/checkupdates.go +++ b/install/operator/pkg/syndesis/action/checkupdates.go @@ -32,7 +32,7 @@ func (a checkUpdatesAction) CanExecute(syndesis *synapi.Syndesis) bool { synapi.SyndesisPhaseStartupFailed) } -func (a checkUpdatesAction) Execute(ctx context.Context, syndesis *synapi.Syndesis, operatorNamespace string) error { +func (a checkUpdatesAction) Execute(ctx context.Context, syndesis *synapi.Syndesis, operatorNamespace string, productName string) error { if a.operatorVersion == "" { a.operatorVersion = pkg.DefaultOperatorTag } @@ -41,7 +41,7 @@ func (a checkUpdatesAction) Execute(ctx context.Context, syndesis *synapi.Syndes // Everything fine return nil } else { - return a.setPhaseToUpgrading(ctx, syndesis, operatorNamespace) + return a.setPhaseToUpgrading(ctx, syndesis, operatorNamespace, productName) } } @@ -50,7 +50,7 @@ func (a checkUpdatesAction) Execute(ctx context.Context, syndesis *synapi.Syndes * needed to avoid race conditions where k8s wasn't able to update or * kubernetes didn't change the object yet */ -func (a checkUpdatesAction) setPhaseToUpgrading(ctx context.Context, syndesis *synapi.Syndesis, operatorNamespace string) (err error) { +func (a checkUpdatesAction) setPhaseToUpgrading(ctx context.Context, syndesis *synapi.Syndesis, operatorNamespace string, productName string) (err error) { // Declare an upgradeable Condition as false if applicable state := olm.ConditionState{ @@ -58,7 +58,7 @@ func (a checkUpdatesAction) setPhaseToUpgrading(ctx context.Context, syndesis *s Reason: "Upgrading", Message: "Operator is upgrading the components", } - err = olm.SetUpgradeCondition(ctx, a.clientTools, operatorNamespace, state) + err = olm.SetUpgradeCondition(ctx, a.clientTools, operatorNamespace, productName, state) if err != nil { a.log.Error(err, "Failed to set the upgrade condition on the operator") } diff --git a/install/operator/pkg/syndesis/action/initialize.go b/install/operator/pkg/syndesis/action/initialize.go index 0aaf1655f2e..05e6eb3b85f 100644 --- a/install/operator/pkg/syndesis/action/initialize.go +++ b/install/operator/pkg/syndesis/action/initialize.go @@ -31,7 +31,7 @@ func (a *initializeAction) CanExecute(syndesis *synapi.Syndesis) bool { synapi.SyndesisPhaseNotInstalled) } -func (a *initializeAction) Execute(ctx context.Context, syndesis *synapi.Syndesis, operatorNamespace string) error { +func (a *initializeAction) Execute(ctx context.Context, syndesis *synapi.Syndesis, operatorNamespace string, productName string) error { list := synapi.SyndesisList{} rtClient, _ := a.clientTools.RuntimeClient() err := rtClient.List(ctx, &list, &client.ListOptions{Namespace: syndesis.Namespace}) @@ -54,7 +54,7 @@ func (a *initializeAction) Execute(ctx context.Context, syndesis *synapi.Syndesi Reason: "Initializing", Message: "Operator is installing", } - err = olm.SetUpgradeCondition(ctx, a.clientTools, operatorNamespace, state) + err = olm.SetUpgradeCondition(ctx, a.clientTools, operatorNamespace, productName, state) if err != nil { a.log.Error(err, "Failed to set the upgrade condition on the operator") } diff --git a/install/operator/pkg/syndesis/action/install.go b/install/operator/pkg/syndesis/action/install.go index 9bce0a4cf63..5749cc9c68f 100644 --- a/install/operator/pkg/syndesis/action/install.go +++ b/install/operator/pkg/syndesis/action/install.go @@ -96,7 +96,7 @@ func (a *installAction) CanExecute(syndesis *synapi.Syndesis) bool { var kindsReportedNotAvailable = map[schema.GroupVersionKind]time.Time{} -func (a *installAction) Execute(ctx context.Context, syndesis *synapi.Syndesis, operatorNamespace string) error { +func (a *installAction) Execute(ctx context.Context, syndesis *synapi.Syndesis, operatorNamespace string, productName string) error { if syndesisPhaseIs(syndesis, synapi.SyndesisPhaseInstalling) { a.log.Info("installing Syndesis resource", "name", syndesis.Name) } else if syndesisPhaseIs(syndesis, synapi.SyndesisPhasePostUpgradeRun) { diff --git a/install/operator/pkg/syndesis/action/pod_scheduling.go b/install/operator/pkg/syndesis/action/pod_scheduling.go index 67b6ed81e15..759752550ca 100644 --- a/install/operator/pkg/syndesis/action/pod_scheduling.go +++ b/install/operator/pkg/syndesis/action/pod_scheduling.go @@ -43,7 +43,7 @@ func (a *podSchedulingAction) CanExecute(syndesis *synapi.Syndesis) bool { return canExecute } -func (a *podSchedulingAction) Execute(ctx context.Context, syndesis *synapi.Syndesis, operatorNamespace string) error { +func (a *podSchedulingAction) Execute(ctx context.Context, syndesis *synapi.Syndesis, operatorNamespace string, productName string) error { if a.updateIntegrationScheduling { a.executeIntegrationScheduling(ctx, syndesis) } diff --git a/install/operator/pkg/syndesis/action/startup.go b/install/operator/pkg/syndesis/action/startup.go index 4f8501a4ec3..14b9ef3805b 100644 --- a/install/operator/pkg/syndesis/action/startup.go +++ b/install/operator/pkg/syndesis/action/startup.go @@ -33,7 +33,7 @@ func (a *startupAction) CanExecute(syndesis *synapi.Syndesis) bool { synapi.SyndesisPhaseStartupFailed) } -func (a *startupAction) Execute(ctx context.Context, syndesis *synapi.Syndesis, operatorNamespace string) error { +func (a *startupAction) Execute(ctx context.Context, syndesis *synapi.Syndesis, operatorNamespace string, productName string) error { list := v1.DeploymentConfigList{ TypeMeta: metav1.TypeMeta{ @@ -78,7 +78,7 @@ func (a *startupAction) Execute(ctx context.Context, syndesis *synapi.Syndesis, Reason: "Started", Message: "Operator and components have been successfully started", } - err = olm.SetUpgradeCondition(ctx, a.clientTools, operatorNamespace, state) + err = olm.SetUpgradeCondition(ctx, a.clientTools, operatorNamespace, productName, state) if err != nil { a.log.Error(err, "Failed to set the upgrade condition on the operator") } diff --git a/install/operator/pkg/syndesis/action/upgrade.go b/install/operator/pkg/syndesis/action/upgrade.go index 04db7d62fc7..9c7bc05ef36 100644 --- a/install/operator/pkg/syndesis/action/upgrade.go +++ b/install/operator/pkg/syndesis/action/upgrade.go @@ -42,7 +42,7 @@ func (a *upgradeAction) CanExecute(syndesis *synapi.Syndesis) bool { ) } -func (a *upgradeAction) Execute(ctx context.Context, syndesis *synapi.Syndesis, operatorNamespace string) error { +func (a *upgradeAction) Execute(ctx context.Context, syndesis *synapi.Syndesis, operatorNamespace string, productName string) error { targetVersion := pkg.DefaultOperatorTag if syndesis.Status.Phase == synapi.SyndesisPhaseUpgrading { @@ -76,7 +76,7 @@ func (a *upgradeAction) Execute(ctx context.Context, syndesis *synapi.Syndesis, } else if syndesis.Status.Phase == synapi.SyndesisPhasePostUpgradeRunSucceed { // We land here only if the install phase after upgrading finished correctly a.log.Info("syndesis resource post upgrade ran successfully", "name", syndesis.Name, "previous version", syndesis.Status.Version, "target version", targetVersion) - return a.completeUpgrade(ctx, syndesis, targetVersion, operatorNamespace) + return a.completeUpgrade(ctx, syndesis, targetVersion, operatorNamespace, productName) } else if syndesis.Status.Phase == synapi.SyndesisPhasePostUpgradeRun { // If the first run of the install action failed, we land here. We need to retry // this few times to consider the cases where install action return error due to @@ -104,14 +104,14 @@ func (a *upgradeAction) Execute(ctx context.Context, syndesis *synapi.Syndesis, * needed to avoid race conditions where k8s wasn't yet able to update or * kubernetes didn't change the object yet */ -func (a *upgradeAction) completeUpgrade(ctx context.Context, syndesis *synapi.Syndesis, newVersion string, operatorNamespace string) (err error) { +func (a *upgradeAction) completeUpgrade(ctx context.Context, syndesis *synapi.Syndesis, newVersion string, operatorNamespace string, productName string) (err error) { // Declare the operator upgradeable, if applicable state := olm.ConditionState{ Status: metav1.ConditionTrue, Reason: "CompletedUpgrade", Message: "Operator component state has been upgraded", } - err = olm.SetUpgradeCondition(ctx, a.clientTools, operatorNamespace, state) + err = olm.SetUpgradeCondition(ctx, a.clientTools, operatorNamespace, productName, state) if err != nil { a.log.Error(err, "Failed to set the upgrade condition on the operator") } diff --git a/install/operator/pkg/syndesis/action/upgradebackoff.go b/install/operator/pkg/syndesis/action/upgradebackoff.go index fa9dfb1c37d..53237990ae8 100644 --- a/install/operator/pkg/syndesis/action/upgradebackoff.go +++ b/install/operator/pkg/syndesis/action/upgradebackoff.go @@ -33,7 +33,7 @@ func (a *upgradeBackoffAction) CanExecute(syndesis *synapi.Syndesis) bool { return syndesisPhaseIs(syndesis, synapi.SyndesisPhaseUpgradeFailureBackoff) } -func (a *upgradeBackoffAction) Execute(ctx context.Context, syndesis *synapi.Syndesis, operatorNamespace string) error { +func (a *upgradeBackoffAction) Execute(ctx context.Context, syndesis *synapi.Syndesis, operatorNamespace string, productName string) error { rtClient, _ := a.clientTools.RuntimeClient() // Check number of attempts to fail fast diff --git a/install/operator/pkg/syndesis/olm/csv.go b/install/operator/pkg/syndesis/olm/csv.go index f935c9c6d85..f7aa9215b67 100644 --- a/install/operator/pkg/syndesis/olm/csv.go +++ b/install/operator/pkg/syndesis/olm/csv.go @@ -178,6 +178,7 @@ func (c *csv) setVariables() { c.config.ApiServer.EmbeddedProvider = true c.config.ApiServer.OlmSupport = true c.config.ApiServer.ConsoleLink = true + c.config.ProductName = "fuse-online" // Dependant on whether it is community or productized c.name = "fuse-online-operator" @@ -189,6 +190,7 @@ func (c *csv) setVariables() { c.provider = "Red Hat" if !c.config.Productized { + c.config.ProductName = "syndesis" c.name = "syndesis-operator" c.displayName = "Syndesis" c.support = "Syndesis" @@ -425,6 +427,8 @@ func (c *csv) loadDeploymentFromTemplate() (r interface{}, err error) { ExporterImage string DevSupport bool LogLevel int + Version string + ProductName string }{ Image: c.image, Tag: c.tag, @@ -441,6 +445,8 @@ func (c *csv) loadDeploymentFromTemplate() (r interface{}, err error) { ExporterImage: c.config.Syndesis.Components.Database.Exporter.Image, DevSupport: false, // Never be true in CSV generation - here for template compatibility LogLevel: 0, // Never to be more in CSV generation - here for template compatibility + Version: c.version, + ProductName: c.config.ProductName, } g, err := generator.Render("assets/install/operator_deployment.yml.tmpl", context) diff --git a/install/operator/pkg/syndesis/olm/operator_conditions.go b/install/operator/pkg/syndesis/olm/operator_conditions.go index 50af68e221e..86bc96bc076 100644 --- a/install/operator/pkg/syndesis/olm/operator_conditions.go +++ b/install/operator/pkg/syndesis/olm/operator_conditions.go @@ -26,7 +26,6 @@ import ( 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" @@ -47,7 +46,7 @@ type ConditionState struct { Message string } -func GetConditionName(ctx context.Context, clientTools *clienttools.ClientTools, namespace string) (string, error) { +func GetConditionName(ctx context.Context, clientTools *clienttools.ClientTools, namespace string, productName string) (string, error) { opCondLog.V(synpkg.DEBUG_LOGGING_LVL).Info("Finding OLM Operator Condition") apiSpec, err := capabilities.ApiCapabilities(clientTools) @@ -73,11 +72,7 @@ func GetConditionName(ctx context.Context, clientTools *clienttools.ClientTools, // // 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" + deploymentName := productName + "-operator" opCondLog.V(synpkg.DEBUG_LOGGING_LVL).Info("Finding Operator Deployment", "name", deploymentName) deployment := &appsv1.Deployment{} @@ -104,9 +99,9 @@ func GetConditionName(ctx context.Context, clientTools *clienttools.ClientTools, // // Creates the condition if it does not already exist // -func SetUpgradeCondition(ctx context.Context, clientTools *clienttools.ClientTools, namespace string, state ConditionState) error { +func SetUpgradeCondition(ctx context.Context, clientTools *clienttools.ClientTools, namespace string, productName string, state ConditionState) error { - conditionName, err := GetConditionName(ctx, clientTools, namespace) + conditionName, err := GetConditionName(ctx, clientTools, namespace, productName) if err != nil { return err } else if conditionName == "" { diff --git a/install/operator/pkg/syndesis/olm/operator_conditions_test.go b/install/operator/pkg/syndesis/olm/operator_conditions_test.go index 707c05f4446..2977b3f2e21 100644 --- a/install/operator/pkg/syndesis/olm/operator_conditions_test.go +++ b/install/operator/pkg/syndesis/olm/operator_conditions_test.go @@ -110,7 +110,7 @@ func TestConditions_GetOperationConditionName(t *testing.T) { nsi := coreClient.Namespaces() nsi.Create(context.TODO(), opsNS, metav1.CreateOptions{}) - name, err := GetConditionName(context.TODO(), clientTools, testNS) + name, err := GetConditionName(context.TODO(), clientTools, testNS, confName) assert.NoError(t, err) assert.Equal(t, csvName, name) @@ -165,8 +165,6 @@ func TestConditions_SetOperationCondition(t *testing.T) { Reason: "testing the turn off", } - err = SetUpgradeCondition(context.TODO(), clientTools, testNS, status) + err = SetUpgradeCondition(context.TODO(), clientTools, testNS, confName, status) assert.NoError(t, err) - - // assert.Equal(t, }