From e8f205b4860bb3368dc59ab49a6811aaef5aee2f Mon Sep 17 00:00:00 2001 From: Nikhil Thomas Date: Fri, 4 Feb 2022 18:02:19 +0530 Subject: [PATCH] Improve Operator upgrade mechanism Improve ReadyChecks for Pipelines and Triggers Add mechanism to detect upgrade scenario in reconcilers and update status with relevant messages Minor fixes to ensure TektonAddon reconciler acts more predictably Signed-off-by: Nikhil Thomas --- Makefile | 2 +- pkg/apis/operator/v1alpha1/const.go | 13 ++ pkg/reconciler/common/common.go | 31 +++++ .../initcontroller.go | 19 ++- .../kubernetes/tektondashboard/controller.go | 10 +- .../tektondashboard/tektondashboard.go | 23 ++-- .../kubernetes/tektoninstallerset/const.go | 26 ---- .../kubernetes/tektoninstallerset/install.go | 7 +- .../kubernetes/tektoninstallerset/query.go | 4 +- .../tektoninstallerset/query_test.go | 30 ++--- .../kubernetes/tektonpipeline/controller.go | 7 +- .../tektonpipeline/tektonpipeline.go | 52 ++++++-- .../kubernetes/tektontrigger/controller.go | 7 +- .../kubernetes/tektontrigger/tektontrigger.go | 54 ++++++-- .../openshift/tektonaddon/controller.go | 2 +- .../openshift/tektonaddon/extension.go | 9 +- .../openshift/tektonaddon/tektonaddon.go | 117 ++++++++++++------ .../openshift/tektonconfig/common.go | 7 +- .../openshift/tektonconfig/extension/addon.go | 7 ++ pkg/reconciler/openshift/tektonconfig/rbac.go | 3 +- .../openshift/tektonpipeline/extension.go | 9 +- .../openshift/tektonpipeline/installerset.go | 15 ++- .../shared/tektonconfig/controller.go | 9 ++ .../shared/tektonconfig/pipeline/pipeline.go | 7 ++ .../shared/tektonconfig/tektonconfig.go | 72 +++++++++-- .../shared/tektonconfig/trigger/trigger.go | 7 ++ test/e2e-common.sh | 16 +++ test/e2e-tests.sh | 3 +- .../e2e/common/tektonconfigdeployment_test.go | 3 +- test/resources/tektonaddons.go | 7 +- 30 files changed, 396 insertions(+), 182 deletions(-) rename pkg/reconciler/{kubernetes/initcontroller => common}/initcontroller.go (85%) delete mode 100644 pkg/reconciler/kubernetes/tektoninstallerset/const.go diff --git a/Makefile b/Makefile index f024572476..96f4e0e874 100644 --- a/Makefile +++ b/Makefile @@ -111,7 +111,7 @@ clean-cr: | ; $(info $(M) clean CRs on $(TARGET)) @ ## Clean the CRs to the curr resolve: | $(KO) $(KUSTOMIZE) get-releases ; $(info $(M) ko resolve on $(TARGET)) @ ## Resolve config to the current cluster @ ## --load-restrictor LoadRestrictionsNone is needed in kustomize build as files which not in child tree of kustomize base are pulled @ ## https://github.com/kubernetes-sigs/kustomize/issues/766 - $Q $(KUSTOMIZE) build --load-restrictor LoadRestrictionsNone config/$(TARGET) | $(KO) resolve --push=false --oci-layout-path=$(BIN)/oci -f - + $Q $(KUSTOMIZE) build --load-restrictor LoadRestrictionsNone config/$(TARGET)/overlays/default | $(KO) resolve --push=false --oci-layout-path=$(BIN)/oci -f - .PHONY: generated generated: | vendor ; $(info $(M) update generated files) ## Update generated files diff --git a/pkg/apis/operator/v1alpha1/const.go b/pkg/apis/operator/v1alpha1/const.go index a5c5933b9d..ad3ff59943 100644 --- a/pkg/apis/operator/v1alpha1/const.go +++ b/pkg/apis/operator/v1alpha1/const.go @@ -36,6 +36,15 @@ const ( ApiFieldAlpha = "alpha" ApiFieldStable = "stable" + + LastAppliedHashKey = "operator.tekton.dev/last-applied-hash" + CreatedByKey = "operator.tekton.dev/created-by" + ReleaseVersionKey = "operator.tekton.dev/release-version" + ReleaseMinorVersionKey = "operator.tekton.dev/release-minor-version" + TargetNamespaceKey = "operator.tekton.dev/target-namespace" + InstallerSetType = "operator.tekton.dev/type" + + UpgradePending = "upgrade pending" ) var ( @@ -44,6 +53,10 @@ var ( // that we proceed ahead with updated object RECONCILE_AGAIN_ERR = fmt.Errorf("reconcile again and proceed") + // DEPENDENCY_UPGRADE_PENDING_ERR + // When a reconciler cannot proceed due to an upgrade in progress of a dependency + DEPENDENCY_UPGRADE_PENDING_ERR = fmt.Errorf("dependency upgrade pending") + // VERSION_ENV_NOT_SET_ERR Error when VERSION environment variable is not set VERSION_ENV_NOT_SET_ERR = fmt.Errorf("version environment variable %s is not set or empty", VersionEnvKey) ) diff --git a/pkg/reconciler/common/common.go b/pkg/reconciler/common/common.go index 91ac2d5f0b..60a8a1a369 100644 --- a/pkg/reconciler/common/common.go +++ b/pkg/reconciler/common/common.go @@ -17,6 +17,7 @@ limitations under the License. package common import ( + "context" "fmt" "time" @@ -48,6 +49,13 @@ func PipelineReady(informer informer.TektonPipelineInformer) (*v1alpha1.TektonPi } return nil, err } + upgradePending, err := CheckUpgradePending(ppln) + if err != nil { + return nil, err + } + if upgradePending { + return nil, v1alpha1.DEPENDENCY_UPGRADE_PENDING_ERR + } if !ppln.Status.IsReady() { return nil, fmt.Errorf(PipelineNotReady) } @@ -67,6 +75,13 @@ func TriggerReady(informer informer.TektonTriggerInformer) (*v1alpha1.TektonTrig } return nil, err } + upgradePending, err := CheckUpgradePending(trigger) + if err != nil { + return nil, err + } + if upgradePending { + return nil, v1alpha1.DEPENDENCY_UPGRADE_PENDING_ERR + } if !trigger.Status.IsReady() { return nil, fmt.Errorf(TriggerNotReady) } @@ -77,3 +92,19 @@ func getTriggerRes(informer informer.TektonTriggerInformer) (*v1alpha1.TektonTri res, err := informer.Lister().Get(v1alpha1.TriggerResourceName) return res, err } + +func CheckUpgradePending(tc v1alpha1.TektonComponent) (bool, error) { + labels := tc.GetLabels() + ver, ok := labels[v1alpha1.ReleaseVersionKey] + if !ok { + return true, nil + } + operatorVersion, err := OperatorVersion(context.TODO()) + if err != nil { + return false, err + } + if ver != operatorVersion { + return true, nil + } + return false, nil +} diff --git a/pkg/reconciler/kubernetes/initcontroller/initcontroller.go b/pkg/reconciler/common/initcontroller.go similarity index 85% rename from pkg/reconciler/kubernetes/initcontroller/initcontroller.go rename to pkg/reconciler/common/initcontroller.go index 0994dedddf..7eb8217c8c 100644 --- a/pkg/reconciler/kubernetes/initcontroller/initcontroller.go +++ b/pkg/reconciler/common/initcontroller.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package initcontroller +package common import ( "context" @@ -26,7 +26,6 @@ import ( mfc "github.com/manifestival/client-go-client" mf "github.com/manifestival/manifestival" "github.com/tektoncd/operator/pkg/apis/operator/v1alpha1" - "github.com/tektoncd/operator/pkg/reconciler/common" "go.uber.org/zap" "knative.dev/pkg/injection" "knative.dev/pkg/logging" @@ -72,9 +71,9 @@ func (ctrl Controller) InitController(ctx context.Context, opts PayloadOptions) var releaseVersion string // Read the release version of component - releaseVersion, err = common.FetchVersionFromConfigMap(manifest, ctrl.VersionConfigMap) + releaseVersion, err = FetchVersionFromConfigMap(manifest, ctrl.VersionConfigMap) if err != nil { - if common.IsFetchVersionError(err) { + if IsFetchVersionError(err) { ctrl.Logger.Warnf("failed to read version information from ConfigMap %s", ctrl.VersionConfigMap, err) releaseVersion = "Unknown" } else { @@ -91,29 +90,29 @@ func (ctrl Controller) fetchSourceManifests(ctx context.Context, opts PayloadOpt switch { case strings.Contains(ctrl.VersionConfigMap, "pipeline"): var pipeline *v1alpha1.TektonPipeline - if err := common.AppendTarget(ctx, ctrl.Manifest, pipeline); err != nil { + if err := AppendTarget(ctx, ctrl.Manifest, pipeline); err != nil { return err } // add proxy configs to pipeline if any return addProxy(ctrl.Manifest) case strings.Contains(ctrl.VersionConfigMap, "triggers"): var trigger *v1alpha1.TektonTrigger - return common.AppendTarget(ctx, ctrl.Manifest, trigger) + return AppendTarget(ctx, ctrl.Manifest, trigger) case strings.Contains(ctrl.VersionConfigMap, "dashboard") && opts.ReadOnly: var dashboard v1alpha1.TektonDashboard dashboard.Spec.Readonly = true - return common.AppendTarget(ctx, ctrl.Manifest, &dashboard) + return AppendTarget(ctx, ctrl.Manifest, &dashboard) case strings.Contains(ctrl.VersionConfigMap, "dashboard") && !opts.ReadOnly: var dashboard v1alpha1.TektonDashboard dashboard.Spec.Readonly = false - return common.AppendTarget(ctx, ctrl.Manifest, &dashboard) + return AppendTarget(ctx, ctrl.Manifest, &dashboard) } return nil } func addProxy(manifest *mf.Manifest) error { - koDataDir := os.Getenv(common.KoEnvKey) + koDataDir := os.Getenv(KoEnvKey) proxyLocation := filepath.Join(koDataDir, "webhook") - return common.AppendManifest(manifest, proxyLocation) + return AppendManifest(manifest, proxyLocation) } diff --git a/pkg/reconciler/kubernetes/tektondashboard/controller.go b/pkg/reconciler/kubernetes/tektondashboard/controller.go index d07bfdc9ac..27e6fb17b9 100644 --- a/pkg/reconciler/kubernetes/tektondashboard/controller.go +++ b/pkg/reconciler/kubernetes/tektondashboard/controller.go @@ -19,8 +19,6 @@ package tektondashboard import ( "context" - "github.com/tektoncd/operator/pkg/reconciler/kubernetes/initcontroller" - "github.com/tektoncd/operator/pkg/apis/operator/v1alpha1" operatorclient "github.com/tektoncd/operator/pkg/client/injection/client" tektonDashboardinformer "github.com/tektoncd/operator/pkg/client/injection/informers/operator/v1alpha1/tektondashboard" @@ -52,16 +50,16 @@ func NewExtendedController(generator common.ExtensionGenerator) injection.Contro kubeClient := kubeclient.Get(ctx) logger := logging.FromContext(ctx) - ctrl := initcontroller.Controller{ + ctrl := common.Controller{ Logger: logger, VersionConfigMap: versionConfigMap, } - readonlyManifest, dashboardVer := ctrl.InitController(ctx, initcontroller.PayloadOptions{ReadOnly: true}) + readonlyManifest, dashboardVer := ctrl.InitController(ctx, common.PayloadOptions{ReadOnly: true}) - fullaccessManifest, _ := ctrl.InitController(ctx, initcontroller.PayloadOptions{ReadOnly: false}) + fullaccessManifest, _ := ctrl.InitController(ctx, common.PayloadOptions{ReadOnly: false}) - operatorVer, err := initcontroller.OperatorVersion(ctx) + operatorVer, err := common.OperatorVersion(ctx) if err != nil { logger.Fatal(err) } diff --git a/pkg/reconciler/kubernetes/tektondashboard/tektondashboard.go b/pkg/reconciler/kubernetes/tektondashboard/tektondashboard.go index f2f84a681f..8ddc8e023e 100644 --- a/pkg/reconciler/kubernetes/tektondashboard/tektondashboard.go +++ b/pkg/reconciler/kubernetes/tektondashboard/tektondashboard.go @@ -27,7 +27,6 @@ import ( pipelineinformer "github.com/tektoncd/operator/pkg/client/informers/externalversions/operator/v1alpha1" tektondashboardreconciler "github.com/tektoncd/operator/pkg/client/injection/reconciler/operator/v1alpha1/tektondashboard" "github.com/tektoncd/operator/pkg/reconciler/common" - "github.com/tektoncd/operator/pkg/reconciler/kubernetes/tektoninstallerset" "github.com/tektoncd/operator/pkg/reconciler/shared/hash" corev1 "k8s.io/api/core/v1" apierrors "k8s.io/apimachinery/pkg/api/errors" @@ -89,7 +88,7 @@ func (r *Reconciler) FinalizeKind(ctx context.Context, original *v1alpha1.Tekton ls := metav1.LabelSelector{ MatchLabels: map[string]string{ - tektoninstallerset.CreatedByKey: createdByValue, + v1alpha1.CreatedByKey: createdByValue, }, } labelSelector, err := common.LabelSelector(ls) @@ -135,7 +134,9 @@ func (r *Reconciler) ReconcileKind(ctx context.Context, td *v1alpha1.TektonDashb if err.Error() == common.PipelineNotReady { td.Status.MarkDependencyInstalling("tekton-pipelines is still installing") // wait for pipeline status to change - return fmt.Errorf(common.PipelineNotReady) + r.enqueueAfter(td, 10*time.Second) + return nil + } // (tektonpipeline.opeator.tekton.dev instance not available yet) td.Status.MarkDependencyMissing("tekton-pipelines does not exist") @@ -179,8 +180,8 @@ func (r *Reconciler) ReconcileKind(ctx context.Context, td *v1alpha1.TektonDashb return err } - installerSetTargetNamespace := installedTIS.Annotations[tektoninstallerset.TargetNamespaceKey] - installerSetReleaseVersion := installedTIS.Annotations[tektoninstallerset.ReleaseVersionKey] + installerSetTargetNamespace := installedTIS.Annotations[v1alpha1.TargetNamespaceKey] + installerSetReleaseVersion := installedTIS.Annotations[v1alpha1.ReleaseVersionKey] // Check if TargetNamespace of existing TektonInstallerSet is same as expected // Check if Release Version in TektonInstallerSet is same as expected @@ -223,7 +224,7 @@ func (r *Reconciler) ReconcileKind(ctx context.Context, td *v1alpha1.TektonDashb } // spec hash stored on installerSet - lastAppliedHash := installedTIS.GetAnnotations()[tektoninstallerset.LastAppliedHashKey] + lastAppliedHash := installedTIS.GetAnnotations()[v1alpha1.LastAppliedHashKey] if lastAppliedHash != expectedSpecHash { @@ -241,7 +242,7 @@ func (r *Reconciler) ReconcileKind(ctx context.Context, td *v1alpha1.TektonDashb // Update the spec hash current := installedTIS.GetAnnotations() - current[tektoninstallerset.LastAppliedHashKey] = expectedSpecHash + current[v1alpha1.LastAppliedHashKey] = expectedSpecHash installedTIS.SetAnnotations(current) // Update the manifests @@ -358,12 +359,12 @@ func makeInstallerSet(td *v1alpha1.TektonDashboard, manifest mf.Manifest, tdSpec ObjectMeta: metav1.ObjectMeta{ GenerateName: fmt.Sprintf("%s-", v1alpha1.DashboardResourceName), Labels: map[string]string{ - tektoninstallerset.CreatedByKey: createdByValue, + v1alpha1.CreatedByKey: createdByValue, }, Annotations: map[string]string{ - tektoninstallerset.ReleaseVersionKey: releaseVersion, - tektoninstallerset.TargetNamespaceKey: td.Spec.TargetNamespace, - tektoninstallerset.LastAppliedHashKey: tdSpecHash, + v1alpha1.ReleaseVersionKey: releaseVersion, + v1alpha1.TargetNamespaceKey: td.Spec.TargetNamespace, + v1alpha1.LastAppliedHashKey: tdSpecHash, }, OwnerReferences: []metav1.OwnerReference{ownerRef}, }, diff --git a/pkg/reconciler/kubernetes/tektoninstallerset/const.go b/pkg/reconciler/kubernetes/tektoninstallerset/const.go deleted file mode 100644 index 2bf1124691..0000000000 --- a/pkg/reconciler/kubernetes/tektoninstallerset/const.go +++ /dev/null @@ -1,26 +0,0 @@ -/* -Copyright 2021 The Tekton Authors - -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 tektoninstallerset - -const ( - LastAppliedHashKey = "operator.tekton.dev/last-applied-hash" - CreatedByKey = "operator.tekton.dev/created-by" - ReleaseVersionKey = "operator.tekton.dev/release-version" - ReleaseMinorVersionKey = "operator.tekton.dev/release-minor-version" - TargetNamespaceKey = "operator.tekton.dev/target-namespace" - InstallerSetType = "operator.tekton.dev/type" -) diff --git a/pkg/reconciler/kubernetes/tektoninstallerset/install.go b/pkg/reconciler/kubernetes/tektoninstallerset/install.go index 4d1c4b21d8..fec796a29d 100644 --- a/pkg/reconciler/kubernetes/tektoninstallerset/install.go +++ b/pkg/reconciler/kubernetes/tektoninstallerset/install.go @@ -21,6 +21,7 @@ import ( "strings" mf "github.com/manifestival/manifestival" + "github.com/tektoncd/operator/pkg/apis/operator/v1alpha1" "github.com/tektoncd/operator/pkg/reconciler/shared/hash" appsv1 "k8s.io/api/apps/v1" corev1 "k8s.io/api/core/v1" @@ -156,7 +157,7 @@ func (i *installer) createDeployment(expected *unstructured.Unstructured) error if len(dep.Annotations) == 0 { dep.Annotations = map[string]string{} } - dep.Annotations[LastAppliedHashKey] = hash + dep.Annotations[v1alpha1.LastAppliedHashKey] = hash unstrObj, err := runtime.DefaultUnstructuredConverter.ToUnstructured(dep) if err != nil { @@ -185,7 +186,7 @@ func (i *installer) updateDeployment(existing *unstructured.Unstructured, existi existingDeployment.Annotations = map[string]string{} } - existingDeployment.Annotations[LastAppliedHashKey] = newHash + existingDeployment.Annotations[v1alpha1.LastAppliedHashKey] = newHash unstrObj, err := runtime.DefaultUnstructuredConverter.ToUnstructured(existingDeployment) if err != nil { @@ -228,7 +229,7 @@ func (i *installer) ensureDeployment(expected *unstructured.Unstructured) error return fmt.Errorf("failed to compute hash of existing deployment: %v", err) } - hashFromAnnotation, hashExist := existingDeployment.Annotations[LastAppliedHashKey] + hashFromAnnotation, hashExist := existingDeployment.Annotations[v1alpha1.LastAppliedHashKey] // if hash doesn't exist then update the deployment with hash if !hashExist { diff --git a/pkg/reconciler/kubernetes/tektoninstallerset/query.go b/pkg/reconciler/kubernetes/tektoninstallerset/query.go index 3476d19f34..b3d49b2dc0 100644 --- a/pkg/reconciler/kubernetes/tektoninstallerset/query.go +++ b/pkg/reconciler/kubernetes/tektoninstallerset/query.go @@ -64,7 +64,7 @@ func CurrentInstallerSetName(ctx context.Context, client clientset.Interface, la func CleanUpObsoleteResources(ctx context.Context, client clientset.Interface, createdBy string) error { labelSelector := labels.NewSelector() - createdReq, _ := labels.NewRequirement(CreatedByKey, selection.Equals, []string{createdBy}) + createdReq, _ := labels.NewRequirement(v1alpha1.CreatedByKey, selection.Equals, []string{createdBy}) if createdReq != nil { labelSelector = labelSelector.Add(*createdReq) } @@ -81,7 +81,7 @@ func CleanUpObsoleteResources(ctx context.Context, client clientset.Interface, c for _, i := range list.Items { // check if installerSet has InstallerSetType label // if it doesn't exist then delete it - if _, ok := i.Labels[InstallerSetType]; !ok { + if _, ok := i.Labels[v1alpha1.InstallerSetType]; !ok { err := client.OperatorV1alpha1().TektonInstallerSets().Delete(ctx, i.Name, v1.DeleteOptions{}) if err != nil { return err diff --git a/pkg/reconciler/kubernetes/tektoninstallerset/query_test.go b/pkg/reconciler/kubernetes/tektoninstallerset/query_test.go index c577b90211..00e4d84153 100644 --- a/pkg/reconciler/kubernetes/tektoninstallerset/query_test.go +++ b/pkg/reconciler/kubernetes/tektoninstallerset/query_test.go @@ -30,14 +30,14 @@ import ( var ( pipelineLS = metav1.LabelSelector{ MatchLabels: map[string]string{ - CreatedByKey: "TektonPipeline", - InstallerSetType: "pipeline", + v1alpha1.CreatedByKey: "TektonPipeline", + v1alpha1.InstallerSetType: "pipeline", }, } triggersLS = metav1.LabelSelector{ MatchLabels: map[string]string{ - CreatedByKey: "TektonTriggers", - InstallerSetType: "triggers", + v1alpha1.CreatedByKey: "TektonTriggers", + v1alpha1.InstallerSetType: "triggers", }, } ) @@ -51,8 +51,8 @@ func TestCurrentInstallerSetName(t *testing.T) { ObjectMeta: metav1.ObjectMeta{ Name: "pipeline", Labels: map[string]string{ - CreatedByKey: "TektonPipeline", - InstallerSetType: "pipeline", + v1alpha1.CreatedByKey: "TektonPipeline", + v1alpha1.InstallerSetType: "pipeline", }, }, }, @@ -78,8 +78,8 @@ func TestCurrentInstallerSetNameNoMatching(t *testing.T) { ObjectMeta: metav1.ObjectMeta{ Name: "pipeline", Labels: map[string]string{ - CreatedByKey: "TektonPipeline", - InstallerSetType: "pipeline", + v1alpha1.CreatedByKey: "TektonPipeline", + v1alpha1.InstallerSetType: "pipeline", }, }, }, @@ -105,8 +105,8 @@ func TestCurrentInstallerSetNameWithDuplicates(t *testing.T) { ObjectMeta: metav1.ObjectMeta{ Name: "pipeline-1", Labels: map[string]string{ - CreatedByKey: "TektonPipeline", - InstallerSetType: "pipeline", + v1alpha1.CreatedByKey: "TektonPipeline", + v1alpha1.InstallerSetType: "pipeline", }, }, }, @@ -114,8 +114,8 @@ func TestCurrentInstallerSetNameWithDuplicates(t *testing.T) { ObjectMeta: metav1.ObjectMeta{ Name: "pipeline-2", Labels: map[string]string{ - CreatedByKey: "TektonPipeline", - InstallerSetType: "pipeline", + v1alpha1.CreatedByKey: "TektonPipeline", + v1alpha1.InstallerSetType: "pipeline", }, }, }, @@ -140,7 +140,7 @@ func TestCleanUpObsoleteResources(t *testing.T) { ObjectMeta: metav1.ObjectMeta{ Name: "pipeline-1", Labels: map[string]string{ - CreatedByKey: "Abc", + v1alpha1.CreatedByKey: "Abc", }, }, }, @@ -148,8 +148,8 @@ func TestCleanUpObsoleteResources(t *testing.T) { ObjectMeta: metav1.ObjectMeta{ Name: "pipeline-2", Labels: map[string]string{ - CreatedByKey: "Abc", - InstallerSetType: "pipeline", + v1alpha1.CreatedByKey: "Abc", + v1alpha1.InstallerSetType: "pipeline", }, }, }, diff --git a/pkg/reconciler/kubernetes/tektonpipeline/controller.go b/pkg/reconciler/kubernetes/tektonpipeline/controller.go index cef532678c..894b31b5fc 100644 --- a/pkg/reconciler/kubernetes/tektonpipeline/controller.go +++ b/pkg/reconciler/kubernetes/tektonpipeline/controller.go @@ -25,7 +25,6 @@ import ( tektonPipelineInformer "github.com/tektoncd/operator/pkg/client/injection/informers/operator/v1alpha1/tektonpipeline" tektonPipelineReconciler "github.com/tektoncd/operator/pkg/client/injection/reconciler/operator/v1alpha1/tektonpipeline" "github.com/tektoncd/operator/pkg/reconciler/common" - "github.com/tektoncd/operator/pkg/reconciler/kubernetes/initcontroller" "k8s.io/client-go/tools/cache" kubeclient "knative.dev/pkg/client/injection/kube/client" "knative.dev/pkg/configmap" @@ -47,19 +46,19 @@ func NewExtendedController(generator common.ExtensionGenerator) injection.Contro return func(ctx context.Context, cmw configmap.Watcher) *controller.Impl { logger := logging.FromContext(ctx) - ctrl := initcontroller.Controller{ + ctrl := common.Controller{ Logger: logger, VersionConfigMap: versionConfigMap, } - manifest, pipelineVer := ctrl.InitController(ctx, initcontroller.PayloadOptions{}) + manifest, pipelineVer := ctrl.InitController(ctx, common.PayloadOptions{}) metrics, err := NewRecorder() if err != nil { logger.Errorf("Failed to create pipeline metrics recorder %v", err) } - operatorVer, err := initcontroller.OperatorVersion(ctx) + operatorVer, err := common.OperatorVersion(ctx) if err != nil { logger.Fatal(err) } diff --git a/pkg/reconciler/kubernetes/tektonpipeline/tektonpipeline.go b/pkg/reconciler/kubernetes/tektonpipeline/tektonpipeline.go index 900d804318..92192fa9fc 100644 --- a/pkg/reconciler/kubernetes/tektonpipeline/tektonpipeline.go +++ b/pkg/reconciler/kubernetes/tektonpipeline/tektonpipeline.go @@ -71,8 +71,8 @@ type Reconciler struct { var ( ls = metav1.LabelSelector{ MatchLabels: map[string]string{ - tektoninstallerset.CreatedByKey: createdByValue, - tektoninstallerset.InstallerSetType: v1alpha1.PipelineResourceName, + v1alpha1.CreatedByKey: createdByValue, + v1alpha1.InstallerSetType: v1alpha1.PipelineResourceName, }, } ) @@ -131,6 +131,11 @@ func (r *Reconciler) ReconcileKind(ctx context.Context, tp *v1alpha1.TektonPipel // Pass the object through defaulting tp.SetDefaults(ctx) + // Mark TektonPipeline Instance as Not Ready if an upgrade is needed + if err := r.markUpgrade(ctx, tp); err != nil { + return err + } + if err := tektoninstallerset.CleanUpObsoleteResources(ctx, r.operatorClientSet, createdByValue); err != nil { return err } @@ -186,8 +191,8 @@ func (r *Reconciler) ReconcileKind(ctx context.Context, tp *v1alpha1.TektonPipel return err } - installerSetTargetNamespace := installedTIS.Annotations[tektoninstallerset.TargetNamespaceKey] - installerSetReleaseVersion := installedTIS.Labels[tektoninstallerset.ReleaseVersionKey] + installerSetTargetNamespace := installedTIS.Annotations[v1alpha1.TargetNamespaceKey] + installerSetReleaseVersion := installedTIS.Labels[v1alpha1.ReleaseVersionKey] // Check if TargetNamespace of existing TektonInstallerSet is same as expected // Check if Release Version in TektonInstallerSet is same as expected @@ -229,7 +234,7 @@ func (r *Reconciler) ReconcileKind(ctx context.Context, tp *v1alpha1.TektonPipel } // spec hash stored on installerSet - lastAppliedHash := installedTIS.GetAnnotations()[tektoninstallerset.LastAppliedHashKey] + lastAppliedHash := installedTIS.GetAnnotations()[v1alpha1.LastAppliedHashKey] if lastAppliedHash != expectedSpecHash { manifest := r.manifest @@ -240,7 +245,7 @@ func (r *Reconciler) ReconcileKind(ctx context.Context, tp *v1alpha1.TektonPipel // Update the spec hash current := installedTIS.GetAnnotations() - current[tektoninstallerset.LastAppliedHashKey] = expectedSpecHash + current[v1alpha1.LastAppliedHashKey] = expectedSpecHash installedTIS.SetAnnotations(current) // Update the manifests @@ -352,13 +357,13 @@ func (r *Reconciler) makeInstallerSet(tp *v1alpha1.TektonPipeline, manifest mf.M ObjectMeta: metav1.ObjectMeta{ GenerateName: fmt.Sprintf("%s-", v1alpha1.PipelineResourceName), Labels: map[string]string{ - tektoninstallerset.CreatedByKey: createdByValue, - tektoninstallerset.InstallerSetType: v1alpha1.PipelineResourceName, - tektoninstallerset.ReleaseVersionKey: r.operatorVersion, + v1alpha1.CreatedByKey: createdByValue, + v1alpha1.InstallerSetType: v1alpha1.PipelineResourceName, + v1alpha1.ReleaseVersionKey: r.operatorVersion, }, Annotations: map[string]string{ - tektoninstallerset.TargetNamespaceKey: tp.Spec.TargetNamespace, - tektoninstallerset.LastAppliedHashKey: tpSpecHash, + v1alpha1.TargetNamespaceKey: tp.Spec.TargetNamespace, + v1alpha1.LastAppliedHashKey: tpSpecHash, }, OwnerReferences: []metav1.OwnerReference{ownerRef}, }, @@ -411,3 +416,28 @@ func (m *Recorder) logMetrics(status, version string, logger *zap.SugaredLogger) logger.Warnf("Failed to log the metrics : %v", err) } } + +func (r *Reconciler) markUpgrade(ctx context.Context, tp *v1alpha1.TektonPipeline) error { + labels := tp.GetLabels() + ver, ok := labels[v1alpha1.ReleaseVersionKey] + if ok && ver == r.operatorVersion { + return nil + } + if ok && ver != r.operatorVersion { + tp.Status.MarkInstallerSetNotReady(v1alpha1.UpgradePending) + tp.Status.MarkPreReconcilerFailed(v1alpha1.UpgradePending) + tp.Status.MarkPostReconcilerFailed(v1alpha1.UpgradePending) + tp.Status.MarkNotReady(v1alpha1.UpgradePending) + } + if labels == nil { + labels = map[string]string{} + } + labels[v1alpha1.ReleaseVersionKey] = r.operatorVersion + tp.SetLabels(labels) + + if _, err := r.operatorClientSet.OperatorV1alpha1().TektonPipelines().Update(ctx, + tp, v1.UpdateOptions{}); err != nil { + return err + } + return v1alpha1.RECONCILE_AGAIN_ERR +} diff --git a/pkg/reconciler/kubernetes/tektontrigger/controller.go b/pkg/reconciler/kubernetes/tektontrigger/controller.go index 71f3845dd5..a8cf3c025d 100644 --- a/pkg/reconciler/kubernetes/tektontrigger/controller.go +++ b/pkg/reconciler/kubernetes/tektontrigger/controller.go @@ -19,7 +19,6 @@ package tektontrigger import ( "context" - "github.com/tektoncd/operator/pkg/reconciler/kubernetes/initcontroller" kubeclient "knative.dev/pkg/client/injection/kube/client" tektonInstallerinformer "github.com/tektoncd/operator/pkg/client/injection/informers/operator/v1alpha1/tektoninstallerset" @@ -50,19 +49,19 @@ func NewExtendedController(generator common.ExtensionGenerator) injection.Contro return func(ctx context.Context, cmw configmap.Watcher) *controller.Impl { logger := logging.FromContext(ctx) - ctrl := initcontroller.Controller{ + ctrl := common.Controller{ Logger: logger, VersionConfigMap: versionConfigMap, } - manifest, triggersVer := ctrl.InitController(ctx, initcontroller.PayloadOptions{}) + manifest, triggersVer := ctrl.InitController(ctx, common.PayloadOptions{}) metrics, err := NewRecorder() if err != nil { logger.Errorf("Failed to create trigger metrics recorder %v", err) } - operatorVer, err := initcontroller.OperatorVersion(ctx) + operatorVer, err := common.OperatorVersion(ctx) if err != nil { logger.Fatal(err) } diff --git a/pkg/reconciler/kubernetes/tektontrigger/tektontrigger.go b/pkg/reconciler/kubernetes/tektontrigger/tektontrigger.go index ef05ca8062..897f15711a 100644 --- a/pkg/reconciler/kubernetes/tektontrigger/tektontrigger.go +++ b/pkg/reconciler/kubernetes/tektontrigger/tektontrigger.go @@ -73,8 +73,8 @@ type Reconciler struct { var ( ls = metav1.LabelSelector{ MatchLabels: map[string]string{ - tektoninstallerset.CreatedByKey: createdByValue, - tektoninstallerset.InstallerSetType: v1alpha1.TriggerResourceName, + v1alpha1.CreatedByKey: createdByValue, + v1alpha1.InstallerSetType: v1alpha1.TriggerResourceName, }, } ) @@ -136,7 +136,8 @@ func (r *Reconciler) ReconcileKind(ctx context.Context, tt *v1alpha1.TektonTrigg if err.Error() == common.PipelineNotReady { tt.Status.MarkDependencyInstalling("tekton-pipelines is still installing") // wait for pipeline status to change - return fmt.Errorf(common.PipelineNotReady) + r.enqueueAfter(tt, 10*time.Second) + return nil } // (tektonpipeline.operator.tekton.dev instance not available yet) tt.Status.MarkDependencyMissing("tekton-pipelines does not exist") @@ -146,6 +147,10 @@ func (r *Reconciler) ReconcileKind(ctx context.Context, tt *v1alpha1.TektonTrigg // Pass the object through defaulting tt.SetDefaults(ctx) + // Mark TektonTrigger Instance as Not Ready if an upgrade is needed + if err := r.markUpgrade(ctx, tt); err != nil { + return err + } if err := tektoninstallerset.CleanUpObsoleteResources(ctx, r.operatorClientSet, createdByValue); err != nil { return err @@ -199,8 +204,8 @@ func (r *Reconciler) ReconcileKind(ctx context.Context, tt *v1alpha1.TektonTrigg return err } - installerSetTargetNamespace := installedTIS.Annotations[tektoninstallerset.TargetNamespaceKey] - installerSetReleaseVersion := installedTIS.Labels[tektoninstallerset.ReleaseVersionKey] + installerSetTargetNamespace := installedTIS.Annotations[v1alpha1.TargetNamespaceKey] + installerSetReleaseVersion := installedTIS.Labels[v1alpha1.ReleaseVersionKey] // Check if TargetNamespace of existing TektonInstallerSet is same as expected // Check if Release Version in TektonInstallerSet is same as expected @@ -244,7 +249,7 @@ func (r *Reconciler) ReconcileKind(ctx context.Context, tt *v1alpha1.TektonTrigg } // spec hash stored on installerSet - lastAppliedHash := installedTIS.GetAnnotations()[tektoninstallerset.LastAppliedHashKey] + lastAppliedHash := installedTIS.GetAnnotations()[v1alpha1.LastAppliedHashKey] if lastAppliedHash != expectedSpecHash { @@ -256,7 +261,7 @@ func (r *Reconciler) ReconcileKind(ctx context.Context, tt *v1alpha1.TektonTrigg // Update the spec hash current := installedTIS.GetAnnotations() - current[tektoninstallerset.LastAppliedHashKey] = expectedSpecHash + current[v1alpha1.LastAppliedHashKey] = expectedSpecHash installedTIS.SetAnnotations(current) // Update the manifests @@ -387,13 +392,13 @@ func makeInstallerSet(tt *v1alpha1.TektonTrigger, manifest mf.Manifest, ttSpecHa ObjectMeta: metav1.ObjectMeta{ GenerateName: fmt.Sprintf("%s-", v1alpha1.TriggerResourceName), Labels: map[string]string{ - tektoninstallerset.CreatedByKey: createdByValue, - tektoninstallerset.ReleaseVersionKey: releaseVersion, - tektoninstallerset.InstallerSetType: v1alpha1.TriggerResourceName, + v1alpha1.CreatedByKey: createdByValue, + v1alpha1.ReleaseVersionKey: releaseVersion, + v1alpha1.InstallerSetType: v1alpha1.TriggerResourceName, }, Annotations: map[string]string{ - tektoninstallerset.TargetNamespaceKey: tt.Spec.TargetNamespace, - tektoninstallerset.LastAppliedHashKey: ttSpecHash, + v1alpha1.TargetNamespaceKey: tt.Spec.TargetNamespace, + v1alpha1.LastAppliedHashKey: ttSpecHash, }, OwnerReferences: []metav1.OwnerReference{ownerRef}, }, @@ -409,3 +414,28 @@ func (m *Recorder) logMetrics(status, version string, logger *zap.SugaredLogger) logger.Warnf("Failed to log the metrics : %v", err) } } + +func (r *Reconciler) markUpgrade(ctx context.Context, tt *v1alpha1.TektonTrigger) error { + labels := tt.GetLabels() + ver, ok := labels[v1alpha1.ReleaseVersionKey] + if ok && ver == r.operatorVersion { + return nil + } + if ok && ver != r.operatorVersion { + tt.Status.MarkInstallerSetNotReady(v1alpha1.UpgradePending) + tt.Status.MarkPreReconcilerFailed(v1alpha1.UpgradePending) + tt.Status.MarkPostReconcilerFailed(v1alpha1.UpgradePending) + tt.Status.MarkNotReady(v1alpha1.UpgradePending) + } + if labels == nil { + labels = map[string]string{} + } + labels[v1alpha1.ReleaseVersionKey] = r.operatorVersion + tt.SetLabels(labels) + + if _, err := r.operatorClientSet.OperatorV1alpha1().TektonTriggers().Update(ctx, + tt, v1.UpdateOptions{}); err != nil { + return err + } + return v1alpha1.RECONCILE_AGAIN_ERR +} diff --git a/pkg/reconciler/openshift/tektonaddon/controller.go b/pkg/reconciler/openshift/tektonaddon/controller.go index 26794dfc82..8744d4a9a4 100644 --- a/pkg/reconciler/openshift/tektonaddon/controller.go +++ b/pkg/reconciler/openshift/tektonaddon/controller.go @@ -75,7 +75,7 @@ func NewExtendedController(generator common.ExtensionGenerator) injection.Contro pipelineInformer: tektonPipelineinformer.Get(ctx), triggerInformer: tektonTriggerinformer.Get(ctx), manifest: manifest, - version: version, + operatorVersion: version, } impl := tektonAddonreconciler.NewImpl(ctx, c) diff --git a/pkg/reconciler/openshift/tektonaddon/extension.go b/pkg/reconciler/openshift/tektonaddon/extension.go index 5733904a4e..8dbefd2cc8 100644 --- a/pkg/reconciler/openshift/tektonaddon/extension.go +++ b/pkg/reconciler/openshift/tektonaddon/extension.go @@ -31,7 +31,6 @@ import ( "github.com/tektoncd/operator/pkg/client/clientset/versioned" operatorclient "github.com/tektoncd/operator/pkg/client/injection/client" "github.com/tektoncd/operator/pkg/reconciler/common" - "github.com/tektoncd/operator/pkg/reconciler/kubernetes/tektoninstallerset" "github.com/tektoncd/operator/pkg/reconciler/shared/hash" "go.uber.org/zap" corev1 "k8s.io/api/core/v1" @@ -89,7 +88,7 @@ func (oe openshiftExtension) PostReconcile(ctx context.Context, comp v1alpha1.Te miscellaneousLS := metav1.LabelSelector{ MatchLabels: map[string]string{ - tektoninstallerset.InstallerSetType: MiscellaneousResourcesInstallerSet, + v1alpha1.InstallerSetType: MiscellaneousResourcesInstallerSet, }, } miscellaneousLabelSelector, err := common.LabelSelector(miscellaneousLS) @@ -141,7 +140,7 @@ func (oe openshiftExtension) PostReconcile(ctx context.Context, comp v1alpha1.Te } // spec hash stored on installerSet - lastAppliedHash := installedTIS.Items[0].GetAnnotations()[tektoninstallerset.LastAppliedHashKey] + lastAppliedHash := installedTIS.Items[0].GetAnnotations()[v1alpha1.LastAppliedHashKey] if lastAppliedHash != expectedSpecHash { @@ -152,7 +151,7 @@ func (oe openshiftExtension) PostReconcile(ctx context.Context, comp v1alpha1.Te // Update the spec hash current := installedTIS.Items[0].GetAnnotations() - current[tektoninstallerset.LastAppliedHashKey] = expectedSpecHash + current[v1alpha1.LastAppliedHashKey] = expectedSpecHash installedTIS.Items[0].SetAnnotations(current) // Update the manifests @@ -188,7 +187,7 @@ func (oe openshiftExtension) PostReconcile(ctx context.Context, comp v1alpha1.Te consoleCLILS := metav1.LabelSelector{ MatchLabels: map[string]string{ - tektoninstallerset.InstallerSetType: ConsoleCLIInstallerSet, + v1alpha1.InstallerSetType: ConsoleCLIInstallerSet, }, } consoleCLILabelSelector, err := common.LabelSelector(consoleCLILS) diff --git a/pkg/reconciler/openshift/tektonaddon/tektonaddon.go b/pkg/reconciler/openshift/tektonaddon/tektonaddon.go index 54a86bd463..38cff2dfb0 100644 --- a/pkg/reconciler/openshift/tektonaddon/tektonaddon.go +++ b/pkg/reconciler/openshift/tektonaddon/tektonaddon.go @@ -54,7 +54,7 @@ type Reconciler struct { pipelineInformer informer.TektonPipelineInformer triggerInformer informer.TektonTriggerInformer - version string + operatorVersion string } const ( @@ -121,6 +121,14 @@ func (r *Reconciler) ReconcileKind(ctx context.Context, ta *v1alpha1.TektonAddon return nil } + // Pass the object through defaulting + ta.SetDefaults(ctx) + + // Mark TektonAddon Instance as Not Ready if an upgrade is needed + if err := r.markUpgrade(ctx, ta); err != nil { + return err + } + // Make sure TektonPipeline & TektonTrigger is installed before proceeding with // TektonAddons @@ -128,7 +136,8 @@ func (r *Reconciler) ReconcileKind(ctx context.Context, ta *v1alpha1.TektonAddon if err.Error() == common.PipelineNotReady { ta.Status.MarkDependencyInstalling("tekton-pipelines is still installing") // wait for pipeline status to change - return fmt.Errorf(common.PipelineNotReady) + r.enqueueAfter(ta, 10*time.Second) + return nil } // (tektonpipeline.operator.tekton.dev instance not available yet) ta.Status.MarkDependencyMissing("tekton-pipelines does not exist") @@ -139,7 +148,8 @@ func (r *Reconciler) ReconcileKind(ctx context.Context, ta *v1alpha1.TektonAddon if err.Error() == common.TriggerNotReady { ta.Status.MarkDependencyInstalling("tekton-triggers is still installing") // wait for trigger status to change - return fmt.Errorf(common.TriggerNotReady) + r.enqueueAfter(ta, 10*time.Second) + return nil } // (tektontrigger.operator.tekton.dev instance not available yet) ta.Status.MarkDependencyMissing("tekton-triggers does not exist") @@ -148,9 +158,6 @@ func (r *Reconciler) ReconcileKind(ctx context.Context, ta *v1alpha1.TektonAddon ta.Status.MarkDependenciesInstalled() - // Pass the object through defaulting - ta.SetDefaults(ctx) - if err := tektoninstallerset.CleanUpObsoleteResources(ctx, r.operatorClientSet, CreatedByValue); err != nil { return err } @@ -175,7 +182,7 @@ func (r *Reconciler) ReconcileKind(ctx context.Context, ta *v1alpha1.TektonAddon // with their manifest clusterTaskLS := metav1.LabelSelector{ MatchLabels: map[string]string{ - tektoninstallerset.InstallerSetType: ClusterTaskInstallerSet, + v1alpha1.InstallerSetType: ClusterTaskInstallerSet, }, } clusterTaskLabelSelector, err := common.LabelSelector(clusterTaskLS) @@ -185,12 +192,14 @@ func (r *Reconciler) ReconcileKind(ctx context.Context, ta *v1alpha1.TektonAddon if ctVal == "true" { - exist, err := checkIfInstallerSetExist(ctx, r.operatorClientSet, r.version, clusterTaskLabelSelector) + exist, err := checkIfInstallerSetExist(ctx, r.operatorClientSet, r.operatorVersion, clusterTaskLabelSelector) if err != nil { return err } if !exist { + msg := fmt.Sprintf("%s being created/upgraded", ClusterTaskInstallerSet) + ta.Status.MarkInstallerSetNotReady(msg) return r.ensureClusterTasks(ctx, ta) } } else { @@ -209,8 +218,8 @@ func (r *Reconciler) ReconcileKind(ctx context.Context, ta *v1alpha1.TektonAddon // with the versioned clustertask manifest versionedClusterTaskLS := metav1.LabelSelector{ MatchLabels: map[string]string{ - tektoninstallerset.InstallerSetType: VersionedClusterTaskInstallerSet, - tektoninstallerset.ReleaseMinorVersionKey: getPatchVersionTrimmed(r.version), + v1alpha1.InstallerSetType: VersionedClusterTaskInstallerSet, + v1alpha1.ReleaseMinorVersionKey: getPatchVersionTrimmed(r.operatorVersion), }, } versionedClusterTaskLabelSelector, err := common.LabelSelector(versionedClusterTaskLS) @@ -220,12 +229,14 @@ func (r *Reconciler) ReconcileKind(ctx context.Context, ta *v1alpha1.TektonAddon if ctVal == "true" { // here pass two labels one for type and other for minor release version to remove the previous minor release installerset only not all - exist, err := checkIfInstallerSetExist(ctx, r.operatorClientSet, r.version, versionedClusterTaskLabelSelector) + exist, err := checkIfInstallerSetExist(ctx, r.operatorClientSet, r.operatorVersion, versionedClusterTaskLabelSelector) if err != nil { return err } if !exist { + msg := fmt.Sprintf("%s being created/upgraded", VersionedClusterTaskInstallerSet) + ta.Status.MarkInstallerSetNotReady(msg) return r.ensureVersionedClusterTasks(ctx, ta) } } else { @@ -238,8 +249,8 @@ func (r *Reconciler) ReconcileKind(ctx context.Context, ta *v1alpha1.TektonAddon // here pass two labels one for type and other for operator release version to get the latest installerset of current version vClusterTaskLS := metav1.LabelSelector{ MatchLabels: map[string]string{ - tektoninstallerset.InstallerSetType: VersionedClusterTaskInstallerSet, - tektoninstallerset.ReleaseVersionKey: r.version, + v1alpha1.InstallerSetType: VersionedClusterTaskInstallerSet, + v1alpha1.ReleaseVersionKey: r.operatorVersion, }, } vClusterTaskLabelSelector, err := common.LabelSelector(vClusterTaskLS) @@ -255,7 +266,7 @@ func (r *Reconciler) ReconcileKind(ctx context.Context, ta *v1alpha1.TektonAddon // with their manifest pipelineTemplateLS := metav1.LabelSelector{ MatchLabels: map[string]string{ - tektoninstallerset.InstallerSetType: PipelinesTemplateInstallerSet, + v1alpha1.InstallerSetType: PipelinesTemplateInstallerSet, }, } pipelineTemplateLSLabelSelector, err := common.LabelSelector(pipelineTemplateLS) @@ -264,11 +275,13 @@ func (r *Reconciler) ReconcileKind(ctx context.Context, ta *v1alpha1.TektonAddon } if ptVal == "true" { - exist, err := checkIfInstallerSetExist(ctx, r.operatorClientSet, r.version, pipelineTemplateLSLabelSelector) + exist, err := checkIfInstallerSetExist(ctx, r.operatorClientSet, r.operatorVersion, pipelineTemplateLSLabelSelector) if err != nil { return err } if !exist { + msg := fmt.Sprintf("%s being created/upgraded", PipelinesTemplateInstallerSet) + ta.Status.MarkInstallerSetNotReady(msg) return r.ensurePipelineTemplates(ctx, ta) } } else { @@ -286,18 +299,20 @@ func (r *Reconciler) ReconcileKind(ctx context.Context, ta *v1alpha1.TektonAddon // Ensure Triggers resources triggerResourceLS := metav1.LabelSelector{ MatchLabels: map[string]string{ - tektoninstallerset.InstallerSetType: TriggersResourcesInstallerSet, + v1alpha1.InstallerSetType: TriggersResourcesInstallerSet, }, } triggerResourceLabelSelector, err := common.LabelSelector(triggerResourceLS) if err != nil { return err } - exist, err := checkIfInstallerSetExist(ctx, r.operatorClientSet, r.version, triggerResourceLabelSelector) + exist, err := checkIfInstallerSetExist(ctx, r.operatorClientSet, r.operatorVersion, triggerResourceLabelSelector) if err != nil { return err } if !exist { + msg := fmt.Sprintf("%s being created/upgraded", TriggersResourcesInstallerSet) + ta.Status.MarkInstallerSetNotReady(msg) return r.ensureTriggerResources(ctx, ta) } @@ -320,7 +335,7 @@ func (r *Reconciler) ReconcileKind(ctx context.Context, ta *v1alpha1.TektonAddon ta.Status.MarkPostReconcilerComplete() - ta.Status.SetVersion(r.version) + ta.Status.SetVersion(r.operatorVersion) return nil } @@ -363,7 +378,7 @@ func (r *Reconciler) ensureTriggerResources(ctx context.Context, ta *v1alpha1.Te return err } - if err := createInstallerSet(ctx, r.operatorClientSet, ta, triggerResourcesManifest, r.version, + if err := createInstallerSet(ctx, r.operatorClientSet, ta, triggerResourcesManifest, r.operatorVersion, TriggersResourcesInstallerSet, "addon-triggers"); err != nil { return err } @@ -389,7 +404,7 @@ func (r *Reconciler) ensurePipelineTemplates(ctx context.Context, ta *v1alpha1.T return err } - if err := createInstallerSet(ctx, r.operatorClientSet, ta, pipelineTemplateManifest, r.version, + if err := createInstallerSet(ctx, r.operatorClientSet, ta, pipelineTemplateManifest, r.operatorVersion, PipelinesTemplateInstallerSet, "addon-pipelines"); err != nil { return err } @@ -410,7 +425,7 @@ func (r *Reconciler) ensureClusterTasks(ctx context.Context, ta *v1alpha1.Tekton } clusterTaskManifest = clusterTaskManifest.Filter( - mf.Not(byContains(getFormattedVersion(r.version))), + mf.Not(byContains(getFormattedVersion(r.operatorVersion))), ) communityClusterTaskManifest := r.manifest @@ -427,7 +442,7 @@ func (r *Reconciler) ensureClusterTasks(ctx context.Context, ta *v1alpha1.Tekton } if err := createInstallerSet(ctx, r.operatorClientSet, ta, clusterTaskManifest, - r.version, ClusterTaskInstallerSet, "addon-clustertasks"); err != nil { + r.operatorVersion, ClusterTaskInstallerSet, "addon-clustertasks"); err != nil { return err } @@ -447,11 +462,11 @@ func (r *Reconciler) ensureVersionedClusterTasks(ctx context.Context, ta *v1alph } clusterTaskManifest = clusterTaskManifest.Filter( - byContains(getFormattedVersion(r.version)), + byContains(getFormattedVersion(r.operatorVersion)), ) if err := createInstallerSet(ctx, r.operatorClientSet, ta, clusterTaskManifest, - r.version, VersionedClusterTaskInstallerSet, "addon-versioned-clustertasks"); err != nil { + r.operatorVersion, VersionedClusterTaskInstallerSet, "addon-versioned-clustertasks"); err != nil { return err } @@ -469,15 +484,16 @@ func checkIfInstallerSetExist(ctx context.Context, oc clientset.Interface, relVe LabelSelector: labelSelector, }) if err != nil { - if errors.IsNotFound(err) { - return false, nil - } return false, err } + if len(installerSets.Items) == 0 { + return false, nil + } + if len(installerSets.Items) == 1 { // if already created then check which version it is - version, ok := installerSets.Items[0].Labels[tektoninstallerset.ReleaseVersionKey] + version, ok := installerSets.Items[0].Labels[v1alpha1.ReleaseVersionKey] if ok && version == relVersion { // if installer set already exist and release version is same // then ignore and move on @@ -495,7 +511,7 @@ func checkIfInstallerSetExist(ctx context.Context, oc clientset.Interface, relVe return false, err } - return false, nil + return false, v1alpha1.RECONCILE_AGAIN_ERR } func createInstallerSet(ctx context.Context, oc clientset.Interface, ta *v1alpha1.TektonAddon, @@ -513,28 +529,30 @@ func createInstallerSet(ctx context.Context, oc clientset.Interface, ta *v1alpha return err } - return nil + return v1alpha1.RECONCILE_AGAIN_ERR } func makeInstallerSet(ta *v1alpha1.TektonAddon, manifest mf.Manifest, prefix, releaseVersion, component, specHash string) *v1alpha1.TektonInstallerSet { ownerRef := *metav1.NewControllerRef(ta, ta.GetGroupVersionKind()) labels := map[string]string{ - tektoninstallerset.CreatedByKey: CreatedByValue, - tektoninstallerset.InstallerSetType: component, - tektoninstallerset.ReleaseVersionKey: releaseVersion, + v1alpha1.CreatedByKey: CreatedByValue, + v1alpha1.InstallerSetType: component, + v1alpha1.ReleaseVersionKey: releaseVersion, } + namePrefix := fmt.Sprintf("%s-", prefix) // special label to make sure no two versioned clustertask installerset exist // for all patch releases if component == VersionedClusterTaskInstallerSet { - labels[tektoninstallerset.ReleaseMinorVersionKey] = getPatchVersionTrimmed(releaseVersion) + labels[v1alpha1.ReleaseMinorVersionKey] = getPatchVersionTrimmed(releaseVersion) + namePrefix = fmt.Sprintf("%s%s-", namePrefix, getFormattedVersion(releaseVersion)) } return &v1alpha1.TektonInstallerSet{ ObjectMeta: metav1.ObjectMeta{ - GenerateName: fmt.Sprintf("%s-", prefix), + GenerateName: namePrefix, Labels: labels, Annotations: map[string]string{ - tektoninstallerset.TargetNamespaceKey: ta.Spec.TargetNamespace, - tektoninstallerset.LastAppliedHashKey: specHash, + v1alpha1.TargetNamespaceKey: ta.Spec.TargetNamespace, + v1alpha1.LastAppliedHashKey: specHash, }, OwnerReferences: []metav1.OwnerReference{ownerRef}, }, @@ -634,3 +652,28 @@ func getPatchVersionTrimmed(version string) string { } return version } + +func (r *Reconciler) markUpgrade(ctx context.Context, ta *v1alpha1.TektonAddon) error { + labels := ta.GetLabels() + ver, ok := labels[v1alpha1.ReleaseVersionKey] + if ok && ver == r.operatorVersion { + return nil + } + if ok && ver != r.operatorVersion { + ta.Status.MarkInstallerSetNotReady(v1alpha1.UpgradePending) + ta.Status.MarkPreReconcilerFailed(v1alpha1.UpgradePending) + ta.Status.MarkPostReconcilerFailed(v1alpha1.UpgradePending) + ta.Status.MarkNotReady(v1alpha1.UpgradePending) + } + if labels == nil { + labels = map[string]string{} + } + labels[v1alpha1.ReleaseVersionKey] = r.operatorVersion + ta.SetLabels(labels) + + if _, err := r.operatorClientSet.OperatorV1alpha1().TektonAddons().Update(ctx, + ta, metav1.UpdateOptions{}); err != nil { + return err + } + return v1alpha1.RECONCILE_AGAIN_ERR +} diff --git a/pkg/reconciler/openshift/tektonconfig/common.go b/pkg/reconciler/openshift/tektonconfig/common.go index 13a7a097a4..eb02f686e7 100644 --- a/pkg/reconciler/openshift/tektonconfig/common.go +++ b/pkg/reconciler/openshift/tektonconfig/common.go @@ -21,7 +21,6 @@ import ( "github.com/tektoncd/operator/pkg/apis/operator/v1alpha1" "github.com/tektoncd/operator/pkg/client/clientset/versioned" - "github.com/tektoncd/operator/pkg/reconciler/kubernetes/tektoninstallerset" "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) @@ -68,8 +67,8 @@ func makeInstallerSet(tc *v1alpha1.TektonConfig, name, releaseVersion string, la Name: name, Labels: labels, Annotations: map[string]string{ - tektoninstallerset.ReleaseVersionKey: releaseVersion, - tektoninstallerset.TargetNamespaceKey: tc.Spec.TargetNamespace, + v1alpha1.ReleaseVersionKey: releaseVersion, + v1alpha1.TargetNamespaceKey: tc.Spec.TargetNamespace, }, OwnerReferences: []metav1.OwnerReference{ownerRef}, }, @@ -123,7 +122,7 @@ func checkIfInstallerSetExist(ctx context.Context, oc versioned.Interface, relVe return false, err } - if version, ok := ctIs.Annotations[tektoninstallerset.ReleaseVersionKey]; ok && version == relVersion { + if version, ok := ctIs.Annotations[v1alpha1.ReleaseVersionKey]; ok && version == relVersion { // if installer set already exist and release version is same // then ignore and move on return true, nil diff --git a/pkg/reconciler/openshift/tektonconfig/extension/addon.go b/pkg/reconciler/openshift/tektonconfig/extension/addon.go index e3e0bfe5d8..17b6af2297 100644 --- a/pkg/reconciler/openshift/tektonconfig/extension/addon.go +++ b/pkg/reconciler/openshift/tektonconfig/extension/addon.go @@ -127,6 +127,13 @@ func waitForTektonAddonState(ctx context.Context, clients op.TektonAddonInterfac // isTektonAddonReady will check the status conditions of the TektonAddon and return true if the TektonAddon is ready. func isTektonAddonReady(s *v1alpha1.TektonAddon, err error) (bool, error) { + upgradePending, errInternal := common.CheckUpgradePending(s) + if err != nil { + return false, errInternal + } + if upgradePending { + return false, v1alpha1.DEPENDENCY_UPGRADE_PENDING_ERR + } return s.Status.IsReady(), err } diff --git a/pkg/reconciler/openshift/tektonconfig/rbac.go b/pkg/reconciler/openshift/tektonconfig/rbac.go index fbbafe1a1d..2b6771f904 100644 --- a/pkg/reconciler/openshift/tektonconfig/rbac.go +++ b/pkg/reconciler/openshift/tektonconfig/rbac.go @@ -24,7 +24,6 @@ import ( "github.com/tektoncd/operator/pkg/apis/operator/v1alpha1" clientset "github.com/tektoncd/operator/pkg/client/clientset/versioned" "github.com/tektoncd/operator/pkg/reconciler/common" - "github.com/tektoncd/operator/pkg/reconciler/kubernetes/tektoninstallerset" corev1 "k8s.io/api/core/v1" rbacv1 "k8s.io/api/rbac/v1" "k8s.io/apimachinery/pkg/api/errors" @@ -139,7 +138,7 @@ func (r *rbac) createResources(ctx context.Context) error { } if !exist { if err := createInstallerSet(ctx, r.operatorClientSet, r.tektonConfig, map[string]string{ - tektoninstallerset.CreatedByKey: createdByValue, + v1alpha1.CreatedByKey: createdByValue, }, r.version, componentName, "rbac-resources"); err != nil { return err } diff --git a/pkg/reconciler/openshift/tektonpipeline/extension.go b/pkg/reconciler/openshift/tektonpipeline/extension.go index 74d16486a7..b69063403d 100644 --- a/pkg/reconciler/openshift/tektonpipeline/extension.go +++ b/pkg/reconciler/openshift/tektonpipeline/extension.go @@ -28,7 +28,6 @@ import ( "github.com/tektoncd/operator/pkg/client/clientset/versioned" operatorclient "github.com/tektoncd/operator/pkg/client/injection/client" "github.com/tektoncd/operator/pkg/reconciler/common" - "github.com/tektoncd/operator/pkg/reconciler/kubernetes/tektoninstallerset" occommon "github.com/tektoncd/operator/pkg/reconciler/openshift/common" "go.uber.org/zap" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -54,14 +53,14 @@ const ( var ( preReconcileSelector = metav1.LabelSelector{ MatchLabels: map[string]string{ - tektoninstallerset.CreatedByKey: createdByValue, - tektoninstallerset.InstallerSetType: prePipelineInstallerSet, + v1alpha1.CreatedByKey: createdByValue, + v1alpha1.InstallerSetType: prePipelineInstallerSet, }, } postReconcileSelector = metav1.LabelSelector{ MatchLabels: map[string]string{ - tektoninstallerset.CreatedByKey: createdByValue, - tektoninstallerset.InstallerSetType: postPipelineInstallerSet, + v1alpha1.CreatedByKey: createdByValue, + v1alpha1.InstallerSetType: postPipelineInstallerSet, }, } ) diff --git a/pkg/reconciler/openshift/tektonpipeline/installerset.go b/pkg/reconciler/openshift/tektonpipeline/installerset.go index d0da85ac59..79b57c409f 100644 --- a/pkg/reconciler/openshift/tektonpipeline/installerset.go +++ b/pkg/reconciler/openshift/tektonpipeline/installerset.go @@ -25,7 +25,6 @@ import ( mf "github.com/manifestival/manifestival" "github.com/tektoncd/operator/pkg/apis/operator/v1alpha1" clientset "github.com/tektoncd/operator/pkg/client/clientset/versioned" - "github.com/tektoncd/operator/pkg/reconciler/kubernetes/tektoninstallerset" "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) @@ -74,8 +73,8 @@ func checkIfInstallerSetExist(ctx context.Context, oc clientset.Interface, relVe // If anyone of this is not as expected then delete existing // InstallerSet and return false - version, vOk := installerSets.Items[0].Labels[tektoninstallerset.ReleaseVersionKey] - namespace, nOk := installerSets.Items[0].Annotations[tektoninstallerset.TargetNamespaceKey] + version, vOk := installerSets.Items[0].Labels[v1alpha1.ReleaseVersionKey] + namespace, nOk := installerSets.Items[0].Annotations[v1alpha1.TargetNamespaceKey] if vOk && nOk { if version == relVersion && namespace == tp.Spec.TargetNamespace { @@ -131,13 +130,13 @@ func makeInstallerSet(tp *v1alpha1.TektonPipeline, manifest mf.Manifest, install ObjectMeta: metav1.ObjectMeta{ GenerateName: fmt.Sprintf("%s-", strings.ToLower(installerSetType)), Labels: map[string]string{ - tektoninstallerset.CreatedByKey: createdByValue, - tektoninstallerset.ReleaseVersionKey: releaseVersion, - tektoninstallerset.InstallerSetType: installerSetType, + v1alpha1.CreatedByKey: createdByValue, + v1alpha1.ReleaseVersionKey: releaseVersion, + v1alpha1.InstallerSetType: installerSetType, }, Annotations: map[string]string{ - tektoninstallerset.ReleaseVersionKey: releaseVersion, - tektoninstallerset.TargetNamespaceKey: tp.Spec.TargetNamespace, + v1alpha1.ReleaseVersionKey: releaseVersion, + v1alpha1.TargetNamespaceKey: tp.Spec.TargetNamespace, }, OwnerReferences: []metav1.OwnerReference{ownerRef}, }, diff --git a/pkg/reconciler/shared/tektonconfig/controller.go b/pkg/reconciler/shared/tektonconfig/controller.go index 4fdc5f99d4..b8437c90d4 100644 --- a/pkg/reconciler/shared/tektonconfig/controller.go +++ b/pkg/reconciler/shared/tektonconfig/controller.go @@ -62,14 +62,23 @@ func NewExtensibleController(generator common.ExtensionGenerator) injection.Cont logger.Fatalw("Error creating initial manifest", zap.Error(err)) } + operatorVer, err := common.OperatorVersion(ctx) + if err != nil { + logger.Fatal(err) + } + c := &Reconciler{ kubeClientSet: kubeclient.Get(ctx), operatorClientSet: operatorclient.Get(ctx), extension: generator(ctx), manifest: manifest, + operatorVersion: operatorVer, } impl := tektonConfigreconciler.NewImpl(ctx, c) + // Add enqueue func in reconciler + c.enqueueAfter = impl.EnqueueAfter + logger.Info("Setting up event handlers for TektonConfig") tektonConfiginformer.Get(ctx).Informer().AddEventHandler(controller.HandleAll(impl.Enqueue)) diff --git a/pkg/reconciler/shared/tektonconfig/pipeline/pipeline.go b/pkg/reconciler/shared/tektonconfig/pipeline/pipeline.go index 8e7e8b82b9..8470fdd355 100644 --- a/pkg/reconciler/shared/tektonconfig/pipeline/pipeline.go +++ b/pkg/reconciler/shared/tektonconfig/pipeline/pipeline.go @@ -126,6 +126,13 @@ func waitForTektonPipelineState(ctx context.Context, clients op.TektonPipelineIn // IsTektonPipelineReady will check the status conditions of the TektonPipeline and return true if the TektonPipeline is ready. func isTektonPipelineReady(s *v1alpha1.TektonPipeline, err error) (bool, error) { + upgradePending, errInternal := common.CheckUpgradePending(s) + if err != nil { + return false, errInternal + } + if upgradePending { + return false, v1alpha1.DEPENDENCY_UPGRADE_PENDING_ERR + } return s.Status.IsReady(), err } diff --git a/pkg/reconciler/shared/tektonconfig/tektonconfig.go b/pkg/reconciler/shared/tektonconfig/tektonconfig.go index f2ad0ca04b..970c877c5f 100644 --- a/pkg/reconciler/shared/tektonconfig/tektonconfig.go +++ b/pkg/reconciler/shared/tektonconfig/tektonconfig.go @@ -21,8 +21,10 @@ import ( "fmt" "os" "path/filepath" + "time" corev1 "k8s.io/api/core/v1" + "k8s.io/apimachinery/pkg/api/errors" mf "github.com/manifestival/manifestival" "github.com/tektoncd/operator/pkg/apis/operator/v1alpha1" @@ -46,7 +48,10 @@ type Reconciler struct { operatorClientSet clientset.Interface // Platform-specific behavior to affect the transform extension common.Extension - manifest mf.Manifest + // enqueueAfter enqueues a obj after a duration + enqueueAfter func(obj interface{}, after time.Duration) + manifest mf.Manifest + operatorVersion string } // Check that our Reconciler implements controller.Reconciler @@ -94,6 +99,10 @@ func (r *Reconciler) ReconcileKind(ctx context.Context, tc *v1alpha1.TektonConfi } tc.SetDefaults(ctx) + // Mark TektonConfig Instance as Not Ready if an upgrade is needed + if err := r.markUpgrade(ctx, tc); err != nil { + return err + } if err := r.ensureTargetNamespaceExists(ctx, tc); err != nil { return err @@ -105,7 +114,8 @@ func (r *Reconciler) ReconcileKind(ctx context.Context, tc *v1alpha1.TektonConfi if err := r.extension.PreReconcile(ctx, tc); err != nil { if err == v1alpha1.RECONCILE_AGAIN_ERR { - return err + r.enqueueAfter(tc, 10*time.Second) + return nil } tc.Status.MarkPreInstallFailed(err.Error()) return err @@ -116,19 +126,22 @@ func (r *Reconciler) ReconcileKind(ctx context.Context, tc *v1alpha1.TektonConfi // Create TektonPipeline CR if err := pipeline.CreatePipelineCR(ctx, tc, r.operatorClientSet.OperatorV1alpha1()); err != nil { tc.Status.MarkComponentNotReady(fmt.Sprintf("TektonPipeline: %s", err.Error())) - return err + r.enqueueAfter(tc, 10*time.Second) + return nil } // Create TektonTrigger CR if the profile is all or basic if tc.Spec.Profile == v1alpha1.ProfileAll || tc.Spec.Profile == v1alpha1.ProfileBasic { if err := trigger.CreateTriggerCR(ctx, tc, r.operatorClientSet.OperatorV1alpha1()); err != nil { tc.Status.MarkComponentNotReady(fmt.Sprintf("TektonTrigger: %s", err.Error())) - return err + r.enqueueAfter(tc, 10*time.Second) + return nil } } else { if err := trigger.TektonTriggerCRDelete(ctx, r.operatorClientSet.OperatorV1alpha1().TektonTriggers(), v1alpha1.TriggerResourceName); err != nil { tc.Status.MarkComponentNotReady(fmt.Sprintf("TektonTrigger: %s", err.Error())) - return err + r.enqueueAfter(tc, 10*time.Second) + return nil } } @@ -141,7 +154,8 @@ func (r *Reconciler) ReconcileKind(ctx context.Context, tc *v1alpha1.TektonConfi if err := r.extension.PostReconcile(ctx, tc); err != nil { tc.Status.MarkPostInstallFailed(err.Error()) - return err + r.enqueueAfter(tc, 10*time.Second) + return nil } tc.Status.MarkPostInstallComplete() @@ -213,12 +227,13 @@ func (r *Reconciler) ensureTargetNamespaceExists(ctx context.Context, tc *v1alph }, }, } - if _, err = r.kubeClientSet.CoreV1().Namespaces().Create(ctx, ns, metav1.CreateOptions{}); err != nil { + if errors.IsAlreadyExists(err) { + return r.addTargetNamespaceLabel(ctx, tc.GetSpec().GetTargetNamespace()) + } return err } } - return nil } @@ -244,3 +259,44 @@ func (r *Reconciler) deleteObsoleteTargetNamespaces(ctx context.Context, tc *v1a return nil } + +func (r *Reconciler) markUpgrade(ctx context.Context, tc *v1alpha1.TektonConfig) error { + labels := tc.GetLabels() + ver, ok := labels[v1alpha1.ReleaseVersionKey] + if ok && ver == r.operatorVersion { + return nil + } + if ok && ver != r.operatorVersion { + tc.Status.MarkComponentNotReady("Upgrade Pending") + tc.Status.MarkPreInstallFailed(v1alpha1.UpgradePending) + tc.Status.MarkPostInstallFailed(v1alpha1.UpgradePending) + tc.Status.MarkNotReady("Upgrade Pending") + } + if labels == nil { + labels = map[string]string{} + } + labels[v1alpha1.ReleaseVersionKey] = r.operatorVersion + tc.SetLabels(labels) + // Update the object for any spec changes + if _, err := r.operatorClientSet.OperatorV1alpha1().TektonConfigs().Update(ctx, + tc, v1.UpdateOptions{}); err != nil { + return err + } + return v1alpha1.RECONCILE_AGAIN_ERR +} + +func (r *Reconciler) addTargetNamespaceLabel(ctx context.Context, targetNamespace string) error { + ns, err := r.kubeClientSet.CoreV1().Namespaces().Get(ctx, targetNamespace, v1.GetOptions{}) + if err != nil { + return err + } + labels := ns.GetLabels() + if labels == nil { + labels = map[string]string{ + "operator.tekton.dev/targetNamespace": "true", + } + } + ns.SetLabels(labels) + _, err = r.kubeClientSet.CoreV1().Namespaces().Update(ctx, ns, v1.UpdateOptions{}) + return err +} diff --git a/pkg/reconciler/shared/tektonconfig/trigger/trigger.go b/pkg/reconciler/shared/tektonconfig/trigger/trigger.go index a36aedcf51..ac29fc2767 100644 --- a/pkg/reconciler/shared/tektonconfig/trigger/trigger.go +++ b/pkg/reconciler/shared/tektonconfig/trigger/trigger.go @@ -126,6 +126,13 @@ func waitForTektonTriggerState(ctx context.Context, clients op.TektonTriggerInte // isTektonTriggerReady will check the status conditions of the TektonTrigger and return true if the TektonTrigger is ready. func isTektonTriggerReady(s *v1alpha1.TektonTrigger, err error) (bool, error) { + upgradePending, errInternal := common.CheckUpgradePending(s) + if err != nil { + return false, errInternal + } + if upgradePending { + return false, v1alpha1.DEPENDENCY_UPGRADE_PENDING_ERR + } return s.Status.IsReady(), err } diff --git a/test/e2e-common.sh b/test/e2e-common.sh index 5bf3095307..b780751c97 100755 --- a/test/e2e-common.sh +++ b/test/e2e-common.sh @@ -47,5 +47,21 @@ function install_operator_resources() { # Wait for pods to be running in the namespaces we are deploying to # TODO: parameterize namespace, operator can run in a namespace different from the namespace where tektonpipelines is installed wait_until_pods_running ${OPERATOR_NAMESPACE} || fail_test "Tekton Operator controller did not come up" +} + +function tektonconfig_ready_wait() { + echo "Wait for controller to start and create TektonConfig" + TEKTONCONFIG_READY=False + until [[ "${TEKTONCONFIG_READY}" = "True" ]]; do + echo waiting for TektonConfig config Ready status + sleep 5 + kubectl get TektonConfig config > /dev/null 2>&1 + if [[ $? -ne 0 ]]; then + echo TektonConfig config not yet created + continue + fi + TEKTONCONFIG_READY=$(kubectl get tektonconfig config -o jsonpath='{.status.conditions[?(@.type=="Ready")].status}') + done + echo "TektonConfig config Ready: True" } diff --git a/test/e2e-tests.sh b/test/e2e-tests.sh index 6b4b7466a2..15dbbf1d8d 100755 --- a/test/e2e-tests.sh +++ b/test/e2e-tests.sh @@ -32,8 +32,7 @@ failed=0 header "Setting up environment" [[ -z ${E2E_SKIP_OPERATOR_INSTALLATION} ]] && install_operator_resources -echo "Wait for controller to start and create TektonConfig" -sleep 30 +tektonconfig_ready_wait header "Running Go e2e tests" go_test_e2e -timeout=20m ./test/e2e/common ${KUBECONFIG_PARAM} || failed=1 diff --git a/test/e2e/common/tektonconfigdeployment_test.go b/test/e2e/common/tektonconfigdeployment_test.go index 4e09e46ebf..00fcae9ddd 100644 --- a/test/e2e/common/tektonconfigdeployment_test.go +++ b/test/e2e/common/tektonconfigdeployment_test.go @@ -27,7 +27,6 @@ import ( "github.com/google/go-cmp/cmp" "github.com/tektoncd/operator/pkg/apis/operator/v1alpha1" "github.com/tektoncd/operator/pkg/reconciler/common" - "github.com/tektoncd/operator/pkg/reconciler/kubernetes/tektoninstallerset" "github.com/tektoncd/operator/pkg/reconciler/kubernetes/tektonpipeline" "github.com/tektoncd/operator/pkg/reconciler/kubernetes/tektontrigger" "github.com/tektoncd/operator/test/client" @@ -298,7 +297,7 @@ func runAddonTest(t *testing.T, clients *utils.Clients, tc *v1alpha1.TektonConfi ls := metav1.LabelSelector{ MatchLabels: map[string]string{ - tektoninstallerset.CreatedByKey: "TektonAddon", + v1alpha1.CreatedByKey: "TektonAddon", }, } labelSelector, err := common.LabelSelector(ls) diff --git a/test/resources/tektonaddons.go b/test/resources/tektonaddons.go index 7f0f0d971e..a522e82861 100644 --- a/test/resources/tektonaddons.go +++ b/test/resources/tektonaddons.go @@ -20,11 +20,12 @@ import ( "context" "errors" "fmt" - "github.com/tektoncd/operator/pkg/reconciler/common" "path/filepath" "runtime" "testing" + "github.com/tektoncd/operator/pkg/reconciler/common" + mfc "github.com/manifestival/client-go-client" mf "github.com/manifestival/manifestival" @@ -35,7 +36,6 @@ import ( "github.com/tektoncd/operator/pkg/apis/operator/v1alpha1" addonv1alpha1 "github.com/tektoncd/operator/pkg/client/clientset/versioned/typed/operator/v1alpha1" - "github.com/tektoncd/operator/pkg/reconciler/kubernetes/tektoninstallerset" "github.com/tektoncd/operator/pkg/reconciler/openshift/tektonaddon" apierrs "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -97,6 +97,7 @@ func AssertTektonAddonCRReadyStatus(t *testing.T, clients *utils.Clients, names // AssertTektonInstallerSets verifies if the TektonInstallerSets are created. func AssertTektonInstallerSets(t *testing.T, clients *utils.Clients) { assertInstallerSetsForAddon(t, clients, tektonaddon.ClusterTaskInstallerSet) + assertInstallerSetsForAddon(t, clients, tektonaddon.VersionedClusterTaskInstallerSet) assertInstallerSetsForAddon(t, clients, tektonaddon.PipelinesTemplateInstallerSet) assertInstallerSetsForAddon(t, clients, tektonaddon.TriggersResourcesInstallerSet) assertInstallerSetsForAddon(t, clients, tektonaddon.ConsoleCLIInstallerSet) @@ -106,7 +107,7 @@ func AssertTektonInstallerSets(t *testing.T, clients *utils.Clients) { func assertInstallerSetsForAddon(t *testing.T, clients *utils.Clients, component string) { ls := metav1.LabelSelector{ MatchLabels: map[string]string{ - tektoninstallerset.InstallerSetType: component, + v1alpha1.InstallerSetType: component, }, } labelSelector, err := common.LabelSelector(ls)