{"record":{"id":"4a009842127e068e","repo":"GoogleContainerTools/skaffold","slug":"kubectl-delete-w","errorCode":null,"errorMessage":"kubectl delete: %w","messagePattern":"kubectl delete: %w","errorType":"exception","errorClass":"CleanupErr","httpStatus":null,"severity":"error","filePath":"pkg/skaffold/deploy/kubectl/cli.go","lineNumber":84,"sourceCode":"\tJSONParseConfig() latest.JSONParseConfig\n\tEnablePlatformNodeAffinityInRenderedManifests() bool\n\tEnableGKEARMNodeTolerationInRenderedManifests() bool\n}\n\nfunc NewCLI(cfg Config, flags latest.KubectlFlags, defaultNamespace string) CLI {\n\treturn CLI{\n\t\tCLI:              kubectl.NewCLI(cfg, defaultNamespace),\n\t\tFlags:            flags,\n\t\tforceDeploy:      cfg.ForceDeploy(),\n\t\twaitForDeletions: cfg.WaitForDeletions(),\n\t}\n}\n\n// Delete runs `kubectl delete` on a list of manifests.\nfunc (c *CLI) Delete(ctx context.Context, out io.Writer, manifests manifest.ManifestList) error {\n\targs := c.args(c.Flags.Delete, \"--ignore-not-found=true\", \"--wait=false\", \"-f\", \"-\")\n\tif err := c.Run(ctx, manifests.Reader(), out, \"delete\", args...); err != nil {\n\t\treturn deployerr.CleanupErr(fmt.Errorf(\"kubectl delete: %w\", err))\n\t}\n\n\treturn nil\n}\n\n// Apply runs `kubectl apply` on a list of manifests.\nfunc (c *CLI) Apply(ctx context.Context, out io.Writer, manifests manifest.ManifestList) error {\n\tctx, endTrace := instrumentation.StartTrace(ctx, \"Apply\", map[string]string{\n\t\t\"AppliedBy\": \"kubectl\",\n\t})\n\tdefer endTrace()\n\t// Only redeploy modified or new manifests\n\t// TODO(dgageot): should we delete a manifest that was deployed and is not anymore?\n\tupdated := c.previousApply.Diff(manifests)\n\tlog.Entry(ctx).Debugf(\"%d manifests to deploy. %d are updated or new\", len(manifests), len(updated))\n\tif len(updated) == 0 {\n\t\treturn nil\n\t}","sourceCodeStart":66,"sourceCodeEnd":102,"githubUrl":"https://github.com/GoogleContainerTools/skaffold/blob/a1189de023efc32d4b8e11f395acc678aa555011/pkg/skaffold/deploy/kubectl/cli.go#L66-L102","documentation":"The kubectl CLI wrapper runs `kubectl delete` with --ignore-not-found and --wait=false to clean up deployed resources. If the kubectl command exits non-zero, the error is wrapped as a CleanupErr. This typically means kubectl itself failed (connection, auth, invalid manifest) rather than the resource being absent.","triggerScenarios":"c.Run(...) for `kubectl delete -f -` returns an error during Cleanup — cluster unreachable, auth expired, malformed stdin manifests, or kubectl binary issues.","commonSituations":"Cluster torn down or kubeconfig pointing at a dead endpoint; expired cloud credentials (gke/eks); context renamed or removed; manifests referencing APIs the cluster can't process on delete.","solutions":["Run `kubectl cluster-info` with the same kubeconfig/context to verify connectivity and fix kubeconfig or credentials.","Re-authenticate to the cluster (gcloud auth login / aws eks update-kubeconfig / az aks get-credentials).","Run `kubectl version` to confirm the kubectl binary is compatible with the cluster.","Since --ignore-not-found is set, retry cleanup after connectivity is restored."],"exampleFix":"// before: stale context\nkubectl config use-context stale-cluster\n// after\nkubectl config use-context my-cluster\nkubectl cluster-info  # verify reachable, then re-run skaffold delete","handlingStrategy":"try-catch","validationCode":"// Verify cluster reachability before cleanup\nif err := exec.Command(\"kubectl\", \"cluster-info\").Run(); err != nil {\n    return fmt.Errorf(\"cluster unreachable, skipping cleanup: %w\", err)\n}","typeGuard":null,"tryCatchPattern":"err := cli.Delete(ctx, out, manifests)\nvar cleanupErr *deployerr.CleanupErr\nif errors.As(err, &cleanupErr) {\n    log.Warnf(\"cleanup failed: %v — check kubeconfig/credentials\", cleanupErr)\n}","preventionTips":["Run `kubectl cluster-info` in CI preflight before skaffold delete","Refresh cloud credentials (gcloud/aws/az) before long-running jobs","Pin kubeconfig context per environment","Note --ignore-not-found only masks missing resources, not connection errors"],"tags":["kubectl","kubernetes","cleanup","cli"],"backgroundTag":"kubectl-command-failed","analyzedSha":"a1189de023efc32d4b8e11f395acc678aa555011","analyzedAt":"2026-09-05T12:09:27.064Z","contentChangedAt":"2026-09-05T12:09:27.064Z","schemaVersion":2},"datasetVersion":"2026-09-12T17:17:11.597Z"}