Skip to content

Commit

Permalink
gracefully skip patch if resource doesn't exist
Browse files Browse the repository at this point in the history
  • Loading branch information
linki committed Jan 18, 2023
1 parent e873e6a commit 405d61b
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions provisioner/clusterpy.go
Expand Up @@ -1116,7 +1116,7 @@ func performDeletion(ctx context.Context, logger *log.Entry, client dynamic.Inte
iface = client.Resource(gvr)
}
if deletion.Name != "" {
err := overrideDeletionProtection(ctx, deletion.Kind, deletion.Name, iface)
err := overrideDeletionProtection(ctx, logger, deletion.Kind, deletion.Name, iface)
if err != nil {
return err
}
Expand All @@ -1132,7 +1132,7 @@ func performDeletion(ctx context.Context, logger *log.Entry, client dynamic.Inte
}

for _, item := range items {
err := overrideDeletionProtection(ctx, deletion.Kind, item.GetName(), iface)
err := overrideDeletionProtection(ctx, logger, deletion.Kind, item.GetName(), iface)
if err != nil {
return err
}
Expand All @@ -1146,7 +1146,7 @@ func performDeletion(ctx context.Context, logger *log.Entry, client dynamic.Inte
return nil
}

func overrideDeletionProtection(ctx context.Context, kind, name string, iface dynamic.ResourceInterface) error {
func overrideDeletionProtection(ctx context.Context, logger *log.Entry, kind, name string, iface dynamic.ResourceInterface) error {
annotation := ""
switch kind {
case "Namespace":
Expand All @@ -1170,6 +1170,10 @@ func overrideDeletionProtection(ctx context.Context, kind, name string, iface dy
return err
}
_, err = iface.Patch(ctx, name, k8stypes.JSONPatchType, payload, metav1.PatchOptions{})
if apierrors.IsNotFound(err) {
logger.Infof("Skipping patch of %s %s: resource not found", kind, name)
return nil
}
if err != nil {
return err
}
Expand Down

0 comments on commit 405d61b

Please sign in to comment.