{"record":{"id":"0f3f7a786e01132d","repo":"argoproj/argo-workflows","slug":"error-deleting-workflow-s-w","errorCode":null,"errorMessage":"error deleting workflow '%s': %w","messagePattern":"error deleting workflow '(.+?)': %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"workflow/cron/operator.go","lineNumber":467,"sourceCode":"}\n\nfunc (woc *cronWfOperationCtx) deleteOldestWorkflows(ctx context.Context, jobList []v1alpha1.Workflow, workflowsToKeep int) error {\n\tif workflowsToKeep >= len(jobList) {\n\t\treturn nil\n\t}\n\n\tsort.SliceStable(jobList, func(i, j int) bool {\n\t\treturn jobList[i].Status.FinishedAt.After(jobList[j].Status.FinishedAt.Time)\n\t})\n\n\tfor _, wf := range jobList[workflowsToKeep:] {\n\t\terr := woc.wfClient.Delete(ctx, wf.Name, v1.DeleteOptions{})\n\t\tif err != nil {\n\t\t\tif apierrors.IsNotFound(err) {\n\t\t\t\twoc.log.WithField(\"workflow\", wf.Name).Info(ctx, \"Workflow was already deleted\")\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\treturn fmt.Errorf(\"error deleting workflow '%s': %w\", wf.Name, err)\n\t\t}\n\t\twoc.log.WithField(\"workflow\", wf.Name).Info(ctx, \"Deleted Workflow due to CronWorkflow history limit\")\n\t}\n\treturn nil\n}\n\nfunc (woc *cronWfOperationCtx) reportCronWorkflowError(ctx context.Context, conditionType v1alpha1.ConditionType, errString string) {\n\twoc.log.WithField(\"conditionType\", conditionType).Error(ctx, errString)\n\twoc.cronWf.Status.Conditions.UpsertCondition(v1alpha1.Condition{\n\t\tType:    conditionType,\n\t\tMessage: errString,\n\t\tStatus:  v1.ConditionTrue,\n\t})\n\tif conditionType == v1alpha1.ConditionTypeSpecError {\n\t\twoc.metrics.CronWorkflowSpecError(ctx)\n\t} else {\n\t\tif conditionType == v1alpha1.ConditionTypeSubmissionError {\n\t\t\twoc.cronWf.Status.Failed++","sourceCodeStart":449,"sourceCodeEnd":485,"githubUrl":"https://github.com/argoproj/argo-workflows/blob/35bff19146f5a6ada77468c431f2624bd577e373/workflow/cron/operator.go#L449-L485","documentation":"A specific child workflow could not be deleted while enforcing CronWorkflow history limits. NotFound errors are tolerated and logged (the workflow was already gone), but any other Kubernetes API error from wfClient.Delete is wrapped with the workflow name and aborts the pruning loop.","triggerScenarios":"wfClient.Delete(ctx, wf.Name, DeleteOptions{}) fails with a non-NotFound error: 403 Forbidden from RBAC, 409 Conflict from finalizers/ownership, 429 from API throttling, or network failure to the API server.","commonSituations":"Namespace-scoped controller lacking delete rights in another namespace, workflows with blocking finalizers, or API server connectivity issues in the cluster.","solutions":["Inspect the wrapped k8s error in the controller log (Forbidden/Conflict/Timeout)","Fix RBAC so the controller can delete workflows in the target namespace","Check kubectl describe wf <name> for stuck finalizers and resolve them","If API throttling, scale down concurrent deletions or wait — the next sync retries"],"exampleFix":"# before\nkubectl auth can-i delete workflows.argoproj.io -n my-ns --as=system:serviceaccount:argo:workflow-controller\n# no\n# after: add to controller role\n- apiGroups: [argoproj.io]\n  resources: [workflows]\n  verbs: [delete]","handlingStrategy":"retry","validationCode":"// Pre-check deletability\nwf, err := wfClient.Get(ctx, wfName, metav1.GetOptions{})\nif err == nil && len(wf.Finalizers) > 0 {\n    // resolve finalizers before history pruning will succeed\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Ensure namespace-scoped controllers have rights in every namespace they manage","Avoid adding custom finalizers to workflows that can never be satisfied","Monitor API server throttling (429s) which can make bulk deletes fail","Treat NotFound as success — the operator already does; alert only on other causes"],"tags":["kubernetes","rbac","deletion","argo-workflows"],"backgroundTag":"kubernetes-api-delete-failed","analyzedSha":"35bff19146f5a6ada77468c431f2624bd577e373","analyzedAt":"2026-09-03T19:34:35.908Z","contentChangedAt":"2026-09-03T19:34:35.908Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}