Omit checksum label if GC is disabled
Signed-off-by: Stefan Prodan <stefan.prodan@gmail.com>
This commit is contained in:
parent
5f697457c9
commit
46f828ff43
|
|
@ -186,7 +186,7 @@ func (r *KustomizationReconciler) Reconcile(req ctrl.Request) (ctrl.Result, erro
|
|||
// set the reconciliation status to progressing
|
||||
kustomization = kustomizev1.KustomizationProgressing(kustomization)
|
||||
if err := r.Status().Update(ctx, &kustomization); err != nil {
|
||||
log.Error(err, "unable to update status")
|
||||
log.Error(err, "unable to update status to progressing")
|
||||
return ctrl.Result{Requeue: true}, err
|
||||
}
|
||||
r.recordReadiness(kustomization, false)
|
||||
|
|
@ -765,13 +765,11 @@ func (r *KustomizationReconciler) applyWithRetry(kustomization kustomizev1.Kusto
|
|||
}
|
||||
|
||||
func (r *KustomizationReconciler) prune(client client.Client, kustomization kustomizev1.Kustomization, snapshot *kustomizev1.Snapshot, force bool) error {
|
||||
if kustomization.Status.Snapshot == nil || snapshot == nil {
|
||||
if !kustomization.Spec.Prune || kustomization.Status.Snapshot == nil || snapshot == nil {
|
||||
return nil
|
||||
}
|
||||
if !force {
|
||||
if kustomization.Status.Snapshot.Checksum == snapshot.Checksum {
|
||||
return nil
|
||||
}
|
||||
if !force && kustomization.Status.Snapshot.Checksum == snapshot.Checksum {
|
||||
return nil
|
||||
}
|
||||
|
||||
gc := NewGarbageCollector(client, *kustomization.Status.Snapshot, r.Log)
|
||||
|
|
|
|||
|
|
@ -131,3 +131,10 @@ func gcLabels(name, namespace, checksum string) map[string]string {
|
|||
fmt.Sprintf("%s/checksum", kustomizev1.GroupVersion.Group): checksum,
|
||||
}
|
||||
}
|
||||
|
||||
func selectorLabels(name, namespace string) map[string]string {
|
||||
return map[string]string{
|
||||
fmt.Sprintf("%s/name", kustomizev1.GroupVersion.Group): name,
|
||||
fmt.Sprintf("%s/namespace", kustomizev1.GroupVersion.Group): namespace,
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -214,6 +214,13 @@ func (kg *KustomizeGenerator) checksum(dirPath string) (string, error) {
|
|||
}
|
||||
|
||||
func (kg *KustomizeGenerator) generateLabelTransformer(checksum, dirPath string) error {
|
||||
labels := selectorLabels(kg.kustomization.GetName(), kg.kustomization.GetNamespace())
|
||||
|
||||
// add checksum label only if GC is enabled
|
||||
if kg.kustomization.Spec.Prune {
|
||||
labels = gcLabels(kg.kustomization.GetName(), kg.kustomization.GetNamespace(), checksum)
|
||||
}
|
||||
|
||||
var lt = struct {
|
||||
ApiVersion string `json:"apiVersion" yaml:"apiVersion"`
|
||||
Kind string `json:"kind" yaml:"kind"`
|
||||
|
|
@ -230,7 +237,7 @@ func (kg *KustomizeGenerator) generateLabelTransformer(checksum, dirPath string)
|
|||
}{
|
||||
Name: kg.kustomization.GetName(),
|
||||
},
|
||||
Labels: gcLabels(kg.kustomization.GetName(), kg.kustomization.GetNamespace(), checksum),
|
||||
Labels: labels,
|
||||
FieldSpecs: []kustypes.FieldSpec{
|
||||
{Path: "metadata/labels", CreateIfNotPresent: true},
|
||||
},
|
||||
|
|
|
|||
Loading…
Reference in New Issue