kubernetes/kops · error

error marshaling manifest to yaml: %v

Error message

error marshaling manifest to yaml: %v

What it means

After building the etcd-manager Pod manifest, the builder converts it to a versioned YAML with k8scodecs.ToVersionedYaml and wraps any failure. This means the in-memory Pod object could not be serialized to YAML — a marshaling failure of a struct that is normally always serializable, so the underlying error (from %v) is the real cause.

Source

Thrown at pkg/model/components/etcdmanager/model.go:116

	for _, etcdCluster := range b.Cluster.Spec.EtcdClusters {
		backupStore := ""
		if etcdCluster.Backups != nil {
			backupStore = etcdCluster.Backups.BackupStore
		}
		if backupStore == "" {
			return fmt.Errorf("backupStore must be set for use with etcd-manager")
		}

		for _, member := range etcdCluster.Members {
			instanceGroupName := fi.ValueOf(member.InstanceGroup)
			manifest, err := b.buildManifest(etcdCluster, instanceGroupName)
			if err != nil {
				return err
			}

			manifestYAML, err := k8scodecs.ToVersionedYaml(manifest)
			if err != nil {
				return fmt.Errorf("error marshaling manifest to yaml: %v", err)
			}

			name := fmt.Sprintf("%s-%s", etcdCluster.Name, instanceGroupName)
			c.AddTask(&fitasks.ManagedFile{
				Contents:  fi.NewBytesResource(manifestYAML),
				Lifecycle: b.Lifecycle,
				Location:  new("manifests/etcd/" + name + ".yaml"),
				Name:      new("manifests-etcdmanager-" + name),
			})
		}

		info := &etcdClusterSpec{
			EtcdVersion: etcdCluster.Version,
			MemberCount: int32(len(etcdCluster.Members)),
		}

		d, err := json.MarshalIndent(info, "", "  ")
		if err != nil {

View on GitHub (pinned to 4c8573c808)

Solutions

  1. Read the wrapped %v cause and fix the offending field in the etcd cluster spec / image override it points at.
  2. Ensure kOps dependencies (k8s.io/apimachinery, k8s.io/api) are consistent: `make gomod` after dependency changes.
  3. Upgrade or rebuild kops so the bundled etcd-manager manifest template matches the installed k8s codecs.
  4. Run with --v=2+ to capture which manifest (bundle) failed and file an issue if it reproduces with a stock template.
Defensive patterns

Strategy: try-catch

Validate before calling

if _, err := k8scodecs.ToVersionedYaml(manifest); err != nil {
	return fmt.Errorf("manifest for %q not serializable: %w", etcdCluster.Name, err)
}

Try / catch

if err := buildModel(); err != nil {
	if strings.Contains(err.Error(), "error marshaling manifest to yaml") {
		// inspect wrapped cause with --v=2 and fix the offending spec field
	}
}

Prevention

When it happens

Trigger: buildManifest produces a Pod containing values the Kubernetes codec cannot marshal (e.g. malformed typed fields, custom object injected into the manifest) during `kops update cluster`.

Common situations: kOps/k8s.io/api version skew where ToVersionedYaml cannot map the Pod to a registered versioned type; corrupted or patched etcd-manager template manifest; custom builds with modified Pod structs.

Related errors


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