mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-22 11:21:47 +00:00
Do not raise an error proposing to use '--overwrite' when annotating with the same value
This commit is contained in:
parent
e11e226b23
commit
9feaf478c6
@ -404,16 +404,16 @@ func validateAnnotations(removeAnnotations []string, newAnnotations map[string]s
|
||||
// validateNoAnnotationOverwrites validates that when overwrite is false, to-be-updated annotations don't exist in the object annotation map (yet)
|
||||
func validateNoAnnotationOverwrites(accessor metav1.Object, annotations map[string]string) error {
|
||||
var buf bytes.Buffer
|
||||
for key := range annotations {
|
||||
for key, value := range annotations {
|
||||
// change-cause annotation can always be overwritten
|
||||
if key == polymorphichelpers.ChangeCauseAnnotation {
|
||||
continue
|
||||
}
|
||||
if value, found := accessor.GetAnnotations()[key]; found {
|
||||
if currValue, found := accessor.GetAnnotations()[key]; found && currValue != value {
|
||||
if buf.Len() > 0 {
|
||||
buf.WriteString("; ")
|
||||
}
|
||||
buf.WriteString(fmt.Sprintf("'%s' already has a value (%s)", key, value))
|
||||
buf.WriteString(fmt.Sprintf("'%s' already has a value (%s)", key, currValue))
|
||||
}
|
||||
}
|
||||
if buf.Len() > 0 {
|
||||
|
@ -236,6 +236,19 @@ func TestUpdateAnnotations(t *testing.T) {
|
||||
},
|
||||
},
|
||||
annotations: map[string]string{"a": "b"},
|
||||
expected: &v1.Pod{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Annotations: map[string]string{"a": "b"},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
obj: &v1.Pod{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Annotations: map[string]string{"a": "b"},
|
||||
},
|
||||
},
|
||||
annotations: map[string]string{"a": "c"},
|
||||
expectErr: true,
|
||||
},
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user