Skip to content

Commit

Permalink
Merge pull request #92 from jkhelil/BUILD-430
Browse files Browse the repository at this point in the history
Use operator.tekton.dev/release label to detect Tekton version
  • Loading branch information
openshift-merge-robot authored Aug 4, 2023
2 parents 5cc7189 + ba2bd7e commit f607171
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 22 deletions.
3 changes: 2 additions & 1 deletion controllers/default_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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{
Expand Down
4 changes: 3 additions & 1 deletion controllers/shipwrightbuild_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion docs/development/local-development.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions pkg/common/const.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package common

const (
TektonOpMinSupportedVersion = "v0.50.0"
TektonOpMinSupportedMajor = 0
TektonOpMinSupportedMinor = 50
)
11 changes: 6 additions & 5 deletions pkg/tekton/tekton.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
20 changes: 11 additions & 9 deletions pkg/tekton/tekton_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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",
},
},
},
Expand All @@ -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,
},
},
},
Expand All @@ -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,
},
},
},
Expand All @@ -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,
},
},
},
Expand Down Expand Up @@ -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",
Expand All @@ -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",
},
},
},
Expand All @@ -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 {
Expand Down
8 changes: 4 additions & 4 deletions test/catalog/operatorhubio/tektoncd-operator-bundle.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down Expand Up @@ -48,7 +48,7 @@
"type": "olm.package",
"value": {
"packageName": "tektoncd-operator",
"version": "0.49.0"
"version": "0.61.0"
}
}
],
Expand All @@ -63,7 +63,7 @@
},
{
"name": "",
"image": "quay.io/operatorhubio/tektoncd-operator:v0.49.0"
"image": "quay.io/operatorhubio/tektoncd-operator:v0.61.0"
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"package": "tektoncd-operator",
"entries": [
{
"name": "tektoncd-operator.v0.49.0"
"name": "tektoncd-operator.v0.61.0"
}
]
}

0 comments on commit f607171

Please sign in to comment.