Browse Source

Fixing when orphaned secret deletion when target.Name is not set (#2609)

* Fixing  when orphaned secret deletion when target.Name is not set

Signed-off-by: Gustavo Carvalho <gusfcarvalho@gmail.com>

* Linting

Signed-off-by: Gustavo Carvalho <gusfcarvalho@gmail.com>

* Fixing e2e tests

Signed-off-by: Gustavo Carvalho <gusfcarvalho@gmail.com>

---------

Signed-off-by: Gustavo Carvalho <gusfcarvalho@gmail.com>
Gustavo Fernandes de Carvalho 2 years ago
parent
commit
6319977e63

+ 7 - 1
e2e/framework/eso.go

@@ -104,6 +104,13 @@ func equalSecrets(exp, ts *v1.Secret) bool {
 	if exp.Type != ts.Type {
 		return false
 	}
+
+	// secret contains label owner which must be ignored
+	delete(ts.ObjectMeta.Labels, esv1beta1.LabelOwner)
+	if len(ts.ObjectMeta.Labels) == 0 {
+		ts.ObjectMeta.Labels = nil
+	}
+
 	expLabels, _ := json.Marshal(exp.ObjectMeta.Labels)
 	tsLabels, _ := json.Marshal(ts.ObjectMeta.Labels)
 	if !bytes.Equal(expLabels, tsLabels) {
@@ -115,7 +122,6 @@ func equalSecrets(exp, ts *v1.Secret) bool {
 	if len(ts.ObjectMeta.Annotations) == 0 {
 		ts.ObjectMeta.Annotations = nil
 	}
-
 	expAnnotations, _ := json.Marshal(exp.ObjectMeta.Annotations)
 	tsAnnotations, _ := json.Marshal(ts.ObjectMeta.Annotations)
 	if !bytes.Equal(expAnnotations, tsAnnotations) {

+ 1 - 1
pkg/controllers/externalsecret/externalsecret_controller.go

@@ -353,7 +353,7 @@ func deleteOrphanedSecrets(ctx context.Context, cl client.Client, externalSecret
 		return err
 	}
 	for key, secret := range secretList.Items {
-		if secret.Name != externalSecret.Spec.Target.Name {
+		if externalSecret.Spec.Target.Name != "" && secret.Name != externalSecret.Spec.Target.Name {
 			err = cl.Delete(ctx, &secretList.Items[key])
 			if err != nil {
 				return err