kubernetes/kops · error

cluster name label %q not yet set

Error message

cluster name label %q not yet set

What it means

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.

Source

Thrown at pkg/controllers/clusterapi/kopsconfig_controller.go:120

	if err := r.storeBootstrapData(ctx, obj, data); err != nil {
		return ctrl.Result{}, err
	}

	if err := r.client.Status().Update(ctx, obj); err != nil {
		return ctrl.Result{}, fmt.Errorf("error patching status: %w", err)
	}
	return ctrl.Result{}, nil
}

// storeBootstrapData creates a new secret with the data passed in as input,
// sets the reference in the configuration status and ready to true.
func (r *KopsConfigReconciler) storeBootstrapData(ctx context.Context, parent *api.KopsConfig, data []byte) error {
	// log := ctrl.LoggerFrom(ctx)

	clusterName := parent.Labels[clusterv1.ClusterNameLabel]

	if clusterName == "" {
		return fmt.Errorf("cluster name label %q not yet set", clusterv1.ClusterNameLabel)
	}

	secretName := types.NamespacedName{
		Namespace: parent.GetNamespace(),
		Name:      parent.GetName(),
	}

	secret := &corev1.Secret{
		ObjectMeta: metav1.ObjectMeta{
			Name:      secretName.Name,
			Namespace: secretName.Namespace,
			Labels: map[string]string{
				clusterv1.ClusterNameLabel: clusterName,
			},
		},
		Data: map[string][]byte{
			"value": data,
			// "format": []byte(scope.Config.Spec.Format),

View on GitHub (pinned to 4c8573c808)

Solutions

  1. Add labels: cluster.x-k8s.io/cluster-name: <cluster-name> to the KopsConfig metadata and re-apply
  2. Verify with kubectl get kopsconfig <name> -o jsonpath='{.metadata.labels.cluster\.x-k8s\.io/cluster-name}'
  3. Ensure the machine/bootstrap provider (e.g. clusterctl or kops create cluster --cluster-api) sets the label on creation
  4. Check for webhooks/kustomize overlays stripping labels

Example fix

# before
apiVersion: bootstrap.cluster.x-k8s.io/v1beta1
kind: KopsConfig
metadata:
  name: my-cluster-node
# after
apiVersion: bootstrap.cluster.x-k8s.io/v1beta1
kind: KopsConfig
metadata:
  name: my-cluster-node
  labels:
    cluster.x-k8s.io/cluster-name: my-cluster
Defensive patterns

Strategy: validation

Validate before calling

// check the label before reconcile
clusterName := parent.Labels["cluster.x-k8s.io/cluster-name"]
if clusterName == "" {
    return fmt.Errorf("KopsConfig %s/%s missing cluster-name label", parent.Namespace, parent.Name)
}

Try / catch

if err := r.storeBootstrapData(ctx, obj, data); err != nil {
    if strings.Contains(err.Error(), clusterv1.ClusterNameLabel) {
        klog.Warningf("KopsConfig %s not yet labeled with cluster name, waiting", obj.Name)
        return ctrl.Result{RequeueAfter: 10 * time.Second}, nil
    }
    return ctrl.Result{}, err
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


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