Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -96,3 +96,11 @@ repos:
entry: go generate ./...
pass_filenames: false
files: (^\.md\.tmpl|\.go$)

- repo: local
hooks:
- id: go-fix
name: go fix
language: golang
entry: go fix ./...
pass_filenames: false
4 changes: 2 additions & 2 deletions hcloud/instances_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,15 @@ func (er *MockEventRecorder) Event(_ runtime.Object, _, _, _ string) {
func (er *MockEventRecorder) Eventf(
_ runtime.Object,
_, _, _ string,
_ ...interface{},
_ ...any,
) {
}

func (er *MockEventRecorder) AnnotatedEventf(
_ runtime.Object,
_ map[string]string,
_, _, _ string,
_ ...interface{},
_ ...any,
) {
}

Expand Down
4 changes: 2 additions & 2 deletions hcloud/load_balancers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ func TestLoadBalancers_GetLoadBalancer(t *testing.T) {
{
Name: "get load balancer with private network and without private ingress",
ServiceUID: "1",
UsePrivateIngressDefault: hcloud.Ptr(false),
UsePrivateIngressDefault: new(false),
LB: &hcloud.LoadBalancer{
ID: 1,
Name: "with-priv-net-without-private-ingress",
Expand Down Expand Up @@ -374,7 +374,7 @@ func TestLoadBalancers_EnsureLoadBalancer_CreateLoadBalancer(t *testing.T) {
ServiceAnnotations: map[annotation.Name]string{
annotation.LBName: "with-priv-net-no-priv-ingress",
},
UsePrivateIngressDefault: hcloud.Ptr(false),
UsePrivateIngressDefault: new(false),
LB: &hcloud.LoadBalancer{
ID: 1,
Name: "with-priv-net-no-priv-ingress",
Expand Down
4 changes: 2 additions & 2 deletions hcloud/testing.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@ func (tt *LoadBalancerTestCase) run(t *testing.T) {
t.Helper()

if tt.UsePrivateIngressDefault == nil {
tt.UsePrivateIngressDefault = hcloud.Ptr(true)
tt.UsePrivateIngressDefault = new(true)
}

if tt.UseIPv6Default == nil {
tt.UseIPv6Default = hcloud.Ptr(true)
tt.UseIPv6Default = new(true)
}

tt.LBOps = &hcops.MockLoadBalancerOps{}
Expand Down
28 changes: 14 additions & 14 deletions internal/annotation/name_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func TestName_StringsFromService(t *testing.T) {
},
}

runAllTypedAccessorTests(t, tests, func(svc *corev1.Service) (interface{}, error) {
runAllTypedAccessorTests(t, tests, func(svc *corev1.Service) (any, error) {
return ann.StringsFromService(svc)
})
}
Expand Down Expand Up @@ -98,7 +98,7 @@ func TestName_BoolFromService(t *testing.T) {
},
}

runAllTypedAccessorTests(t, tests, func(svc *corev1.Service) (interface{}, error) {
runAllTypedAccessorTests(t, tests, func(svc *corev1.Service) (any, error) {
return ann.BoolFromService(svc)
})
}
Expand All @@ -123,7 +123,7 @@ func TestName_IntFromService(t *testing.T) {
},
}

runAllTypedAccessorTests(t, tests, func(svc *corev1.Service) (interface{}, error) {
runAllTypedAccessorTests(t, tests, func(svc *corev1.Service) (any, error) {
return ann.IntFromService(svc)
})
}
Expand All @@ -148,7 +148,7 @@ func TestName_IntsFromService(t *testing.T) {
},
}

runAllTypedAccessorTests(t, tests, func(svc *corev1.Service) (interface{}, error) {
runAllTypedAccessorTests(t, tests, func(svc *corev1.Service) (any, error) {
return ann.IntsFromService(svc)
})
}
Expand Down Expand Up @@ -182,7 +182,7 @@ func TestName_IPFromService(t *testing.T) {
},
}

runAllTypedAccessorTests(t, tests, func(svc *corev1.Service) (interface{}, error) {
runAllTypedAccessorTests(t, tests, func(svc *corev1.Service) (any, error) {
return ann.IPFromService(svc)
})
}
Expand All @@ -209,7 +209,7 @@ func TestName_DurationFromService(t *testing.T) {
},
}

runAllTypedAccessorTests(t, tests, func(svc *corev1.Service) (interface{}, error) {
runAllTypedAccessorTests(t, tests, func(svc *corev1.Service) (any, error) {
return ann.DurationFromService(svc)
})
}
Expand All @@ -236,7 +236,7 @@ func TestName_LBSvcProtocolFromService(t *testing.T) {
},
}

runAllTypedAccessorTests(t, tests, func(svc *corev1.Service) (interface{}, error) {
runAllTypedAccessorTests(t, tests, func(svc *corev1.Service) (any, error) {
return ann.LBSvcProtocolFromService(svc)
})
}
Expand All @@ -263,7 +263,7 @@ func TestName_LBAlgorithmTypeFromService(t *testing.T) {
},
}

runAllTypedAccessorTests(t, tests, func(svc *corev1.Service) (interface{}, error) {
runAllTypedAccessorTests(t, tests, func(svc *corev1.Service) (any, error) {
return ann.LBAlgorithmTypeFromService(svc)
})
}
Expand All @@ -283,7 +283,7 @@ func TestName_NetworkZoneFromService(t *testing.T) {
},
}

runAllTypedAccessorTests(t, tests, func(svc *corev1.Service) (interface{}, error) {
runAllTypedAccessorTests(t, tests, func(svc *corev1.Service) (any, error) {
return ann.NetworkZoneFromService(svc)
})
}
Expand All @@ -310,7 +310,7 @@ func TestName_CertificatesFromService(t *testing.T) {
},
}

runAllTypedAccessorTests(t, tests, func(svc *corev1.Service) (interface{}, error) {
runAllTypedAccessorTests(t, tests, func(svc *corev1.Service) (any, error) {
return ann.CertificatesFromService(svc)
})
}
Expand Down Expand Up @@ -340,7 +340,7 @@ func TestName_CertificateTypeFromService(t *testing.T) {
},
}

runAllTypedAccessorTests(t, tests, func(svc *corev1.Service) (interface{}, error) {
runAllTypedAccessorTests(t, tests, func(svc *corev1.Service) (any, error) {
return ann.CertificateTypeFromService(svc)
})
}
Expand All @@ -349,10 +349,10 @@ type typedAccessorTest struct {
name string
svcAnnotations map[annotation.Name]string
err error
expected interface{}
expected any
}

func (tt *typedAccessorTest) run(t *testing.T, call func(svc *corev1.Service) (interface{}, error)) {
func (tt *typedAccessorTest) run(t *testing.T, call func(svc *corev1.Service) (any, error)) {
t.Helper()

var svc corev1.Service
Expand Down Expand Up @@ -380,7 +380,7 @@ func (tt *typedAccessorTest) run(t *testing.T, call func(svc *corev1.Service) (i
}

func runAllTypedAccessorTests(
t *testing.T, tests []typedAccessorTest, call func(svc *corev1.Service) (interface{}, error),
t *testing.T, tests []typedAccessorTest, call func(svc *corev1.Service) (any, error),
) {
t.Helper()

Expand Down
4 changes: 2 additions & 2 deletions internal/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,12 +150,12 @@ failed to read ROBOT_PASSWORD_FILE: open /tmp/hetzner-password: no such file or
PrivateIngressEnabled: true,
IPv6Enabled: true,
PrivateSubnetIPRange: "10.1.0.0/24",
ProxyProtocolEnabled: hcloud.Ptr(true),
ProxyProtocolEnabled: new(true),
AlgorithmType: hcloud.LoadBalancerAlgorithmTypeLeastConnections,
HealthCheckInterval: 30 * time.Second,
HealthCheckTimeout: 5 * time.Second,
HealthCheckRetries: 5,
DisablePublicNetwork: hcloud.Ptr(true),
DisablePublicNetwork: new(true),
Type: "lb21",
},
},
Expand Down
29 changes: 14 additions & 15 deletions internal/hcops/load_balancer.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"errors"
"fmt"
"maps"
"net"
"sync"
"time"
Expand Down Expand Up @@ -167,10 +168,10 @@ func (l *LoadBalancerOps) Create(
disablePubIface, err := annotation.LBDisablePublicNetwork.BoolFromService(svc)
switch {
case err == nil:
opts.PublicInterface = hcloud.Ptr(!disablePubIface)
opts.PublicInterface = new(!disablePubIface)
case errors.Is(err, annotation.ErrNotSet):
if l.Cfg.LoadBalancer.DisablePublicNetwork != nil {
opts.PublicInterface = hcloud.Ptr(!*l.Cfg.LoadBalancer.DisablePublicNetwork)
opts.PublicInterface = new(!*l.Cfg.LoadBalancer.DisablePublicNetwork)
}
default:
return nil, fmt.Errorf("%s: %w", op, err)
Expand Down Expand Up @@ -285,9 +286,7 @@ func (l *LoadBalancerOps) changeHCLBInfo(ctx context.Context, lb *hcloud.LoadBal
// updating is really successful.
labels := make(map[string]string, len(lb.Labels)+1)
labels[LabelServiceUID] = string(svc.ObjectMeta.UID)
for k, v := range lb.Labels {
labels[k] = v
}
maps.Copy(labels, lb.Labels)
opts.Labels = labels
update = true
}
Expand Down Expand Up @@ -536,7 +535,7 @@ func (l *LoadBalancerOps) togglePublicInterface(ctx context.Context, lb *hcloud.
var desiredDisable *bool
switch {
case err == nil:
desiredDisable = hcloud.Ptr(disable)
desiredDisable = new(disable)
case errors.Is(err, annotation.ErrNotSet):
desiredDisable = l.Cfg.LoadBalancer.DisablePublicNetwork
default:
Expand Down Expand Up @@ -1075,7 +1074,7 @@ func (b *hclbServiceOptsBuilder) extract() {
b.do(func() error {
pp, err := annotation.LBSvcProxyProtocol.BoolFromService(b.Service)
if err == nil {
b.proxyProtocol = hcloud.Ptr(pp)
b.proxyProtocol = new(pp)
return nil
}
if errors.Is(err, annotation.ErrNotSet) {
Expand Down Expand Up @@ -1242,7 +1241,7 @@ func (b *hclbServiceOptsBuilder) extractHealthCheck() {
if err != nil {
return fmt.Errorf("%s: %w", op, err)
}
b.healthCheckOpts.Port = hcloud.Ptr(hcPort)
b.healthCheckOpts.Port = new(hcPort)
b.addHealthCheck = true
return nil
})
Expand Down Expand Up @@ -1356,8 +1355,8 @@ func (b *hclbServiceOptsBuilder) buildAddServiceOpts() (hcloud.LoadBalancerAddSe
}

opts := hcloud.LoadBalancerAddServiceOpts{
ListenPort: hcloud.Ptr(b.listenPort),
DestinationPort: hcloud.Ptr(b.destinationPort),
ListenPort: new(b.listenPort),
DestinationPort: new(b.destinationPort),
Protocol: b.protocol,
Proxyprotocol: b.proxyProtocol,
}
Expand All @@ -1373,7 +1372,7 @@ func (b *hclbServiceOptsBuilder) buildAddServiceOpts() (hcloud.LoadBalancerAddSe
if b.addHealthCheck {
port := b.healthCheckOpts.Port
if port == nil {
port = hcloud.Ptr(b.destinationPort)
port = new(b.destinationPort)
}
opts.HealthCheck = &hcloud.LoadBalancerAddServiceOptsHealthCheck{
Protocol: b.healthCheckOpts.Protocol,
Expand All @@ -1395,7 +1394,7 @@ func (b *hclbServiceOptsBuilder) buildAddServiceOpts() (hcloud.LoadBalancerAddSe
} else {
opts.HealthCheck = &hcloud.LoadBalancerAddServiceOptsHealthCheck{
Protocol: hcloud.LoadBalancerServiceProtocolTCP,
Port: hcloud.Ptr(b.destinationPort),
Port: new(b.destinationPort),
}
}

Expand All @@ -1411,7 +1410,7 @@ func (b *hclbServiceOptsBuilder) buildUpdateServiceOpts() (hcloud.LoadBalancerUp
}

opts := hcloud.LoadBalancerUpdateServiceOpts{
DestinationPort: hcloud.Ptr(b.destinationPort),
DestinationPort: new(b.destinationPort),
Protocol: b.protocol,
Proxyprotocol: b.proxyProtocol,
}
Expand All @@ -1427,7 +1426,7 @@ func (b *hclbServiceOptsBuilder) buildUpdateServiceOpts() (hcloud.LoadBalancerUp
if b.addHealthCheck {
port := b.healthCheckOpts.Port
if port == nil {
port = hcloud.Ptr(b.destinationPort)
port = new(b.destinationPort)
}
opts.HealthCheck = &hcloud.LoadBalancerUpdateServiceOptsHealthCheck{
Protocol: b.healthCheckOpts.Protocol,
Expand All @@ -1449,7 +1448,7 @@ func (b *hclbServiceOptsBuilder) buildUpdateServiceOpts() (hcloud.LoadBalancerUp
} else {
opts.HealthCheck = &hcloud.LoadBalancerUpdateServiceOptsHealthCheck{
Protocol: hcloud.LoadBalancerServiceProtocolTCP,
Port: hcloud.Ptr(b.destinationPort),
Port: new(b.destinationPort),
}
}

Expand Down
Loading
Loading