{"record":{"id":"9bb48ff8dc7c88b5","repo":"kubernetes/kops","slug":"failed-to-parse-objects-w","errorCode":null,"errorMessage":"failed to parse objects: %w","messagePattern":"failed to parse objects: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"channels/pkg/channels/clientapplier.go","lineNumber":39,"sourceCode":"\t\"fmt\"\n\n\tmetav1 \"k8s.io/apimachinery/pkg/apis/meta/v1\"\n\t\"k8s.io/client-go/dynamic\"\n\t\"k8s.io/client-go/restmapper\"\n\t\"k8s.io/kops/pkg/applylib/applyset\"\n\t\"k8s.io/kops/pkg/kubemanifest\"\n)\n\ntype ClientApplier struct {\n\tClient     dynamic.Interface\n\tRESTMapper *restmapper.DeferredDiscoveryRESTMapper\n}\n\n// Apply applies the manifest to the cluster.\nfunc (p *ClientApplier) Apply(ctx context.Context, manifest []byte) error {\n\tobjects, err := kubemanifest.LoadObjectsFrom(manifest)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to parse objects: %w\", err)\n\t}\n\n\t// TODO: Cache applyset for more efficient applying\n\tpatchOptions := metav1.PatchOptions{\n\t\tFieldManager: \"kops\",\n\t}\n\n\t// We force to overcome errors like: Apply failed with 1 conflict: conflict with \"kubectl-client-side-apply\" using apps/v1: .spec.template.spec.containers[name=\"foo\"].image\n\t// TODO: How to handle this better?   In a controller we don't have a choice and have to force eventually.\n\t// But we could do something like try first without forcing, log the conflict if there is one, and then force.\n\t// This would mean that if there was a loop we could log/detect it.\n\t// We could even do things like back-off on the force apply.\n\tforce := true\n\tpatchOptions.Force = &force\n\n\ts, err := applyset.New(applyset.Options{\n\t\tRESTMapper:   p.RESTMapper,\n\t\tClient:       p.Client,","sourceCodeStart":21,"sourceCodeEnd":57,"githubUrl":"https://github.com/kubernetes/kops/blob/4c8573c808a73d578c5eadc86d410646ea0b0d73/channels/pkg/channels/clientapplier.go#L21-L57","documentation":"ClientApplier.Apply parses the raw YAML manifest into typed Kubernetes objects via kubemanifest.LoadObjectsFrom before applying them. If the manifest is not valid YAML or an object is malformed, parsing fails and the underlying error is wrapped with this message. Nothing is sent to the cluster.","triggerScenarios":"Calling Apply with a manifest containing YAML syntax errors, invalid Kubernetes object structure, unknown/malformed kinds, or non-UTF8 bytes.","commonSituations":"Hand-edited addon manifests; templating left unresolved placeholders (e.g. {{ }}) in the YAML; wrong file loaded (HTML error page from a failed fetch); schema drift after Kubernetes API changes.","solutions":["Validate the manifest locally: kubectl apply --dry-run=client -f manifest.yaml or yamllint.","Check for unresolved template placeholders and render templates before calling Apply.","Confirm the fetched data is the actual YAML (not an HTML error page).","Fix YAML indentation/syntax at the position given in the wrapped error.","Regenerate the manifest from the upstream addon source."],"exampleFix":"// before\nerr := applier.Apply(ctx, manifestBytes) // manifestBytes contains templated {{ .Foo }}\n// after\nrendered, err := renderTemplate(tmpl, data)\nif err != nil { return err }\nif err := yaml.Unmarshal(rendered, &struct{}{}); err != nil { return fmt.Errorf(\"invalid manifest: %w\", err) }\nerr = applier.Apply(ctx, rendered)","handlingStrategy":"validation","validationCode":"var raw []map[string]any\nif err := yaml.Unmarshal(manifest, &raw); err != nil {\n    return fmt.Errorf(\"manifest is not valid YAML: %w\", err)\n}\nfor i, o := range raw {\n    if o[\"apiVersion\"] == nil || o[\"kind\"] == nil {\n        return fmt.Errorf(\"object %d missing apiVersion/kind\", i)\n    }\n}","typeGuard":"func isParseFailure(err error) bool {\n    return strings.Contains(err.Error(), \"failed to parse objects\")\n}","tryCatchPattern":"if err := applier.Apply(ctx, manifest); err != nil {\n    if isParseFailure(err) {\n        return fmt.Errorf(\"fix manifest before applying: %w\", err)\n    }\n    return err\n}","preventionTips":["Render all templates before passing bytes to Apply.","Run kubectl apply --dry-run=client -f as a pre-check.","Lint YAML with yamllint/kubeconform in CI.","Ensure fetched URLs return YAML, not HTML error pages."],"tags":["yaml","manifest","parsing","validation"],"backgroundTag":"yaml-parse-error","analyzedSha":"4c8573c808a73d578c5eadc86d410646ea0b0d73","analyzedAt":"2026-09-05T04:13:19.212Z","contentChangedAt":"2026-09-05T04:13:19.212Z","schemaVersion":2},"datasetVersion":"2026-09-12T07:17:12.445Z"}