Skip to content

Commit ac21af6

Browse files
authored
feat: Support TargetGroupBinding on targets outside the cluster's VPC (#3479)
* feat: Support TargetGroupBinding on targets outside the cluster's VPC * Update docs * Make vpcid optional * Add vpcid missing test case - update docs * Fix failing e2e test * fix to use k8s API convention * Add tests to improve coverage * generate crds
1 parent a513f0c commit ac21af6

File tree

15 files changed

+520
-8
lines changed

15 files changed

+520
-8
lines changed

apis/elbv2/v1beta1/targetgroupbinding_types.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,10 @@ type TargetGroupBindingSpec struct {
145145
// ipAddressType specifies whether the target group is of type IPv4 or IPv6. If unspecified, it will be automatically inferred.
146146
// +optional
147147
IPAddressType *TargetGroupIPAddressType `json:"ipAddressType,omitempty"`
148+
149+
// VpcID is the VPC of the TargetGroup. If unspecified, it will be automatically inferred.
150+
// +optional
151+
VpcID string `json:"vpcID,omitempty"`
148152
}
149153

150154
// TargetGroupBindingStatus defines the observed state of TargetGroupBinding

config/crd/bases/elbv2.k8s.aws_targetgroupbindings.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,10 @@ spec:
386386
- instance
387387
- ip
388388
type: string
389+
vpcID:
390+
description: VpcID is the VPC of the TargetGroup. If unspecified,
391+
it will be automatically inferred.
392+
type: string
389393
required:
390394
- serviceRef
391395
- targetGroupARN

docs/guide/targetgroupbinding/targetgroupbinding.md

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ This will allow you to provision the load balancer infrastructure completely out
55

66
!!!tip "usage to support Ingress and Service"
77
The AWS LoadBalancer controller internally used TargetGroupBinding to support the functionality for Ingress and Service resource as well.
8-
It automatically creates TargetGroupBinding in the same namespace of the Service used.
9-
8+
It automatically creates TargetGroupBinding in the same namespace of the Service used.
9+
1010
You can view all TargetGroupBindings in a namespace by `kubectl get targetgroupbindings -n <your-namespace> -o wide`
1111

1212

@@ -31,6 +31,28 @@ spec:
3131
```
3232
3333
34+
## VpcID
35+
TargetGroupBinding CR supports the explicit definition of the Virtual Private Cloud (VPC) of your TargetGroup.
36+
37+
!!!tip ""
38+
If the VpcID is not explicitly specified, a mutating webhook will automatically call AWS API to find the VpcID for your TargetGroup and set it to correct value.
39+
40+
41+
## Sample YAML
42+
```yaml
43+
apiVersion: elbv2.k8s.aws/v1beta1
44+
kind: TargetGroupBinding
45+
metadata:
46+
name: my-tgb
47+
spec:
48+
serviceRef:
49+
name: awesome-service # route traffic to the awesome-service
50+
port: 80
51+
targetGroupARN: <arn-to-targetGroup>
52+
vpcID: <vpcID>
53+
```
54+
55+
3456
## NodeSelector
3557
3658
### Default Node Selector

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/deploy/elbv2/target_group_binding_manager.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@ func buildK8sTargetGroupBindingSpec(ctx context.Context, resTGB *elbv2model.Targ
187187
}
188188
k8sTGBSpec.NodeSelector = resTGB.Spec.Template.Spec.NodeSelector
189189
k8sTGBSpec.IPAddressType = resTGB.Spec.Template.Spec.IPAddressType
190+
k8sTGBSpec.VpcID = resTGB.Spec.Template.Spec.VpcID
190191
return k8sTGBSpec, nil
191192
}
192193

pkg/ingress/model_build_target_group.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ func (t *defaultModelBuildTask) buildTargetGroupBindingSpec(ctx context.Context,
7777
Networking: tgbNetworking,
7878
NodeSelector: nodeSelector,
7979
IPAddressType: (*elbv2api.TargetGroupIPAddressType)(tg.Spec.IPAddressType),
80+
VpcID: t.vpcID,
8081
},
8182
},
8283
}

pkg/ingress/model_builder_test.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,7 @@ const baseStackJSON = `
308308
"$ref":"#/resources/AWS::ElasticLoadBalancingV2::TargetGroup/ns-1/ing-1-svc-1:http/status/targetGroupARN"
309309
},
310310
"targetType":"instance",
311+
"vpcID": "vpc-dummy",
311312
"ipAddressType":"ipv4",
312313
"serviceRef":{
313314
"name":"svc-1",
@@ -350,6 +351,7 @@ const baseStackJSON = `
350351
},
351352
"targetType":"instance",
352353
"ipAddressType":"ipv4",
354+
"vpcID": "vpc-dummy",
353355
"serviceRef":{
354356
"name":"svc-2",
355357
"port":"http"
@@ -390,6 +392,7 @@ const baseStackJSON = `
390392
"$ref":"#/resources/AWS::ElasticLoadBalancingV2::TargetGroup/ns-1/ing-1-svc-3:https/status/targetGroupARN"
391393
},
392394
"targetType":"ip",
395+
"vpcID": "vpc-dummy",
393396
"ipAddressType":"ipv4",
394397
"serviceRef":{
395398
"name":"svc-3",
@@ -1131,7 +1134,7 @@ func Test_defaultModelBuilder_Build(t *testing.T) {
11311134
"port": 443,
11321135
"protocol": "HTTPS",
11331136
"sslPolicy": "ELBSecurityPolicy-2016-08",
1134-
"mutualAuthentication" : {
1137+
"mutualAuthentication" : {
11351138
"mode" : "off"
11361139
}
11371140
}
@@ -1442,6 +1445,7 @@ func Test_defaultModelBuilder_Build(t *testing.T) {
14421445
},
14431446
"spec": {
14441447
"ipAddressType": "ipv4",
1448+
"vpcID": "vpc-dummy",
14451449
"networking": {
14461450
"ingress": [
14471451
{
@@ -2429,6 +2433,7 @@ func Test_defaultModelBuilder_Build(t *testing.T) {
24292433
},
24302434
"spec": {
24312435
"ipAddressType": "ipv6",
2436+
"vpcID": "vpc-dummy",
24322437
"networking": {
24332438
"ingress": [
24342439
{
@@ -2695,6 +2700,7 @@ func Test_defaultModelBuilder_Build(t *testing.T) {
26952700
},
26962701
"spec": {
26972702
"ipAddressType": "ipv4",
2703+
"vpcID": "vpc-dummy",
26982704
"networking": {
26992705
"ingress": [
27002706
{
@@ -2854,6 +2860,7 @@ func Test_defaultModelBuilder_Build(t *testing.T) {
28542860
},
28552861
"spec": {
28562862
"ipAddressType": "ipv4",
2863+
"vpcID": "vpc-dummy",
28572864
"networking": {
28582865
"ingress": [
28592866
{

pkg/model/elbv2/target_group_binding.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,10 @@ type TargetGroupBindingSpec struct {
103103
// ipAddressType specifies whether the target group is of type IPv4 or IPv6. If unspecified, it will be automatically inferred.
104104
// +optional
105105
IPAddressType *elbv2api.TargetGroupIPAddressType `json:"ipAddressType,omitempty"`
106+
107+
// VpcID is the VPC of the TargetGroup. If unspecified, it will be automatically inferred.
108+
// +optional
109+
VpcID string `json:"vpcID,omitempty"`
106110
}
107111

108112
// Template for TargetGroupBinding Custom Resource.

pkg/service/model_build_target_group.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -444,6 +444,7 @@ func (t *defaultModelBuildTask) buildTargetGroupBindingSpec(ctx context.Context,
444444
Networking: tgbNetworking,
445445
NodeSelector: nodeSelector,
446446
IPAddressType: (*elbv2api.TargetGroupIPAddressType)(targetGroup.Spec.IPAddressType),
447+
VpcID: t.vpcID,
447448
},
448449
},
449450
}, nil

0 commit comments

Comments
 (0)