kubernetes/kops · error

cannot specify additional objects when multiple clusters are

Error message

cannot specify additional objects when multiple clusters are created

What it means

Add-on (unstructured) objects have no cluster labels, so RunCreate attaches them only when exactly one cluster is created in the same invocation, using clusters[0]. If the -f input creates more than one Cluster plus additional objects, the target is ambiguous and the command aborts.

Source

Thrown at cmd/kops/create.go:219

					return err
				}
				fmt.Fprintf(&sb, "Added ssh credential\n")

			case *unstructured.Unstructured:
				addons = append(addons, kubemanifest.NewObject(v.Object))

			default:
				klog.V(2).Infof("Type of object was %T", v)
				return fmt.Errorf("unhandled kind %q in %s", gvk, f)
			}
		}
	}

	// Because not all addons support labels, we can only support one cluster here.
	// A single cluster per create is probably a good idea anyway.
	if len(addons) != 0 {
		if len(clusters) > 1 {
			return fmt.Errorf("cannot specify additional objects when multiple clusters are created")
		}
		if len(clusters) == 0 {
			return fmt.Errorf("must specify a cluster when creating additional objects")
		}
		cluster := clusters[0]

		addonsClient := clientset.AddonsFor(cluster)

		if err := addonsClient.Replace(addons); err != nil {
			return fmt.Errorf("error writing additional objects: %v", err)
		}
	}

	{
		// If there is a value in this sb, this should mean that we have something to deploy
		// so let's advise the user how to engage the cloud provider and deploy
		if sb.String() != "" {
			fmt.Fprintf(&sb, "\n")

View on GitHub (pinned to 4c8573c808)

Solutions

  1. Split the input: run `kops create -f` once per cluster, with add-ons only in the single-cluster file
  2. Remove the extra unstructured add-on objects from the multi-cluster file and apply them separately with `kops replace -f`
  3. Add cluster-scoping labels / use separate files per cluster

Example fix

// before
kops create -f bundle.yaml   # 2 clusters + addons
// after
kops create -f cluster1+addons.yaml
kops create -f cluster2.yaml
Defensive patterns

Strategy: validation

Validate before calling

clusters, addons := classify(docs)
if len(clusters) > 1 && len(addons) > 0 {
    return fmt.Errorf("split input: addons only allowed with exactly one cluster")
}

Prevention

When it happens

Trigger: `kops create -f bundle.yaml` where bundle.yaml contains two Cluster documents plus unstructured add-on manifests; or a directory-style -f concat producing multiple clusters and addons together.

Common situations: Multi-cluster provisioning bundles; generated config files that combine several clusters and shared add-ons; users migrating from per-file apply scripts to one big -f file.

Related errors


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