{"record":{"id":"cec7a3400b859781","repo":"argoproj/argo-workflows","slug":"error-applying-podspecpatch","errorCode":null,"errorMessage":"Error applying PodSpecPatch","messagePattern":"Error applying PodSpecPatch","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"workflow/controller/workflowpod.go","lineNumber":744,"sourceCode":"\t\t\t}\n\t\t}\n\t\treturn nil\n\t})\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\t// Apply the patch string from workflow and template\n\tvar podSpecPatchs []string\n\tpodSpecPatchs, err = pb.processPodSpecPatch(ctx, tmpl, pod)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\tif len(podSpecPatchs) > 0 {\n\t\tvar patchedPodSpec *apiv1.PodSpec\n\t\tpatchedPodSpec, err = util.ApplyPodSpecPatch(pod.Spec, podSpecPatchs...)\n\t\tif err != nil {\n\t\t\treturn nil, errors.Wrap(err, \"\", \"Error applying PodSpecPatch\")\n\t\t}\n\t\tpod.Spec = *patchedPodSpec\n\t}\n\n\t// In init-less mode the emissary binary is mounted at /argo-bin via the\n\t// argoexec-bin image volume, not copied to /var/run/argo by an init container.\n\t// K8s image volumes expose the image's root filesystem as-is.\n\targoexecBinaryPath := pb.layout.argoexecBinaryPath()\n\tfor i, c := range pod.Spec.Containers {\n\t\tif !common.IsArgoSidecar(c.Name) {\n\t\t\t// https://kubernetes.io/docs/tasks/inject-data-application/define-command-argument-container/#notes\n\t\t\tif len(c.Command) == 0 {\n\t\t\t\tvar x *entrypoint.Image\n\t\t\t\tx, err = pb.deps.lookupImage(ctx, c.Image, entrypoint.Options{\n\t\t\t\t\tNamespace: pb.in.namespace, ServiceAccountName: pb.in.execWfSpec.ServiceAccountName, ImagePullSecrets: pb.in.execWfSpec.ImagePullSecrets,\n\t\t\t\t})\n\t\t\t\tif err != nil {\n\t\t\t\t\treturn nil, fmt.Errorf(\"failed to look-up entrypoint/cmd for image %q, you must either explicitly specify the command, or list the image's command in the index: https://argo-workflows.readthedocs.io/en/latest/workflow-executors/#emissary-emissary: %w\", c.Image, err)","sourceCodeStart":726,"sourceCodeEnd":762,"githubUrl":"https://github.com/argoproj/argo-workflows/blob/35bff19146f5a6ada77468c431f2624bd577e373/workflow/controller/workflowpod.go#L726-L762","documentation":"After building the pod spec, the controller applies any podSpecPatch(es) with util.ApplyPodSpecPatch. If the resulting JSON/strategic-merge patch is invalid or cannot be applied to the generated pod spec, the build fails with this wrapped error.","triggerScenarios":"podSpecPatch with invalid JSON, patching a container name that doesn't exist (e.g. not 'main'), or a patch incompatible with the generated pod spec structure.","commonSituations":"Hand-written JSON patches with wrong container names; strategic-merge patches that conflict with injected volumes/volumes mounts; multi-patch templates (with pod_spec_patch as output parameter) producing incompatible patches at runtime.","solutions":["Validate the patch JSON syntax and patch operations","Ensure patched container names match generated containers ('main', 'init', 'wait')","Print the generated pod (kubectl get pod -o yaml) and align the patch with its structure"],"exampleFix":"// before\npodSpecPatch: '[{\"op\":\"replace\",\"path\":\"/containers/1/image\",\"value\":\"foo\"}]' // container 1 may not exist\n// after\npodSpecPatch: '[{\"op\":\"replace\",\"path\":\"/containers/0/image\",\"value\":\"foo\"}]'","handlingStrategy":"validation","validationCode":"// validate patch JSON before applying\nvar check interface{}\nif err := json.Unmarshal([]byte(patchStr), &check); err != nil {\n  return fmt.Errorf(\"invalid podSpecPatch JSON: %w\", err)\n}","typeGuard":null,"tryCatchPattern":"patched, err := util.ApplyPodSpecPatch(pod.Spec, patches...)\nif err != nil {\n  return nil, fmt.Errorf(\"error applying PodSpecPatch: %w\", err)\n}\npod.Spec = *patched","preventionTips":["Use correct container names ('main') in patches","Validate JSON/strategic-merge patch syntax offline (kubectl patch --dry-run)","Inspect generated pods and keep patches aligned with the spec structure"],"tags":["kubernetes","podspec-patch","json-patch","argo-workflows"],"backgroundTag":"podspec-patch-application-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"}