Skip to content
Open
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
1 change: 1 addition & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ linters:
- importas
- ineffassign
- misspell
- modernize
- nakedret
- noctx
- nolintlint
Expand Down
4 changes: 1 addition & 3 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
module github.com/stackitcloud/cloud-provider-stackit

go 1.25.0

toolchain go1.26.1
go 1.26.1

require (
github.com/container-storage-interface/spec v1.12.0
Expand Down
25 changes: 12 additions & 13 deletions pkg/ccm/instances_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import (
"go.uber.org/mock/gomock"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/utils/ptr"
)

var _ = Describe("Node Controller", func() {
Expand Down Expand Up @@ -83,7 +82,7 @@ var _ = Describe("Node Controller", func() {
It("successfully get the instance when provider ID not there", func() {
nodeMockClient.EXPECT().ListServers(gomock.Any(), projectID, region).Return(&[]iaas.Server{
{
Name: ptr.To("foo"),
Name: new("foo"),
},
}, nil)

Expand All @@ -98,7 +97,7 @@ var _ = Describe("Node Controller", func() {

It("successfully get the instance when provider ID is there", func() {
nodeMockClient.EXPECT().GetServer(gomock.Any(), projectID, region, serverID).Return(&iaas.Server{
Name: ptr.To("foo"),
Name: new("foo"),
}, nil)

node := &corev1.Node{
Expand All @@ -115,7 +114,7 @@ var _ = Describe("Node Controller", func() {

It("successfully get the instance when old provider ID is there", func() {
nodeMockClient.EXPECT().GetServer(gomock.Any(), projectID, region, serverID).Return(&iaas.Server{
Name: ptr.To("foo"),
Name: new("foo"),
}, nil)

node := &corev1.Node{
Expand All @@ -132,7 +131,7 @@ var _ = Describe("Node Controller", func() {

It("successfully get the instance when old regional provider ID is there", func() {
nodeMockClient.EXPECT().GetServer(gomock.Any(), projectID, region, serverID).Return(&iaas.Server{
Name: ptr.To("foo"),
Name: new("foo"),
}, nil)

node := &corev1.Node{
Expand Down Expand Up @@ -178,8 +177,8 @@ var _ = Describe("Node Controller", func() {
It("successfully gets the instance status with provider ID", func() {
nodeMockClient.EXPECT().ListServers(gomock.Any(), projectID, region).Return(&[]iaas.Server{
{
Name: ptr.To("foo"),
Status: ptr.To(instanceStopping),
Name: new("foo"),
Status: new(instanceStopping),
},
}, nil)

Expand All @@ -194,8 +193,8 @@ var _ = Describe("Node Controller", func() {

It("successfully gets the instance status without provider ID", func() {
nodeMockClient.EXPECT().GetServer(gomock.Any(), projectID, region, serverID).Return(&iaas.Server{
Name: ptr.To("foo"),
Status: ptr.To("ACTIVE"),
Name: new("foo"),
Status: new("ACTIVE"),
}, nil)

node := &corev1.Node{
Expand Down Expand Up @@ -239,12 +238,12 @@ var _ = Describe("Node Controller", func() {
It("successfully get all the metadata values", func() {
nodeMockClient.EXPECT().ListServers(gomock.Any(), projectID, region).Return(&[]iaas.Server{
{
Name: ptr.To("foo"),
Id: ptr.To(serverID),
MachineType: ptr.To("flatcar"),
Name: new("foo"),
Id: new(serverID),
MachineType: new("flatcar"),
Nics: &[]iaas.ServerNetwork{
{
Ipv4: ptr.To("10.10.100.24"),
Ipv4: new("10.10.100.24"),
},
},
},
Expand Down
5 changes: 2 additions & 3 deletions pkg/ccm/loadbalancer.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
"k8s.io/client-go/tools/record"
cloudprovider "k8s.io/cloud-provider"
"k8s.io/cloud-provider/api"
"k8s.io/utils/ptr"

"github.com/stackitcloud/cloud-provider-stackit/pkg/cmp"
"github.com/stackitcloud/cloud-provider-stackit/pkg/stackit"
Expand Down Expand Up @@ -215,7 +214,7 @@ func (l *LoadBalancer) createLoadBalancer(ctx context.Context, clusterName strin
return nil, fmt.Errorf("invalid load balancer specification: %w", err)
}
if l.opts.ExtraLabels != nil {
spec.Labels = ptr.To(l.opts.ExtraLabels)
spec.Labels = new(l.opts.ExtraLabels)
}
for _, event := range events {
l.recorder.Event(service, event.Type, event.Reason, event.Message)
Expand Down Expand Up @@ -433,7 +432,7 @@ func loadBalancerStatus(lb *loadbalancer.LoadBalancer, svc *corev1.Service) *cor
if ip != nil {
ingress := corev1.LoadBalancerIngress{IP: *ip}
if ipModeProxy, _ := strconv.ParseBool(svc.Annotations[ipModeProxyAnnotation]); ipModeProxy {
ingress.IPMode = ptr.To(corev1.LoadBalancerIPModeProxy)
ingress.IPMode = new(corev1.LoadBalancerIPModeProxy)
}
ingresses = []corev1.LoadBalancerIngress{ingress}
}
Expand Down
37 changes: 17 additions & 20 deletions pkg/ccm/loadbalancer_spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@ package ccm
import (
"fmt"
"net/netip"
"slices"
"strconv"
"strings"
"time"

"github.com/stackitcloud/stackit-sdk-go/core/utils"
"github.com/stackitcloud/stackit-sdk-go/services/loadbalancer"
corev1 "k8s.io/api/core/v1"
"k8s.io/utils/ptr"

"github.com/stackitcloud/cloud-provider-stackit/pkg/cmp"
)
Expand Down Expand Up @@ -216,10 +215,8 @@ func proxyProtocolEnableForPort(tcpProxyProtocolEnabled bool, tcpProxyProtocolPo
func getPlanID(service *corev1.Service) (planID *string, msgs []string, err error) {
msgs = make([]string, 0)
if planID, found := service.Annotations[servicePlanAnnotation]; found {
for _, availablePlan := range availablePlanIDs {
if planID == availablePlan {
return &planID, nil, nil
}
if slices.Contains(availablePlanIDs, planID) {
return &planID, nil, nil
}
return nil, nil, fmt.Errorf("unsupported plan ID value %q, supported values are %v", planID, availablePlanIDs)
}
Expand Down Expand Up @@ -251,7 +248,7 @@ func lbSpecFromService( //nolint:funlen,gocyclo // It is long but not complex.
Options: &loadbalancer.LoadBalancerOptions{},
Networks: &[]loadbalancer.Network{
{
Role: utils.Ptr(loadbalancer.NETWORKROLE_LISTENERS_AND_TARGETS),
Role: new(loadbalancer.NETWORKROLE_LISTENERS_AND_TARGETS),
NetworkId: &opts.NetworkID,
},
},
Expand All @@ -260,25 +257,25 @@ func lbSpecFromService( //nolint:funlen,gocyclo // It is long but not complex.
if listenerNetwork := service.Annotations[listenerNetworkAnnotation]; listenerNetwork != "" {
lb.Networks = &[]loadbalancer.Network{
{
Role: utils.Ptr(loadbalancer.NETWORKROLE_TARGETS),
Role: new(loadbalancer.NETWORKROLE_TARGETS),
NetworkId: &opts.NetworkID,
}, {
Role: utils.Ptr(loadbalancer.NETWORKROLE_LISTENERS),
Role: new(loadbalancer.NETWORKROLE_LISTENERS),
NetworkId: &listenerNetwork,
},
}
} else {
lb.Networks = &[]loadbalancer.Network{
{
Role: utils.Ptr(loadbalancer.NETWORKROLE_LISTENERS_AND_TARGETS),
Role: new(loadbalancer.NETWORKROLE_LISTENERS_AND_TARGETS),
NetworkId: &opts.NetworkID,
},
}
}

// Add extraLabels if set
if opts.ExtraLabels != nil {
lb.Labels = ptr.To(opts.ExtraLabels)
lb.Labels = new(opts.ExtraLabels)
}

// Add metric metricsRemoteWrite settings
Expand All @@ -288,7 +285,7 @@ func lbSpecFromService( //nolint:funlen,gocyclo // It is long but not complex.

// Parse private network from annotations.
// TODO: Split into separate function.
lb.Options.PrivateNetworkOnly = utils.Ptr(false)
lb.Options.PrivateNetworkOnly = new(false)
var internal *bool
var yawolInternal *bool
if internalStr, found := service.Annotations[internalLBAnnotation]; found {
Expand Down Expand Up @@ -333,9 +330,9 @@ func lbSpecFromService( //nolint:funlen,gocyclo // It is long but not complex.
"incompatible values for annotations %s and %s", yawolExistingFloatingIPAnnotation, externalIPAnnotation,
)
}
lb.Options.EphemeralAddress = utils.Ptr(false)
lb.Options.EphemeralAddress = new(false)
if !found && !yawolFound && !*lb.Options.PrivateNetworkOnly {
lb.Options.EphemeralAddress = utils.Ptr(true)
lb.Options.EphemeralAddress = new(true)
}
if !found && yawolFound {
externalIP = yawolExternalIP
Expand Down Expand Up @@ -507,32 +504,32 @@ func lbSpecFromService( //nolint:funlen,gocyclo // It is long but not complex.
protocol = loadbalancer.LISTENERPROTOCOL_TCP
}
tcpOptions = &loadbalancer.OptionsTCP{
IdleTimeout: utils.Ptr(fmt.Sprintf("%.0fs", tcpIdleTimeout.Seconds())),
IdleTimeout: new(fmt.Sprintf("%.0fs", tcpIdleTimeout.Seconds())),
}
case corev1.ProtocolUDP:
protocol = loadbalancer.LISTENERPROTOCOL_UDP
udpOptions = &loadbalancer.OptionsUDP{
IdleTimeout: utils.Ptr(fmt.Sprintf("%.0fs", udpIdleTimeout.Seconds())),
IdleTimeout: new(fmt.Sprintf("%.0fs", udpIdleTimeout.Seconds())),
}
default:
return nil, nil, fmt.Errorf("unsupported protocol %q for port %q", port.Protocol, port.Name)
}

listeners = append(listeners, loadbalancer.Listener{
DisplayName: &name,
Port: utils.Ptr(int64(port.Port)),
Port: new(int64(port.Port)),
TargetPool: &name,
Protocol: utils.Ptr(protocol),
Protocol: new(protocol),
Tcp: tcpOptions,
Udp: udpOptions,
})

targetPools = append(targetPools, loadbalancer.TargetPool{
Name: &name,
TargetPort: utils.Ptr(int64(port.NodePort)),
TargetPort: new(int64(port.NodePort)),
Targets: &targets,
SessionPersistence: &loadbalancer.SessionPersistence{
UseSourceIpAddress: utils.Ptr(useSourceIP),
UseSourceIpAddress: new(useSourceIP),
},
})
}
Expand Down
Loading