Skip to content
This repository has been archived by the owner on Oct 29, 2023. It is now read-only.

Commit

Permalink
Merge pull request #8 from johnnyrun/hotfix-internal-lb
Browse files Browse the repository at this point in the history
Fix internal load balancer prefix case
  • Loading branch information
oxyno-zeta authored Dec 30, 2020
2 parents 2c22338 + 979229e commit ff5e404
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 2 deletions.
9 changes: 7 additions & 2 deletions pkg/kubernetes-tagger/providerClient/awsClient.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,14 @@ func getAWSLoadBalancerName(svc *v1.Service) string {
// Split hostname on . and after split the first part on -
splitHostname := strings.Split(svc.Status.LoadBalancer.Ingress[0].Hostname, ".")
splitSubDomain := strings.Split(splitHostname[0], "-")
name := splitSubDomain[0]
fromSplit := 0
if strings.Contains(svc.Status.LoadBalancer.Ingress[0].Hostname, "internal") {
// ex: internal-acc1b0155441645c6902a362c6821a9e-138903596.eu-west-1.elb.amazonaws.com
fromSplit = 1
}
name := splitSubDomain[fromSplit]
// Don't take the last one
for i := 1; i < len(splitSubDomain)-1; i++ {
for i := fromSplit+1; i < len(splitSubDomain)-1; i++ {
name = name + "-" + splitSubDomain[i]
}
return name
Expand Down
40 changes: 40 additions & 0 deletions pkg/kubernetes-tagger/providerClient/awsClient_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,26 @@ func Test_getAWSLoadBalancerName(t *testing.T) {
},
"aa59f0ca83",
},
{
"test with one dash in the name and internal prefix",
args{
svc: &v1.Service{
Spec: v1.ServiceSpec{
Type: v1.ServiceTypeLoadBalancer,
},
Status: v1.ServiceStatus{
LoadBalancer: v1.LoadBalancerStatus{
Ingress: []v1.LoadBalancerIngress{
v1.LoadBalancerIngress{
Hostname: "internal-aa59f0ca83-7455.eu-west-1.elb.amazonaws.com",
},
},
},
},
},
},
"aa59f0ca83",
},
{
"test with two dash in the name",
args{
Expand All @@ -55,6 +75,26 @@ func Test_getAWSLoadBalancerName(t *testing.T) {
},
"aa59f0-ca83",
},
{
"test with two dash in the name and internal prefix",
args{
svc: &v1.Service{
Spec: v1.ServiceSpec{
Type: v1.ServiceTypeLoadBalancer,
},
Status: v1.ServiceStatus{
LoadBalancer: v1.LoadBalancerStatus{
Ingress: []v1.LoadBalancerIngress{
v1.LoadBalancerIngress{
Hostname: "internal-aa59f0-ca83-7455.eu-west-1.elb.amazonaws.com",
},
},
},
},
},
},
"aa59f0-ca83",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down

0 comments on commit ff5e404

Please sign in to comment.