From a45907b4682c950832da7bc32a065e4876b5a3e3 Mon Sep 17 00:00:00 2001 From: Erik Godding Boye Date: Sun, 7 Jul 2024 19:22:30 +0200 Subject: [PATCH] simplify logic (not found) Signed-off-by: Erik Godding Boye --- pkg/bundle/target.go | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/pkg/bundle/target.go b/pkg/bundle/target.go index 9c003ac6..9191909d 100644 --- a/pkg/bundle/target.go +++ b/pkg/bundle/target.go @@ -52,14 +52,13 @@ func (b *bundle) syncConfigMapTarget( return false, fmt.Errorf("failed to get ConfigMap %s: %w", name, err) } - // If the ConfigMap exists, but the Bundle is being deleted, delete the ConfigMap. - if apierrors.IsNotFound(err) && !shouldExist { - return false, nil - } - - // If the ConfigMap should not exist, but it does, delete it. - if !apierrors.IsNotFound(err) && !shouldExist { - // apply empty patch to remove the key + if !shouldExist { + // If the ConfigMap is not found and should not exist we are done. + if apierrors.IsNotFound(err) { + return false, nil + } + // If the ConfigMap should not exist, but it does, delete it. + // Apply empty patch to remove the keys configMap, err := b.targetReconciler.PatchConfigMap(ctx, target.NewConfigMapPatch(name, *bundle)) if err != nil { return false, fmt.Errorf("failed to patch ConfigMap %s: %w", name, err) @@ -133,14 +132,13 @@ func (b *bundle) syncSecretTarget( return false, fmt.Errorf("failed to get Secret %s: %w", name, err) } - // If the target obj exists, but the Bundle is being deleted, delete the Secret. - if apierrors.IsNotFound(err) && !shouldExist { - return false, nil - } - - // If the Secret should not exist, but it does, delete it. - if !apierrors.IsNotFound(err) && !shouldExist { - // apply empty patch to remove the key + if !shouldExist { + // If the Secret is not found and should not exist we are done. + if apierrors.IsNotFound(err) { + return false, nil + } + // If the Secret should not exist, but it does, delete it. + // Apply empty patch to remove the keys secret, err := b.targetReconciler.PatchSecret(ctx, target.NewSecretPatch(name, *bundle)) if err != nil { return false, fmt.Errorf("failed to patch Secret %s: %w", name, err)