Skip to content

Commit e1a95fb

Browse files
committed
🐛: revert to using hardcoded prefix for target groups
Using the LB's name as prefix has the potential of exceeding the 32 characters limit.
1 parent 810bbf4 commit e1a95fb

File tree

2 files changed

+2
-73
lines changed

2 files changed

+2
-73
lines changed

pkg/cloud/services/elb/loadbalancer.go

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -239,18 +239,6 @@ func (s *Service) getAdditionalTargetGroupHealthCheck(ln infrav1.AdditionalListe
239239
return healthCheck
240240
}
241241

242-
// getTargetGroupName creates the target group name based on LB Name, when defined, otherwise return
243-
// the standard name created from the timestamp.
244-
func (s *Service) getTargetGroupName(lbSpec *infrav1.AWSLoadBalancerSpec, defaultPrefix string, port int64) string {
245-
targetName := fmt.Sprintf("%s-%d", defaultPrefix, time.Now().Unix())
246-
247-
if lbSpec != nil && lbSpec.Name != nil {
248-
targetName = fmt.Sprintf("%s-%d", *lbSpec.Name, port)
249-
}
250-
251-
return targetName
252-
}
253-
254242
func (s *Service) getAPIServerLBSpec(elbName string, lbSpec *infrav1.AWSLoadBalancerSpec) (*infrav1.LoadBalancer, error) {
255243
var securityGroupIDs []string
256244
if lbSpec != nil {
@@ -266,7 +254,6 @@ func (s *Service) getAPIServerLBSpec(elbName string, lbSpec *infrav1.AWSLoadBala
266254

267255
// The default API health check is TCP, allowing customization to HTTP or HTTPS when HealthCheckProtocol is set.
268256
apiHealthCheck := s.getAPITargetGroupHealthCheck(lbSpec)
269-
apiTargetGroupName := s.getTargetGroupName(lbSpec, "apiserver-target", infrav1.DefaultAPIServerPort)
270257
res := &infrav1.LoadBalancer{
271258
Name: elbName,
272259
Scheme: scheme,
@@ -276,7 +263,7 @@ func (s *Service) getAPIServerLBSpec(elbName string, lbSpec *infrav1.AWSLoadBala
276263
Protocol: infrav1.ELBProtocolTCP,
277264
Port: infrav1.DefaultAPIServerPort,
278265
TargetGroup: infrav1.TargetGroupSpec{
279-
Name: apiTargetGroupName,
266+
Name: fmt.Sprintf("apiserver-target-%d", time.Now().Unix()),
280267
Port: infrav1.DefaultAPIServerPort,
281268
Protocol: infrav1.ELBProtocolTCP,
282269
VpcID: s.scope.VPC().ID,
@@ -289,7 +276,6 @@ func (s *Service) getAPIServerLBSpec(elbName string, lbSpec *infrav1.AWSLoadBala
289276

290277
if lbSpec != nil {
291278
for _, listener := range lbSpec.AdditionalListeners {
292-
targetGroupName := s.getTargetGroupName(lbSpec, "additional-listener", listener.Port)
293279
lnHealthCheck := &infrav1.TargetGroupHealthCheck{
294280
Protocol: aws.String(string(listener.Protocol)),
295281
Port: aws.String(strconv.FormatInt(listener.Port, 10)),
@@ -302,7 +288,7 @@ func (s *Service) getAPIServerLBSpec(elbName string, lbSpec *infrav1.AWSLoadBala
302288
Protocol: listener.Protocol,
303289
Port: listener.Port,
304290
TargetGroup: infrav1.TargetGroupSpec{
305-
Name: targetGroupName,
291+
Name: fmt.Sprintf("additional-listener-%d", time.Now().Unix()),
306292
Port: listener.Port,
307293
Protocol: listener.Protocol,
308294
VpcID: s.scope.VPC().ID,

pkg/cloud/services/elb/loadbalancer_test.go

Lines changed: 0 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -3341,63 +3341,6 @@ func stubGetBaseService(t *testing.T, clusterName string) *Service {
33413341
}
33423342
}
33433343

3344-
func TestService_getTargetGroupName(t *testing.T) {
3345-
type argWant struct {
3346-
value string
3347-
prefixOnly bool
3348-
}
3349-
type args struct {
3350-
lbSpec *infrav1.AWSLoadBalancerSpec
3351-
defaultPrefix string
3352-
port int64
3353-
}
3354-
tests := []struct {
3355-
name string
3356-
args args
3357-
want argWant
3358-
}{
3359-
{
3360-
name: "default name",
3361-
args: args{
3362-
lbSpec: &infrav1.AWSLoadBalancerSpec{},
3363-
defaultPrefix: "apiserver-target",
3364-
port: 6443,
3365-
},
3366-
want: argWant{
3367-
value: "apiserver-target-",
3368-
prefixOnly: true,
3369-
},
3370-
},
3371-
{
3372-
name: "custom name",
3373-
args: args{
3374-
lbSpec: &infrav1.AWSLoadBalancerSpec{
3375-
Name: ptr.To("foo"),
3376-
},
3377-
defaultPrefix: "api",
3378-
port: 6443,
3379-
},
3380-
want: argWant{
3381-
value: "foo-6443",
3382-
},
3383-
},
3384-
}
3385-
for _, tt := range tests {
3386-
t.Run(tt.name, func(t *testing.T) {
3387-
s := stubGetBaseService(t, "foo")
3388-
if tt.want.prefixOnly {
3389-
if got := s.getTargetGroupName(tt.args.lbSpec, tt.args.defaultPrefix, tt.args.port); !strings.HasPrefix(got, tt.want.value) {
3390-
t.Errorf("Service.getTargetGroupName() = %v, wantPrefix %v", got, tt.want.value)
3391-
}
3392-
return
3393-
}
3394-
if got := s.getTargetGroupName(tt.args.lbSpec, tt.args.defaultPrefix, tt.args.port); got != tt.want.value {
3395-
t.Errorf("Service.getTargetGroupName() = %v, want %v", got, tt.want)
3396-
}
3397-
})
3398-
}
3399-
}
3400-
34013344
func TestService_getAPITargetGroupHealthCheck(t *testing.T) {
34023345
tests := []struct {
34033346
name string

0 commit comments

Comments
 (0)