{"record":{"id":"1682a798806cca9e","repo":"kubernetes/kops","slug":"cluster-name-label-q-not-yet-set","errorCode":null,"errorMessage":"cluster name label %q not yet set","messagePattern":"cluster name label %q not yet set","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/controllers/clusterapi/kopsconfig_controller.go","lineNumber":120,"sourceCode":"\tif err := r.storeBootstrapData(ctx, obj, data); err != nil {\n\t\treturn ctrl.Result{}, err\n\t}\n\n\tif err := r.client.Status().Update(ctx, obj); err != nil {\n\t\treturn ctrl.Result{}, fmt.Errorf(\"error patching status: %w\", err)\n\t}\n\treturn ctrl.Result{}, nil\n}\n\n// storeBootstrapData creates a new secret with the data passed in as input,\n// sets the reference in the configuration status and ready to true.\nfunc (r *KopsConfigReconciler) storeBootstrapData(ctx context.Context, parent *api.KopsConfig, data []byte) error {\n\t// log := ctrl.LoggerFrom(ctx)\n\n\tclusterName := parent.Labels[clusterv1.ClusterNameLabel]\n\n\tif clusterName == \"\" {\n\t\treturn fmt.Errorf(\"cluster name label %q not yet set\", clusterv1.ClusterNameLabel)\n\t}\n\n\tsecretName := types.NamespacedName{\n\t\tNamespace: parent.GetNamespace(),\n\t\tName:      parent.GetName(),\n\t}\n\n\tsecret := &corev1.Secret{\n\t\tObjectMeta: metav1.ObjectMeta{\n\t\t\tName:      secretName.Name,\n\t\t\tNamespace: secretName.Namespace,\n\t\t\tLabels: map[string]string{\n\t\t\t\tclusterv1.ClusterNameLabel: clusterName,\n\t\t\t},\n\t\t},\n\t\tData: map[string][]byte{\n\t\t\t\"value\": data,\n\t\t\t// \"format\": []byte(scope.Config.Spec.Format),","sourceCodeStart":102,"sourceCodeEnd":138,"githubUrl":"https://github.com/kubernetes/kops/blob/4c8573c808a73d578c5eadc86d410646ea0b0d73/pkg/controllers/clusterapi/kopsconfig_controller.go#L102-L138","documentation":"storeBootstrapData requires the KopsConfig object to carry the cluster.x-k8s.io/cluster-name label, which links a bootstrap config to its CAPI Cluster. If the label is absent or empty, the controller refuses to proceed because the created secret must be labeled with the cluster name for CAPI ownership/lookup. The %q verb prints the label key name (cluster.x-k8s.io/cluster-name), not a value — a slightly confusing message.","triggerScenarios":"A KopsConfig object was created without the clusterv1.ClusterNameLabel label; the label was removed by a mutating webhook, a GitOps prune/re-apply, or manual kubectl edit; the bootstrap provider was adopted onto a pre-existing KopsConfig that predates CAPI labeling conventions.","commonSituations":"Hand-crafted or GitOps-managed KopsConfig manifests missing metadata.labels; label stripped by a namespace-scoped policy or kustomize transform; clusterctl move operations that dropped labels.","solutions":["Add labels: cluster.x-k8s.io/cluster-name: <cluster-name> to the KopsConfig metadata and re-apply","Verify with kubectl get kopsconfig <name> -o jsonpath='{.metadata.labels.cluster\\.x-k8s\\.io/cluster-name}'","Ensure the machine/bootstrap provider (e.g. clusterctl or kops create cluster --cluster-api) sets the label on creation","Check for webhooks/kustomize overlays stripping labels"],"exampleFix":"# before\napiVersion: bootstrap.cluster.x-k8s.io/v1beta1\nkind: KopsConfig\nmetadata:\n  name: my-cluster-node\n# after\napiVersion: bootstrap.cluster.x-k8s.io/v1beta1\nkind: KopsConfig\nmetadata:\n  name: my-cluster-node\n  labels:\n    cluster.x-k8s.io/cluster-name: my-cluster","handlingStrategy":"validation","validationCode":"// check the label before reconcile\nclusterName := parent.Labels[\"cluster.x-k8s.io/cluster-name\"]\nif clusterName == \"\" {\n    return fmt.Errorf(\"KopsConfig %s/%s missing cluster-name label\", parent.Namespace, parent.Name)\n}","typeGuard":null,"tryCatchPattern":"if err := r.storeBootstrapData(ctx, obj, data); err != nil {\n    if strings.Contains(err.Error(), clusterv1.ClusterNameLabel) {\n        klog.Warningf(\"KopsConfig %s not yet labeled with cluster name, waiting\", obj.Name)\n        return ctrl.Result{RequeueAfter: 10 * time.Second}, nil\n    }\n    return ctrl.Result{}, err\n}","preventionTips":["Always create KopsConfig via tooling that sets cluster.x-k8s.io/cluster-name","Validate manifests with a policy (Kyverno/OPA) requiring the label","Re-check after clusterctl move or GitOps syncs that labels survive","Remember the error message prints the label KEY, not the missing value"],"tags":["labels","kubernetes","bootstrap","cluster-api"],"backgroundTag":"missing-cluster-name-label","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"}