From df78e1fd5dab0b918bf026e2dfeb1717ae626c05 Mon Sep 17 00:00:00 2001 From: PuneetPunamiya Date: Thu, 11 Nov 2021 14:42:05 +0530 Subject: [PATCH] Validates component CR name in webhook - This patch adds a check where it validates the name of the component CR before applying it on the cluster - This patch also moves all the constants to `pkg/apis/const.go` Fixes: #497 Signed-off-by: Puneet Punamiya --- pkg/apis/operator/v1alpha1/const.go | 26 ++++++++++++- .../v1alpha1/tektonaddon_validation.go | 4 ++ .../v1alpha1/tektonaddon_validation_test.go | 6 +-- .../v1alpha1/tektonconfig_validation.go | 4 ++ .../v1alpha1/tektonconfig_validation_test.go | 18 ++++----- .../v1alpha1/tektondashboard_validation.go | 4 ++ .../tektondashboard_validation_test.go | 2 +- .../v1alpha1/tektonpipeline_validation.go | 4 ++ .../tektonpipeline_validation_test.go | 2 +- .../v1alpha1/tektontrigger_validation.go | 4 ++ .../v1alpha1/tektontrigger_validation_test.go | 2 +- pkg/reconciler/common/common.go | 38 ++++--------------- pkg/reconciler/common/prune.go | 3 +- .../kubernetes/tektonconfig/extension.go | 11 +++--- .../tektonconfig/extension/dashboard.go | 14 +++---- .../tektonconfig/extension/dashboard_test.go | 6 +-- .../tektondashboard/tektondashboard.go | 5 ++- .../tektonpipeline/tektonpipeline.go | 7 ++-- .../kubernetes/tektonresult/tektonresult.go | 9 +++-- .../kubernetes/tektontrigger/tektontrigger.go | 11 +++--- .../openshift/tektonaddon/tektonaddon.go | 13 ++++--- .../openshift/tektonconfig/extension.go | 5 ++- .../openshift/tektonconfig/extension/addon.go | 14 +++---- .../tektonconfig/extension/addon_test.go | 6 +-- pkg/reconciler/openshift/tektonconfig/rbac.go | 4 +- .../openshift/tektonpipeline/extension.go | 3 +- .../openshift/tektontrigger/extension.go | 3 +- .../shared/tektonconfig/controller.go | 5 ++- .../shared/tektonconfig/instance.go | 6 +-- .../shared/tektonconfig/pipeline/pipeline.go | 16 ++++---- .../tektonconfig/pipeline/pipeline_test.go | 6 +-- .../shared/tektonconfig/tektonconfig.go | 13 ++++--- .../shared/tektonconfig/trigger/trigger.go | 14 +++---- .../tektonconfig/trigger/trigger_test.go | 6 +-- .../e2e/common/tektonconfigdeployment_test.go | 11 +++--- test/resources/tektonconfigs.go | 4 +- 36 files changed, 170 insertions(+), 139 deletions(-) diff --git a/pkg/apis/operator/v1alpha1/const.go b/pkg/apis/operator/v1alpha1/const.go index 1ef9aaa73d..24b256753f 100644 --- a/pkg/apis/operator/v1alpha1/const.go +++ b/pkg/apis/operator/v1alpha1/const.go @@ -16,7 +16,10 @@ limitations under the License. package v1alpha1 -import "fmt" +import ( + "fmt" + "time" +) var ( // RECONCILE_AGAIN_ERR @@ -62,3 +65,24 @@ var ( PipelineTemplatesParam: defaultParamValue, } ) + +var ( + // DefaultSA is the default service account + DefaultSA = "pipeline" + PipelineResourceName = "pipeline" + TriggerResourceName = "trigger" + DashboardResourceName = "dashboard" + AddonResourceName = "addon" + ConfigResourceName = "config" + ResultResourceName = "result" + Interval = 10 * time.Second + Timeout = 1 * time.Minute +) + +const ( + PipelineNotReady = "tekton-pipelines not ready" + PipelineNotFound = "tekton-pipelines not installed" + TriggerNotReady = "tekton-triggers not ready" + TriggerNotFound = "tekton-triggers not installed" + NamespaceIgnorePattern = "^(openshift|kube)-" +) diff --git a/pkg/apis/operator/v1alpha1/tektonaddon_validation.go b/pkg/apis/operator/v1alpha1/tektonaddon_validation.go index 48d8c21802..838d1712d8 100644 --- a/pkg/apis/operator/v1alpha1/tektonaddon_validation.go +++ b/pkg/apis/operator/v1alpha1/tektonaddon_validation.go @@ -28,6 +28,10 @@ func (ta *TektonAddon) Validate(ctx context.Context) (errs *apis.FieldError) { return nil } + if ta.GetName() != AddonResourceName { + errs = errs.Also(apis.ErrInvalidValue(ta.GetName(), "metadata.name, Only one instance of TektonAddon is allowed by name `addon`")) + } + if ta.Spec.TargetNamespace == "" { errs = errs.Also(apis.ErrMissingField("spec.targetNamespace")) } diff --git a/pkg/apis/operator/v1alpha1/tektonaddon_validation_test.go b/pkg/apis/operator/v1alpha1/tektonaddon_validation_test.go index 63f1aaeed5..02a30fd7c9 100644 --- a/pkg/apis/operator/v1alpha1/tektonaddon_validation_test.go +++ b/pkg/apis/operator/v1alpha1/tektonaddon_validation_test.go @@ -49,7 +49,7 @@ func Test_ValidateTektonAddon_InvalidParam(t *testing.T) { ta := &TektonAddon{ ObjectMeta: metav1.ObjectMeta{ - Name: "name", + Name: "addon", Namespace: "namespace", }, Spec: TektonAddonSpec{ @@ -73,7 +73,7 @@ func Test_ValidateTektonAddon_InvalidParamValue(t *testing.T) { ta := &TektonAddon{ ObjectMeta: metav1.ObjectMeta{ - Name: "name", + Name: "addon", Namespace: "namespace", }, Spec: TektonAddonSpec{ @@ -97,7 +97,7 @@ func Test_ValidateTektonAddon_ClusterTaskIsFalseAndPipelineTemplateIsTrue(t *tes ta := &TektonAddon{ ObjectMeta: metav1.ObjectMeta{ - Name: "name", + Name: "addon", Namespace: "namespace", }, Spec: TektonAddonSpec{ diff --git a/pkg/apis/operator/v1alpha1/tektonconfig_validation.go b/pkg/apis/operator/v1alpha1/tektonconfig_validation.go index d5ee1802e3..59e2a9ac6a 100644 --- a/pkg/apis/operator/v1alpha1/tektonconfig_validation.go +++ b/pkg/apis/operator/v1alpha1/tektonconfig_validation.go @@ -28,6 +28,10 @@ func (tc *TektonConfig) Validate(ctx context.Context) (errs *apis.FieldError) { return nil } + if tc.GetName() != ConfigResourceName { + errs = errs.Also(apis.ErrInvalidValue(tc.GetName(), "metadata.name, Only one instance of TektonConfig is allowed by name `config`")) + } + if tc.Spec.TargetNamespace == "" { errs = errs.Also(apis.ErrMissingField("spec.targetNamespace")) } diff --git a/pkg/apis/operator/v1alpha1/tektonconfig_validation_test.go b/pkg/apis/operator/v1alpha1/tektonconfig_validation_test.go index 11f39dc2b7..30f9529ba6 100644 --- a/pkg/apis/operator/v1alpha1/tektonconfig_validation_test.go +++ b/pkg/apis/operator/v1alpha1/tektonconfig_validation_test.go @@ -50,7 +50,7 @@ func Test_ValidateTektonConfig_MissingTargetNamespace(t *testing.T) { tc := &TektonConfig{ ObjectMeta: metav1.ObjectMeta{ - Name: "name", + Name: "config", Namespace: "namespace", }, Spec: TektonConfigSpec{}, @@ -64,7 +64,7 @@ func Test_ValidateTektonConfig_InvalidProfile(t *testing.T) { tc := &TektonConfig{ ObjectMeta: metav1.ObjectMeta{ - Name: "name", + Name: "config", Namespace: "namespace", }, Spec: TektonConfigSpec{ @@ -83,7 +83,7 @@ func Test_ValidateTektonConfig_InvalidPruningResource(t *testing.T) { tc := &TektonConfig{ ObjectMeta: metav1.ObjectMeta{ - Name: "name", + Name: "config", Namespace: "namespace", }, Spec: TektonConfigSpec{ @@ -106,7 +106,7 @@ func Test_ValidateTektonConfig_MissingKeepKeepsinceSchedule(t *testing.T) { tc := &TektonConfig{ ObjectMeta: metav1.ObjectMeta{ - Name: "name", + Name: "config", Namespace: "namespace", }, Spec: TektonConfigSpec{ @@ -128,7 +128,7 @@ func Test_ValidateTektonConfig_MissingSchedule(t *testing.T) { keep := uint(2) tc := &TektonConfig{ ObjectMeta: metav1.ObjectMeta{ - Name: "name", + Name: "config", Namespace: "namespace", }, Spec: TektonConfigSpec{ @@ -151,7 +151,7 @@ func Test_ValidateTektonConfig_InvalidAddonParam(t *testing.T) { tc := &TektonConfig{ ObjectMeta: metav1.ObjectMeta{ - Name: "name", + Name: "config", Namespace: "namespace", }, Spec: TektonConfigSpec{ @@ -178,7 +178,7 @@ func Test_ValidateTektonConfig_InvalidAddonParamValue(t *testing.T) { tc := &TektonConfig{ ObjectMeta: metav1.ObjectMeta{ - Name: "name", + Name: "config", Namespace: "namespace", }, Spec: TektonConfigSpec{ @@ -205,7 +205,7 @@ func Test_ValidateTektonConfig_InvalidPipelineProperties(t *testing.T) { tc := &TektonConfig{ ObjectMeta: metav1.ObjectMeta{ - Name: "name", + Name: "config", Namespace: "namespace", }, Spec: TektonConfigSpec{ @@ -229,7 +229,7 @@ func Test_ValidateTektonConfig_InvalidTriggerProperties(t *testing.T) { tc := &TektonConfig{ ObjectMeta: metav1.ObjectMeta{ - Name: "name", + Name: "config", Namespace: "namespace", }, Spec: TektonConfigSpec{ diff --git a/pkg/apis/operator/v1alpha1/tektondashboard_validation.go b/pkg/apis/operator/v1alpha1/tektondashboard_validation.go index 186f8473db..a5669fac16 100644 --- a/pkg/apis/operator/v1alpha1/tektondashboard_validation.go +++ b/pkg/apis/operator/v1alpha1/tektondashboard_validation.go @@ -28,6 +28,10 @@ func (td *TektonDashboard) Validate(ctx context.Context) (errs *apis.FieldError) return nil } + if td.GetName() != DashboardResourceName { + errs = errs.Also(apis.ErrInvalidValue(td.GetName(), "metadata.name, Only one instance of TektonDashboard is allowed by name `dashboard`")) + } + if td.Spec.TargetNamespace == "" { errs = errs.Also(apis.ErrMissingField("spec.targetNamespace")) } diff --git a/pkg/apis/operator/v1alpha1/tektondashboard_validation_test.go b/pkg/apis/operator/v1alpha1/tektondashboard_validation_test.go index c83e8e4a78..4ddaf08ede 100644 --- a/pkg/apis/operator/v1alpha1/tektondashboard_validation_test.go +++ b/pkg/apis/operator/v1alpha1/tektondashboard_validation_test.go @@ -29,7 +29,7 @@ func Test_ValidateTektonDashboard_MissingTargetNamespace(t *testing.T) { td := &TektonDashboard{ ObjectMeta: metav1.ObjectMeta{ - Name: "name", + Name: "dashboard", Namespace: "namespace", }, Spec: TektonDashboardSpec{}, diff --git a/pkg/apis/operator/v1alpha1/tektonpipeline_validation.go b/pkg/apis/operator/v1alpha1/tektonpipeline_validation.go index 94578665c5..5d24ddde5c 100644 --- a/pkg/apis/operator/v1alpha1/tektonpipeline_validation.go +++ b/pkg/apis/operator/v1alpha1/tektonpipeline_validation.go @@ -28,6 +28,10 @@ func (tp *TektonPipeline) Validate(ctx context.Context) (errs *apis.FieldError) return nil } + if tp.GetName() != PipelineResourceName { + errs = errs.Also(apis.ErrInvalidValue(tp.GetName(), "metadata.name, Only one instance of TektonPipeline is allowed by name `pipeline`")) + } + if tp.Spec.TargetNamespace == "" { errs = errs.Also(apis.ErrMissingField("spec.targetNamespace")) } diff --git a/pkg/apis/operator/v1alpha1/tektonpipeline_validation_test.go b/pkg/apis/operator/v1alpha1/tektonpipeline_validation_test.go index 0e49fa39c9..56b37e1a38 100644 --- a/pkg/apis/operator/v1alpha1/tektonpipeline_validation_test.go +++ b/pkg/apis/operator/v1alpha1/tektonpipeline_validation_test.go @@ -29,7 +29,7 @@ func Test_ValidateTektonPipeline_MissingTargetNamespace(t *testing.T) { tp := &TektonPipeline{ ObjectMeta: metav1.ObjectMeta{ - Name: "name", + Name: "pipeline", Namespace: "namespace", }, Spec: TektonPipelineSpec{}, diff --git a/pkg/apis/operator/v1alpha1/tektontrigger_validation.go b/pkg/apis/operator/v1alpha1/tektontrigger_validation.go index e3e58b513d..70cb7fa93b 100644 --- a/pkg/apis/operator/v1alpha1/tektontrigger_validation.go +++ b/pkg/apis/operator/v1alpha1/tektontrigger_validation.go @@ -28,6 +28,10 @@ func (tr *TektonTrigger) Validate(ctx context.Context) (errs *apis.FieldError) { return nil } + if tr.GetName() != TriggerResourceName { + errs = errs.Also(apis.ErrInvalidValue(tr.GetName(), "metadata.name, Only one instance of TektonTrigger is allowed by name `trigger`")) + } + if tr.Spec.TargetNamespace == "" { errs = errs.Also(apis.ErrMissingField("spec.targetNamespace")) } diff --git a/pkg/apis/operator/v1alpha1/tektontrigger_validation_test.go b/pkg/apis/operator/v1alpha1/tektontrigger_validation_test.go index 1e44716ac2..57f0dabeb7 100644 --- a/pkg/apis/operator/v1alpha1/tektontrigger_validation_test.go +++ b/pkg/apis/operator/v1alpha1/tektontrigger_validation_test.go @@ -29,7 +29,7 @@ func Test_ValidateTektonTrigger_MissingTargetNamespace(t *testing.T) { tr := &TektonTrigger{ ObjectMeta: metav1.ObjectMeta{ - Name: "name", + Name: "trigger", Namespace: "namespace", }, Spec: TektonTriggerSpec{}, diff --git a/pkg/reconciler/common/common.go b/pkg/reconciler/common/common.go index 1a84c75bbd..453fb917f9 100644 --- a/pkg/reconciler/common/common.go +++ b/pkg/reconciler/common/common.go @@ -18,57 +18,33 @@ package common import ( "fmt" - "time" "github.com/tektoncd/operator/pkg/apis/operator/v1alpha1" + res "github.com/tektoncd/operator/pkg/apis/operator/v1alpha1" informer "github.com/tektoncd/operator/pkg/client/informers/externalversions/operator/v1alpha1" corev1 "k8s.io/api/core/v1" apierrors "k8s.io/apimachinery/pkg/api/errors" ) -var ( - // DefaultSA is the default service account - DefaultSA = "pipeline" - PipelineResourceName = "pipeline" - TriggerResourceName = "trigger" - DashboardResourceName = "dashboard" - AddonResourceName = "addon" - ConfigResourceName = "config" - ResultResourceName = "result" - ProfileLite = "lite" - ProfileBasic = "basic" - ProfileAll = "all" - Interval = 10 * time.Second - Timeout = 1 * time.Minute -) - -const ( - PipelineNotReady = "tekton-pipelines not ready" - PipelineNotFound = "tekton-pipelines not installed" - TriggerNotReady = "tekton-triggers not ready" - TriggerNotFound = "tekton-triggers not installed" - NamespaceIgnorePattern = "^(openshift|kube)-" -) - func PipelineReady(informer informer.TektonPipelineInformer) (*v1alpha1.TektonPipeline, error) { ppln, err := getPipelineRes(informer) if err != nil { if apierrors.IsNotFound(err) { - return nil, fmt.Errorf(PipelineNotFound) + return nil, fmt.Errorf(res.PipelineNotFound) } return nil, err } if len(ppln.Status.Conditions) != 0 { if ppln.Status.Conditions[0].Status != corev1.ConditionTrue { - return nil, fmt.Errorf(PipelineNotReady) + return nil, fmt.Errorf(res.PipelineNotReady) } } return ppln, nil } func getPipelineRes(informer informer.TektonPipelineInformer) (*v1alpha1.TektonPipeline, error) { - res, err := informer.Lister().Get(PipelineResourceName) + res, err := informer.Lister().Get(res.PipelineResourceName) return res, err } @@ -76,20 +52,20 @@ func TriggerReady(informer informer.TektonTriggerInformer) (*v1alpha1.TektonTrig trigger, err := getTriggerRes(informer) if err != nil { if apierrors.IsNotFound(err) { - return nil, fmt.Errorf(TriggerNotFound) + return nil, fmt.Errorf(res.TriggerNotFound) } return nil, err } if len(trigger.Status.Conditions) != 0 { if trigger.Status.Conditions[0].Status != corev1.ConditionTrue { - return nil, fmt.Errorf(TriggerNotReady) + return nil, fmt.Errorf(res.TriggerNotReady) } } return trigger, nil } func getTriggerRes(informer informer.TektonTriggerInformer) (*v1alpha1.TektonTrigger, error) { - res, err := informer.Lister().Get(TriggerResourceName) + res, err := informer.Lister().Get(res.TriggerResourceName) return res, err } diff --git a/pkg/reconciler/common/prune.go b/pkg/reconciler/common/prune.go index 3ef40bf301..d1de4ad063 100644 --- a/pkg/reconciler/common/prune.go +++ b/pkg/reconciler/common/prune.go @@ -25,6 +25,7 @@ import ( "strings" "github.com/tektoncd/operator/pkg/apis/operator/v1alpha1" + res "github.com/tektoncd/operator/pkg/apis/operator/v1alpha1" batchv1 "k8s.io/api/batch/v1" corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/api/errors" @@ -146,7 +147,7 @@ func prunableNamespaces(ctx context.Context, k kubernetes.Interface, defaultPrun var prunableNs pruningNs commonSchedule := make(map[string]*pruneConfigPerNS) uniqueSchedule := make(map[string]*pruneConfigPerNS) - re := regexp.MustCompile(NamespaceIgnorePattern) + re := regexp.MustCompile(res.NamespaceIgnorePattern) for _, ns := range nsList.Items { if ignore := re.MatchString(ns.GetName()); ignore { continue diff --git a/pkg/reconciler/kubernetes/tektonconfig/extension.go b/pkg/reconciler/kubernetes/tektonconfig/extension.go index 75132d759a..079bd0747a 100644 --- a/pkg/reconciler/kubernetes/tektonconfig/extension.go +++ b/pkg/reconciler/kubernetes/tektonconfig/extension.go @@ -21,6 +21,7 @@ import ( mf "github.com/manifestival/manifestival" "github.com/tektoncd/operator/pkg/apis/operator/v1alpha1" + res "github.com/tektoncd/operator/pkg/apis/operator/v1alpha1" "github.com/tektoncd/operator/pkg/client/clientset/versioned" operatorclient "github.com/tektoncd/operator/pkg/client/injection/client" "github.com/tektoncd/operator/pkg/reconciler/common" @@ -46,20 +47,20 @@ func (oe kubernetesExtension) PreReconcile(context.Context, v1alpha1.TektonCompo func (oe kubernetesExtension) PostReconcile(ctx context.Context, comp v1alpha1.TektonComponent) error { configInstance := comp.(*v1alpha1.TektonConfig) - if configInstance.Spec.Profile == common.ProfileAll { + if configInstance.Spec.Profile == res.ProfileAll { return extension.CreateDashboardCR(comp, oe.operatorClientSet.OperatorV1alpha1()) } - if configInstance.Spec.Profile == common.ProfileLite || configInstance.Spec.Profile == common.ProfileBasic { - return extension.TektonDashboardCRDelete(oe.operatorClientSet.OperatorV1alpha1().TektonDashboards(), common.DashboardResourceName) + if configInstance.Spec.Profile == res.ProfileLite || configInstance.Spec.Profile == res.ProfileBasic { + return extension.TektonDashboardCRDelete(oe.operatorClientSet.OperatorV1alpha1().TektonDashboards(), res.DashboardResourceName) } return nil } func (oe kubernetesExtension) Finalize(ctx context.Context, comp v1alpha1.TektonComponent) error { configInstance := comp.(*v1alpha1.TektonConfig) - if configInstance.Spec.Profile == common.ProfileAll { - return extension.TektonDashboardCRDelete(oe.operatorClientSet.OperatorV1alpha1().TektonDashboards(), common.DashboardResourceName) + if configInstance.Spec.Profile == res.ProfileAll { + return extension.TektonDashboardCRDelete(oe.operatorClientSet.OperatorV1alpha1().TektonDashboards(), res.DashboardResourceName) } return nil } diff --git a/pkg/reconciler/kubernetes/tektonconfig/extension/dashboard.go b/pkg/reconciler/kubernetes/tektonconfig/extension/dashboard.go index 3cb4b237a7..bf88f91cff 100644 --- a/pkg/reconciler/kubernetes/tektonconfig/extension/dashboard.go +++ b/pkg/reconciler/kubernetes/tektonconfig/extension/dashboard.go @@ -24,9 +24,9 @@ import ( "reflect" "github.com/tektoncd/operator/pkg/apis/operator/v1alpha1" + res "github.com/tektoncd/operator/pkg/apis/operator/v1alpha1" op "github.com/tektoncd/operator/pkg/client/clientset/versioned/typed/operator/v1alpha1" operatorv1alpha1 "github.com/tektoncd/operator/pkg/client/clientset/versioned/typed/operator/v1alpha1" - "github.com/tektoncd/operator/pkg/reconciler/common" apierrs "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/util/wait" @@ -38,7 +38,7 @@ func CreateDashboardCR(instance v1alpha1.TektonComponent, client operatorv1alpha if _, err := ensureTektonDashboardExists(client.TektonDashboards(), configInstance); err != nil { return errors.New(err.Error()) } - if _, err := waitForTektonDashboardState(client.TektonDashboards(), common.DashboardResourceName, + if _, err := waitForTektonDashboardState(client.TektonDashboards(), res.DashboardResourceName, isTektonDashboardReady); err != nil { log.Println("TektonDashboard is not in ready state: ", err) return err @@ -47,7 +47,7 @@ func CreateDashboardCR(instance v1alpha1.TektonComponent, client operatorv1alpha } func ensureTektonDashboardExists(clients op.TektonDashboardInterface, config *v1alpha1.TektonConfig) (*v1alpha1.TektonDashboard, error) { - tdCR, err := GetDashboard(clients, common.DashboardResourceName) + tdCR, err := GetDashboard(clients, res.DashboardResourceName) if err == nil { // if the dashboard spec is changed then update the instance updated := false @@ -83,7 +83,7 @@ func ensureTektonDashboardExists(clients op.TektonDashboardInterface, config *v1 if apierrs.IsNotFound(err) { tdCR = &v1alpha1.TektonDashboard{ ObjectMeta: metav1.ObjectMeta{ - Name: common.DashboardResourceName, + Name: res.DashboardResourceName, }, Spec: v1alpha1.TektonDashboardSpec{ CommonSpec: v1alpha1.CommonSpec{ @@ -111,7 +111,7 @@ func waitForTektonDashboardState(clients op.TektonDashboardInterface, name strin defer span.End() var lastState *v1alpha1.TektonDashboard - waitErr := wait.PollImmediate(common.Interval, common.Timeout, func() (bool, error) { + waitErr := wait.PollImmediate(res.Interval, res.Timeout, func() (bool, error) { lastState, err := clients.Get(context.TODO(), name, metav1.GetOptions{}) return inState(lastState, err) }) @@ -128,7 +128,7 @@ func isTektonDashboardReady(s *v1alpha1.TektonDashboard, err error) (bool, error // TektonDashboardCRDelete deletes tha TektonDashboard to see if all resources will be deleted func TektonDashboardCRDelete(clients op.TektonDashboardInterface, name string) error { - if _, err := GetDashboard(clients, common.DashboardResourceName); err != nil { + if _, err := GetDashboard(clients, res.DashboardResourceName); err != nil { if apierrs.IsNotFound(err) { return nil } @@ -137,7 +137,7 @@ func TektonDashboardCRDelete(clients op.TektonDashboardInterface, name string) e if err := clients.Delete(context.TODO(), name, metav1.DeleteOptions{}); err != nil { return fmt.Errorf("TektonDashboard %q failed to delete: %v", name, err) } - err := wait.PollImmediate(common.Interval, common.Timeout, func() (bool, error) { + err := wait.PollImmediate(res.Interval, res.Timeout, func() (bool, error) { _, err := clients.Get(context.TODO(), name, metav1.GetOptions{}) if apierrs.IsNotFound(err) { return true, nil diff --git a/pkg/reconciler/kubernetes/tektonconfig/extension/dashboard_test.go b/pkg/reconciler/kubernetes/tektonconfig/extension/dashboard_test.go index d346b6ea6a..dc046afd47 100644 --- a/pkg/reconciler/kubernetes/tektonconfig/extension/dashboard_test.go +++ b/pkg/reconciler/kubernetes/tektonconfig/extension/dashboard_test.go @@ -19,8 +19,8 @@ package extension import ( "testing" + res "github.com/tektoncd/operator/pkg/apis/operator/v1alpha1" "github.com/tektoncd/operator/pkg/client/injection/client/fake" - "github.com/tektoncd/operator/pkg/reconciler/common" util "github.com/tektoncd/operator/pkg/reconciler/common/testing" "github.com/tektoncd/operator/pkg/reconciler/shared/tektonconfig/pipeline" ts "knative.dev/pkg/reconciler/testing" @@ -32,13 +32,13 @@ func TestTektonDashboardCreateAndDeleteCR(t *testing.T) { tConfig := pipeline.GetTektonConfig() err := CreateDashboardCR(tConfig, c.OperatorV1alpha1()) util.AssertNotEqual(t, err, nil) - err = TektonDashboardCRDelete(c.OperatorV1alpha1().TektonDashboards(), common.DashboardResourceName) + err = TektonDashboardCRDelete(c.OperatorV1alpha1().TektonDashboards(), res.DashboardResourceName) util.AssertEqual(t, err, nil) } func TestTektonDashboardCRDelete(t *testing.T) { ctx, _, _ := ts.SetupFakeContextWithCancel(t) c := fake.Get(ctx) - err := TektonDashboardCRDelete(c.OperatorV1alpha1().TektonDashboards(), common.DashboardResourceName) + err := TektonDashboardCRDelete(c.OperatorV1alpha1().TektonDashboards(), res.DashboardResourceName) util.AssertEqual(t, err, nil) } diff --git a/pkg/reconciler/kubernetes/tektondashboard/tektondashboard.go b/pkg/reconciler/kubernetes/tektondashboard/tektondashboard.go index 44f9ae0cc0..4b4ff47652 100644 --- a/pkg/reconciler/kubernetes/tektondashboard/tektondashboard.go +++ b/pkg/reconciler/kubernetes/tektondashboard/tektondashboard.go @@ -25,6 +25,7 @@ import ( "k8s.io/client-go/kubernetes" "github.com/tektoncd/operator/pkg/apis/operator/v1alpha1" + res "github.com/tektoncd/operator/pkg/apis/operator/v1alpha1" clientset "github.com/tektoncd/operator/pkg/client/clientset/versioned" pipelineinformer "github.com/tektoncd/operator/pkg/client/informers/externalversions/operator/v1alpha1" tektondashboardreconciler "github.com/tektoncd/operator/pkg/client/injection/reconciler/operator/v1alpha1/tektondashboard" @@ -109,10 +110,10 @@ func (r *Reconciler) ReconcileKind(ctx context.Context, tt *v1alpha1.TektonDashb // find the valid tekton-pipeline installation if _, err := common.PipelineReady(r.pipelineInformer); err != nil { - if err.Error() == common.PipelineNotReady { + if err.Error() == res.PipelineNotReady { tt.Status.MarkDependencyInstalling("tekton-pipelines is still installing") // wait for pipeline status to change - return fmt.Errorf(common.PipelineNotReady) + return fmt.Errorf(res.PipelineNotReady) } // (tektonpipeline.opeator.tekton.dev instance not available yet) tt.Status.MarkDependencyMissing("tekton-pipelines does not exist") diff --git a/pkg/reconciler/kubernetes/tektonpipeline/tektonpipeline.go b/pkg/reconciler/kubernetes/tektonpipeline/tektonpipeline.go index c09a92882d..4e9299b8ab 100644 --- a/pkg/reconciler/kubernetes/tektonpipeline/tektonpipeline.go +++ b/pkg/reconciler/kubernetes/tektonpipeline/tektonpipeline.go @@ -24,6 +24,7 @@ import ( mf "github.com/manifestival/manifestival" "github.com/tektoncd/operator/pkg/apis/operator/v1alpha1" + res "github.com/tektoncd/operator/pkg/apis/operator/v1alpha1" clientset "github.com/tektoncd/operator/pkg/client/clientset/versioned" tektonpipelinereconciler "github.com/tektoncd/operator/pkg/client/injection/reconciler/operator/v1alpha1/tektonpipeline" "github.com/tektoncd/operator/pkg/reconciler/common" @@ -106,9 +107,9 @@ func (r *Reconciler) ReconcileKind(ctx context.Context, tp *v1alpha1.TektonPipel logger := logging.FromContext(ctx) tp.Status.InitializeConditions() - if tp.GetName() != common.PipelineResourceName { + if tp.GetName() != res.PipelineResourceName { msg := fmt.Sprintf("Resource ignored, Expected Name: %s, Got Name: %s", - common.PipelineResourceName, + res.PipelineResourceName, tp.GetName(), ) logger.Error(msg) @@ -312,7 +313,7 @@ func makeInstallerSet(tp *v1alpha1.TektonPipeline, manifest mf.Manifest, tpSpecH ownerRef := *metav1.NewControllerRef(tp, tp.GetGroupVersionKind()) return &v1alpha1.TektonInstallerSet{ ObjectMeta: metav1.ObjectMeta{ - GenerateName: fmt.Sprintf("%s-", common.PipelineResourceName), + GenerateName: fmt.Sprintf("%s-", res.PipelineResourceName), Labels: map[string]string{ createdByKey: createdByValue, }, diff --git a/pkg/reconciler/kubernetes/tektonresult/tektonresult.go b/pkg/reconciler/kubernetes/tektonresult/tektonresult.go index 69a8d45032..b9f62bf72b 100644 --- a/pkg/reconciler/kubernetes/tektonresult/tektonresult.go +++ b/pkg/reconciler/kubernetes/tektonresult/tektonresult.go @@ -25,6 +25,7 @@ import ( mf "github.com/manifestival/manifestival" "github.com/tektoncd/operator/pkg/apis/operator/v1alpha1" + res "github.com/tektoncd/operator/pkg/apis/operator/v1alpha1" clientset "github.com/tektoncd/operator/pkg/client/clientset/versioned" pipelineInformer "github.com/tektoncd/operator/pkg/client/informers/externalversions/operator/v1alpha1" tektonresultconciler "github.com/tektoncd/operator/pkg/client/injection/reconciler/operator/v1alpha1/tektonresult" @@ -101,9 +102,9 @@ func (r *Reconciler) ReconcileKind(ctx context.Context, tr *v1alpha1.TektonResul logger.Infow("Reconciling TektonResults", "status", tr.Status) - if tr.GetName() != common.ResultResourceName { + if tr.GetName() != res.ResultResourceName { msg := fmt.Sprintf("Resource ignored, Expected Name: %s, Got Name: %s", - common.ResultResourceName, + res.ResultResourceName, tr.GetName(), ) logger.Error(msg) @@ -114,10 +115,10 @@ func (r *Reconciler) ReconcileKind(ctx context.Context, tr *v1alpha1.TektonResul // find the valid tekton-pipeline installation tp, err := common.PipelineReady(r.pipelineInformer) if err != nil { - if err.Error() == common.PipelineNotReady { + if err.Error() == res.PipelineNotReady { tr.Status.MarkDependencyInstalling("tekton-pipelines is still installing") // wait for pipeline status to change - return fmt.Errorf(common.PipelineNotReady) + return fmt.Errorf(res.PipelineNotReady) } // tektonpipeline.operator.tekton.dev instance not available yet tr.Status.MarkDependencyMissing("tekton-pipelines does not exist") diff --git a/pkg/reconciler/kubernetes/tektontrigger/tektontrigger.go b/pkg/reconciler/kubernetes/tektontrigger/tektontrigger.go index 00ac222601..6ef3411867 100644 --- a/pkg/reconciler/kubernetes/tektontrigger/tektontrigger.go +++ b/pkg/reconciler/kubernetes/tektontrigger/tektontrigger.go @@ -24,6 +24,7 @@ import ( mf "github.com/manifestival/manifestival" "github.com/tektoncd/operator/pkg/apis/operator/v1alpha1" + res "github.com/tektoncd/operator/pkg/apis/operator/v1alpha1" clientset "github.com/tektoncd/operator/pkg/client/clientset/versioned" pipelineinformer "github.com/tektoncd/operator/pkg/client/informers/externalversions/operator/v1alpha1" tektontriggerreconciler "github.com/tektoncd/operator/pkg/client/injection/reconciler/operator/v1alpha1/tektontrigger" @@ -106,9 +107,9 @@ func (r *Reconciler) ReconcileKind(ctx context.Context, tt *v1alpha1.TektonTrigg logger := logging.FromContext(ctx) tt.Status.InitializeConditions() - if tt.GetName() != common.TriggerResourceName { + if tt.GetName() != res.TriggerResourceName { msg := fmt.Sprintf("Resource ignored, Expected Name: %s, Got Name: %s", - common.TriggerResourceName, + res.TriggerResourceName, tt.GetName(), ) logger.Error(msg) @@ -119,10 +120,10 @@ func (r *Reconciler) ReconcileKind(ctx context.Context, tt *v1alpha1.TektonTrigg // Make sure TektonPipeline is installed before proceeding with // TektonTrigger if _, err := common.PipelineReady(r.pipelineInformer); err != nil { - if err.Error() == common.PipelineNotReady { + if err.Error() == res.PipelineNotReady { tt.Status.MarkDependencyInstalling("tekton-pipelines is still installing") // wait for pipeline status to change - return fmt.Errorf(common.PipelineNotReady) + return fmt.Errorf(res.PipelineNotReady) } // (tektonpipeline.operator.tekton.dev instance not available yet) tt.Status.MarkDependencyMissing("tekton-pipelines does not exist") @@ -352,7 +353,7 @@ func makeInstallerSet(tt *v1alpha1.TektonTrigger, manifest mf.Manifest, ttSpecHa ownerRef := *metav1.NewControllerRef(tt, tt.GetGroupVersionKind()) return &v1alpha1.TektonInstallerSet{ ObjectMeta: metav1.ObjectMeta{ - GenerateName: fmt.Sprintf("%s-", common.TriggerResourceName), + GenerateName: fmt.Sprintf("%s-", res.TriggerResourceName), Labels: map[string]string{ createdByKey: createdByValue, }, diff --git a/pkg/reconciler/openshift/tektonaddon/tektonaddon.go b/pkg/reconciler/openshift/tektonaddon/tektonaddon.go index c893ac1e0a..305773be6e 100644 --- a/pkg/reconciler/openshift/tektonaddon/tektonaddon.go +++ b/pkg/reconciler/openshift/tektonaddon/tektonaddon.go @@ -26,6 +26,7 @@ import ( mf "github.com/manifestival/manifestival" "github.com/tektoncd/operator/pkg/apis/operator/v1alpha1" + res "github.com/tektoncd/operator/pkg/apis/operator/v1alpha1" clientset "github.com/tektoncd/operator/pkg/client/clientset/versioned" informer "github.com/tektoncd/operator/pkg/client/informers/externalversions/operator/v1alpha1" tektonaddonreconciler "github.com/tektoncd/operator/pkg/client/injection/reconciler/operator/v1alpha1/tektonaddon" @@ -120,9 +121,9 @@ func (r *Reconciler) ReconcileKind(ctx context.Context, ta *v1alpha1.TektonAddon logger := logging.FromContext(ctx) ta.Status.InitializeConditions() - if ta.GetName() != common.AddonResourceName { + if ta.GetName() != res.AddonResourceName { msg := fmt.Sprintf("Resource ignored, Expected Name: %s, Got Name: %s", - common.AddonResourceName, + res.AddonResourceName, ta.GetName(), ) logger.Error(msg) @@ -134,10 +135,10 @@ func (r *Reconciler) ReconcileKind(ctx context.Context, ta *v1alpha1.TektonAddon // TektonAddons if _, err := common.PipelineReady(r.pipelineInformer); err != nil { - if err.Error() == common.PipelineNotReady { + if err.Error() == res.PipelineNotReady { ta.Status.MarkDependencyInstalling("tekton-pipelines is still installing") // wait for pipeline status to change - return fmt.Errorf(common.PipelineNotReady) + return fmt.Errorf(res.PipelineNotReady) } // (tektonpipeline.operator.tekton.dev instance not available yet) ta.Status.MarkDependencyMissing("tekton-pipelines does not exist") @@ -145,10 +146,10 @@ func (r *Reconciler) ReconcileKind(ctx context.Context, ta *v1alpha1.TektonAddon } if _, err := common.TriggerReady(r.triggerInformer); err != nil { - if err.Error() == common.TriggerNotReady { + if err.Error() == res.TriggerNotReady { ta.Status.MarkDependencyInstalling("tekton-triggers is still installing") // wait for trigger status to change - return fmt.Errorf(common.TriggerNotReady) + return fmt.Errorf(res.TriggerNotReady) } // (tektontrigger.operator.tekton.dev instance not available yet) ta.Status.MarkDependencyMissing("tekton-triggers does not exist") diff --git a/pkg/reconciler/openshift/tektonconfig/extension.go b/pkg/reconciler/openshift/tektonconfig/extension.go index 9d905e5e9d..55a4ced3da 100644 --- a/pkg/reconciler/openshift/tektonconfig/extension.go +++ b/pkg/reconciler/openshift/tektonconfig/extension.go @@ -22,6 +22,7 @@ import ( mf "github.com/manifestival/manifestival" "github.com/tektoncd/operator/pkg/apis/operator/v1alpha1" + res "github.com/tektoncd/operator/pkg/apis/operator/v1alpha1" "github.com/tektoncd/operator/pkg/client/clientset/versioned" operatorclient "github.com/tektoncd/operator/pkg/client/injection/client" "github.com/tektoncd/operator/pkg/reconciler/common" @@ -108,7 +109,7 @@ func (oe openshiftExtension) PostReconcile(ctx context.Context, comp v1alpha1.Te } if configInstance.Spec.Profile == v1alpha1.ProfileBasic || configInstance.Spec.Profile == v1alpha1.ProfileLite { - return extension.TektonAddonCRDelete(oe.operatorClientSet.OperatorV1alpha1().TektonAddons(), common.AddonResourceName) + return extension.TektonAddonCRDelete(oe.operatorClientSet.OperatorV1alpha1().TektonAddons(), res.AddonResourceName) } return nil @@ -116,7 +117,7 @@ func (oe openshiftExtension) PostReconcile(ctx context.Context, comp v1alpha1.Te func (oe openshiftExtension) Finalize(ctx context.Context, comp v1alpha1.TektonComponent) error { configInstance := comp.(*v1alpha1.TektonConfig) if configInstance.Spec.Profile == v1alpha1.ProfileAll { - if err := extension.TektonAddonCRDelete(oe.operatorClientSet.OperatorV1alpha1().TektonAddons(), common.AddonResourceName); err != nil { + if err := extension.TektonAddonCRDelete(oe.operatorClientSet.OperatorV1alpha1().TektonAddons(), res.AddonResourceName); err != nil { return err } } diff --git a/pkg/reconciler/openshift/tektonconfig/extension/addon.go b/pkg/reconciler/openshift/tektonconfig/extension/addon.go index 50f9e57dc2..fdcdee6f18 100644 --- a/pkg/reconciler/openshift/tektonconfig/extension/addon.go +++ b/pkg/reconciler/openshift/tektonconfig/extension/addon.go @@ -24,9 +24,9 @@ import ( "reflect" "github.com/tektoncd/operator/pkg/apis/operator/v1alpha1" + res "github.com/tektoncd/operator/pkg/apis/operator/v1alpha1" op "github.com/tektoncd/operator/pkg/client/clientset/versioned/typed/operator/v1alpha1" operatorv1alpha1 "github.com/tektoncd/operator/pkg/client/clientset/versioned/typed/operator/v1alpha1" - "github.com/tektoncd/operator/pkg/reconciler/common" apierrs "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/util/wait" @@ -38,7 +38,7 @@ func CreateAddonCR(instance v1alpha1.TektonComponent, client operatorv1alpha1.Op if _, err := ensureTektonAddonExists(client.TektonAddons(), configInstance); err != nil { return errors.New(err.Error()) } - if _, err := waitForTektonAddonState(client.TektonAddons(), common.AddonResourceName, + if _, err := waitForTektonAddonState(client.TektonAddons(), res.AddonResourceName, isTektonAddonReady); err != nil { log.Println("TektonAddon is not in ready state: ", err) return err @@ -47,7 +47,7 @@ func CreateAddonCR(instance v1alpha1.TektonComponent, client operatorv1alpha1.Op } func ensureTektonAddonExists(clients op.TektonAddonInterface, config *v1alpha1.TektonConfig) (*v1alpha1.TektonAddon, error) { - taCR, err := GetAddon(clients, common.AddonResourceName) + taCR, err := GetAddon(clients, res.AddonResourceName) if err == nil { // if the addon spec is changed then update the instance updated := false @@ -80,7 +80,7 @@ func ensureTektonAddonExists(clients op.TektonAddonInterface, config *v1alpha1.T if apierrs.IsNotFound(err) { taCR = &v1alpha1.TektonAddon{ ObjectMeta: metav1.ObjectMeta{ - Name: common.AddonResourceName, + Name: res.AddonResourceName, OwnerReferences: []metav1.OwnerReference{ownerRef}, }, Spec: v1alpha1.TektonAddonSpec{ @@ -108,7 +108,7 @@ func waitForTektonAddonState(clients op.TektonAddonInterface, name string, defer span.End() var lastState *v1alpha1.TektonAddon - waitErr := wait.PollImmediate(common.Interval, common.Timeout, func() (bool, error) { + waitErr := wait.PollImmediate(res.Interval, res.Timeout, func() (bool, error) { lastState, err := clients.Get(context.TODO(), name, metav1.GetOptions{}) return inState(lastState, err) }) @@ -126,7 +126,7 @@ func isTektonAddonReady(s *v1alpha1.TektonAddon, err error) (bool, error) { // TektonAddonCRDelete deletes tha TektonAddon to see if all resources will be deleted func TektonAddonCRDelete(clients op.TektonAddonInterface, name string) error { - if _, err := GetAddon(clients, common.AddonResourceName); err != nil { + if _, err := GetAddon(clients, res.AddonResourceName); err != nil { if apierrs.IsNotFound(err) { return nil } @@ -135,7 +135,7 @@ func TektonAddonCRDelete(clients op.TektonAddonInterface, name string) error { if err := clients.Delete(context.TODO(), name, metav1.DeleteOptions{}); err != nil { return fmt.Errorf("TektonAddon %q failed to delete: %v", name, err) } - err := wait.PollImmediate(common.Interval, common.Timeout, func() (bool, error) { + err := wait.PollImmediate(res.Interval, res.Timeout, func() (bool, error) { _, err := clients.Get(context.TODO(), name, metav1.GetOptions{}) if apierrs.IsNotFound(err) { return true, nil diff --git a/pkg/reconciler/openshift/tektonconfig/extension/addon_test.go b/pkg/reconciler/openshift/tektonconfig/extension/addon_test.go index 895aa43b92..dcf071f31a 100644 --- a/pkg/reconciler/openshift/tektonconfig/extension/addon_test.go +++ b/pkg/reconciler/openshift/tektonconfig/extension/addon_test.go @@ -19,8 +19,8 @@ package extension import ( "testing" + res "github.com/tektoncd/operator/pkg/apis/operator/v1alpha1" "github.com/tektoncd/operator/pkg/client/injection/client/fake" - "github.com/tektoncd/operator/pkg/reconciler/common" util "github.com/tektoncd/operator/pkg/reconciler/common/testing" "github.com/tektoncd/operator/pkg/reconciler/shared/tektonconfig/pipeline" ts "knative.dev/pkg/reconciler/testing" @@ -32,13 +32,13 @@ func TestTektonAddonCreateAndDeleteCR(t *testing.T) { tConfig := pipeline.GetTektonConfig() err := CreateAddonCR(tConfig, c.OperatorV1alpha1()) util.AssertNotEqual(t, err, nil) - err = TektonAddonCRDelete(c.OperatorV1alpha1().TektonAddons(), common.AddonResourceName) + err = TektonAddonCRDelete(c.OperatorV1alpha1().TektonAddons(), res.AddonResourceName) util.AssertEqual(t, err, nil) } func TestTektonAddonCRDelete(t *testing.T) { ctx, _, _ := ts.SetupFakeContextWithCancel(t) c := fake.Get(ctx) - err := TektonAddonCRDelete(c.OperatorV1alpha1().TektonAddons(), common.AddonResourceName) + err := TektonAddonCRDelete(c.OperatorV1alpha1().TektonAddons(), res.AddonResourceName) util.AssertEqual(t, err, nil) } diff --git a/pkg/reconciler/openshift/tektonconfig/rbac.go b/pkg/reconciler/openshift/tektonconfig/rbac.go index 919b109905..9346a79080 100644 --- a/pkg/reconciler/openshift/tektonconfig/rbac.go +++ b/pkg/reconciler/openshift/tektonconfig/rbac.go @@ -22,8 +22,8 @@ import ( "regexp" "github.com/tektoncd/operator/pkg/apis/operator/v1alpha1" + res "github.com/tektoncd/operator/pkg/apis/operator/v1alpha1" clientset "github.com/tektoncd/operator/pkg/client/clientset/versioned" - "github.com/tektoncd/operator/pkg/reconciler/common" corev1 "k8s.io/api/core/v1" rbacv1 "k8s.io/api/rbac/v1" "k8s.io/apimachinery/pkg/api/errors" @@ -51,7 +51,7 @@ const ( ) // Namespace Regex to ignore the namespace for creating rbac resources. -var nsRegex = regexp.MustCompile(common.NamespaceIgnorePattern) +var nsRegex = regexp.MustCompile(res.NamespaceIgnorePattern) type rbac struct { kubeClientSet kubernetes.Interface diff --git a/pkg/reconciler/openshift/tektonpipeline/extension.go b/pkg/reconciler/openshift/tektonpipeline/extension.go index 00b90036c0..183f2443ef 100644 --- a/pkg/reconciler/openshift/tektonpipeline/extension.go +++ b/pkg/reconciler/openshift/tektonpipeline/extension.go @@ -26,6 +26,7 @@ import ( mfc "github.com/manifestival/client-go-client" mf "github.com/manifestival/manifestival" "github.com/tektoncd/operator/pkg/apis/operator/v1alpha1" + res "github.com/tektoncd/operator/pkg/apis/operator/v1alpha1" "github.com/tektoncd/operator/pkg/client/clientset/versioned" operatorclient "github.com/tektoncd/operator/pkg/client/injection/client" "github.com/tektoncd/operator/pkg/reconciler/common" @@ -210,7 +211,7 @@ func SetDefault(pipeline *v1alpha1.Pipeline) bool { // Set default service account as pipeline if pipeline.DefaultServiceAccount == "" { - pipeline.DefaultServiceAccount = common.DefaultSA + pipeline.DefaultServiceAccount = res.DefaultSA updated = true } diff --git a/pkg/reconciler/openshift/tektontrigger/extension.go b/pkg/reconciler/openshift/tektontrigger/extension.go index 19e84f2c00..bd228c2b01 100644 --- a/pkg/reconciler/openshift/tektontrigger/extension.go +++ b/pkg/reconciler/openshift/tektontrigger/extension.go @@ -22,6 +22,7 @@ import ( mf "github.com/manifestival/manifestival" "github.com/tektoncd/operator/pkg/apis/operator/v1alpha1" + res "github.com/tektoncd/operator/pkg/apis/operator/v1alpha1" "github.com/tektoncd/operator/pkg/client/clientset/versioned" operatorclient "github.com/tektoncd/operator/pkg/client/injection/client" "github.com/tektoncd/operator/pkg/reconciler/common" @@ -71,7 +72,7 @@ func SetDefault(properties *v1alpha1.TriggersProperties) bool { // Set default service account as pipeline if properties.DefaultServiceAccount == "" { - properties.DefaultServiceAccount = common.DefaultSA + properties.DefaultServiceAccount = res.DefaultSA updated = true } return updated diff --git a/pkg/reconciler/shared/tektonconfig/controller.go b/pkg/reconciler/shared/tektonconfig/controller.go index c1587d8fd3..f76639086f 100644 --- a/pkg/reconciler/shared/tektonconfig/controller.go +++ b/pkg/reconciler/shared/tektonconfig/controller.go @@ -27,6 +27,7 @@ import ( namespaceinformer "knative.dev/pkg/client/injection/kube/informers/core/v1/namespace" "github.com/tektoncd/operator/pkg/apis/operator/v1alpha1" + res "github.com/tektoncd/operator/pkg/apis/operator/v1alpha1" operatorclient "github.com/tektoncd/operator/pkg/client/injection/client" tektonConfiginformer "github.com/tektoncd/operator/pkg/client/injection/informers/operator/v1alpha1/tektonconfig" tektonPipelineinformer "github.com/tektoncd/operator/pkg/client/injection/informers/operator/v1alpha1/tektonpipeline" @@ -67,7 +68,7 @@ func NewExtensibleController(generator common.ExtensionGenerator) injection.Cont Handler: controller.HandleAll(impl.EnqueueControllerOf), }) - namespaceinformer.Get(ctx).Informer().AddEventHandler(controller.HandleAll(enqueueCustomName(impl, common.ConfigResourceName))) + namespaceinformer.Get(ctx).Informer().AddEventHandler(controller.HandleAll(enqueueCustomName(impl, res.ConfigResourceName))) if os.Getenv("AUTOINSTALL_COMPONENTS") == "true" { // try to ensure that there is an instance of tektonConfig @@ -87,7 +88,7 @@ func NewExtensibleController(generator common.ExtensionGenerator) injection.Cont // and enqueue only when namespace doesn't match the regex func enqueueCustomName(impl *controller.Impl, name string) func(obj interface{}) { return func(obj interface{}) { - var nsRegex = regexp.MustCompile(common.NamespaceIgnorePattern) + var nsRegex = regexp.MustCompile(res.NamespaceIgnorePattern) object, err := kmeta.DeletionHandlingAccessor(obj) if err == nil && !nsRegex.MatchString(object.GetName()) { impl.EnqueueKey(types.NamespacedName{Namespace: "", Name: name}) diff --git a/pkg/reconciler/shared/tektonconfig/instance.go b/pkg/reconciler/shared/tektonconfig/instance.go index 4852d434ec..c9e71f7c10 100644 --- a/pkg/reconciler/shared/tektonconfig/instance.go +++ b/pkg/reconciler/shared/tektonconfig/instance.go @@ -22,8 +22,8 @@ import ( "time" "github.com/tektoncd/operator/pkg/apis/operator/v1alpha1" + res "github.com/tektoncd/operator/pkg/apis/operator/v1alpha1" "github.com/tektoncd/operator/pkg/client/clientset/versioned" - "github.com/tektoncd/operator/pkg/reconciler/common" apierrs "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/util/wait" @@ -102,10 +102,10 @@ func (tc tektonConfig) ensureInstance(ctx context.Context) { func (tc tektonConfig) createInstance(ctx context.Context) error { tcCR := &v1alpha1.TektonConfig{ ObjectMeta: metav1.ObjectMeta{ - Name: common.ConfigResourceName, + Name: res.ConfigResourceName, }, Spec: v1alpha1.TektonConfigSpec{ - Profile: common.ProfileAll, + Profile: res.ProfileAll, CommonSpec: v1alpha1.CommonSpec{ TargetNamespace: tc.namespace, }, diff --git a/pkg/reconciler/shared/tektonconfig/pipeline/pipeline.go b/pkg/reconciler/shared/tektonconfig/pipeline/pipeline.go index ed82c891b7..4cf67380dc 100644 --- a/pkg/reconciler/shared/tektonconfig/pipeline/pipeline.go +++ b/pkg/reconciler/shared/tektonconfig/pipeline/pipeline.go @@ -25,9 +25,9 @@ import ( "github.com/tektoncd/operator/pkg/apis/operator/v1alpha1" + res "github.com/tektoncd/operator/pkg/apis/operator/v1alpha1" op "github.com/tektoncd/operator/pkg/client/clientset/versioned/typed/operator/v1alpha1" operatorv1alpha1 "github.com/tektoncd/operator/pkg/client/clientset/versioned/typed/operator/v1alpha1" - "github.com/tektoncd/operator/pkg/reconciler/common" apierrs "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/util/wait" @@ -39,7 +39,7 @@ func CreatePipelineCR(instance v1alpha1.TektonComponent, client operatorv1alpha1 if _, err := ensureTektonPipelineExists(client.TektonPipelines(), configInstance); err != nil { return errors.New(err.Error()) } - if _, err := waitForTektonPipelineState(client.TektonPipelines(), common.PipelineResourceName, + if _, err := waitForTektonPipelineState(client.TektonPipelines(), res.PipelineResourceName, isTektonPipelineReady); err != nil { log.Println("TektonPipeline is not in ready state: ", err) return err @@ -48,7 +48,7 @@ func CreatePipelineCR(instance v1alpha1.TektonComponent, client operatorv1alpha1 } func ensureTektonPipelineExists(clients op.TektonPipelineInterface, config *v1alpha1.TektonConfig) (*v1alpha1.TektonPipeline, error) { - tpCR, err := GetPipeline(clients, common.PipelineResourceName) + tpCR, err := GetPipeline(clients, res.PipelineResourceName) if err == nil { // if the pipeline spec is changed then update the instance updated := false @@ -84,7 +84,7 @@ func ensureTektonPipelineExists(clients op.TektonPipelineInterface, config *v1al if apierrs.IsNotFound(err) { tpCR = &v1alpha1.TektonPipeline{ ObjectMeta: metav1.ObjectMeta{ - Name: common.PipelineResourceName, + Name: res.PipelineResourceName, }, Spec: v1alpha1.TektonPipelineSpec{ CommonSpec: v1alpha1.CommonSpec{ @@ -113,7 +113,7 @@ func waitForTektonPipelineState(clients op.TektonPipelineInterface, name string, defer span.End() var lastState *v1alpha1.TektonPipeline - waitErr := wait.PollImmediate(common.Interval, common.Timeout, func() (bool, error) { + waitErr := wait.PollImmediate(res.Interval, res.Timeout, func() (bool, error) { lastState, err := clients.Get(context.TODO(), name, metav1.GetOptions{}) return inState(lastState, err) }) @@ -131,7 +131,7 @@ func isTektonPipelineReady(s *v1alpha1.TektonPipeline, err error) (bool, error) // TektonPipelineCRDelete deletes tha TektonPipeline to see if all resources will be deleted func TektonPipelineCRDelete(clients op.TektonPipelineInterface, name string) error { - if _, err := GetPipeline(clients, common.PipelineResourceName); err != nil { + if _, err := GetPipeline(clients, res.PipelineResourceName); err != nil { if apierrs.IsNotFound(err) { return nil } @@ -140,7 +140,7 @@ func TektonPipelineCRDelete(clients op.TektonPipelineInterface, name string) err if err := clients.Delete(context.TODO(), name, metav1.DeleteOptions{}); err != nil { return fmt.Errorf("TektonPipeline %q failed to delete: %v", name, err) } - err := wait.PollImmediate(common.Interval, common.Timeout, func() (bool, error) { + err := wait.PollImmediate(res.Interval, res.Timeout, func() (bool, error) { _, err := clients.Get(context.TODO(), name, metav1.GetOptions{}) if apierrs.IsNotFound(err) { return true, nil @@ -167,7 +167,7 @@ func verifyNoTektonPipelineCR(clients op.TektonPipelineInterface) error { func GetTektonConfig() *v1alpha1.TektonConfig { return &v1alpha1.TektonConfig{ ObjectMeta: metav1.ObjectMeta{ - Name: common.ConfigResourceName, + Name: res.ConfigResourceName, }, Spec: v1alpha1.TektonConfigSpec{ Profile: "all", diff --git a/pkg/reconciler/shared/tektonconfig/pipeline/pipeline_test.go b/pkg/reconciler/shared/tektonconfig/pipeline/pipeline_test.go index 9c58a25983..83d8f70995 100644 --- a/pkg/reconciler/shared/tektonconfig/pipeline/pipeline_test.go +++ b/pkg/reconciler/shared/tektonconfig/pipeline/pipeline_test.go @@ -19,8 +19,8 @@ package pipeline import ( "testing" + res "github.com/tektoncd/operator/pkg/apis/operator/v1alpha1" "github.com/tektoncd/operator/pkg/client/injection/client/fake" - "github.com/tektoncd/operator/pkg/reconciler/common" util "github.com/tektoncd/operator/pkg/reconciler/common/testing" ts "knative.dev/pkg/reconciler/testing" ) @@ -31,13 +31,13 @@ func TestTektonPipelineCreateAndDeleteCR(t *testing.T) { tConfig := GetTektonConfig() err := CreatePipelineCR(tConfig, c.OperatorV1alpha1()) util.AssertNotEqual(t, err, nil) - err = TektonPipelineCRDelete(c.OperatorV1alpha1().TektonPipelines(), common.PipelineResourceName) + err = TektonPipelineCRDelete(c.OperatorV1alpha1().TektonPipelines(), res.PipelineResourceName) util.AssertEqual(t, err, nil) } func TestTektonPipelineCRDelete(t *testing.T) { ctx, _, _ := ts.SetupFakeContextWithCancel(t) c := fake.Get(ctx) - err := TektonPipelineCRDelete(c.OperatorV1alpha1().TektonPipelines(), common.PipelineResourceName) + err := TektonPipelineCRDelete(c.OperatorV1alpha1().TektonPipelines(), res.PipelineResourceName) util.AssertEqual(t, err, nil) } diff --git a/pkg/reconciler/shared/tektonconfig/tektonconfig.go b/pkg/reconciler/shared/tektonconfig/tektonconfig.go index 893c6d2c72..8501b2978c 100644 --- a/pkg/reconciler/shared/tektonconfig/tektonconfig.go +++ b/pkg/reconciler/shared/tektonconfig/tektonconfig.go @@ -21,6 +21,7 @@ import ( "fmt" "github.com/tektoncd/operator/pkg/apis/operator/v1alpha1" + res "github.com/tektoncd/operator/pkg/apis/operator/v1alpha1" clientset "github.com/tektoncd/operator/pkg/client/clientset/versioned" tektonConfigreconciler "github.com/tektoncd/operator/pkg/client/injection/reconciler/operator/v1alpha1/tektonconfig" "github.com/tektoncd/operator/pkg/reconciler/common" @@ -50,13 +51,13 @@ func (r *Reconciler) FinalizeKind(ctx context.Context, original *v1alpha1.Tekton logger := logging.FromContext(ctx) if original.Spec.Profile == v1alpha1.ProfileLite { - return pipeline.TektonPipelineCRDelete(r.operatorClientSet.OperatorV1alpha1().TektonPipelines(), common.PipelineResourceName) + return pipeline.TektonPipelineCRDelete(r.operatorClientSet.OperatorV1alpha1().TektonPipelines(), res.PipelineResourceName) } else { // TektonPipeline and TektonTrigger is common for profile type basic and all - if err := pipeline.TektonPipelineCRDelete(r.operatorClientSet.OperatorV1alpha1().TektonPipelines(), common.PipelineResourceName); err != nil { + if err := pipeline.TektonPipelineCRDelete(r.operatorClientSet.OperatorV1alpha1().TektonPipelines(), res.PipelineResourceName); err != nil { return err } - if err := trigger.TektonTriggerCRDelete(r.operatorClientSet.OperatorV1alpha1().TektonTriggers(), common.TriggerResourceName); err != nil { + if err := trigger.TektonTriggerCRDelete(r.operatorClientSet.OperatorV1alpha1().TektonTriggers(), res.TriggerResourceName); err != nil { return err } } @@ -75,9 +76,9 @@ func (r *Reconciler) ReconcileKind(ctx context.Context, tc *v1alpha1.TektonConfi tc.Status.InitializeConditions() logger.Infow("Reconciling TektonConfig", "status", tc.Status) - if tc.GetName() != common.ConfigResourceName { + if tc.GetName() != res.ConfigResourceName { msg := fmt.Sprintf("Resource ignored, Expected Name: %s, Got Name: %s", - common.ConfigResourceName, + res.ConfigResourceName, tc.GetName(), ) logger.Error(msg) @@ -110,7 +111,7 @@ func (r *Reconciler) ReconcileKind(ctx context.Context, tc *v1alpha1.TektonConfi return err } } else { - if err := trigger.TektonTriggerCRDelete(r.operatorClientSet.OperatorV1alpha1().TektonTriggers(), common.TriggerResourceName); err != nil { + if err := trigger.TektonTriggerCRDelete(r.operatorClientSet.OperatorV1alpha1().TektonTriggers(), res.TriggerResourceName); err != nil { tc.Status.MarkComponentNotReady(fmt.Sprintf("TektonTrigger: %s", err.Error())) return err } diff --git a/pkg/reconciler/shared/tektonconfig/trigger/trigger.go b/pkg/reconciler/shared/tektonconfig/trigger/trigger.go index ee7041e75e..b932483ed6 100644 --- a/pkg/reconciler/shared/tektonconfig/trigger/trigger.go +++ b/pkg/reconciler/shared/tektonconfig/trigger/trigger.go @@ -30,9 +30,9 @@ import ( "k8s.io/apimachinery/pkg/util/wait" "knative.dev/pkg/test/logging" + res "github.com/tektoncd/operator/pkg/apis/operator/v1alpha1" op "github.com/tektoncd/operator/pkg/client/clientset/versioned/typed/operator/v1alpha1" operatorv1alpha1 "github.com/tektoncd/operator/pkg/client/clientset/versioned/typed/operator/v1alpha1" - "github.com/tektoncd/operator/pkg/reconciler/common" ) func CreateTriggerCR(instance v1alpha1.TektonComponent, client operatorv1alpha1.OperatorV1alpha1Interface) error { @@ -40,7 +40,7 @@ func CreateTriggerCR(instance v1alpha1.TektonComponent, client operatorv1alpha1. if _, err := ensureTektonTriggerExists(client.TektonTriggers(), configInstance); err != nil { return errors.New(err.Error()) } - if _, err := waitForTektonTriggerState(client.TektonTriggers(), common.TriggerResourceName, + if _, err := waitForTektonTriggerState(client.TektonTriggers(), res.TriggerResourceName, isTektonTriggerReady); err != nil { log.Println("TektonTrigger is not in ready state: ", err) return err @@ -49,7 +49,7 @@ func CreateTriggerCR(instance v1alpha1.TektonComponent, client operatorv1alpha1. } func ensureTektonTriggerExists(clients op.TektonTriggerInterface, config *v1alpha1.TektonConfig) (*v1alpha1.TektonTrigger, error) { - ttCR, err := GetTrigger(clients, common.TriggerResourceName) + ttCR, err := GetTrigger(clients, res.TriggerResourceName) if err == nil { // if the trigger spec is changed then update the instance updated := false @@ -85,7 +85,7 @@ func ensureTektonTriggerExists(clients op.TektonTriggerInterface, config *v1alph if apierrs.IsNotFound(err) { ttCR = &v1alpha1.TektonTrigger{ ObjectMeta: metav1.ObjectMeta{ - Name: common.TriggerResourceName, + Name: res.TriggerResourceName, }, Spec: v1alpha1.TektonTriggerSpec{ CommonSpec: v1alpha1.CommonSpec{ @@ -113,7 +113,7 @@ func waitForTektonTriggerState(clients op.TektonTriggerInterface, name string, defer span.End() var lastState *v1alpha1.TektonTrigger - waitErr := wait.PollImmediate(common.Interval, common.Timeout, func() (bool, error) { + waitErr := wait.PollImmediate(res.Interval, res.Timeout, func() (bool, error) { lastState, err := clients.Get(context.TODO(), name, metav1.GetOptions{}) return inState(lastState, err) }) @@ -131,7 +131,7 @@ func isTektonTriggerReady(s *v1alpha1.TektonTrigger, err error) (bool, error) { // TektonTriggerCRDelete deletes tha TektonTrigger to see if all resources will be deleted func TektonTriggerCRDelete(clients op.TektonTriggerInterface, name string) error { - if _, err := GetTrigger(clients, common.TriggerResourceName); err != nil { + if _, err := GetTrigger(clients, res.TriggerResourceName); err != nil { if apierrs.IsNotFound(err) { return nil } @@ -140,7 +140,7 @@ func TektonTriggerCRDelete(clients op.TektonTriggerInterface, name string) error if err := clients.Delete(context.TODO(), name, metav1.DeleteOptions{}); err != nil { return fmt.Errorf("TektonTrigger %q failed to delete: %v", name, err) } - err := wait.PollImmediate(common.Interval, common.Timeout, func() (bool, error) { + err := wait.PollImmediate(res.Interval, res.Timeout, func() (bool, error) { _, err := clients.Get(context.TODO(), name, metav1.GetOptions{}) if apierrs.IsNotFound(err) { return true, nil diff --git a/pkg/reconciler/shared/tektonconfig/trigger/trigger_test.go b/pkg/reconciler/shared/tektonconfig/trigger/trigger_test.go index 64ef5f0e88..dd64d5caac 100644 --- a/pkg/reconciler/shared/tektonconfig/trigger/trigger_test.go +++ b/pkg/reconciler/shared/tektonconfig/trigger/trigger_test.go @@ -19,8 +19,8 @@ package trigger import ( "testing" + res "github.com/tektoncd/operator/pkg/apis/operator/v1alpha1" "github.com/tektoncd/operator/pkg/client/injection/client/fake" - "github.com/tektoncd/operator/pkg/reconciler/common" util "github.com/tektoncd/operator/pkg/reconciler/common/testing" "github.com/tektoncd/operator/pkg/reconciler/shared/tektonconfig/pipeline" ts "knative.dev/pkg/reconciler/testing" @@ -35,13 +35,13 @@ func TestTektonTriggerCreateAndDeleteCR(t *testing.T) { // recheck triggers creation err = CreateTriggerCR(tConfig, c.OperatorV1alpha1()) util.AssertNotEqual(t, err, nil) - err = TektonTriggerCRDelete(c.OperatorV1alpha1().TektonTriggers(), common.TriggerResourceName) + err = TektonTriggerCRDelete(c.OperatorV1alpha1().TektonTriggers(), res.TriggerResourceName) util.AssertEqual(t, err, nil) } func TestTektonTriggerCRDelete(t *testing.T) { ctx, _, _ := ts.SetupFakeContextWithCancel(t) c := fake.Get(ctx) - err := TektonTriggerCRDelete(c.OperatorV1alpha1().TektonTriggers(), common.TriggerResourceName) + err := TektonTriggerCRDelete(c.OperatorV1alpha1().TektonTriggers(), res.TriggerResourceName) util.AssertEqual(t, err, nil) } diff --git a/test/e2e/common/tektonconfigdeployment_test.go b/test/e2e/common/tektonconfigdeployment_test.go index f09d8fcc80..2b3530df27 100644 --- a/test/e2e/common/tektonconfigdeployment_test.go +++ b/test/e2e/common/tektonconfigdeployment_test.go @@ -24,8 +24,7 @@ import ( "testing" "github.com/google/go-cmp/cmp" - "github.com/tektoncd/operator/pkg/apis/operator/v1alpha1" - "github.com/tektoncd/operator/pkg/reconciler/common" + res "github.com/tektoncd/operator/pkg/apis/operator/v1alpha1" "github.com/tektoncd/operator/test/client" "github.com/tektoncd/operator/test/resources" "github.com/tektoncd/operator/test/utils" @@ -38,7 +37,7 @@ func TestTektonConfigDeployment(t *testing.T) { clients := client.Setup(t) crNames := utils.ResourceNames{ - TektonConfig: common.ConfigResourceName, + TektonConfig: res.ConfigResourceName, Namespace: "tekton-operator", } @@ -73,7 +72,7 @@ func TestTektonConfigDeployment(t *testing.T) { runRbacTest(t, clients) } - if platform == "openshift" && tc.Spec.Profile == common.ProfileAll { + if platform == "openshift" && tc.Spec.Profile == res.ProfileAll { runAddonTest(t, clients, tc) } @@ -93,9 +92,9 @@ func runAddonTest(t *testing.T, clients *utils.Clients, tc *v1alpha1.TektonConfi // Make sure TektonAddon is created t.Run("ensure-addon-is-created", func(t *testing.T) { - addon, err = clients.Operator.TektonAddons().Get(context.TODO(), common.AddonResourceName, metav1.GetOptions{}) + addon, err = clients.Operator.TektonAddons().Get(context.TODO(), res.AddonResourceName, metav1.GetOptions{}) if err != nil { - t.Fatalf("failed to get TektonAddon CR: %s : %v", common.AddonResourceName, err) + t.Fatalf("failed to get TektonAddon CR: %s : %v", res.AddonResourceName, err) } }) diff --git a/test/resources/tektonconfigs.go b/test/resources/tektonconfigs.go index 1c113f2354..0457d00b90 100644 --- a/test/resources/tektonconfigs.go +++ b/test/resources/tektonconfigs.go @@ -27,7 +27,6 @@ import ( mfc "github.com/manifestival/client-go-client" mf "github.com/manifestival/manifestival" - "github.com/tektoncd/operator/pkg/reconciler/common" "knative.dev/pkg/test/logging" @@ -36,6 +35,7 @@ import ( "k8s.io/client-go/kubernetes" "github.com/tektoncd/operator/pkg/apis/operator/v1alpha1" + res "github.com/tektoncd/operator/pkg/apis/operator/v1alpha1" configv1alpha1 "github.com/tektoncd/operator/pkg/client/clientset/versioned/typed/operator/v1alpha1" apierrs "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -67,7 +67,7 @@ func EnsureTektonConfigExists(kubeClientSet *kubernetes.Clientset, clients confi Name: names.TektonConfig, }, Spec: v1alpha1.TektonConfigSpec{ - Profile: common.ProfileAll, + Profile: res.ProfileAll, CommonSpec: v1alpha1.CommonSpec{ TargetNamespace: cm.Data["DEFAULT_TARGET_NAMESPACE"], },