Skip to content

Commit 457e981

Browse files
authored
Merge pull request #420 from kubernetes-sigs/annotation-cleanup
Replaced successCodes annotation with success-codes, but kept support…
2 parents 7ae701a + f3fdc88 commit 457e981

File tree

3 files changed

+41
-7
lines changed

3 files changed

+41
-7
lines changed

docs/ingress-resources.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ alb.ingress.kubernetes.io/unhealthy-threshold-count
6565
alb.ingress.kubernetes.io/listen-ports
6666
alb.ingress.kubernetes.io/security-groups
6767
alb.ingress.kubernetes.io/subnets
68-
alb.ingress.kubernetes.io/successCodes
68+
alb.ingress.kubernetes.io/success-codes
6969
alb.ingress.kubernetes.io/tags
7070
alb.ingress.kubernetes.io/target-group-attributes
7171
alb.ingress.kubernetes.io/ignore-host-header
@@ -101,15 +101,15 @@ Optional annotations are:
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
104-
- **subnets**: The subnets where the ALB instance should be deployed. Must include 2 subnets, each in a different [availability zone](http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/using-regions-availability-zones.html). These can be referenced by subnet IDs or the name tag associated with the subnet. Example values for subnet IDs are `subnet-a4f0098e,subnet-457ed533,subnet-95c904cd`. Example values for name tags are: `webSubnet,appSubnet`. If subnets are not specified the ALB controller will attempt to detect qualified subnets. This qualification is done by locating subnets that match the following criteria.
104+
- **subnets**: The subnets where the ALB instance should be deployed. Must include 2 subnets, each in a different [availability zone](http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/using-regions-availability-zones.html). These can be referenced by subnet IDs or the name tag associated with the subnet. Example values for subnet IDs are `subnet-a4f0098e,subnet-457ed533,subnet-95c904cd`. Example values for name tags are: `webSubnet,appSubnet`. If subnets are not specified the ALB controller will attempt to detect qualified subnets. This qualification is done by locating subnets that match the following criteria.
105105
106106
- kubernetes.io/cluster/$CLUSTER_NAME where $CLUSTER_NAME is the same cluster name specified on the ingress controller. The value of this tag must be 'shared'.
107107
108108
- kubernetes.io/role/alb-ingress the value of this tag should be empty.
109109
110110
- After subnets matching the above 2 tags have been located, they are checked to ensure 2 or more are in unique AZs, otherwise the ALB will not be created. If 2 subnets share the same AZ, only 1 of the 2 is used.
111111
112-
- **successCodes**: Defines the HTTP status code that should be expected when doing health checks against the defined `healthcheck-path`. When omitted, `200` is used.
112+
- **success-codes**: Defines the HTTP status code that should be expected when doing health checks against the defined `healthcheck-path`. When omitted, `200` is used.
113113
114114
- **tags**: Defines [AWS Tags](http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/Using_Tags.html) that should be applied to the ALB instance and Target groups.
115115
@@ -119,4 +119,4 @@ Optional annotations are:
119119
120120
- **ip-address-type**: The IP address type thats used to either route IPv4 traffic only or to route both IPv4 and IPv6 traffic. Can be either `dualstack` or `ipv4`. When omitted `ipv4` is used.
121121
122-
- **ssl-policy**: Defines the [Security Policy](https://docs.aws.amazon.com/elasticloadbalancing/latest/application/create-https-listener.html#describe-ssl-policies) that should be assigned to the ALB, allowing you to control the protocol and ciphers.
122+
- **ssl-policy**: Defines the [Security Policy](https://docs.aws.amazon.com/elasticloadbalancing/latest/application/create-https-listener.html#describe-ssl-policies) that should be assigned to the ALB, allowing you to control the protocol and ciphers.

pkg/annotations/annotations.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ const (
4444
ipAddressTypeKey = "alb.ingress.kubernetes.io/ip-address-type"
4545
securityGroupsKey = "alb.ingress.kubernetes.io/security-groups"
4646
subnetsKey = "alb.ingress.kubernetes.io/subnets"
47-
successCodesKey = "alb.ingress.kubernetes.io/successCodes"
47+
successCodesKey = "alb.ingress.kubernetes.io/success-codes"
48+
successCodesAltKey = "alb.ingress.kubernetes.io/successCodes"
4849
tagsKey = "alb.ingress.kubernetes.io/tags"
4950
ignoreHostHeader = "alb.ingress.kubernetes.io/ignore-host-header"
5051
targetGroupAttributesKey = "alb.ingress.kubernetes.io/target-group-attributes"
@@ -622,10 +623,14 @@ func subnetIsUsable(new *ec2.Subnet, existing []*ec2.Subnet) bool {
622623
}
623624

624625
func (a *Annotations) setSuccessCodes(annotations map[string]string) error {
625-
if annotations[successCodesKey] == "" {
626+
key := successCodesKey
627+
if annotations[successCodesKey] == "" && annotations[successCodesAltKey] != "" {
628+
key = successCodesAltKey
629+
}
630+
if annotations[key] == "" {
626631
a.SuccessCodes = aws.String("200")
627632
} else {
628-
a.SuccessCodes = aws.String(annotations[successCodesKey])
633+
a.SuccessCodes = aws.String(annotations[key])
629634
}
630635
return nil
631636
}

pkg/annotations/annotations_test.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,35 @@ func TestParseAnnotations(t *testing.T) {
2424
}
2525
}
2626

27+
func TestSetSuccessCodes(t *testing.T) {
28+
var tests = []struct {
29+
annotations map[string]string
30+
expected string
31+
pass bool
32+
}{
33+
{map[string]string{}, "200", true},
34+
{map[string]string{successCodesKey: "1"}, "1", true},
35+
{map[string]string{successCodesAltKey: "1"}, "1", true},
36+
{map[string]string{successCodesKey: "1"}, "2", false},
37+
{map[string]string{successCodesAltKey: "1"}, "2", false},
38+
{map[string]string{successCodesKey: "1", successCodesAltKey: "2"}, "1", true},
39+
}
40+
for _, tt := range tests {
41+
a := &Annotations{}
42+
43+
err := a.setSuccessCodes(tt.annotations)
44+
if err != nil && tt.pass {
45+
t.Errorf("setSuccessCodes(%v): expected %v, errored: %v", tt.annotations, tt.expected, err)
46+
}
47+
if err == nil && tt.pass && tt.expected != *a.SuccessCodes {
48+
t.Errorf("setSuccessCodes(%v): expected %v, actual %v", tt.annotations, tt.expected, *a.SuccessCodes)
49+
}
50+
if err == nil && !tt.pass && tt.expected == *a.SuccessCodes {
51+
t.Errorf("setSuccessCodes(%v): expected %v, actual %v", tt.annotations, tt.expected, *a.SuccessCodes)
52+
}
53+
}
54+
}
55+
2756
func TestSetScheme(t *testing.T) {
2857
var tests = []struct {
2958
scheme string

0 commit comments

Comments
 (0)