Skip to content

feat: Support TargetGroupBinding on targets outside the cluster's VPC #3479

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

Merged
merged 8 commits into from
Mar 15, 2024
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
4 changes: 4 additions & 0 deletions apis/elbv2/v1beta1/targetgroupbinding_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,10 @@ type TargetGroupBindingSpec struct {
// ipAddressType specifies whether the target group is of type IPv4 or IPv6. If unspecified, it will be automatically inferred.
// +optional
IPAddressType *TargetGroupIPAddressType `json:"ipAddressType,omitempty"`

// VpcID is the VPC of the TargetGroup. If unspecified, it will be automatically inferred.
// +optional
VpcID string `json:"vpcID,omitempty"`
}

// TargetGroupBindingStatus defines the observed state of TargetGroupBinding
Expand Down
4 changes: 4 additions & 0 deletions config/crd/bases/elbv2.k8s.aws_targetgroupbindings.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,10 @@ spec:
- instance
- ip
type: string
vpcID:
description: VpcID is the VPC of the TargetGroup. If unspecified,
it will be automatically inferred.
type: string
required:
- serviceRef
- targetGroupARN
Expand Down
26 changes: 24 additions & 2 deletions docs/guide/targetgroupbinding/targetgroupbinding.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ This will allow you to provision the load balancer infrastructure completely out

!!!tip "usage to support Ingress and Service"
The AWS LoadBalancer controller internally used TargetGroupBinding to support the functionality for Ingress and Service resource as well.
It automatically creates TargetGroupBinding in the same namespace of the Service used.
It automatically creates TargetGroupBinding in the same namespace of the Service used.

You can view all TargetGroupBindings in a namespace by `kubectl get targetgroupbindings -n <your-namespace> -o wide`


Expand All @@ -31,6 +31,28 @@ spec:
```


## VpcID
TargetGroupBinding CR supports the explicit definition of the Virtual Private Cloud (VPC) of your TargetGroup.

!!!tip ""
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.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please also add a sample yaml file here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

comment addressed


## Sample YAML
```yaml
apiVersion: elbv2.k8s.aws/v1beta1
kind: TargetGroupBinding
metadata:
name: my-tgb
spec:
serviceRef:
name: awesome-service # route traffic to the awesome-service
port: 80
targetGroupARN: <arn-to-targetGroup>
vpcID: <vpcID>
```


## NodeSelector

### Default Node Selector
Expand Down
4 changes: 4 additions & 0 deletions helm/aws-load-balancer-controller/crds/crds.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -587,6 +587,10 @@ spec:
- instance
- ip
type: string
vpcID:
description: VpcID is the VPC of the TargetGroup. If unspecified,
it will be automatically inferred.
type: string
required:
- serviceRef
- targetGroupARN
Expand Down
1 change: 1 addition & 0 deletions pkg/deploy/elbv2/target_group_binding_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ func buildK8sTargetGroupBindingSpec(ctx context.Context, resTGB *elbv2model.Targ
}
k8sTGBSpec.NodeSelector = resTGB.Spec.Template.Spec.NodeSelector
k8sTGBSpec.IPAddressType = resTGB.Spec.Template.Spec.IPAddressType
k8sTGBSpec.VpcID = resTGB.Spec.Template.Spec.VpcID
return k8sTGBSpec, nil
}

Expand Down
1 change: 1 addition & 0 deletions pkg/ingress/model_build_target_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ func (t *defaultModelBuildTask) buildTargetGroupBindingSpec(ctx context.Context,
Networking: tgbNetworking,
NodeSelector: nodeSelector,
IPAddressType: (*elbv2api.TargetGroupIPAddressType)(tg.Spec.IPAddressType),
VpcID: t.vpcID,
},
},
}
Expand Down
9 changes: 8 additions & 1 deletion pkg/ingress/model_builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,7 @@ const baseStackJSON = `
"$ref":"#/resources/AWS::ElasticLoadBalancingV2::TargetGroup/ns-1/ing-1-svc-1:http/status/targetGroupARN"
},
"targetType":"instance",
"vpcID": "vpc-dummy",
"ipAddressType":"ipv4",
"serviceRef":{
"name":"svc-1",
Expand Down Expand Up @@ -350,6 +351,7 @@ const baseStackJSON = `
},
"targetType":"instance",
"ipAddressType":"ipv4",
"vpcID": "vpc-dummy",
"serviceRef":{
"name":"svc-2",
"port":"http"
Expand Down Expand Up @@ -390,6 +392,7 @@ const baseStackJSON = `
"$ref":"#/resources/AWS::ElasticLoadBalancingV2::TargetGroup/ns-1/ing-1-svc-3:https/status/targetGroupARN"
},
"targetType":"ip",
"vpcID": "vpc-dummy",
"ipAddressType":"ipv4",
"serviceRef":{
"name":"svc-3",
Expand Down Expand Up @@ -1131,7 +1134,7 @@ func Test_defaultModelBuilder_Build(t *testing.T) {
"port": 443,
"protocol": "HTTPS",
"sslPolicy": "ELBSecurityPolicy-2016-08",
"mutualAuthentication" : {
"mutualAuthentication" : {
"mode" : "off"
}
}
Expand Down Expand Up @@ -1442,6 +1445,7 @@ func Test_defaultModelBuilder_Build(t *testing.T) {
},
"spec": {
"ipAddressType": "ipv4",
"vpcID": "vpc-dummy",
"networking": {
"ingress": [
{
Expand Down Expand Up @@ -2429,6 +2433,7 @@ func Test_defaultModelBuilder_Build(t *testing.T) {
},
"spec": {
"ipAddressType": "ipv6",
"vpcID": "vpc-dummy",
"networking": {
"ingress": [
{
Expand Down Expand Up @@ -2695,6 +2700,7 @@ func Test_defaultModelBuilder_Build(t *testing.T) {
},
"spec": {
"ipAddressType": "ipv4",
"vpcID": "vpc-dummy",
"networking": {
"ingress": [
{
Expand Down Expand Up @@ -2854,6 +2860,7 @@ func Test_defaultModelBuilder_Build(t *testing.T) {
},
"spec": {
"ipAddressType": "ipv4",
"vpcID": "vpc-dummy",
"networking": {
"ingress": [
{
Expand Down
4 changes: 4 additions & 0 deletions pkg/model/elbv2/target_group_binding.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,10 @@ type TargetGroupBindingSpec struct {
// ipAddressType specifies whether the target group is of type IPv4 or IPv6. If unspecified, it will be automatically inferred.
// +optional
IPAddressType *elbv2api.TargetGroupIPAddressType `json:"ipAddressType,omitempty"`

// VpcID is the VPC of the TargetGroup. If unspecified, it will be automatically inferred.
// +optional
VpcID string `json:"vpcID,omitempty"`
}

// Template for TargetGroupBinding Custom Resource.
Expand Down
1 change: 1 addition & 0 deletions pkg/service/model_build_target_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,7 @@ func (t *defaultModelBuildTask) buildTargetGroupBindingSpec(ctx context.Context,
Networking: tgbNetworking,
NodeSelector: nodeSelector,
IPAddressType: (*elbv2api.TargetGroupIPAddressType)(targetGroup.Spec.IPAddressType),
VpcID: t.vpcID,
},
},
}, nil
Expand Down
Loading