Do not raise an error proposing to use '--overwrite' when annotating with the same value

This commit is contained in:
Alexandre Garnier 2022-04-15 14:31:56 +02:00
parent e11e226b23
commit 9feaf478c6
No known key found for this signature in database
2 changed files with 16 additions and 3 deletions

View File

@ -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 {

View File

@ -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,
},
{