argoproj/argo-workflows · error
Failed to convert the PodSpecPatch yaml to json
Error message
Failed to convert the PodSpecPatch yaml to json
What it means
ApplyPodSpecPatch accepts podSpecPatch values as YAML (workflow fields allow YAML there) and converts each to JSON via ConvertYAMLToJSON before strategic-merging, because PodSpec only carries JSON tags. If the YAML→JSON conversion fails — malformed YAML syntax, invalid types, or content that isn't a valid mapping — the underlying convert error is returned wrapped as "Failed to convert the PodSpecPatch yaml to json".
Source
Thrown at workflow/util/util.go:1689
if err != nil {
return str, err
}
return string(jsonStr), nil
}
return str, nil
}
func ApplyPodSpecPatch(podSpec apiv1.PodSpec, podSpecPatchYamls ...string) (*apiv1.PodSpec, error) {
podSpecJSON, err := json.Marshal(podSpec)
if err != nil {
return nil, errors.Wrap(err, "", "Failed to marshal the Pod spec")
}
for _, podSpecPatchYaml := range podSpecPatchYamls {
// must convert to json because PodSpec has only json tags
podSpecPatchJSON, convertErr := ConvertYAMLToJSON(podSpecPatchYaml)
if convertErr != nil {
return nil, errors.Wrap(convertErr, "", "Failed to convert the PodSpecPatch yaml to json")
}
// validate the patch to be a PodSpec
if unmarshalErr := json.Unmarshal([]byte(podSpecPatchJSON), &apiv1.PodSpec{}); unmarshalErr != nil {
return nil, fmt.Errorf("invalid podSpecPatch %q: %w", podSpecPatchYaml, unmarshalErr)
}
podSpecJSON, err = strategicpatch.StrategicMergePatch(podSpecJSON, []byte(podSpecPatchJSON), apiv1.PodSpec{})
if err != nil {
return nil, errors.Wrap(err, "", "Error occurred during strategic merge patch")
}
}
var newPodSpec apiv1.PodSpec
err = json.Unmarshal(podSpecJSON, &newPodSpec)
if err != nil {
return nil, errors.Wrap(err, "", "Error in Unmarshalling after merge the patch")
}View on GitHub (pinned to 35bff19146)
Solutions
- Validate the patch text with a YAML parser (e.g. `yq . podspec-patch.yaml`) and fix syntax errors — remember tabs are illegal in YAML.
- Ensure the patch is a mapping at top level (keys like spec.containers...), not a scalar or list.
- Test the patch locally with `argo lint` or a minimal workflow before applying to production.
Example fix
# before
podSpecPatch: |
containers: # tab indentation -> YAML parse error
- name: main
# after
podSpecPatch: |
containers: # spaces only
- name: main Defensive patterns
Strategy: validation
Validate before calling
# shell: validate the patch is well-formed YAML before submitting
yq eval '.' podspec-patch.yaml > /dev/null || { echo "podSpecPatch is not valid YAML"; exit 1; }
# Go: same check in-process
if _, err := util.ConvertYAMLToJSON(patch); err != nil {
return fmt.Errorf("podSpecPatch not convertible: %w", err)
} Try / catch
// Go: surface the exact YAML failure to the user
if _, err := util.ApplyPodSpecPatch(podSpec, patchYaml); err != nil {
if strings.Contains(err.Error(), "Failed to convert the PodSpecPatch yaml to json") {
return fmt.Errorf("fix podSpecPatch YAML syntax (no tabs, mapping at top level): %w", err)
}
return err
} Prevention
- Lint podSpecPatch YAML with yq or `argo lint` before submission.
- Use spaces, never tabs, in YAML patches.
- Keep patches as top-level mappings keyed by PodSpec fields.
- When templating patches, assert the rendered output is non-empty and parses.
When it happens
Trigger: Calling ApplyPodSpecPatch (used by the controller when applying spec.podSpecPatch, workflow-level podMetadata patches, etc.) with a podSpecPatch string that is not well-formed YAML or has a type error (e.g. a scalar where a map is required, tabs for indentation).
Common situations: Hand-editing podSpecPatch in workflow YAML with tabs or bad indentation; passing a JSON string with syntax errors; templating mistakes that inject empty or partially-rendered text into podSpecPatch; quoting issues when the patch is passed through environment variables or CLI flags.
Related errors
- Error occurred during strategic merge patch
- failed to parse TypeMeta: %w
- json: unknown field "%s"
- Internal
- Failed to marshal the Pod spec
AI-assisted analysis of argoproj/argo-workflows@35bff19146 (2026-09-03).
Data as JSON: /api/errors/574be7da62ca5a50.
Report an issue: GitHub.