{"record":{"id":"e05bec0cc3f256f0","repo":"kubernetes/kops","slug":"must-specify-a-cluster-when-creating-additional-ob","errorCode":null,"errorMessage":"must specify a cluster when creating additional objects","messagePattern":"must specify a cluster when creating additional objects","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/kops/create.go","lineNumber":222,"sourceCode":"\n\t\t\tcase *unstructured.Unstructured:\n\t\t\t\taddons = append(addons, kubemanifest.NewObject(v.Object))\n\n\t\t\tdefault:\n\t\t\t\tklog.V(2).Infof(\"Type of object was %T\", v)\n\t\t\t\treturn fmt.Errorf(\"unhandled kind %q in %s\", gvk, f)\n\t\t\t}\n\t\t}\n\t}\n\n\t// Because not all addons support labels, we can only support one cluster here.\n\t// A single cluster per create is probably a good idea anyway.\n\tif len(addons) != 0 {\n\t\tif len(clusters) > 1 {\n\t\t\treturn fmt.Errorf(\"cannot specify additional objects when multiple clusters are created\")\n\t\t}\n\t\tif len(clusters) == 0 {\n\t\t\treturn fmt.Errorf(\"must specify a cluster when creating additional objects\")\n\t\t}\n\t\tcluster := clusters[0]\n\n\t\taddonsClient := clientset.AddonsFor(cluster)\n\n\t\tif err := addonsClient.Replace(addons); err != nil {\n\t\t\treturn fmt.Errorf(\"error writing additional objects: %v\", err)\n\t\t}\n\t}\n\n\t{\n\t\t// If there is a value in this sb, this should mean that we have something to deploy\n\t\t// so let's advise the user how to engage the cloud provider and deploy\n\t\tif sb.String() != \"\" {\n\t\t\tfmt.Fprintf(&sb, \"\\n\")\n\t\t\tfmt.Fprintf(&sb, \"To deploy these resources, run: kops update cluster --name %s --yes\\n\", clusterName)\n\t\t\tfmt.Fprintf(&sb, \"\\n\")\n\t\t}","sourceCodeStart":204,"sourceCodeEnd":240,"githubUrl":"https://github.com/kubernetes/kops/blob/4c8573c808a73d578c5eadc86d410646ea0b0d73/cmd/kops/create.go#L204-L240","documentation":"Unstructured add-on objects cannot be attached to any cluster by themselves; RunCreate requires that at least one Cluster was created in the same `kops create -f` invocation. With addons present and zero clusters created, it returns this error instead of guessing a target.","triggerScenarios":"`kops create -f addons.yaml` containing only unstructured manifests (no kind: Cluster section) while the cluster already exists or was created in an earlier run.","commonSituations":"Applying add-on manifests against an existing cluster using `create` instead of `replace`; forgetting to include the Cluster document; automation assuming create can add addons to an existing cluster.","solutions":["Include the Cluster document in the same -f file when creating addons with `kops create`","Use `kops replace -f addons.yaml` to apply add-ons to an existing cluster","Create the cluster first, then pass add-ons in a subsequent `kops create -f` that also (re)includes the cluster, or use apply/replace"],"exampleFix":"// before\nkops create -f addons.yaml\n// after\nkops replace -f addons.yaml   # addons against existing cluster","handlingStrategy":"validation","validationCode":"clusters, addons := classify(docs)\nif len(addons) > 0 && len(clusters) == 0 {\n    return fmt.Errorf(\"add-on objects require a Cluster in the same create, or use kops replace\")\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use `kops replace -f` for add-ons against existing clusters","Include the Cluster document when using `kops create -f` for addons","Document in tooling that create is for new clusters, not incremental addon pushes"],"tags":["kops","cli","addons","missing-cluster"],"backgroundTag":"missing-parent-resource","analyzedSha":"4c8573c808a73d578c5eadc86d410646ea0b0d73","analyzedAt":"2026-09-05T04:13:19.212Z","contentChangedAt":"2026-09-05T04:13:19.212Z","schemaVersion":2},"datasetVersion":"2026-09-12T07:17:12.445Z"}