Skip to content

Commit 6484249

Browse files
committed
Include the key of invalid label's value in error message
For e.g., when specifying an invalid value for a label, it is not always clear which label the value was specified for. Including the key in the error message makes debugging easier.
1 parent 62219e1 commit 6484249

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

staging/src/k8s.io/apimachinery/pkg/labels/labels.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ func ConvertSelectorToLabelsMap(selector string) (Set, error) {
172172
return labelsMap, err
173173
}
174174
value := strings.TrimSpace(l[1])
175-
if err := validateLabelValue(value); err != nil {
175+
if err := validateLabelValue(key, value); err != nil {
176176
return labelsMap, err
177177
}
178178
labelsMap[key] = value

staging/src/k8s.io/apimachinery/pkg/labels/selector.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ func NewRequirement(key string, op selection.Operator, vals []string) (*Requirem
162162
}
163163

164164
for i := range vals {
165-
if err := validateLabelValue(vals[i]); err != nil {
165+
if err := validateLabelValue(key, vals[i]); err != nil {
166166
return nil, err
167167
}
168168
}
@@ -837,9 +837,9 @@ func validateLabelKey(k string) error {
837837
return nil
838838
}
839839

840-
func validateLabelValue(v string) error {
840+
func validateLabelValue(k, v string) error {
841841
if errs := validation.IsValidLabelValue(v); len(errs) != 0 {
842-
return fmt.Errorf("invalid label value: %q: %s", v, strings.Join(errs, "; "))
842+
return fmt.Errorf("invalid label value: %q: at key: %q: %s", v, k, strings.Join(errs, "; "))
843843
}
844844
return nil
845845
}

0 commit comments

Comments
 (0)