From d06fdcfafb52f6f96953740620298c09eb46b9e1 Mon Sep 17 00:00:00 2001 From: Frederic Mereu Date: Thu, 5 Oct 2023 08:40:26 +0200 Subject: [PATCH] fix: remove service from function args --- pkg/service/model_build_listener.go | 10 ++++----- pkg/service/model_build_target_group.go | 22 ++++++++++---------- pkg/service/model_build_target_group_test.go | 4 ++-- 3 files changed, 18 insertions(+), 18 deletions(-) diff --git a/pkg/service/model_build_listener.go b/pkg/service/model_build_listener.go index 2fa0c4805..d320fe5ea 100644 --- a/pkg/service/model_build_listener.go +++ b/pkg/service/model_build_listener.go @@ -20,7 +20,7 @@ func (t *defaultModelBuildTask) buildListeners(ctx context.Context, scheme elbv2 } for _, port := range t.service.Spec.Ports { - _, err := t.buildListener(ctx, t.service, port, *cfg, scheme) + _, err := t.buildListener(ctx, port, *cfg, scheme) if err != nil { return err } @@ -28,9 +28,9 @@ func (t *defaultModelBuildTask) buildListeners(ctx context.Context, scheme elbv2 return nil } -func (t *defaultModelBuildTask) buildListener(ctx context.Context, svc *corev1.Service, port corev1.ServicePort, cfg listenerConfig, +func (t *defaultModelBuildTask) buildListener(ctx context.Context, port corev1.ServicePort, cfg listenerConfig, scheme elbv2model.LoadBalancerScheme) (*elbv2model.Listener, error) { - lsSpec, err := t.buildListenerSpec(ctx, svc, port, cfg, scheme) + lsSpec, err := t.buildListenerSpec(ctx, port, cfg, scheme) if err != nil { return nil, err } @@ -39,7 +39,7 @@ func (t *defaultModelBuildTask) buildListener(ctx context.Context, svc *corev1.S return ls, nil } -func (t *defaultModelBuildTask) buildListenerSpec(ctx context.Context, svc *corev1.Service, port corev1.ServicePort, cfg listenerConfig, +func (t *defaultModelBuildTask) buildListenerSpec(ctx context.Context, port corev1.ServicePort, cfg listenerConfig, scheme elbv2model.LoadBalancerScheme) (elbv2model.ListenerSpec, error) { tgProtocol := elbv2model.Protocol(port.Protocol) listenerProtocol := elbv2model.Protocol(port.Protocol) @@ -55,7 +55,7 @@ func (t *defaultModelBuildTask) buildListenerSpec(ctx context.Context, svc *core if err != nil { return elbv2model.ListenerSpec{}, err } - targetGroup, err := t.buildTargetGroup(ctx, svc, port, tgProtocol, scheme) + targetGroup, err := t.buildTargetGroup(ctx, port, tgProtocol, scheme) if err != nil { return elbv2model.ListenerSpec{}, err } diff --git a/pkg/service/model_build_target_group.go b/pkg/service/model_build_target_group.go index 7d71562ac..f03991cb0 100644 --- a/pkg/service/model_build_target_group.go +++ b/pkg/service/model_build_target_group.go @@ -30,7 +30,7 @@ const ( healthCheckPortTrafficPort = "traffic-port" ) -func (t *defaultModelBuildTask) buildTargetGroup(ctx context.Context, svc *corev1.Service, port corev1.ServicePort, tgProtocol elbv2model.Protocol, scheme elbv2model.LoadBalancerScheme) (*elbv2model.TargetGroup, error) { +func (t *defaultModelBuildTask) buildTargetGroup(ctx context.Context, port corev1.ServicePort, tgProtocol elbv2model.Protocol, scheme elbv2model.LoadBalancerScheme) (*elbv2model.TargetGroup, error) { svcPort := intstr.FromInt(int(port.Port)) tgResourceID := t.buildTargetGroupResourceID(k8s.NamespacedName(t.service), svcPort) if targetGroup, exists := t.tgByResID[tgResourceID]; exists { @@ -40,7 +40,7 @@ func (t *defaultModelBuildTask) buildTargetGroup(ctx context.Context, svc *corev if err != nil { return nil, err } - healthCheckConfig, err := t.buildTargetGroupHealthCheckConfig(ctx, svc, targetType) + healthCheckConfig, err := t.buildTargetGroupHealthCheckConfig(ctx, targetType) if err != nil { return nil, err } @@ -89,22 +89,22 @@ func (t *defaultModelBuildTask) buildTargetGroupSpec(ctx context.Context, tgProt }, nil } -func (t *defaultModelBuildTask) buildTargetGroupHealthCheckConfig(ctx context.Context, svc *corev1.Service, targetType elbv2model.TargetType) (*elbv2model.TargetGroupHealthCheckConfig, error) { +func (t *defaultModelBuildTask) buildTargetGroupHealthCheckConfig(ctx context.Context, targetType elbv2model.TargetType) (*elbv2model.TargetGroupHealthCheckConfig, error) { if targetType == elbv2model.TargetTypeInstance && t.service.Spec.ExternalTrafficPolicy == corev1.ServiceExternalTrafficPolicyTypeLocal && t.service.Spec.Type == corev1.ServiceTypeLoadBalancer { - return t.buildTargetGroupHealthCheckConfigForInstanceModeLocal(ctx, svc, targetType) + return t.buildTargetGroupHealthCheckConfigForInstanceModeLocal(ctx, targetType) } - return t.buildTargetGroupHealthCheckConfigDefault(ctx, svc, targetType) + return t.buildTargetGroupHealthCheckConfigDefault(ctx, targetType) } -func (t *defaultModelBuildTask) buildTargetGroupHealthCheckConfigDefault(ctx context.Context, svc *corev1.Service, targetType elbv2model.TargetType) (*elbv2model.TargetGroupHealthCheckConfig, error) { +func (t *defaultModelBuildTask) buildTargetGroupHealthCheckConfigDefault(ctx context.Context, targetType elbv2model.TargetType) (*elbv2model.TargetGroupHealthCheckConfig, error) { healthCheckProtocol, err := t.buildTargetGroupHealthCheckProtocol(ctx, t.defaultHealthCheckProtocol) if err != nil { return nil, err } healthCheckPathPtr := t.buildTargetGroupHealthCheckPath(ctx, t.defaultHealthCheckPath, healthCheckProtocol) healthCheckMatcherPtr := t.buildTargetGroupHealthCheckMatcher(ctx, healthCheckProtocol) - healthCheckPort, err := t.buildTargetGroupHealthCheckPort(ctx, svc, t.defaultHealthCheckPort, targetType) + healthCheckPort, err := t.buildTargetGroupHealthCheckPort(ctx, t.defaultHealthCheckPort, targetType) if err != nil { return nil, err } @@ -137,14 +137,14 @@ func (t *defaultModelBuildTask) buildTargetGroupHealthCheckConfigDefault(ctx con }, nil } -func (t *defaultModelBuildTask) buildTargetGroupHealthCheckConfigForInstanceModeLocal(ctx context.Context, svc *corev1.Service, targetType elbv2model.TargetType) (*elbv2model.TargetGroupHealthCheckConfig, error) { +func (t *defaultModelBuildTask) buildTargetGroupHealthCheckConfigForInstanceModeLocal(ctx context.Context, targetType elbv2model.TargetType) (*elbv2model.TargetGroupHealthCheckConfig, error) { healthCheckProtocol, err := t.buildTargetGroupHealthCheckProtocol(ctx, t.defaultHealthCheckProtocolForInstanceModeLocal) if err != nil { return nil, err } healthCheckPathPtr := t.buildTargetGroupHealthCheckPath(ctx, t.defaultHealthCheckPathForInstanceModeLocal, healthCheckProtocol) healthCheckMatcherPtr := t.buildTargetGroupHealthCheckMatcher(ctx, healthCheckProtocol) - healthCheckPort, err := t.buildTargetGroupHealthCheckPort(ctx, svc, t.defaultHealthCheckPortForInstanceModeLocal, targetType) + healthCheckPort, err := t.buildTargetGroupHealthCheckPort(ctx, t.defaultHealthCheckPortForInstanceModeLocal, targetType) if err != nil { return nil, err } @@ -276,7 +276,7 @@ func (t *defaultModelBuildTask) buildTargetGroupPort(_ context.Context, targetTy return 1 } -func (t *defaultModelBuildTask) buildTargetGroupHealthCheckPort(_ context.Context, svc *corev1.Service, defaultHealthCheckPort string, targetType elbv2model.TargetType) (intstr.IntOrString, error) { +func (t *defaultModelBuildTask) buildTargetGroupHealthCheckPort(_ context.Context, defaultHealthCheckPort string, targetType elbv2model.TargetType) (intstr.IntOrString, error) { rawHealthCheckPort := defaultHealthCheckPort t.annotationParser.ParseStringAnnotation(annotations.SvcLBSuffixHCPort, &rawHealthCheckPort, t.service.Annotations) if rawHealthCheckPort == healthCheckPortTrafficPort { @@ -287,7 +287,7 @@ func (t *defaultModelBuildTask) buildTargetGroupHealthCheckPort(_ context.Contex return healthCheckPort, nil } - svcPort, err := k8s.LookupServicePort(svc, healthCheckPort) + svcPort, err := k8s.LookupServicePort(t.service, healthCheckPort) if err != nil { return intstr.IntOrString{}, errors.Wrap(err, "failed to resolve healthCheckPort") } diff --git a/pkg/service/model_build_target_group_test.go b/pkg/service/model_build_target_group_test.go index 9aa0c2014..78bebd158 100644 --- a/pkg/service/model_build_target_group_test.go +++ b/pkg/service/model_build_target_group_test.go @@ -387,7 +387,7 @@ func Test_defaultModelBuilderTask_buildTargetHealthCheck(t *testing.T) { defaultHealthCheckHealthyThresholdForInstanceModeLocal: 2, defaultHealthCheckUnhealthyThresholdForInstanceModeLocal: 2, } - hc, err := builder.buildTargetGroupHealthCheckConfig(context.Background(), tt.svc, tt.targetType) + hc, err := builder.buildTargetGroupHealthCheckConfig(context.Background(), tt.targetType) if tt.wantError { assert.Error(t, err) } else { @@ -2013,7 +2013,7 @@ func Test_defaultModelBuilder_buildTargetGroupHealthCheckPort(t *testing.T) { service: tt.svc, defaultHealthCheckPort: tt.defaultPort, } - got, err := builder.buildTargetGroupHealthCheckPort(context.Background(), tt.svc, tt.defaultPort, tt.targetType) + got, err := builder.buildTargetGroupHealthCheckPort(context.Background(), tt.defaultPort, tt.targetType) if tt.wantErr != nil { assert.EqualError(t, err, tt.wantErr.Error()) } else {