Skip to content

Commit f20c9a3

Browse files
authored
Merge pull request #4282 from zac-nixon/znixon/type-refactor
Add TG protocol into TGB
2 parents 210f0de + b61ebc6 commit f20c9a3

20 files changed

+702
-341
lines changed

apis/elbv2/v1beta1/targetgroupbinding_types.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package v1beta1
1919
import (
2020
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2121
"k8s.io/apimachinery/pkg/util/intstr"
22+
"sigs.k8s.io/aws-load-balancer-controller/pkg/model/elbv2"
2223
)
2324

2425
// +kubebuilder:validation:Enum=instance;ip
@@ -139,6 +140,11 @@ type TargetGroupBindingSpec struct {
139140
// +optional
140141
TargetType *TargetType `json:"targetType,omitempty"`
141142

143+
// targetGroupProtocol is the Protocol of the TargetGroup. If unspecified, it will be automatically inferred.
144+
// +optional
145+
// +kubebuilder:validation:Enum=HTTP;HTTPS;TCP;TLS;UDP;TCP_UDP
146+
TargetGroupProtocol *elbv2.Protocol `json:"targetGroupProtocol,omitempty"`
147+
142148
// serviceRef is a reference to a Kubernetes Service and ServicePort.
143149
ServiceRef ServiceReference `json:"serviceRef"`
144150

apis/elbv2/v1beta1/zz_generated.deepcopy.go

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,17 @@ spec:
421421
targetGroupName:
422422
description: targetGroupName is the Name of the TargetGroup.
423423
type: string
424+
targetGroupProtocol:
425+
description: targetGroupProtocol is the Protocol of the TargetGroup.
426+
If unspecified, it will be automatically inferred.
427+
enum:
428+
- HTTP
429+
- HTTPS
430+
- TCP
431+
- TLS
432+
- UDP
433+
- TCP_UDP
434+
type: string
424435
targetType:
425436
description: targetType is the TargetType of TargetGroup. If unspecified,
426437
it will be automatically inferred.

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -695,6 +695,17 @@ spec:
695695
targetGroupName:
696696
description: targetGroupName is the Name of the TargetGroup.
697697
type: string
698+
targetGroupProtocol:
699+
description: targetGroupProtocol is the Protocol of the TargetGroup.
700+
If unspecified, it will be automatically inferred.
701+
enum:
702+
- HTTP
703+
- HTTPS
704+
- TCP
705+
- TLS
706+
- UDP
707+
- TCP_UDP
708+
type: string
698709
targetType:
699710
description: targetType is the TargetType of TargetGroup. If unspecified,
700711
it will be automatically inferred.

pkg/deploy/elbv2/target_group_binding_manager.go

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import (
1515
"sigs.k8s.io/aws-load-balancer-controller/pkg/annotations"
1616
"sigs.k8s.io/aws-load-balancer-controller/pkg/deploy/tracking"
1717
"sigs.k8s.io/aws-load-balancer-controller/pkg/k8s"
18-
elbv2model "sigs.k8s.io/aws-load-balancer-controller/pkg/model/elbv2"
18+
elbv2modelk8s "sigs.k8s.io/aws-load-balancer-controller/pkg/model/elbv2/k8s"
1919
"sigs.k8s.io/controller-runtime/pkg/client"
2020
"time"
2121
)
@@ -29,9 +29,9 @@ const (
2929

3030
// TargetGroupBindingManager is responsible for create/update/delete TargetGroupBinding resources.
3131
type TargetGroupBindingManager interface {
32-
Create(ctx context.Context, resTGB *elbv2model.TargetGroupBindingResource) (elbv2model.TargetGroupBindingResourceStatus, error)
32+
Create(ctx context.Context, resTGB *elbv2modelk8s.TargetGroupBindingResource) (elbv2modelk8s.TargetGroupBindingResourceStatus, error)
3333

34-
Update(ctx context.Context, resTGB *elbv2model.TargetGroupBindingResource, k8sTGB *elbv2api.TargetGroupBinding) (elbv2model.TargetGroupBindingResourceStatus, error)
34+
Update(ctx context.Context, resTGB *elbv2modelk8s.TargetGroupBindingResource, k8sTGB *elbv2api.TargetGroupBinding) (elbv2modelk8s.TargetGroupBindingResourceStatus, error)
3535

3636
Delete(ctx context.Context, k8sTGB *elbv2api.TargetGroupBinding) error
3737
}
@@ -64,10 +64,10 @@ type defaultTargetGroupBindingManager struct {
6464
waitTGBDeletionTimeout time.Duration
6565
}
6666

67-
func (m *defaultTargetGroupBindingManager) Create(ctx context.Context, resTGB *elbv2model.TargetGroupBindingResource) (elbv2model.TargetGroupBindingResourceStatus, error) {
67+
func (m *defaultTargetGroupBindingManager) Create(ctx context.Context, resTGB *elbv2modelk8s.TargetGroupBindingResource) (elbv2modelk8s.TargetGroupBindingResourceStatus, error) {
6868
k8sTGBSpec, err := buildK8sTargetGroupBindingSpec(ctx, resTGB)
6969
if err != nil {
70-
return elbv2model.TargetGroupBindingResourceStatus{}, err
70+
return elbv2modelk8s.TargetGroupBindingResourceStatus{}, err
7171
}
7272

7373
labels := m.trackingProvider.StackLabels(resTGB.Stack())
@@ -90,7 +90,7 @@ func (m *defaultTargetGroupBindingManager) Create(ctx context.Context, resTGB *e
9090
"stackID", resTGB.Stack().StackID(),
9191
"resourceID", resTGB.ID())
9292
if err := m.k8sClient.Create(ctx, k8sTGB); err != nil {
93-
return elbv2model.TargetGroupBindingResourceStatus{}, err
93+
return elbv2modelk8s.TargetGroupBindingResourceStatus{}, err
9494
}
9595
m.logger.Info("created targetGroupBinding",
9696
"stackID", resTGB.Stack().StackID(),
@@ -99,10 +99,10 @@ func (m *defaultTargetGroupBindingManager) Create(ctx context.Context, resTGB *e
9999
return buildResTargetGroupBindingStatus(k8sTGB), nil
100100
}
101101

102-
func (m *defaultTargetGroupBindingManager) Update(ctx context.Context, resTGB *elbv2model.TargetGroupBindingResource, k8sTGB *elbv2api.TargetGroupBinding) (elbv2model.TargetGroupBindingResourceStatus, error) {
102+
func (m *defaultTargetGroupBindingManager) Update(ctx context.Context, resTGB *elbv2modelk8s.TargetGroupBindingResource, k8sTGB *elbv2api.TargetGroupBinding) (elbv2modelk8s.TargetGroupBindingResourceStatus, error) {
103103
k8sTGBSpec, err := buildK8sTargetGroupBindingSpec(ctx, resTGB)
104104
if err != nil {
105-
return elbv2model.TargetGroupBindingResourceStatus{}, err
105+
return elbv2modelk8s.TargetGroupBindingResourceStatus{}, err
106106
}
107107

108108
calculatedLabels := m.trackingProvider.StackLabels(resTGB.Stack())
@@ -129,10 +129,10 @@ func (m *defaultTargetGroupBindingManager) Update(ctx context.Context, resTGB *e
129129
"targetGroupBinding", k8s.NamespacedName(k8sTGB))
130130

131131
if err := m.k8sClient.Patch(ctx, k8sTGB, client.MergeFrom(oldK8sTGB)); err != nil {
132-
return elbv2model.TargetGroupBindingResourceStatus{}, err
132+
return elbv2modelk8s.TargetGroupBindingResourceStatus{}, err
133133
}
134134
if err := m.waitUntilTargetGroupBindingObserved(ctx, k8sTGB); err != nil {
135-
return elbv2model.TargetGroupBindingResourceStatus{}, err
135+
return elbv2modelk8s.TargetGroupBindingResourceStatus{}, err
136136
}
137137
m.logger.Info("modified targetGroupBinding",
138138
"stackID", resTGB.Stack().StackID(),
@@ -189,16 +189,17 @@ func (m *defaultTargetGroupBindingManager) waitUntilTargetGroupBindingDeleted(ct
189189
}, ctx.Done())
190190
}
191191

192-
func buildK8sTargetGroupBindingSpec(ctx context.Context, resTGB *elbv2model.TargetGroupBindingResource) (elbv2api.TargetGroupBindingSpec, error) {
192+
func buildK8sTargetGroupBindingSpec(ctx context.Context, resTGB *elbv2modelk8s.TargetGroupBindingResource) (elbv2api.TargetGroupBindingSpec, error) {
193193
tgARN, err := resTGB.Spec.Template.Spec.TargetGroupARN.Resolve(ctx)
194194
if err != nil {
195195
return elbv2api.TargetGroupBindingSpec{}, err
196196
}
197197

198198
k8sTGBSpec := elbv2api.TargetGroupBindingSpec{
199-
TargetGroupARN: tgARN,
200-
TargetType: resTGB.Spec.Template.Spec.TargetType,
201-
ServiceRef: resTGB.Spec.Template.Spec.ServiceRef,
199+
TargetGroupARN: tgARN,
200+
TargetType: resTGB.Spec.Template.Spec.TargetType,
201+
TargetGroupProtocol: resTGB.Spec.Template.Spec.TargetGroupProtocol,
202+
ServiceRef: resTGB.Spec.Template.Spec.ServiceRef,
202203
}
203204

204205
if resTGB.Spec.Template.Spec.Networking != nil {
@@ -215,7 +216,7 @@ func buildK8sTargetGroupBindingSpec(ctx context.Context, resTGB *elbv2model.Targ
215216
return k8sTGBSpec, nil
216217
}
217218

218-
func buildK8sTargetGroupBindingNetworking(ctx context.Context, resTGBNetworking elbv2model.TargetGroupBindingNetworking) (elbv2api.TargetGroupBindingNetworking, error) {
219+
func buildK8sTargetGroupBindingNetworking(ctx context.Context, resTGBNetworking elbv2modelk8s.TargetGroupBindingNetworking) (elbv2api.TargetGroupBindingNetworking, error) {
219220
k8sIngress := make([]elbv2api.NetworkingIngressRule, 0, len(resTGBNetworking.Ingress))
220221
for _, rule := range resTGBNetworking.Ingress {
221222
k8sPeers := make([]elbv2api.NetworkingPeer, 0, len(rule.From))
@@ -236,7 +237,7 @@ func buildK8sTargetGroupBindingNetworking(ctx context.Context, resTGBNetworking
236237
}, nil
237238
}
238239

239-
func buildK8sNetworkingPeer(ctx context.Context, resNetworkingPeer elbv2model.NetworkingPeer) (elbv2api.NetworkingPeer, error) {
240+
func buildK8sNetworkingPeer(ctx context.Context, resNetworkingPeer elbv2modelk8s.NetworkingPeer) (elbv2api.NetworkingPeer, error) {
240241
if resNetworkingPeer.IPBlock != nil {
241242
return elbv2api.NetworkingPeer{
242243
IPBlock: resNetworkingPeer.IPBlock,
@@ -256,8 +257,8 @@ func buildK8sNetworkingPeer(ctx context.Context, resNetworkingPeer elbv2model.Ne
256257
return elbv2api.NetworkingPeer{}, errors.New("either ipBlock or securityGroup should be specified")
257258
}
258259

259-
func buildResTargetGroupBindingStatus(k8sTGB *elbv2api.TargetGroupBinding) elbv2model.TargetGroupBindingResourceStatus {
260-
return elbv2model.TargetGroupBindingResourceStatus{
260+
func buildResTargetGroupBindingStatus(k8sTGB *elbv2api.TargetGroupBinding) elbv2modelk8s.TargetGroupBindingResourceStatus {
261+
return elbv2modelk8s.TargetGroupBindingResourceStatus{
261262
TargetGroupBindingRef: corev1.ObjectReference{
262263
Namespace: k8sTGB.Namespace,
263264
Name: k8sTGB.Name,
@@ -267,7 +268,7 @@ func buildResTargetGroupBindingStatus(k8sTGB *elbv2api.TargetGroupBinding) elbv2
267268
}
268269

269270
// tgbAnnotationsSame performs map equality with the two sets of annotations. Will ignore the check point annotations inserted by the TGB reconciler.
270-
func tgbAnnotationsSame(resTGB *elbv2model.TargetGroupBindingResource, k8sTGB *elbv2api.TargetGroupBinding) bool {
271+
func tgbAnnotationsSame(resTGB *elbv2modelk8s.TargetGroupBindingResource, k8sTGB *elbv2api.TargetGroupBinding) bool {
271272
annotationsNoCheckpoint := make(map[string]string)
272273

273274
if k8sTGB.Annotations != nil {

pkg/deploy/elbv2/target_group_binding_manager_test.go

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111
"sigs.k8s.io/aws-load-balancer-controller/pkg/annotations"
1212
"sigs.k8s.io/aws-load-balancer-controller/pkg/deploy/tracking"
1313
coremodel "sigs.k8s.io/aws-load-balancer-controller/pkg/model/core"
14-
elbv2model "sigs.k8s.io/aws-load-balancer-controller/pkg/model/elbv2"
14+
elbv2modelk8s "sigs.k8s.io/aws-load-balancer-controller/pkg/model/elbv2/k8s"
1515
"sigs.k8s.io/aws-load-balancer-controller/pkg/testutils"
1616
"sigs.k8s.io/controller-runtime/pkg/client"
1717
"testing"
@@ -23,18 +23,18 @@ func Test_defaultTargetGroupBindingManager_Create(t *testing.T) {
2323
ipv4AddressType := elbv2api.IPAddressTypeIPV4
2424
testCases := []struct {
2525
name string
26-
spec elbv2model.TargetGroupBindingResourceSpec
26+
spec elbv2modelk8s.TargetGroupBindingResourceSpec
2727
expected elbv2api.TargetGroupBinding
2828
}{
2929
{
3030
name: "just spec, no labels or annotation",
31-
spec: elbv2model.TargetGroupBindingResourceSpec{
32-
Template: elbv2model.TargetGroupBindingTemplate{
31+
spec: elbv2modelk8s.TargetGroupBindingResourceSpec{
32+
Template: elbv2modelk8s.TargetGroupBindingTemplate{
3333
ObjectMeta: metav1.ObjectMeta{
3434
Name: "tgb",
3535
Namespace: "tgb-ns",
3636
},
37-
Spec: elbv2model.TargetGroupBindingSpec{
37+
Spec: elbv2modelk8s.TargetGroupBindingSpec{
3838
TargetGroupARN: coremodel.LiteralStringToken("arn:aws:elasticloadbalancing:us-east-1:565768096483:targetgroup/k8s-echoserv-brokentg-0b7ba7f4ef/ae85b8ea9fb69748"),
3939
TargetType: &instanceTargetType,
4040
ServiceRef: elbv2api.ServiceReference{
@@ -69,8 +69,8 @@ func Test_defaultTargetGroupBindingManager_Create(t *testing.T) {
6969
},
7070
{
7171
name: "just spec, labels. no annotation",
72-
spec: elbv2model.TargetGroupBindingResourceSpec{
73-
Template: elbv2model.TargetGroupBindingTemplate{
72+
spec: elbv2modelk8s.TargetGroupBindingResourceSpec{
73+
Template: elbv2modelk8s.TargetGroupBindingTemplate{
7474
ObjectMeta: metav1.ObjectMeta{
7575
Name: "tgb",
7676
Namespace: "tgb-ns",
@@ -79,7 +79,7 @@ func Test_defaultTargetGroupBindingManager_Create(t *testing.T) {
7979
"baz": "bat",
8080
},
8181
},
82-
Spec: elbv2model.TargetGroupBindingSpec{
82+
Spec: elbv2modelk8s.TargetGroupBindingSpec{
8383
TargetGroupARN: coremodel.LiteralStringToken("arn:aws:elasticloadbalancing:us-east-1:565768096483:targetgroup/k8s-echoserv-brokentg-0b7ba7f4ef/ae85b8ea9fb69748"),
8484
TargetType: &instanceTargetType,
8585
ServiceRef: elbv2api.ServiceReference{
@@ -116,8 +116,8 @@ func Test_defaultTargetGroupBindingManager_Create(t *testing.T) {
116116
},
117117
{
118118
name: "spec, labels, annotation",
119-
spec: elbv2model.TargetGroupBindingResourceSpec{
120-
Template: elbv2model.TargetGroupBindingTemplate{
119+
spec: elbv2modelk8s.TargetGroupBindingResourceSpec{
120+
Template: elbv2modelk8s.TargetGroupBindingTemplate{
121121
ObjectMeta: metav1.ObjectMeta{
122122
Name: "tgb",
123123
Namespace: "tgb-ns",
@@ -130,7 +130,7 @@ func Test_defaultTargetGroupBindingManager_Create(t *testing.T) {
130130
"ann3": "ann4",
131131
},
132132
},
133-
Spec: elbv2model.TargetGroupBindingSpec{
133+
Spec: elbv2modelk8s.TargetGroupBindingSpec{
134134
TargetGroupARN: coremodel.LiteralStringToken("arn:aws:elasticloadbalancing:us-east-1:565768096483:targetgroup/k8s-echoserv-brokentg-0b7ba7f4ef/ae85b8ea9fb69748"),
135135
TargetType: &instanceTargetType,
136136
ServiceRef: elbv2api.ServiceReference{
@@ -177,7 +177,7 @@ func Test_defaultTargetGroupBindingManager_Create(t *testing.T) {
177177
Namespace: "test-ns",
178178
Name: "test-stack",
179179
}))
180-
resTGB := elbv2model.NewTargetGroupBindingResource(stack, "my-tgb", tc.spec)
180+
resTGB := elbv2modelk8s.NewTargetGroupBindingResource(stack, "my-tgb", tc.spec)
181181
manager, k8sClient := createTestDefaultTargetGroupBindingManager()
182182
status, err := manager.Create(context.Background(), resTGB)
183183
assert.NoError(t, err)
@@ -198,19 +198,19 @@ func Test_defaultTargetGroupBindingManager_Update(t *testing.T) {
198198
ipv4AddressType := elbv2api.IPAddressTypeIPV4
199199
testCases := []struct {
200200
name string
201-
spec elbv2model.TargetGroupBindingResourceSpec
201+
spec elbv2modelk8s.TargetGroupBindingResourceSpec
202202
existing elbv2api.TargetGroupBinding
203203
expected elbv2api.TargetGroupBinding
204204
}{
205205
{
206206
name: "just spec, no labels or annotation",
207-
spec: elbv2model.TargetGroupBindingResourceSpec{
208-
Template: elbv2model.TargetGroupBindingTemplate{
207+
spec: elbv2modelk8s.TargetGroupBindingResourceSpec{
208+
Template: elbv2modelk8s.TargetGroupBindingTemplate{
209209
ObjectMeta: metav1.ObjectMeta{
210210
Name: "tgb",
211211
Namespace: "tgb-ns",
212212
},
213-
Spec: elbv2model.TargetGroupBindingSpec{
213+
Spec: elbv2modelk8s.TargetGroupBindingSpec{
214214
TargetGroupARN: coremodel.LiteralStringToken("arn:aws:elasticloadbalancing:us-east-1:565768096483:targetgroup/k8s-echoserv-brokentg-0b7ba7f4ef/ae85b8ea9fb69748"),
215215
TargetType: &instanceTargetType,
216216
ServiceRef: elbv2api.ServiceReference{
@@ -264,8 +264,8 @@ func Test_defaultTargetGroupBindingManager_Update(t *testing.T) {
264264
},
265265
{
266266
name: "spec labels annotation",
267-
spec: elbv2model.TargetGroupBindingResourceSpec{
268-
Template: elbv2model.TargetGroupBindingTemplate{
267+
spec: elbv2modelk8s.TargetGroupBindingResourceSpec{
268+
Template: elbv2modelk8s.TargetGroupBindingTemplate{
269269
ObjectMeta: metav1.ObjectMeta{
270270
Name: "tgb",
271271
Namespace: "tgb-ns",
@@ -277,7 +277,7 @@ func Test_defaultTargetGroupBindingManager_Update(t *testing.T) {
277277
"ann3": "ann4",
278278
},
279279
},
280-
Spec: elbv2model.TargetGroupBindingSpec{
280+
Spec: elbv2modelk8s.TargetGroupBindingSpec{
281281
TargetGroupARN: coremodel.LiteralStringToken("arn:aws:elasticloadbalancing:us-east-1:565768096483:targetgroup/k8s-echoserv-brokentg-0b7ba7f4ef/ae85b8ea9fb69748"),
282282
TargetType: &instanceTargetType,
283283
ServiceRef: elbv2api.ServiceReference{
@@ -336,8 +336,8 @@ func Test_defaultTargetGroupBindingManager_Update(t *testing.T) {
336336
},
337337
{
338338
name: "only diff is checkpoint annotation, no update",
339-
spec: elbv2model.TargetGroupBindingResourceSpec{
340-
Template: elbv2model.TargetGroupBindingTemplate{
339+
spec: elbv2modelk8s.TargetGroupBindingResourceSpec{
340+
Template: elbv2modelk8s.TargetGroupBindingTemplate{
341341
ObjectMeta: metav1.ObjectMeta{
342342
Name: "tgb",
343343
Namespace: "tgb-ns",
@@ -349,7 +349,7 @@ func Test_defaultTargetGroupBindingManager_Update(t *testing.T) {
349349
"ann3": "ann4",
350350
},
351351
},
352-
Spec: elbv2model.TargetGroupBindingSpec{
352+
Spec: elbv2modelk8s.TargetGroupBindingSpec{
353353
TargetGroupARN: coremodel.LiteralStringToken("arn:aws:elasticloadbalancing:us-east-1:565768096483:targetgroup/k8s-echoserv-brokentg-0b7ba7f4ef/ae85b8ea9fb69748"),
354354
TargetType: &instanceTargetType,
355355
ServiceRef: elbv2api.ServiceReference{
@@ -422,7 +422,7 @@ func Test_defaultTargetGroupBindingManager_Update(t *testing.T) {
422422
Namespace: "test-ns",
423423
Name: "test-stack",
424424
}))
425-
resTGB := elbv2model.NewTargetGroupBindingResource(stack, "my-tgb", tc.spec)
425+
resTGB := elbv2modelk8s.NewTargetGroupBindingResource(stack, "my-tgb", tc.spec)
426426
manager, k8sClient := createTestDefaultTargetGroupBindingManager()
427427

428428
err := k8sClient.Create(context.Background(), &tc.existing)

0 commit comments

Comments
 (0)