Skip to content

Commit

Permalink
simplify logic (not found)
Browse files Browse the repository at this point in the history
Signed-off-by: Erik Godding Boye <[email protected]>
  • Loading branch information
erikgb committed Jul 7, 2024
1 parent 8251d2a commit a45907b
Showing 1 changed file with 14 additions and 16 deletions.
30 changes: 14 additions & 16 deletions pkg/bundle/target.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit a45907b

Please sign in to comment.