Skip to content

Commit

Permalink
Merge pull request #561 from codingben/unwatch-tekton-crd
Browse files Browse the repository at this point in the history
fix(CNV-29287): do not watch tekton crd
  • Loading branch information
kubevirt-bot committed Jun 5, 2023
2 parents 02101a6 + fa2b1b7 commit bd72aa7
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 78 deletions.
12 changes: 8 additions & 4 deletions internal/operands/tekton-pipelines/tekton-pipelines.go
Expand Up @@ -34,7 +34,9 @@ func init() {

func WatchClusterTypes() []operands.WatchType {
return []operands.WatchType{
{Object: &pipeline.Pipeline{}, Crd: tektonCrd, WatchFullObject: true},
// Solution to optional Tekton CRD is not implemented yet.
// Until then, do not watch to Tekton CRD.
// {Object: &pipeline.Pipeline{}, Crd: tektonCrd, WatchFullObject: true},
{Object: &v1.ConfigMap{}},
{Object: &rbac.RoleBinding{}},
{Object: &v1.ServiceAccount{}},
Expand Down Expand Up @@ -83,9 +85,11 @@ func (t *tektonPipelines) Reconcile(request *common.Request) ([]common.Reconcile
request.Logger.V(1).Info("Tekton Pipelines resources were not deployed, because spec.featureGates.deployTektonTaskResources is set to false")
return nil, nil
}
if !request.CrdList.CrdExists(tektonCrd) {
return nil, fmt.Errorf("Tekton CRD %s does not exist", tektonCrd)
}
// Solution to optional Tekton CRD is not implemented yet.
// Until then, do not check if Tekton CRD exists.
// if !request.CrdList.CrdExists(tektonCrd) {
// return nil, fmt.Errorf("Tekton CRD %s does not exist", tektonCrd)
// }

var reconcileFunc []common.ReconcileFunc
reconcileFunc = append(reconcileFunc, reconcileClusterRolesFuncs(t.clusterRoles)...)
Expand Down
12 changes: 8 additions & 4 deletions internal/operands/tekton-tasks/tekton-tasks.go
Expand Up @@ -69,7 +69,9 @@ func init() {

func WatchClusterTypes() []operands.WatchType {
return []operands.WatchType{
{Object: &pipeline.Task{}, Crd: tektonCrd, WatchFullObject: true},
// Solution to optional Tekton CRD is not implemented yet.
// Until then, do not watch to Tekton CRD.
// {Object: &pipeline.Task{}, Crd: tektonCrd, WatchFullObject: true},
{Object: &rbac.ClusterRole{}},
{Object: &rbac.RoleBinding{}},
{Object: &v1.ServiceAccount{}},
Expand Down Expand Up @@ -147,9 +149,11 @@ func (t *tektonTasks) Reconcile(request *common.Request) ([]common.ReconcileResu
request.Logger.V(1).Info("Tekton Tasks resources were not deployed, because spec.featureGates.deployTektonTaskResources is set to false")
return nil, nil
}
if !request.CrdList.CrdExists(tektonCrd) {
return nil, fmt.Errorf("Tekton CRD %s does not exist", tektonCrd)
}
// Solution to optional Tekton CRD is not implemented yet.
// Until then, do not check if Tekton CRD exists.
// if !request.CrdList.CrdExists(tektonCrd) {
// return nil, fmt.Errorf("Tekton CRD %s does not exist", tektonCrd)
// }

var reconcileFunc []common.ReconcileFunc
reconcileFunc = append(reconcileFunc, reconcileTektonTasksFuncs(t.tasks)...)
Expand Down
91 changes: 46 additions & 45 deletions tests/tekton-pipelines_test.go
Expand Up @@ -5,7 +5,8 @@ import (

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
pipeline "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1"

// pipeline "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1"
v1 "k8s.io/api/core/v1"
rbac "k8s.io/api/rbac/v1"
ssp "kubevirt.io/ssp-operator/api/v1beta1"
Expand Down Expand Up @@ -33,25 +34,25 @@ var _ = Describe("Tekton Pipelines Operand", func() {
strategy.RevertToOriginalSspCr()
})

It("[test_id:TODO] should create pipelines", func() {
pipelineList := &pipeline.PipelineList{}

Eventually(func() bool {
err := apiClient.List(ctx, pipelineList,
client.MatchingLabels{
common.AppKubernetesManagedByLabel: common.AppKubernetesManagedByValue,
common.AppKubernetesComponentLabel: string(common.AppComponentTektonPipelines),
},
)
Expect(err).ToNot(HaveOccurred())
return len(pipelineList.Items) > 0
}, env.ShortTimeout(), time.Second).Should(BeTrue())

for _, pipeline := range pipelineList.Items {
Expect(pipeline.Labels[common.AppKubernetesManagedByLabel]).To(Equal(common.AppKubernetesManagedByValue), "managed by label should equal")
Expect(pipeline.Labels[common.AppKubernetesComponentLabel]).To(Equal(string(common.AppComponentTektonPipelines)), "component label should equal")
}
})
// It("[test_id:TODO] should create pipelines", func() {
// pipelineList := &pipeline.PipelineList{}

// Eventually(func() bool {
// err := apiClient.List(ctx, pipelineList,
// client.MatchingLabels{
// common.AppKubernetesManagedByLabel: common.AppKubernetesManagedByValue,
// common.AppKubernetesComponentLabel: string(common.AppComponentTektonPipelines),
// },
// )
// Expect(err).ToNot(HaveOccurred())
// return len(pipelineList.Items) > 0
// }, env.ShortTimeout(), time.Second).Should(BeTrue())

// for _, pipeline := range pipelineList.Items {
// Expect(pipeline.Labels[common.AppKubernetesManagedByLabel]).To(Equal(common.AppKubernetesManagedByValue), "managed by label should equal")
// Expect(pipeline.Labels[common.AppKubernetesComponentLabel]).To(Equal(string(common.AppComponentTektonPipelines)), "component label should equal")
// }
// })

It("[test_id:TODO] should create cluster roles", func() {
clusterRoleList := &rbac.ClusterRoleList{}
Expand Down Expand Up @@ -133,31 +134,31 @@ var _ = Describe("Tekton Pipelines Operand", func() {
strategy.RevertToOriginalSspCr()
})

It("[test_id:TODO] should revert user update on pipeline", func() {
pipelineList := &pipeline.PipelineList{}

Eventually(func() bool {
err := apiClient.List(ctx, pipelineList,
client.MatchingLabels{
common.AppKubernetesManagedByLabel: common.AppKubernetesManagedByValue,
common.AppKubernetesComponentLabel: string(common.AppComponentTektonPipelines),
},
)
Expect(err).ToNot(HaveOccurred())
return len(pipelineList.Items) > 0
}, env.ShortTimeout(), time.Second).Should(BeTrue())

pipeline := pipelineList.Items[0]
pipeline.Spec.Description = "test"
err := apiClient.Update(ctx, &pipeline)
Expect(err).ToNot(HaveOccurred())

Eventually(func() bool {
err := apiClient.Get(ctx, client.ObjectKeyFromObject(&pipeline), &pipeline)
Expect(err).ToNot(HaveOccurred())
return pipeline.Spec.Description != "test"
}, env.ShortTimeout(), time.Second).Should(BeTrue())
})
// It("[test_id:TODO] should revert user update on pipeline", func() {
// pipelineList := &pipeline.PipelineList{}

// Eventually(func() bool {
// err := apiClient.List(ctx, pipelineList,
// client.MatchingLabels{
// common.AppKubernetesManagedByLabel: common.AppKubernetesManagedByValue,
// common.AppKubernetesComponentLabel: string(common.AppComponentTektonPipelines),
// },
// )
// Expect(err).ToNot(HaveOccurred())
// return len(pipelineList.Items) > 0
// }, env.ShortTimeout(), time.Second).Should(BeTrue())

// pipeline := pipelineList.Items[0]
// pipeline.Spec.Description = "test"
// err := apiClient.Update(ctx, &pipeline)
// Expect(err).ToNot(HaveOccurred())

// Eventually(func() bool {
// err := apiClient.Get(ctx, client.ObjectKeyFromObject(&pipeline), &pipeline)
// Expect(err).ToNot(HaveOccurred())
// return pipeline.Spec.Description != "test"
// }, env.ShortTimeout(), time.Second).Should(BeTrue())
// })

It("[test_id:TODO] should revert user update on configMap", func() {
configMapList := &v1.ConfigMapList{}
Expand Down
51 changes: 26 additions & 25 deletions tests/tekton-tasks_test.go
Expand Up @@ -6,7 +6,8 @@ import (

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
pipeline "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1"

// pipeline "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1"
v1 "k8s.io/api/core/v1"
rbac "k8s.io/api/rbac/v1"
ssp "kubevirt.io/ssp-operator/api/v1beta1"
Expand Down Expand Up @@ -35,30 +36,30 @@ var _ = Describe("Tekton Tasks Operand", func() {
strategy.RevertToOriginalSspCr()
})

It("[test_id:TODO] should create tasks", func() {
taskList := &pipeline.TaskList{}

Eventually(func() bool {
err := apiClient.List(ctx, taskList,
client.MatchingLabels{
common.AppKubernetesManagedByLabel: common.AppKubernetesManagedByValue,
common.AppKubernetesComponentLabel: string(common.AppComponentTektonTasks),
},
)
Expect(err).ToNot(HaveOccurred())
return len(taskList.Items) > 0
}, env.ShortTimeout(), time.Second).Should(BeTrue())

for _, task := range taskList.Items {
if _, found := tekton_tasks.AllowedTasks[strings.TrimSuffix(task.Name, "-task")]; found {
Expect(found).To(BeTrue(), "only allowed task is deployed - "+task.Name)
}

Expect(task.Labels[tekton_tasks.TektonTasksVersionLabel]).To(Equal(common.TektonTasksVersion), "version label should equal")
Expect(task.Labels[common.AppKubernetesManagedByLabel]).To(Equal(common.AppKubernetesManagedByValue), "managed by label should equal")
Expect(task.Labels[common.AppKubernetesComponentLabel]).To(Equal(string(common.AppComponentTektonTasks)), "component label should equal")
}
})
// It("[test_id:TODO] should create tasks", func() {
// taskList := &pipeline.TaskList{}

// Eventually(func() bool {
// err := apiClient.List(ctx, taskList,
// client.MatchingLabels{
// common.AppKubernetesManagedByLabel: common.AppKubernetesManagedByValue,
// common.AppKubernetesComponentLabel: string(common.AppComponentTektonTasks),
// },
// )
// Expect(err).ToNot(HaveOccurred())
// return len(taskList.Items) > 0
// }, env.ShortTimeout(), time.Second).Should(BeTrue())

// for _, task := range taskList.Items {
// if _, found := tekton_tasks.AllowedTasks[strings.TrimSuffix(task.Name, "-task")]; found {
// Expect(found).To(BeTrue(), "only allowed task is deployed - "+task.Name)
// }

// Expect(task.Labels[tekton_tasks.TektonTasksVersionLabel]).To(Equal(common.TektonTasksVersion), "version label should equal")
// Expect(task.Labels[common.AppKubernetesManagedByLabel]).To(Equal(common.AppKubernetesManagedByValue), "managed by label should equal")
// Expect(task.Labels[common.AppKubernetesComponentLabel]).To(Equal(string(common.AppComponentTektonTasks)), "component label should equal")
// }
// })

It("[test_id:TODO] should create service accounts", func() {
serviceAccountList := &v1.ServiceAccountList{}
Expand Down

0 comments on commit bd72aa7

Please sign in to comment.