From ba2bd7e9f779767cc3e2d46c83ea4a9ee151e9d4 Mon Sep 17 00:00:00 2001 From: jkhelil Date: Tue, 6 Sep 2022 09:15:44 +0200 Subject: [PATCH] Use operator.tekton.dev/release label to detect Tekton version --- controllers/default_test.go | 3 ++- .../shipwrightbuild_controller_test.go | 4 +++- docs/development/local-development.md | 2 +- pkg/common/const.go | 7 +++++++ pkg/tekton/tekton.go | 11 +++++----- pkg/tekton/tekton_test.go | 20 ++++++++++--------- .../tektoncd-operator-bundle.json | 8 ++++---- .../tektoncd-operator-channel-alpha.json | 2 +- 8 files changed, 35 insertions(+), 22 deletions(-) create mode 100644 pkg/common/const.go diff --git a/controllers/default_test.go b/controllers/default_test.go index f312530c..caaa8275 100644 --- a/controllers/default_test.go +++ b/controllers/default_test.go @@ -3,6 +3,7 @@ package controllers import ( g "github.com/onsi/ginkgo" o "github.com/onsi/gomega" + "github.com/shipwright-io/operator/pkg/common" appsv1 "k8s.io/api/apps/v1" corev1 "k8s.io/api/core/v1" rbacv1 "k8s.io/api/rbac/v1" @@ -99,7 +100,7 @@ var _ = g.Describe("Reconcile default ShipwrightBuild installation", func() { if errors.IsNotFound(err) { tektonOpCRD := &crdv1.CustomResourceDefinition{} tektonOpCRD.Name = "tektonconfigs.operator.tekton.dev" - tektonOpCRD.Labels = map[string]string{"version": "v0.49.0"} + tektonOpCRD.Labels = map[string]string{"operator.tekton.dev/release": common.TektonOpMinSupportedVersion} tektonOpCRD.Spec.Group = "operator.tekton.dev" tektonOpCRD.Spec.Scope = crdv1.ClusterScoped tektonOpCRD.Spec.Versions = []crdv1.CustomResourceDefinitionVersion{ diff --git a/controllers/shipwrightbuild_controller_test.go b/controllers/shipwrightbuild_controller_test.go index 06c99484..eea9bb1f 100644 --- a/controllers/shipwrightbuild_controller_test.go +++ b/controllers/shipwrightbuild_controller_test.go @@ -5,6 +5,8 @@ import ( "testing" "time" + "github.com/shipwright-io/operator/pkg/common" + o "github.com/onsi/gomega" appsv1 "k8s.io/api/apps/v1" @@ -134,7 +136,7 @@ func testShipwrightBuildReconcilerReconcile(t *testing.T, targetNamespace string crd1.Name = "taskruns.tekton.dev" crd2 := &crdv1.CustomResourceDefinition{} crd2.Name = "tektonconfigs.operator.tekton.dev" - crd2.Labels = map[string]string{"version": "v0.49.0"} + crd2.Labels = map[string]string{"operator.tekton.dev/release": common.TektonOpMinSupportedVersion} crds := []*crdv1.CustomResourceDefinition{crd1, crd2} c, _, _, r := bootstrapShipwrightBuildReconciler(t, b, nil, crds) diff --git a/docs/development/local-development.md b/docs/development/local-development.md index dcf34f63..405568c2 100644 --- a/docs/development/local-development.md +++ b/docs/development/local-development.md @@ -35,7 +35,7 @@ Refer to the [ko documentation](https://github.com/google/ko#local-publishing-op To test the operator on a Kubernetes cluster, you first must have the following: * Access to a Kubernetes cluster v1.20 or higher, with cluster admin permissions. -* Install [Tekton operator](https://github.com/tektoncd/operator) v0.49 or higher on the cluster. +* Install [Tekton operator](https://github.com/tektoncd/operator) v0.50 or higher on the cluster. ```bash $ export KUBECONFIG=/path/to/kubeconfig diff --git a/pkg/common/const.go b/pkg/common/const.go new file mode 100644 index 00000000..3d3d1d6b --- /dev/null +++ b/pkg/common/const.go @@ -0,0 +1,7 @@ +package common + +const ( + TektonOpMinSupportedVersion = "v0.50.0" + TektonOpMinSupportedMajor = 0 + TektonOpMinSupportedMinor = 50 +) diff --git a/pkg/tekton/tekton.go b/pkg/tekton/tekton.go index a40402ad..0b4c28b9 100644 --- a/pkg/tekton/tekton.go +++ b/pkg/tekton/tekton.go @@ -4,6 +4,7 @@ import ( "context" "fmt" + "github.com/shipwright-io/operator/pkg/common" tektonoperatorv1alpha1 "github.com/tektoncd/operator/pkg/apis/operator/v1alpha1" tektonoperatorclientv1alpha1 "github.com/tektoncd/operator/pkg/client/clientset/versioned/typed/operator/v1alpha1" crdclientv1 "k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset/typed/apiextensions/v1" @@ -36,8 +37,8 @@ func ReconcileTekton(ctx context.Context, if err != nil { return nil, true, fmt.Errorf("failed to determine Tekton Operator version: %v", err) } - if tektonVersion.Major() < 1 && tektonVersion.Minor() < 49 { - return nil, true, fmt.Errorf("insufficient Tekton Operator version - must be greater than v0.49.0") + if tektonVersion.Major() < common.TektonOpMinSupportedMajor+1 && tektonVersion.Minor() < common.TektonOpMinSupportedMinor { + return nil, true, fmt.Errorf("insufficient Tekton Operator version - must be greater than %s", common.TektonOpMinSupportedVersion) } tektonConfigPresent, err := IsTektonConfigPresent(ctx, tektonOperatorClient) if err != nil { @@ -85,11 +86,11 @@ func GetTektonOperatorVersion(ctx context.Context, client crdclientv1.Apiextensi return nil, err } if tektonOpCRD.Labels == nil { - return nil, fmt.Errorf("the CRD TektonConfig does not have labels set, inclding its version") + return nil, fmt.Errorf("the CRD TektonConfig does not have the label operator.tekton.dev/release to get its version") } - value, exists := tektonOpCRD.Labels["version"] + value, exists := tektonOpCRD.Labels["operator.tekton.dev/release"] if !exists { - return nil, fmt.Errorf("the CRD TektonConfig does not have labels set, inclding its version") + return nil, fmt.Errorf("the CRD TektonConfig does not have the label operator.tekton.dev/release to get its version") } version, err := version.ParseSemantic(value) if err != nil { diff --git a/pkg/tekton/tekton_test.go b/pkg/tekton/tekton_test.go index c08170a1..2b3a91f5 100644 --- a/pkg/tekton/tekton_test.go +++ b/pkg/tekton/tekton_test.go @@ -6,6 +6,8 @@ import ( "reflect" "testing" + "github.com/shipwright-io/operator/pkg/common" + o "github.com/onsi/gomega" tektonoperatorv1alpha1 "github.com/tektoncd/operator/pkg/apis/operator/v1alpha1" @@ -57,7 +59,7 @@ func TestReconcileTekton(t *testing.T) { ObjectMeta: metav1.ObjectMeta{ Name: "tektonconfigs.operator.tekton.dev", Labels: map[string]string{ - "version": "v0.36.0", + "operator.tekton.dev/release": "v0.36.0", }, }, }, @@ -70,7 +72,7 @@ func TestReconcileTekton(t *testing.T) { ObjectMeta: metav1.ObjectMeta{ Name: "tektonconfigs.operator.tekton.dev", Labels: map[string]string{ - "version": "v0.49.0", + "operator.tekton.dev/release": common.TektonOpMinSupportedVersion, }, }, }, @@ -82,7 +84,7 @@ func TestReconcileTekton(t *testing.T) { ObjectMeta: metav1.ObjectMeta{ Name: "tektonconfigs.operator.tekton.dev", Labels: map[string]string{ - "version": "v0.49.0", + "operator.tekton.dev/release": common.TektonOpMinSupportedVersion, }, }, }, @@ -97,7 +99,7 @@ func TestReconcileTekton(t *testing.T) { ObjectMeta: metav1.ObjectMeta{ Name: "tektonconfigs.operator.tekton.dev", Labels: map[string]string{ - "version": "v0.49.0", + "operator.tekton.dev/release": common.TektonOpMinSupportedVersion, }, }, }, @@ -289,7 +291,7 @@ func TestGetTektonOperatorVersion(t *testing.T) { expectError: true, }, { - name: "No version label on TektonConfig CRD", + name: "No release label on TektonConfig CRD", tektonConfigCRD: &apiextensionsv1.CustomResourceDefinition{ ObjectMeta: metav1.ObjectMeta{ Name: "tektonconfigs.operator.tekton.dev", @@ -301,12 +303,12 @@ func TestGetTektonOperatorVersion(t *testing.T) { expectError: true, }, { - name: "Version label on TektonConfig CRD is not a semver", + name: "release label on TektonConfig CRD is not a semver", tektonConfigCRD: &apiextensionsv1.CustomResourceDefinition{ ObjectMeta: metav1.ObjectMeta{ Name: "tektonconfigs.operator.tekton.dev", Labels: map[string]string{ - "version": "value", + "operator.tekton.dev/release": "value", }, }, }, @@ -318,11 +320,11 @@ func TestGetTektonOperatorVersion(t *testing.T) { ObjectMeta: metav1.ObjectMeta{ Name: "tektonconfigs.operator.tekton.dev", Labels: map[string]string{ - "version": "v0.49.0", + "operator.tekton.dev/release": common.TektonOpMinSupportedVersion, }, }, }, - expectedVersion: version.MustParseSemantic("0.49.0"), + expectedVersion: version.MustParseSemantic(common.TektonOpMinSupportedVersion), }, } for _, tc := range cases { diff --git a/test/catalog/operatorhubio/tektoncd-operator-bundle.json b/test/catalog/operatorhubio/tektoncd-operator-bundle.json index 52ecd00a..10bea07e 100644 --- a/test/catalog/operatorhubio/tektoncd-operator-bundle.json +++ b/test/catalog/operatorhubio/tektoncd-operator-bundle.json @@ -1,8 +1,8 @@ { "schema": "olm.bundle", - "name": "tektoncd-operator.v0.49.0", + "name": "tektoncd-operator.v0.61.0", "package": "tektoncd-operator", - "image": "quay.io/operatorhubio/tektoncd-operator:v0.49.0", + "image": "quay.io/operatorhubio/tektoncd-operator:v0.61.0", "properties": [ { "type": "olm.gvk", @@ -48,7 +48,7 @@ "type": "olm.package", "value": { "packageName": "tektoncd-operator", - "version": "0.49.0" + "version": "0.61.0" } } ], @@ -63,7 +63,7 @@ }, { "name": "", - "image": "quay.io/operatorhubio/tektoncd-operator:v0.49.0" + "image": "quay.io/operatorhubio/tektoncd-operator:v0.61.0" } ] } diff --git a/test/catalog/operatorhubio/tektoncd-operator-channel-alpha.json b/test/catalog/operatorhubio/tektoncd-operator-channel-alpha.json index 55adf3ba..26bf0399 100644 --- a/test/catalog/operatorhubio/tektoncd-operator-channel-alpha.json +++ b/test/catalog/operatorhubio/tektoncd-operator-channel-alpha.json @@ -4,7 +4,7 @@ "package": "tektoncd-operator", "entries": [ { - "name": "tektoncd-operator.v0.49.0" + "name": "tektoncd-operator.v0.61.0" } ] }