Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix TGB webhook error message to report changes to immutable field #4070

Merged
merged 1 commit into from
Feb 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading