kubesphere/kubesphere · error
label %s/%s already exists
Error message
label %s/%s already exists
What it means
createLabels rejects a CreateLabelRequest whose label (per labelExists matching against all existing cluster labels) is already present in the cluster's LabelList. The 400 response names the already-existing label; the whole create request containing it is rejected.
Source
Thrown at pkg/kapis/cluster/v1alpha1/label_handler.go:51
}
func (h *handler) createLabels(request *restful.Request, response *restful.Response) {
var labelRequests []apiv1alpha1.CreateLabelRequest
if err := request.ReadEntity(&labelRequests); err != nil {
api.HandleBadRequest(response, request, err)
return
}
allLabels := &clusterv1alpha1.LabelList{}
if err := h.client.List(context.Background(), allLabels); err != nil {
api.HandleBadRequest(response, request, err)
return
}
results := make([]*clusterv1alpha1.Label, 0)
for _, r := range labelRequests {
if labelExists(r, allLabels) {
api.HandleBadRequest(response, request, fmt.Errorf("label %s/%s already exists", r.Key, r.Value))
return
}
obj := &clusterv1alpha1.Label{
ObjectMeta: metav1.ObjectMeta{
Name: rand.String(6),
Finalizers: []string{clusterv1alpha1.LabelFinalizer},
},
Spec: clusterv1alpha1.LabelSpec{
Key: strings.TrimSpace(r.Key),
Value: strings.TrimSpace(r.Value),
},
}
if err := h.client.Create(context.Background(), obj); err != nil {
api.HandleBadRequest(response, request, err)
return
}
results = append(results, obj)View on GitHub (pinned to 04a29b5c60)
Solutions
- Skip or rename the duplicated label in the request and resubmit
- Reuse the existing label instead of creating a new one
- Pre-filter requested labels against current labels client-side before calling the API
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at pkg/kapis/cluster/v1alpha1/label_handler.go:51 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of kubesphere/kubesphere@04a29b5c60 (2026-09-03).
Data as JSON: /api/errors/affb49d22c5f6e37.
Report an issue: GitHub.