Skip to content

Commit

Permalink
Merge pull request #567 from codingben/CNV-29436
Browse files Browse the repository at this point in the history
fix(CNV-29761): ensure that tekton crd exists
  • Loading branch information
kubevirt-bot committed Jun 12, 2023
2 parents 805c32c + d28f6bd commit 42be785
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 27 deletions.
7 changes: 4 additions & 3 deletions internal/common/labels.go
Expand Up @@ -14,9 +14,10 @@ const (
AppKubernetesManagedByLabel = "app.kubernetes.io/managed-by"
AppKubernetesComponentLabel = "app.kubernetes.io/component"

AppComponentTektonPipelines AppComponent = "tektonPipelines"
AppComponentTektonTasks AppComponent = "tektonTasks"
AppKubernetesManagedByValue string = "ssp-operator"
AppComponentTektonPipelines AppComponent = "tektonPipelines"
AppComponentTektonTasks AppComponent = "tektonTasks"
AppKubernetesManagedByValue string = "ssp-operator"
TektonAppKubernetesManagedByValue string = "tekton-tasks-operator"
)

type AppComponent string
Expand Down
16 changes: 8 additions & 8 deletions internal/operands/tekton-pipelines/tekton-pipelines.go
Expand Up @@ -85,11 +85,9 @@ 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
}
// 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)
// }
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 All @@ -114,9 +112,11 @@ func (t *tektonPipelines) Reconcile(request *common.Request) ([]common.Reconcile

func (t *tektonPipelines) Cleanup(request *common.Request) ([]common.CleanupResult, error) {
var objects []client.Object
for _, p := range t.pipelines {
o := p.DeepCopy()
objects = append(objects, o)
if request.CrdList.CrdExists(tektonCrd) {
for _, p := range t.pipelines {
o := p.DeepCopy()
objects = append(objects, o)
}
}
for _, cm := range t.configMaps {
o := cm.DeepCopy()
Expand Down
35 changes: 19 additions & 16 deletions internal/operands/tekton-tasks/tekton-tasks.go
Expand Up @@ -149,11 +149,9 @@ 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
}
// 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)
// }
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 All @@ -177,9 +175,11 @@ func (t *tektonTasks) Reconcile(request *common.Request) ([]common.ReconcileResu

func (t *tektonTasks) Cleanup(request *common.Request) ([]common.CleanupResult, error) {
var objects []client.Object
for _, t := range t.tasks {
o := t.DeepCopy()
objects = append(objects, o)
if request.CrdList.CrdExists(tektonCrd) {
for _, t := range t.tasks {
o := t.DeepCopy()
objects = append(objects, o)
}
}
for _, rb := range t.roleBindings {
o := rb.DeepCopy()
Expand All @@ -199,14 +199,17 @@ func (t *tektonTasks) Cleanup(request *common.Request) ([]common.CleanupResult,
objects = append(objects, o)
}

clusterTasks, err := listDeprecatedClusterTasks(request)
if err != nil {
return nil, err
}
for _, ct := range clusterTasks {
o := ct.DeepCopy()
objects = append(objects, o)
if request.CrdList.CrdExists(tektonCrd) {
clusterTasks, err := listDeprecatedClusterTasks(request)
if err != nil {
return nil, err
}
for _, ct := range clusterTasks {
o := ct.DeepCopy()
objects = append(objects, o)
}
}

return common.DeleteAll(request, objects...)
}

Expand All @@ -215,7 +218,7 @@ func (t *tektonTasks) Cleanup(request *common.Request) ([]common.CleanupResult,
func listDeprecatedClusterTasks(request *common.Request) ([]pipeline.ClusterTask, error) {
deprecatedClusterTasks := &pipeline.ClusterTaskList{}
err := request.Client.List(request.Context, deprecatedClusterTasks, &client.MatchingLabels{
common.AppKubernetesManagedByLabel: common.AppKubernetesManagedByValue,
common.AppKubernetesManagedByLabel: common.TektonAppKubernetesManagedByValue,
})
if err != nil {
return nil, err
Expand Down

0 comments on commit 42be785

Please sign in to comment.