kubernetes/kops · error
error parsing file %q: %v
Error message
error parsing file %q: %v
What it means
RunCreate splits each input file into YAML sections and decodes them with the kops codecs; this fires when a section cannot be decoded as a known kops object. The file was read successfully, so the problem is its content: invalid YAML structure or an unrecognized kind.
Source
Thrown at cmd/kops/create.go:129
for _, f := range c.Filenames {
var contents []byte
if f == "-" {
contents, err = ConsumeStdin()
if err != nil {
return err
}
} else {
contents, err = vfsContext.ReadFile(f)
if err != nil {
return fmt.Errorf("error reading file %q: %v", f, err)
}
}
// TODO: this does not support a JSON array
sections := text.SplitContentToSections(contents)
for _, section := range sections {
o, gvk, err := kopscodecs.Decode(section, nil)
if err != nil {
return fmt.Errorf("error parsing file %q: %v", f, err)
}
switch v := o.(type) {
case *kopsapi.Cluster:
cloud, err := cloudup.BuildCloud(v)
if err != nil {
return err
}
// Adding a PerformAssignments() call here as the user might be trying to use
// the new `-f` feature, with an old cluster definition.
err = cloudup.PerformAssignments(v, vfsContext, cloud)
if err != nil {
return fmt.Errorf("error populating configuration: %v", err)
}
_, err = clientset.CreateCluster(ctx, v)
if err != nil {
if apierrors.IsAlreadyExists(err) {View on GitHub (pinned to 4c8573c808)
Solutions
- Validate the YAML/JSON syntax (yamllint) and ensure each document has a kops apiVersion and kind (e.g. kops.k8s.io/v1alpha2, Cluster)
- Match the manifest schema to your kops CLI version; upgrade kops if the file uses newer fields
- Test decode with `kops toolbox dump` or `kops get -f` round-trip; fix fields flagged in the wrapped error message
Example fix
// before kind: Cluser apiVersion: v1alpha2 // after kind: Cluster apiVersion: kops.k8s.io/v1alpha2
Defensive patterns
Strategy: validation
Validate before calling
// validate syntax and required headers before kops create
sections := text.SplitContentToSections(contents)
for _, s := range sections {
var probe map[string]interface{}
if err := yaml.Unmarshal(s, &probe); err != nil {
return fmt.Errorf("invalid YAML: %v", err)
}
if probe["kind"] == nil || probe["apiVersion"] == nil {
return fmt.Errorf("manifest missing kind/apiVersion")
}
} Try / catch
if _, _, err := kopscodecs.Decode(section, nil); err != nil {
// print offending section and schema version expected by kops
log.Printf("decode failed for %q: %v", f, err)
} Prevention
- Generate manifests with `kops create cluster`/`kops get -o yaml` rather than writing by hand
- Lint manifests with yamllint and match apiVersion to your kops binary version
- Keep each YAML document a single kops resource (arrays unsupported)
- Round-trip with `kops get -f` in CI before create
When it happens
Trigger: `kops create -f` given a manifest that is not a valid kops resource: wrong apiVersion/kind, invalid YAML/JSON syntax, unknown fields causing strict decode failure, or a spec from a newer kOps version.
Common situations: Hand-written cluster/instancegroup YAML with indentation errors; manifests exported from a newer kOps; using a Kubernetes resource YAML (e.g. a Deployment) instead of a kops resource; missing kind or apiVersion.
Understand the failure class
Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.
Related errors
- error parsing yaml: %v
- error parsing InstanceGroup: %v
- unable decode the configuration file: %s, error: %v
- error parsing addons or manifest: %v
- error parsing addons: %v
AI-assisted analysis of kubernetes/kops@4c8573c808 (2026-09-05).
Data as JSON: /api/errors/158de1b09106bbfa.
Report an issue: GitHub.