Skip to content

Commit 0a27108

Browse files
committed
Make vpcid optional
1 parent ef25167 commit 0a27108

File tree

4 files changed

+13
-5
lines changed

4 files changed

+13
-5
lines changed

helm/aws-load-balancer-controller/crds/crds.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -587,6 +587,10 @@ spec:
587587
- instance
588588
- ip
589589
type: string
590+
vpcId:
591+
description: VpcId is the VPC of the TargetGroup. If unspecified,
592+
it will be automatically inferred.
593+
type: string
590594
required:
591595
- serviceRef
592596
- targetGroupARN

pkg/targetgroupbinding/resource_manager.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,7 @@ func (m *defaultResourceManager) deregisterTargets(ctx context.Context, tgARN st
386386
func (m *defaultResourceManager) registerPodEndpoints(ctx context.Context, tgARN, tgVpcId string, endpoints []backend.PodEndpoint) error {
387387
vpcId := m.vpcID
388388
// Target group is in a different VPC from the cluster's VPC
389-
if tgVpcId != m.vpcID {
389+
if tgVpcId != "" && tgVpcId != m.vpcID {
390390
vpcId = tgVpcId
391391
}
392392
vpcInfo, err := m.vpcInfoProvider.FetchVPCInfo(ctx, vpcId)

webhooks/elbv2/targetgroupbinding_mutator_test.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ func Test_targetGroupBindingMutator_MutateCreate(t *testing.T) {
4141
wantErr error
4242
}{
4343
{
44-
name: "targetGroupBinding with TargetType and ipAddressType already set",
44+
name: "targetGroupBinding with TargetType and ipAddressType and vpcId already set",
4545
fields: fields{
4646
describeTargetGroupsAsListCalls: nil,
4747
},
@@ -51,6 +51,7 @@ func Test_targetGroupBindingMutator_MutateCreate(t *testing.T) {
5151
TargetGroupARN: "tg-1",
5252
TargetType: &instanceTargetType,
5353
IPAddressType: &targetGroupIPAddressTypeIPv4,
54+
VpcId: "vpcid-01",
5455
},
5556
},
5657
},
@@ -59,6 +60,7 @@ func Test_targetGroupBindingMutator_MutateCreate(t *testing.T) {
5960
TargetGroupARN: "tg-1",
6061
TargetType: &instanceTargetType,
6162
IPAddressType: &targetGroupIPAddressTypeIPv4,
63+
VpcId: "vpcid-01",
6264
},
6365
},
6466
},
@@ -166,6 +168,7 @@ func Test_targetGroupBindingMutator_MutateCreate(t *testing.T) {
166168
TargetGroupARN: "tg-1",
167169
TargetType: &instanceTargetType,
168170
IPAddressType: &targetGroupIPAddressTypeIPv6,
171+
VpcId: "vpcid-01",
169172
},
170173
},
171174
},
@@ -174,6 +177,7 @@ func Test_targetGroupBindingMutator_MutateCreate(t *testing.T) {
174177
TargetGroupARN: "tg-1",
175178
TargetType: &instanceTargetType,
176179
IPAddressType: &targetGroupIPAddressTypeIPv6,
180+
VpcId: "vpcid-01",
177181
},
178182
},
179183
},

webhooks/elbv2/targetgroupbinding_validator.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,6 @@ func (v *targetGroupBindingValidator) checkRequiredFields(tgb *elbv2api.TargetGr
8686
if tgb.Spec.TargetType == nil {
8787
absentRequiredFields = append(absentRequiredFields, "spec.targetType")
8888
}
89-
if tgb.Spec.VpcId == "" {
90-
absentRequiredFields = append(absentRequiredFields, "spec.vpcId")
91-
}
9289
if len(absentRequiredFields) != 0 {
9390
return errors.Errorf("%s must specify these fields: %s", "TargetGroupBinding", strings.Join(absentRequiredFields, ","))
9491
}
@@ -162,6 +159,9 @@ func (v *targetGroupBindingValidator) checkTargetGroupIPAddressType(ctx context.
162159

163160
// checkTargetGroupVpcId ensures VpcId matches with that on the AWS target group
164161
func (v *targetGroupBindingValidator) checkTargetGroupVpcId(ctx context.Context, tgb *elbv2api.TargetGroupBinding) error {
162+
if tgb.Spec.VpcId == "" {
163+
return nil
164+
}
165165
vpcId, err := v.getVpcIdFromAWS(ctx, tgb.Spec.TargetGroupARN)
166166
if err != nil {
167167
return errors.Wrap(err, "unable to get target group VpcId")

0 commit comments

Comments
 (0)