Skip to content

Commit d0e0e61

Browse files
committed
Renamed annotation to target-type and fixed tests
1 parent 86a5009 commit d0e0e61

File tree

6 files changed

+42
-19
lines changed

6 files changed

+42
-19
lines changed

docs/ingress-resources.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ alb.ingress.kubernetes.io/healthcheck-timeout-seconds
6262
alb.ingress.kubernetes.io/healthy-threshold-count
6363
alb.ingress.kubernetes.io/unhealthy-threshold-count
6464
alb.ingress.kubernetes.io/listen-ports
65-
alb.ingress.kubernetes.io/routing-target
65+
alb.ingress.kubernetes.io/target-type
6666
alb.ingress.kubernetes.io/security-groups
6767
alb.ingress.kubernetes.io/subnets
6868
alb.ingress.kubernetes.io/success-codes
@@ -97,7 +97,7 @@ Optional annotations are:
9797
9898
- **listen-ports**: Defines the ports the ALB will expose. It defaults to `[{"HTTP": 80}]` unless a certificate ARN is defined, then it is `[{"HTTPS": 443}]`. Uses a format as follows '[{"HTTP":8080,"HTTPS": 443}]'.
9999
100-
- **routing-target**: Defines if the EC2 instance ID or the pod IP is added to the Target Groups. Defaults to `instance`. Valid options are `instance` and `pod`. With `instance` the Target Group targets are `<ec2 instance id>:<node port>`, for `pod` the targets are `<pod ip>:<pod port>`. When using the pod IP, it will route from all availabilty zones. `pod` is to be used when the pod network is routable and can be reached by the ALB.
100+
- **target-type**: Defines if the EC2 instance ID or the pod IP is added to the Target Groups. Defaults to `instance`. Valid options are `instance` and `pod`. With `instance` the Target Group targets are `<ec2 instance id>:<node port>`, for `pod` the targets are `<pod ip>:<pod port>`. When using the pod IP, it will route from all availabilty zones. `pod` is to be used when the pod network is routable and can be reached by the ALB.
101101
102102
- **security-groups**: [Security groups](http://docs.aws.amazon.com/AmazonVPC/latest/UserGuide/VPC_SecurityGroups.html) that should be applied to the ALB instance. These can be referenced by security group IDs or the name tag associated with each security group. Example ID values are `sg-723a380a,sg-a6181ede,sg-a5181edd`. Example tag values are `appSG, webSG`. When the annotation is not present, the controller will create a security group with appropriate ports allowing access to `0.0.0.0/0` and attached to the ALB. It will also create a security group for instances that allows all TCP traffic when the source is the security group created for the ALB.
103103
@@ -136,7 +136,7 @@ alb.ingress.kubernetes.io/healthcheck-protocol
136136
alb.ingress.kubernetes.io/healthcheck-timeout-seconds
137137
alb.ingress.kubernetes.io/healthy-threshold-count
138138
alb.ingress.kubernetes.io/unhealthy-threshold-count
139-
alb.ingress.kubernetes.io/routing-target
139+
alb.ingress.kubernetes.io/target-type
140140
alb.ingress.kubernetes.io/success-codes
141141
alb.ingress.kubernetes.io/target-group-attributes
142142
```

pkg/alb/rs/rule_test.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,13 @@ func TestRuleReconcile(t *testing.T) {
170170
},
171171
},
172172
},
173+
CreateRuleOutput: elbv2.CreateRuleOutput{
174+
Rules: []*elbv2.Rule{
175+
&elbv2.Rule{
176+
Priority: aws.String("1"),
177+
},
178+
},
179+
},
173180
Pass: true,
174181
},
175182
{ // test current rule is nil, desired rule exists, runs create
@@ -365,9 +372,10 @@ func genTG(arn, svcname string) *tg.TargetGroup {
365372
Value: aws.String("namespace/" + svcname),
366373
}}}},
367374
TargetGroup: &elbv2.TargetGroup{
368-
TargetGroupArn: aws.String(arn),
369-
Port: aws.Int64(8080),
370-
Protocol: aws.String("HTTP"),
375+
TargetGroupName: aws.String("name"),
376+
TargetGroupArn: aws.String(arn),
377+
Port: aws.Int64(8080),
378+
Protocol: aws.String("HTTP"),
371379
},
372380
})
373381
return t

pkg/alb/rs/rules_test.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"github.com/aws/aws-sdk-go/aws"
99
"github.com/aws/aws-sdk-go/service/elbv2"
1010
"github.com/kubernetes-sigs/aws-alb-ingress-controller/pkg/alb/tg"
11+
"github.com/kubernetes-sigs/aws-alb-ingress-controller/pkg/aws/albelbv2"
1112
"github.com/kubernetes-sigs/aws-alb-ingress-controller/pkg/util/log"
1213
)
1314

@@ -180,8 +181,9 @@ func TestNewDesiredRules(t *testing.T) {
180181

181182
func TestRulesReconcile(t *testing.T) {
182183
cases := []struct {
183-
Rules Rules
184-
OutputLength int
184+
Rules Rules
185+
OutputLength int
186+
CreateRuleOutput elbv2.CreateRuleOutput
185187
}{
186188
{
187189
Rules: Rules{
@@ -194,6 +196,13 @@ func TestRulesReconcile(t *testing.T) {
194196
}),
195197
},
196198
OutputLength: 1,
199+
CreateRuleOutput: elbv2.CreateRuleOutput{
200+
Rules: []*elbv2.Rule{
201+
&elbv2.Rule{
202+
Priority: aws.String("1"),
203+
},
204+
},
205+
},
197206
},
198207
}
199208

@@ -206,6 +215,9 @@ func TestRulesReconcile(t *testing.T) {
206215
}
207216

208217
for i, c := range cases {
218+
albelbv2.ELBV2svc = mockedELBV2{
219+
CreateRuleOutput: c.CreateRuleOutput,
220+
}
209221
rules, _ := c.Rules.Reconcile(rOpts)
210222
if len(rules) != c.OutputLength {
211223
t.Errorf("rules.Reconcile.%v output length %v, should be %v.", i, len(rules), c.OutputLength)

pkg/alb/tg/targetgroup.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ func NewDesiredTargetGroup(o *NewDesiredTargetGroupOptions) *TargetGroup {
3838
hasher.Write([]byte(o.LoadBalancerID))
3939

4040
targetType := aws.String("instance")
41-
if *o.Annotations.RoutingTarget == "pod" {
41+
if *o.Annotations.TargetType == "pod" {
4242
targetType = aws.String("ip")
4343
hasher.Write([]byte(*targetType))
4444
}

pkg/alb/tg/targetgroups.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ import (
1818
// TODO: This really needs to include port as well
1919
func (t TargetGroups) LookupBySvc(svc string) int {
2020
for p, v := range t {
21+
if v == nil {
22+
continue
23+
}
2124
if v.SvcName == svc {
2225
return p
2326
}
@@ -164,7 +167,7 @@ func NewDesiredTargetGroups(o *NewDesiredTargetGroupsOptions) (TargetGroups, err
164167
Logger: o.Logger,
165168
Namespace: o.Namespace,
166169
SvcName: path.Backend.ServiceName,
167-
Targets: o.TargetsFunc(tgAnnotations.RoutingTarget, o.Namespace, path.Backend.ServiceName, port),
170+
Targets: o.TargetsFunc(tgAnnotations.TargetType, o.Namespace, path.Backend.ServiceName, port),
168171
})
169172

170173
// If this target group is already defined, copy the current state to our new TG

pkg/annotations/annotations.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ const (
4747
subnetsKey = "alb.ingress.kubernetes.io/subnets"
4848
successCodesKey = "alb.ingress.kubernetes.io/success-codes"
4949
successCodesAltKey = "alb.ingress.kubernetes.io/successCodes"
50-
routingTargetKey = "alb.ingress.kubernetes.io/routing-target"
50+
targetTypeKey = "alb.ingress.kubernetes.io/target-type"
5151
tagsKey = "alb.ingress.kubernetes.io/tags"
5252
ignoreHostHeader = "alb.ingress.kubernetes.io/ignore-host-header"
5353
targetGroupAttributesKey = "alb.ingress.kubernetes.io/target-group-attributes"
@@ -73,7 +73,7 @@ type Annotations struct {
7373
Ports []PortData
7474
Scheme *string
7575
IPAddressType *string
76-
RoutingTarget *string
76+
TargetType *string
7777
SecurityGroups util.AWSStringSlice
7878
Subnets util.Subnets
7979
SuccessCodes *string
@@ -151,7 +151,7 @@ func (vf *ValidatingAnnotationFactory) ParseAnnotations(opts *ParseAnnotationsOp
151151
a.setPorts(annotations),
152152
a.setScheme(annotations, opts.Namespace, opts.IngressName, vf.validator),
153153
a.setIPAddressType(annotations),
154-
a.setRoutingTarget(annotations),
154+
a.setTargetType(annotations),
155155
a.setSecurityGroups(annotations, vf.validator),
156156
a.setSubnets(annotations, *vf.clusterName, vf.validator),
157157
a.setSuccessCodes(annotations),
@@ -396,15 +396,15 @@ func (a *Annotations) setIPAddressType(annotations map[string]string) error {
396396
return nil
397397
}
398398

399-
func (a *Annotations) setRoutingTarget(annotations map[string]string) error {
399+
func (a *Annotations) setTargetType(annotations map[string]string) error {
400400
switch {
401-
case annotations[routingTargetKey] == "":
402-
a.RoutingTarget = aws.String("instance")
401+
case annotations[targetTypeKey] == "":
402+
a.TargetType = aws.String("instance")
403403
return nil
404-
case annotations[routingTargetKey] != "instance" && annotations[routingTargetKey] != "pod":
405-
return fmt.Errorf("ALB Routing Type [%v] must be either `instance` or `pod`", annotations[routingTargetKey])
404+
case annotations[targetTypeKey] != "instance" && annotations[targetTypeKey] != "pod":
405+
return fmt.Errorf("ALB Routing Type [%v] must be either `instance` or `pod`", annotations[targetTypeKey])
406406
}
407-
a.RoutingTarget = aws.String(annotations[routingTargetKey])
407+
a.TargetType = aws.String(annotations[targetTypeKey])
408408
return nil
409409
}
410410

0 commit comments

Comments
 (0)