kubernetes/kops · error

error converting boot config to yaml: %w

Error message

error converting boot config to yaml: %w

What it means

Inside the KubeEnv template function, the NodeUpScript's BootConfig struct is serialized to YAML with utils.YamlMarshal to be embedded in the nodeup script. This error is thrown if that marshal fails. It is rare because BootConfig is a plain struct, but a failure here means the bootstrap data cannot be produced.

Source

Thrown at pkg/model/resources/nodeup.go:353

			if b.NodeUpAssets[architectures.ArchitectureAmd64] != nil {
				return b.NodeUpAssets[architectures.ArchitectureAmd64].Hash.Hex()
			}
			return ""
		},
		"NodeUpSourceArm64": func() (string, error) {
			return b.nodeUpSource(architectures.ArchitectureArm64)
		},
		"NodeUpSourceHashArm64": func() string {
			if b.NodeUpAssets[architectures.ArchitectureArm64] != nil {
				return b.NodeUpAssets[architectures.ArchitectureArm64].Hash.Hex()
			}
			return ""
		},

		"KubeEnv": func() (string, error) {
			bootConfigData, err := utils.YamlMarshal(b.BootConfig)
			if err != nil {
				return "", fmt.Errorf("error converting boot config to yaml: %w", err)
			}

			return string(bootConfigData), nil
		},

		"GzipBase64": gzipBase64,

		"CompressUserData": func() bool {
			return b.CompressUserData
		},

		"GetCloudProvider": func() string {
			return b.CloudProvider
		},

		"SetSysctls": func() string {
			return b.SetSysctls
		},

View on GitHub (pinned to 4c8573c808)

Solutions

  1. Check the wrapped marshal error for the offending field/type.
  2. Ensure BootConfig is the standard nodeup.BootConfig struct populated through normal kops constructors.
  3. If you modified BootConfig, make all new fields YAML-serializable (no channels, funcs, or cycles).
  4. Upgrade/align kops versions so BootConfig matches what the template expects.

Example fix

// before
type BootConfig struct { Callback func() `yaml:"callback"` } // not marshallable
// after
type BootConfig struct { Config string `json:"config"` }
Defensive patterns

Strategy: try-catch

Validate before calling

if _, err := utils.YamlMarshal(b.BootConfig); err != nil {
    return fmt.Errorf("boot config not yaml-marshalable: %w", err)
}

Type guard

func marshalable(v interface{}) bool { _, err := utils.YamlMarshal(v); return err == nil }

Try / catch

data, err := utils.YamlMarshal(b.BootConfig)
if err != nil {
    return fmt.Errorf("inspect BootConfig fields for non-serializable types: %w", err)
}

Prevention

When it happens

Trigger: Build executing the KubeEnv template function while YamlMarshal fails on b.BootConfig — e.g. a BootConfig field holding a value the YAML encoder cannot represent (unsupported type such as a channel/func-bearing field or an invalid marshaling state introduced by upstream changes).

Common situations: Custom builds with modified BootConfig types, vendored forks with non-serializable fields, or corrupted/nonsensical BootConfig values injected programmatically.

Related errors


AI-assisted analysis of kubernetes/kops@4c8573c808 (2026-09-05). Data as JSON: /api/errors/54d7c07e956c9ee8. Report an issue: GitHub.