Skip to content

Commit

Permalink
fix: remove service from function args
Browse files Browse the repository at this point in the history
  • Loading branch information
fad3t committed Oct 5, 2023
1 parent 873ac0b commit d06fdcf
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 18 deletions.
10 changes: 5 additions & 5 deletions pkg/service/model_build_listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,17 @@ 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
}
}
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
}
Expand All @@ -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)
Expand All @@ -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
}
Expand Down
22 changes: 11 additions & 11 deletions pkg/service/model_build_target_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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 {
Expand All @@ -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")
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/service/model_build_target_group_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit d06fdcf

Please sign in to comment.