mirror of
				https://github.com/k3s-io/kubernetes.git
				synced 2025-10-30 21:30:16 +00:00 
			
		
		
		
	Merge pull request #34020 from juanvallejo/jvallejo/allow-empty-annotation-values
Automatic merge from submit-queue Allow empty annotation values Related downstream issue: https://github.com/openshift/origin/issues/11175 **Release note**: ```release-note release-note-none ``` Annotations with empty values can be used, for example, in diagnostics logging. This patch removes the client-side check for empty values in an annotation key-value pair. **Before** ``` $ kubectl annotate pod zookeeper-1 node-selector="" --overwrite error: invalid annotation format: node-selector= ``` **After** ``` $ kubectl annotate pod zookeeper-1 node-selector="" --overwrite pod "zookeper-1" annotated ``` ``` $ kubectl get po/zookeeper-1 --template='{{.metadata.annotations}}' map[... node-selector: test-label:test] ``` @fabianofranz @liggitt
This commit is contained in:
		| @@ -624,6 +624,22 @@ runTests() { | ||||
|   # Post-condition: valid-pod is labelled | ||||
|   kube::test::get_object_assert 'pod valid-pod' "{{range$labels_field}}{{.}}:{{end}}" 'valid-pod:new-valid-pod:' | ||||
|  | ||||
|   ### Label the valid-pod POD with empty label value | ||||
|   # Pre-condition: valid-pod does not have label "emptylabel" | ||||
|   kube::test::get_object_assert 'pod valid-pod' "{{range$labels_field}}{{.}}:{{end}}" 'valid-pod:new-valid-pod:' | ||||
|   # Command | ||||
|   kubectl label pods valid-pod emptylabel="" "${kube_flags[@]}" | ||||
|   # Post-condition: valid pod contains "emptylabel" with no value | ||||
|   kube::test::get_object_assert 'pod valid-pod' "{{${labels_field}.emptylabel}}" '' | ||||
|  | ||||
|   ### Annotate the valid-pod POD with empty annotation value | ||||
|   # Pre-condition: valid-pod does not have annotation "emptyannotation" | ||||
|   kube::test::get_object_assert 'pod valid-pod' "{{${annotations_field}.emptyannotation}}" '<no value>' | ||||
|   # Command | ||||
|   kubectl annotate pods valid-pod emptyannotation="" "${kube_flags[@]}" | ||||
|   # Post-condition: valid pod contains "emptyannotation" with no value | ||||
|   kube::test::get_object_assert 'pod valid-pod' "{{${annotations_field}.emptyannotation}}" '' | ||||
|  | ||||
|   ### Record label change | ||||
|   # Pre-condition: valid-pod does not have record annotation | ||||
|   kube::test::get_object_assert 'pod valid-pod' "{{range.items}}{{$annotations_field}}:{{end}}" '' | ||||
|   | ||||
| @@ -144,14 +144,15 @@ func TestParseAnnotations(t *testing.T) { | ||||
| 		}, | ||||
| 		{ | ||||
| 			annotations:    []string{"a="}, | ||||
| 			expectedErr: "invalid annotation format: a=", | ||||
| 			scenario:    "incorrect annotation input (missing value)", | ||||
| 			expectErr:   true, | ||||
| 			expected:       map[string]string{"a": ""}, | ||||
| 			expectedRemove: []string{}, | ||||
| 			scenario:       "add valid annotation with empty value", | ||||
| 			expectErr:      false, | ||||
| 		}, | ||||
| 		{ | ||||
| 			annotations: []string{"ab", "a="}, | ||||
| 			expectedErr: "invalid annotation format: ab, a=", | ||||
| 			scenario:    "incorrect multiple annotation input (missing value)", | ||||
| 			expectedErr: "invalid annotation format: ab", | ||||
| 			scenario:    "incorrect annotation input (missing =value)", | ||||
| 			expectErr:   true, | ||||
| 		}, | ||||
| 	} | ||||
|   | ||||
| @@ -122,7 +122,7 @@ func parseLabels(spec []string) (map[string]string, []string, error) { | ||||
| 	for _, labelSpec := range spec { | ||||
| 		if strings.Index(labelSpec, "=") != -1 { | ||||
| 			parts := strings.Split(labelSpec, "=") | ||||
| 			if len(parts) != 2 || len(parts[1]) == 0 { | ||||
| 			if len(parts) != 2 { | ||||
| 				return nil, nil, fmt.Errorf("invalid label spec: %v", labelSpec) | ||||
| 			} | ||||
| 			if errs := validation.IsValidLabelValue(parts[1]); len(errs) != 0 { | ||||
|   | ||||
| @@ -129,7 +129,7 @@ func TestParseLabels(t *testing.T) { | ||||
| 		}, | ||||
| 		{ | ||||
| 			labels:   []string{"a="}, | ||||
| 			expectErr: true, | ||||
| 			expected: map[string]string{"a": ""}, | ||||
| 		}, | ||||
| 		{ | ||||
| 			labels:    []string{"a=%^$"}, | ||||
|   | ||||
| @@ -605,7 +605,7 @@ func ParsePairs(pairArgs []string, pairType string, supportRemove bool) (newPair | ||||
| 	for _, pairArg := range pairArgs { | ||||
| 		if strings.Index(pairArg, "=") != -1 { | ||||
| 			parts := strings.SplitN(pairArg, "=", 2) | ||||
| 			if len(parts) != 2 || len(parts[1]) == 0 { | ||||
| 			if len(parts) != 2 { | ||||
| 				if invalidBuf.Len() > 0 { | ||||
| 					invalidBuf.WriteString(", ") | ||||
| 				} | ||||
|   | ||||
		Reference in New Issue
	
	Block a user