kubernetes/kops · error

error marshalling host data: %w

Error message

error marshalling host data: %w

What it means

With `--build-host` (dry-run mode), the command marshals the assembled BootstrapData/host configuration to YAML to print it. If yaml.Marshal fails on the hostData structure, the error is wrapped as "error marshalling host data".

Source

Thrown at pkg/commands/toolbox_enroll.go:148

	sudo := options.SSHUser != "root"

	sshTarget, err := NewSSHHost(ctx, options.Host, options.SSHPort, options.SSHUser, sudo)
	if err != nil {
		return err
	}
	defer sshTarget.Close()

	hostData, err := buildHostData(ctx, sshTarget, options)
	if err != nil {
		return err
	}

	if options.BuildHost {
		klog.Infof("building host data for %+v", hostData)
		b, err := yaml.Marshal(hostData)
		if err != nil {
			return fmt.Errorf("error marshalling host data: %w", err)
		}
		fmt.Fprintf(out, "%s\n", string(b))
		return nil
	}

	fullInstanceGroup, err := configBuilder.GetFullInstanceGroup(ctx)
	if err != nil {
		return err
	}
	bootstrapData, err := configBuilder.GetBootstrapData(ctx)
	if err != nil {
		return err
	}

	if err := enrollHost(ctx, fullInstanceGroup, bootstrapData, restConfig, hostData, sshTarget); err != nil {
		return err
	}

View on GitHub (pinned to 4c8573c808)

Solutions

  1. Inspect the wrapped inner error to find the offending field
  2. Upgrade/align kops and Cluster API provider CRD versions so Host schema matches
  3. Re-run without --build-host to see whether the failure is specific to the dry-run path
Defensive patterns

Strategy: try-catch

Try / catch

if err := RunToolboxEnroll(ctx, f, out, opts); err != nil {
    var marshalErr interface{ Unwrap() error }
    if strings.Contains(err.Error(), "error marshalling host data") {
        log.Printf("host data serialization failed: %v", err)
    }
    return err
}

Prevention

When it happens

Trigger: Running `kops toolbox enroll --build-host ...` where the populated hostData contains values that cannot be serialized to YAML/JSON-compatible form.

Common situations: Very rare; usually indicates a version mismatch between kops and the CRD schema (v1alpha2.Host) or corrupted bootstrap data (e.g. binary content in fields).

Related errors


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