Skip to content

Commit

Permalink
Remove explicit - at end of prefix and make it implicit
Browse files Browse the repository at this point in the history
  • Loading branch information
frankh committed Jan 25, 2024
1 parent e7ceaa3 commit cd14986
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 13 deletions.
6 changes: 3 additions & 3 deletions docs/guide/ingress/annotations.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ You can add annotations to kubernetes Ingress and Service objects to customize t
|[alb.ingress.kubernetes.io/backend-protocol](#backend-protocol)|HTTP \| HTTPS|HTTP|Ingress,Service|N/A|
|[alb.ingress.kubernetes.io/backend-protocol-version](#backend-protocol-version)|string | HTTP1 |Ingress,Service|N/A|
|[alb.ingress.kubernetes.io/target-group-attributes](#target-group-attributes)|stringMap|N/A|Ingress,Service|N/A|
|[alb.ingress.kubernetes.io/target-group-prefix](#target-group-prefix)|string|k8s-<i>namespace-name</i>-|Ingress,Service|Merge|
|[alb.ingress.kubernetes.io/target-group-prefix](#target-group-prefix)|string|k8s-<i>namespace-name</i>|Ingress,Service|Merge|
|[alb.ingress.kubernetes.io/healthcheck-port](#healthcheck-port)|integer \| traffic-port|traffic-port|Ingress,Service|N/A|
|[alb.ingress.kubernetes.io/healthcheck-protocol](#healthcheck-protocol)|HTTP \| HTTPS|HTTP|Ingress,Service|N/A|
|[alb.ingress.kubernetes.io/healthcheck-path](#healthcheck-path)|string|/ \| /AWS.ALB/healthcheck |Ingress,Service|N/A|
Expand Down Expand Up @@ -824,9 +824,9 @@ Custom attributes to LoadBalancers and TargetGroups can be controlled with follo
- <a name="target-group-prefix">`alb.ingress.kubernetes.io/target-group-prefix`</a> specifies the name prefix given to Target Groups. The prefix is truncated to 22 characters.

!!!example
- set the target group prefix to "my-service-", the full name will look like "my-service-8f5fe20735"
- set the target group prefix to "my-service", the full name will look like "my-service-8f5fe20735"
```
alb.ingress.kubernetes.io/target-group-prefix: my-service-
alb.ingress.kubernetes.io/target-group-prefix: my-service
```

## Resource Tags
Expand Down
6 changes: 3 additions & 3 deletions docs/guide/service/annotations.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
| [service.beta.kubernetes.io/aws-load-balancer-private-ipv4-addresses](#private-ipv4-addresses) | stringList | | internal lb only. Length must match the number of subnets |
| [service.beta.kubernetes.io/aws-load-balancer-ipv6-addresses](#ipv6-addresses) | stringList | | dualstack lb only. Length must match the number of subnets |
| [service.beta.kubernetes.io/aws-load-balancer-target-group-attributes](#target-group-attributes) | stringMap | | |
| [service.beta.kubernetes.io/aws-load-balancer-target-group-prefix](#target-group-prefix) | string | k8s-<i>namespace-name</i>-| Truncated to 22 characters long |
| [service.beta.kubernetes.io/aws-load-balancer-target-group-prefix](#target-group-prefix) | string | k8s-<i>namespace-name</i> | Truncated to 21 characters long |
| [service.beta.kubernetes.io/aws-load-balancer-subnets](#subnets) | stringList | | |
| [service.beta.kubernetes.io/aws-load-balancer-alpn-policy](#alpn-policy) | string | | |
| [service.beta.kubernetes.io/aws-load-balancer-target-node-labels](#target-node-labels) | stringMap | | |
Expand Down Expand Up @@ -234,9 +234,9 @@ for proxy protocol v2 configuration.
- <a name="target-group-prefix">`service.beta.kubernetes.io/aws-load-balancer-target-group-prefix`</a> specifies the name prefix given to the Target Group. The prefix is truncated to 22 characters.

!!!example
- set the target group prefix to "my-service-", the full name will look like "my-service-8f5fe20735"
- set the target group prefix to "my-service", the full name will look like "my-service-8f5fe20735"
```
service.beta.kubernetes.io/aws-load-balancer-target-group-prefix: my-service-
service.beta.kubernetes.io/aws-load-balancer-target-group-prefix: my-service
```

- <a name="load-balancer-attributes">`service.beta.kubernetes.io/aws-load-balancer-attributes`</a> specifies [Load Balancer Attributes](http://docs.aws.amazon.com/elasticloadbalancing/latest/APIReference/API_LoadBalancerAttribute.html) that should be applied to the NLB.
Expand Down
4 changes: 2 additions & 2 deletions pkg/ingress/model_build_target_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,10 +206,10 @@ func (t *defaultModelBuildTask) buildTargetGroupName(_ context.Context,
if !t.annotationParser.ParseStringAnnotation(annotations.IngressSuffixTargetGroupPrefix, &prefix, svcAndIngAnnotations) {
sanitizedNamespace := invalidTargetGroupNamePattern.ReplaceAllString(svc.Namespace, "")
sanitizedName := invalidTargetGroupNamePattern.ReplaceAllString(svc.Name, "")
prefix = fmt.Sprintf("k8s-%.8s-%.8s-", sanitizedNamespace, sanitizedName)
prefix = fmt.Sprintf("k8s-%.8s-%.8s", sanitizedNamespace, sanitizedName)
}

return fmt.Sprintf("%.22s%.10s", prefix, uuid)
return fmt.Sprintf("%.21s-%.10s", prefix, uuid)
}

func (t *defaultModelBuildTask) buildTargetGroupTargetType(_ context.Context, svcAndIngAnnotations map[string]string) (elbv2model.TargetType, error) {
Expand Down
4 changes: 2 additions & 2 deletions pkg/service/model_build_target_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,10 +203,10 @@ func (t *defaultModelBuildTask) buildTargetGroupName(_ context.Context, svcPort
if !t.annotationParser.ParseStringAnnotation(annotations.SvcLBSuffixTargetGroupPrefix, &prefix, t.service.Annotations) {
sanitizedNamespace := invalidTargetGroupNamePattern.ReplaceAllString(t.service.Namespace, "")
sanitizedName := invalidTargetGroupNamePattern.ReplaceAllString(t.service.Name, "")
prefix = fmt.Sprintf("k8s-%.8s-%.8s-", sanitizedNamespace, sanitizedName)
prefix = fmt.Sprintf("k8s-%.8s-%.8s", sanitizedNamespace, sanitizedName)
}

return fmt.Sprintf("%.22s%.10s", prefix, uuid)
return fmt.Sprintf("%.21s%.10s", prefix, uuid)
}

func (t *defaultModelBuildTask) buildTargetGroupAttributes(_ context.Context) ([]elbv2model.TargetGroupAttribute, error) {
Expand Down
6 changes: 3 additions & 3 deletions pkg/service/model_build_target_group_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ func Test_defaultModelBuilderTask_targetGroupName(t *testing.T) {
Name: "name-1",
UID: "my-uuid",
Annotations: map[string]string{
"service.beta.kubernetes.io/aws-load-balancer-target-group-prefix": "test-",
"service.beta.kubernetes.io/aws-load-balancer-target-group-prefix": "test",
},
},
},
Expand Down Expand Up @@ -271,7 +271,7 @@ func Test_defaultModelBuilderTask_targetGroupName(t *testing.T) {
Name: "name-1",
UID: "my-uuid",
Annotations: map[string]string{
"service.beta.kubernetes.io/aws-load-balancer-target-group-prefix": "test-prefix-this-is-too-long-",
"service.beta.kubernetes.io/aws-load-balancer-target-group-prefix": "test-prefix-this-is-too-long",
},
},
},
Expand All @@ -289,7 +289,7 @@ func Test_defaultModelBuilderTask_targetGroupName(t *testing.T) {
UnhealthyThresholdCount: aws.Int64(2),
},
},
want: "test-prefix-this-is-to81f03d99d5",
want: "test-prefix-this-is-t-81f03d99d5",
},
}
for _, tt := range tests {
Expand Down

0 comments on commit cd14986

Please sign in to comment.