Skip to content

Commit f9699da

Browse files
authored
Merge pull request #4070 from maruina/maruina/flux
Fix TGB webhook error message to report changes to immutable field
2 parents c2437de + e8fef67 commit f9699da

File tree

2 files changed

+17
-16
lines changed

2 files changed

+17
-16
lines changed

webhooks/elbv2/targetgroupbinding_validator.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@ package elbv2
33
import (
44
"context"
55
"fmt"
6-
"k8s.io/apimachinery/pkg/types"
76
"regexp"
87
"strings"
98

9+
"k8s.io/apimachinery/pkg/types"
10+
1011
elbv2types "github.com/aws/aws-sdk-go-v2/service/elasticloadbalancingv2/types"
1112

1213
awssdk "github.com/aws/aws-sdk-go-v2/aws"
@@ -160,7 +161,7 @@ func (v *targetGroupBindingValidator) checkImmutableFields(tgb *elbv2api.TargetG
160161
changedImmutableFields = append(changedImmutableFields, "spec.vpcID")
161162
}
162163
if len(changedImmutableFields) != 0 {
163-
return errors.Errorf("%s update may not change these fields: %s", "TargetGroupBinding", strings.Join(changedImmutableFields, ","))
164+
return errors.Errorf("%s update may not change these immutable fields: %s", "TargetGroupBinding", strings.Join(changedImmutableFields, ","))
164165
}
165166
return nil
166167
}

webhooks/elbv2/targetgroupbinding_validator_test.go

+14-14
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,7 @@ func Test_targetGroupBindingValidator_ValidateUpdate(t *testing.T) {
399399
},
400400
},
401401
},
402-
wantErr: errors.New("TargetGroupBinding update may not change these fields: spec.targetGroupARN"),
402+
wantErr: errors.New("TargetGroupBinding update may not change these immutable fields: spec.targetGroupARN"),
403403
},
404404
{
405405
name: "[err] targetType is ip, nodeSelector is set",
@@ -439,7 +439,7 @@ func Test_targetGroupBindingValidator_ValidateUpdate(t *testing.T) {
439439
},
440440
},
441441
},
442-
wantErr: errors.New("TargetGroupBinding update may not change these fields: spec.ipAddressType"),
442+
wantErr: errors.New("TargetGroupBinding update may not change these immutable fields: spec.ipAddressType"),
443443
},
444444
{
445445
name: "[ok] no update to spec",
@@ -576,7 +576,7 @@ func Test_targetGroupBindingValidator_checkImmutableFields(t *testing.T) {
576576
},
577577
},
578578
},
579-
wantErr: errors.New("TargetGroupBinding update may not change these fields: spec.targetGroupARN"),
579+
wantErr: errors.New("TargetGroupBinding update may not change these immutable fields: spec.targetGroupARN"),
580580
},
581581
{
582582
name: "targetType is changed",
@@ -594,7 +594,7 @@ func Test_targetGroupBindingValidator_checkImmutableFields(t *testing.T) {
594594
},
595595
},
596596
},
597-
wantErr: errors.New("TargetGroupBinding update may not change these fields: spec.targetType"),
597+
wantErr: errors.New("TargetGroupBinding update may not change these immutable fields: spec.targetType"),
598598
},
599599
{
600600
name: "targetType is changed from unset to set",
@@ -612,7 +612,7 @@ func Test_targetGroupBindingValidator_checkImmutableFields(t *testing.T) {
612612
},
613613
},
614614
},
615-
wantErr: errors.New("TargetGroupBinding update may not change these fields: spec.targetType"),
615+
wantErr: errors.New("TargetGroupBinding update may not change these immutable fields: spec.targetType"),
616616
},
617617
{
618618
name: "targetType is changed from set to unset",
@@ -630,7 +630,7 @@ func Test_targetGroupBindingValidator_checkImmutableFields(t *testing.T) {
630630
},
631631
},
632632
},
633-
wantErr: errors.New("TargetGroupBinding update may not change these fields: spec.targetType"),
633+
wantErr: errors.New("TargetGroupBinding update may not change these immutable fields: spec.targetType"),
634634
},
635635
{
636636
name: "both targetGroupARN and targetType are changed",
@@ -648,7 +648,7 @@ func Test_targetGroupBindingValidator_checkImmutableFields(t *testing.T) {
648648
},
649649
},
650650
},
651-
wantErr: errors.New("TargetGroupBinding update may not change these fields: spec.targetGroupARN,spec.targetType"),
651+
wantErr: errors.New("TargetGroupBinding update may not change these immutable fields: spec.targetGroupARN,spec.targetType"),
652652
},
653653
{
654654
name: "both targetGroupARN and targetType are not changed",
@@ -686,7 +686,7 @@ func Test_targetGroupBindingValidator_checkImmutableFields(t *testing.T) {
686686
},
687687
},
688688
},
689-
wantErr: errors.New("TargetGroupBinding update may not change these fields: spec.ipAddressType"),
689+
wantErr: errors.New("TargetGroupBinding update may not change these immutable fields: spec.ipAddressType"),
690690
},
691691
{
692692
name: "ipAddressType modified, old value nil",
@@ -705,7 +705,7 @@ func Test_targetGroupBindingValidator_checkImmutableFields(t *testing.T) {
705705
},
706706
},
707707
},
708-
wantErr: errors.New("TargetGroupBinding update may not change these fields: spec.ipAddressType"),
708+
wantErr: errors.New("TargetGroupBinding update may not change these immutable fields: spec.ipAddressType"),
709709
},
710710
{
711711
name: "ipAddressType modified from nil to ipv4",
@@ -743,7 +743,7 @@ func Test_targetGroupBindingValidator_checkImmutableFields(t *testing.T) {
743743
},
744744
},
745745
},
746-
wantErr: errors.New("TargetGroupBinding update may not change these fields: spec.ipAddressType"),
746+
wantErr: errors.New("TargetGroupBinding update may not change these immutable fields: spec.ipAddressType"),
747747
},
748748
{
749749
name: "ipAddressType modified from nil to ipv6",
@@ -762,7 +762,7 @@ func Test_targetGroupBindingValidator_checkImmutableFields(t *testing.T) {
762762
},
763763
},
764764
},
765-
wantErr: errors.New("TargetGroupBinding update may not change these fields: spec.ipAddressType"),
765+
wantErr: errors.New("TargetGroupBinding update may not change these immutable fields: spec.ipAddressType"),
766766
},
767767
{
768768
name: "VpcID modified from vpc-0aaaaaaa to vpc-0bbbbbbb",
@@ -782,7 +782,7 @@ func Test_targetGroupBindingValidator_checkImmutableFields(t *testing.T) {
782782
},
783783
},
784784
},
785-
wantErr: errors.New("TargetGroupBinding update may not change these fields: spec.vpcID"),
785+
wantErr: errors.New("TargetGroupBinding update may not change these immutable fields: spec.vpcID"),
786786
},
787787
{
788788
name: "VpcID modified from vpc-0aaaaaaa to nil",
@@ -801,7 +801,7 @@ func Test_targetGroupBindingValidator_checkImmutableFields(t *testing.T) {
801801
},
802802
},
803803
},
804-
wantErr: errors.New("TargetGroupBinding update may not change these fields: spec.vpcID"),
804+
wantErr: errors.New("TargetGroupBinding update may not change these immutable fields: spec.vpcID"),
805805
},
806806
{
807807
name: "VpcID modified from nil to vpc-0aaaaaaa",
@@ -820,7 +820,7 @@ func Test_targetGroupBindingValidator_checkImmutableFields(t *testing.T) {
820820
},
821821
},
822822
},
823-
wantErr: errors.New("TargetGroupBinding update may not change these fields: spec.vpcID"),
823+
wantErr: errors.New("TargetGroupBinding update may not change these immutable fields: spec.vpcID"),
824824
},
825825
{
826826
name: "VpcID modified from nil to cluster vpc-id is allowed",

0 commit comments

Comments
 (0)