Skip to content

Commit

Permalink
Merge pull request #4070 from maruina/maruina/flux
Browse files Browse the repository at this point in the history
Fix TGB webhook error message to report changes to immutable field
  • Loading branch information
k8s-ci-robot authored Feb 27, 2025
2 parents c2437de + e8fef67 commit f9699da
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 16 deletions.
5 changes: 3 additions & 2 deletions webhooks/elbv2/targetgroupbinding_validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ package elbv2
import (
"context"
"fmt"
"k8s.io/apimachinery/pkg/types"
"regexp"
"strings"

"k8s.io/apimachinery/pkg/types"

elbv2types "github.com/aws/aws-sdk-go-v2/service/elasticloadbalancingv2/types"

awssdk "github.com/aws/aws-sdk-go-v2/aws"
Expand Down Expand Up @@ -160,7 +161,7 @@ func (v *targetGroupBindingValidator) checkImmutableFields(tgb *elbv2api.TargetG
changedImmutableFields = append(changedImmutableFields, "spec.vpcID")
}
if len(changedImmutableFields) != 0 {
return errors.Errorf("%s update may not change these fields: %s", "TargetGroupBinding", strings.Join(changedImmutableFields, ","))
return errors.Errorf("%s update may not change these immutable fields: %s", "TargetGroupBinding", strings.Join(changedImmutableFields, ","))
}
return nil
}
Expand Down
28 changes: 14 additions & 14 deletions webhooks/elbv2/targetgroupbinding_validator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ func Test_targetGroupBindingValidator_ValidateUpdate(t *testing.T) {
},
},
},
wantErr: errors.New("TargetGroupBinding update may not change these fields: spec.targetGroupARN"),
wantErr: errors.New("TargetGroupBinding update may not change these immutable fields: spec.targetGroupARN"),
},
{
name: "[err] targetType is ip, nodeSelector is set",
Expand Down Expand Up @@ -439,7 +439,7 @@ func Test_targetGroupBindingValidator_ValidateUpdate(t *testing.T) {
},
},
},
wantErr: errors.New("TargetGroupBinding update may not change these fields: spec.ipAddressType"),
wantErr: errors.New("TargetGroupBinding update may not change these immutable fields: spec.ipAddressType"),
},
{
name: "[ok] no update to spec",
Expand Down Expand Up @@ -576,7 +576,7 @@ func Test_targetGroupBindingValidator_checkImmutableFields(t *testing.T) {
},
},
},
wantErr: errors.New("TargetGroupBinding update may not change these fields: spec.targetGroupARN"),
wantErr: errors.New("TargetGroupBinding update may not change these immutable fields: spec.targetGroupARN"),
},
{
name: "targetType is changed",
Expand All @@ -594,7 +594,7 @@ func Test_targetGroupBindingValidator_checkImmutableFields(t *testing.T) {
},
},
},
wantErr: errors.New("TargetGroupBinding update may not change these fields: spec.targetType"),
wantErr: errors.New("TargetGroupBinding update may not change these immutable fields: spec.targetType"),
},
{
name: "targetType is changed from unset to set",
Expand All @@ -612,7 +612,7 @@ func Test_targetGroupBindingValidator_checkImmutableFields(t *testing.T) {
},
},
},
wantErr: errors.New("TargetGroupBinding update may not change these fields: spec.targetType"),
wantErr: errors.New("TargetGroupBinding update may not change these immutable fields: spec.targetType"),
},
{
name: "targetType is changed from set to unset",
Expand All @@ -630,7 +630,7 @@ func Test_targetGroupBindingValidator_checkImmutableFields(t *testing.T) {
},
},
},
wantErr: errors.New("TargetGroupBinding update may not change these fields: spec.targetType"),
wantErr: errors.New("TargetGroupBinding update may not change these immutable fields: spec.targetType"),
},
{
name: "both targetGroupARN and targetType are changed",
Expand All @@ -648,7 +648,7 @@ func Test_targetGroupBindingValidator_checkImmutableFields(t *testing.T) {
},
},
},
wantErr: errors.New("TargetGroupBinding update may not change these fields: spec.targetGroupARN,spec.targetType"),
wantErr: errors.New("TargetGroupBinding update may not change these immutable fields: spec.targetGroupARN,spec.targetType"),
},
{
name: "both targetGroupARN and targetType are not changed",
Expand Down Expand Up @@ -686,7 +686,7 @@ func Test_targetGroupBindingValidator_checkImmutableFields(t *testing.T) {
},
},
},
wantErr: errors.New("TargetGroupBinding update may not change these fields: spec.ipAddressType"),
wantErr: errors.New("TargetGroupBinding update may not change these immutable fields: spec.ipAddressType"),
},
{
name: "ipAddressType modified, old value nil",
Expand All @@ -705,7 +705,7 @@ func Test_targetGroupBindingValidator_checkImmutableFields(t *testing.T) {
},
},
},
wantErr: errors.New("TargetGroupBinding update may not change these fields: spec.ipAddressType"),
wantErr: errors.New("TargetGroupBinding update may not change these immutable fields: spec.ipAddressType"),
},
{
name: "ipAddressType modified from nil to ipv4",
Expand Down Expand Up @@ -743,7 +743,7 @@ func Test_targetGroupBindingValidator_checkImmutableFields(t *testing.T) {
},
},
},
wantErr: errors.New("TargetGroupBinding update may not change these fields: spec.ipAddressType"),
wantErr: errors.New("TargetGroupBinding update may not change these immutable fields: spec.ipAddressType"),
},
{
name: "ipAddressType modified from nil to ipv6",
Expand All @@ -762,7 +762,7 @@ func Test_targetGroupBindingValidator_checkImmutableFields(t *testing.T) {
},
},
},
wantErr: errors.New("TargetGroupBinding update may not change these fields: spec.ipAddressType"),
wantErr: errors.New("TargetGroupBinding update may not change these immutable fields: spec.ipAddressType"),
},
{
name: "VpcID modified from vpc-0aaaaaaa to vpc-0bbbbbbb",
Expand All @@ -782,7 +782,7 @@ func Test_targetGroupBindingValidator_checkImmutableFields(t *testing.T) {
},
},
},
wantErr: errors.New("TargetGroupBinding update may not change these fields: spec.vpcID"),
wantErr: errors.New("TargetGroupBinding update may not change these immutable fields: spec.vpcID"),
},
{
name: "VpcID modified from vpc-0aaaaaaa to nil",
Expand All @@ -801,7 +801,7 @@ func Test_targetGroupBindingValidator_checkImmutableFields(t *testing.T) {
},
},
},
wantErr: errors.New("TargetGroupBinding update may not change these fields: spec.vpcID"),
wantErr: errors.New("TargetGroupBinding update may not change these immutable fields: spec.vpcID"),
},
{
name: "VpcID modified from nil to vpc-0aaaaaaa",
Expand All @@ -820,7 +820,7 @@ func Test_targetGroupBindingValidator_checkImmutableFields(t *testing.T) {
},
},
},
wantErr: errors.New("TargetGroupBinding update may not change these fields: spec.vpcID"),
wantErr: errors.New("TargetGroupBinding update may not change these immutable fields: spec.vpcID"),
},
{
name: "VpcID modified from nil to cluster vpc-id is allowed",
Expand Down

0 comments on commit f9699da

Please sign in to comment.