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)