Skip to content

Commit

Permalink
reconcile pruner resources on targetNamespace change
Browse files Browse the repository at this point in the history
Signed-off-by: Jeeva Kandasamy <jkandasa@redhat.com>
  • Loading branch information
jkandasa authored and tekton-robot committed Sep 6, 2023
1 parent b7ffd5d commit e97e771
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions pkg/reconciler/shared/tektonconfig/installerset_pruner.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,13 @@ var (
)

type prunerManifestSpec struct {
YamlLocation string
ComputedHash string
YamlLocation string
ComputedHash string // this hash value computed from the pruner resources directory
TargetNamespace string
}

func (pms *prunerManifestSpec) GetHash() string {
return fmt.Sprintf("%s-%s", pms.TargetNamespace, pms.ComputedHash)
}

// reconciles pruner InstallerSets
Expand Down Expand Up @@ -79,6 +84,9 @@ func (r *Reconciler) reconcilePrunerInstallerSet(ctx context.Context, tc *v1alph
}
})

// update targetNamespace
prunerManifestHash.TargetNamespace = tc.Spec.TargetNamespace

// report error if the hash not calculated
// actual error will be printer on the log from above func on the first call of this method
if prunerManifestHash.ComputedHash == "" {
Expand Down Expand Up @@ -109,7 +117,7 @@ func (r *Reconciler) reconcilePrunerInstallerSet(ctx context.Context, tc *v1alph
return err
}
appliedHash, found := actualInstallerSet.GetAnnotations()[v1alpha1.LastAppliedHashKey]
if !found || prunerManifestHash.ComputedHash != appliedHash {
if !found || prunerManifestHash.GetHash() != appliedHash {
// delete the existing installerSet
if err := r.operatorClientSet.OperatorV1alpha1().TektonInstallerSets().Delete(ctx, actualInstallerSetName, metav1.DeleteOptions{}); err != nil {
return err
Expand Down Expand Up @@ -154,7 +162,7 @@ func (r *Reconciler) createPrunerInstallerSet(ctx context.Context, tc *v1alpha1.
},
Annotations: map[string]string{
v1alpha1.TargetNamespaceKey: tc.Spec.TargetNamespace,
v1alpha1.LastAppliedHashKey: prunerManifestHash.ComputedHash,
v1alpha1.LastAppliedHashKey: prunerManifestHash.GetHash(),
},
OwnerReferences: []metav1.OwnerReference{ownerRef},
},
Expand Down

0 comments on commit e97e771

Please sign in to comment.