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
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ require (
github.com/spf13/pflag v1.0.10
github.com/stackitcloud/stackit-sdk-go/core v0.26.0
github.com/stackitcloud/stackit-sdk-go/services/iaas v1.12.0
github.com/stackitcloud/stackit-sdk-go/services/loadbalancer v1.13.0
github.com/stackitcloud/stackit-sdk-go/services/loadbalancer v1.14.0
go.uber.org/mock v0.6.0
golang.org/x/sync v0.20.0
golang.org/x/sys v0.45.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,8 @@ github.com/stackitcloud/stackit-sdk-go/core v0.26.0 h1:jQEb9gkehfp6VCP6TcYk7BI10
github.com/stackitcloud/stackit-sdk-go/core v0.26.0/go.mod h1:WU1hhxnjXw2EV7CYa1nlEvNpMiRY6CvmIOaHuL3pOaA=
github.com/stackitcloud/stackit-sdk-go/services/iaas v1.12.0 h1:H4V3H8qSKOaOalIrf4nAPDHhXnHYGs6SDGuK8Zj41Zo=
github.com/stackitcloud/stackit-sdk-go/services/iaas v1.12.0/go.mod h1:Ts06id0KejUlQWbpR+/rm+tKng6QkTuFV1VQTPJ4dA4=
github.com/stackitcloud/stackit-sdk-go/services/loadbalancer v1.13.0 h1:UuLNwFHjJCpL11y4F7B9oBKtZkxpu01VkNPILNkpex4=
github.com/stackitcloud/stackit-sdk-go/services/loadbalancer v1.13.0/go.mod h1:+Ld3dn648I+YKcBV3fEkYpDSr3fel421+LurJGywSBs=
github.com/stackitcloud/stackit-sdk-go/services/loadbalancer v1.14.0 h1:1dvL7tX91ziklayQmOupniE3jM4D5Nbtc0auNcx2p18=
github.com/stackitcloud/stackit-sdk-go/services/loadbalancer v1.14.0/go.mod h1:+Ld3dn648I+YKcBV3fEkYpDSr3fel421+LurJGywSBs=
github.com/stackitcloud/stackit-sdk-go/services/resourcemanager v0.23.0 h1:u2C3oHNcc41Ba5cUqSPuqviDrYSRhpaC5+ELbuHHdwM=
github.com/stackitcloud/stackit-sdk-go/services/resourcemanager v0.23.0/go.mod h1:NEz3f+GV5G++BE9/MmZCsXJyCih7jtg0pZuSyG2sLEs=
github.com/stoewer/go-strcase v1.3.1 h1:iS0MdW+kVTxgMoE1LAZyMiYJFKlOzLooE4MxjirtkAs=
Expand Down
11 changes: 5 additions & 6 deletions pkg/ccm/loadbalancer.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (

stackitconfig "github.com/stackitcloud/cloud-provider-stackit/pkg/stackit/config"
loadbalancer "github.com/stackitcloud/stackit-sdk-go/services/loadbalancer/v2api"
lbwait "github.com/stackitcloud/stackit-sdk-go/services/loadbalancer/v2api/wait"
corev1 "k8s.io/api/core/v1"
"k8s.io/client-go/tools/record"
cloudprovider "k8s.io/cloud-provider"
Expand Down Expand Up @@ -159,7 +158,7 @@ func (l *LoadBalancer) EnsureLoadBalancer( //nolint:gocyclo // not really comple
PrivateAddress: spec.PrivateAddress,
Region: spec.Region,
Labels: spec.Labels,
Status: spec.Status,
Status: new(loadbalancer.UpdateLoadBalancerPayloadStatus(spec.GetStatus())),
TargetPools: spec.TargetPools,
Version: spec.Version,
}
Expand All @@ -179,10 +178,10 @@ func (l *LoadBalancer) EnsureLoadBalancer( //nolint:gocyclo // not really comple
}
}

if lb.Status != nil && *lb.Status == lbwait.LOADBALANCERSTATUS_ERROR {
if lb.Status != nil && *lb.Status == loadbalancer.LOADBALANCERSTATUS_STATUS_ERROR {
return nil, fmt.Errorf("the load balancer is in an error state")
}
if lb.Status == nil || *lb.Status != lbwait.LOADBALANCERSTATUS_READY {
if lb.Status == nil || *lb.Status != loadbalancer.LOADBALANCERSTATUS_STATUS_READY {
return nil, api.NewRetryError("waiting for load balancer to become ready. This error is normal while the load balancer starts.", retryDuration)
}

Expand Down Expand Up @@ -222,7 +221,7 @@ func (l *LoadBalancer) createLoadBalancer(ctx context.Context, clusterName strin
return nil, createErr
}

if lb.Status == nil || *lb.Status != lbwait.LOADBALANCERSTATUS_READY {
if lb.Status == nil || *lb.Status != loadbalancer.LOADBALANCERSTATUS_STATUS_READY {
return nil, api.NewRetryError("waiting for load balancer to become ready. This error is normal while the load balancer starts.", retryDuration)
}

Expand Down Expand Up @@ -275,7 +274,7 @@ func (l *LoadBalancer) EnsureLoadBalancerDeleted(
return nil
case err != nil:
return err
case lb.Status != nil && *lb.Status == lbwait.LOADBALANCERSTATUS_TERMINATING:
case lb.Status != nil && *lb.Status == loadbalancer.LOADBALANCERSTATUS_STATUS_TERMINATING:
return nil
}

Expand Down
29 changes: 13 additions & 16 deletions pkg/ccm/loadbalancer_spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ import (
"time"

stackitconfig "github.com/stackitcloud/cloud-provider-stackit/pkg/stackit/config"
//nolint:staticcheck // Temporary workaround: v2api OpenAPI generator currently misses enum constants.
lbLegacy "github.com/stackitcloud/stackit-sdk-go/services/loadbalancer"
loadbalancer "github.com/stackitcloud/stackit-sdk-go/services/loadbalancer/v2api"
corev1 "k8s.io/api/core/v1"

Expand Down Expand Up @@ -248,7 +246,7 @@ func getPlanID(service *corev1.Service) (planID *string, msgs []string, err erro
// The property name will be empty and must be set by the caller to produce a valid payload for the API.
// An error is returned if the service has invalid options.
//
//nolint:gocyclo,funlen,staticcheck // Temporary workaround: v2api OpenAPI generator currently misses enum constants.
//nolint:gocyclo,funlen // main function to create a lb from a service, this includes many options and is therefore complex.
func lbSpecFromService(
service *corev1.Service,
nodes []*corev1.Node,
Expand All @@ -259,7 +257,7 @@ func lbSpecFromService(
Options: &loadbalancer.LoadBalancerOptions{},
Networks: []loadbalancer.Network{
{
Role: new(string(lbLegacy.NETWORKROLE_LISTENERS_AND_TARGETS)),
Role: new(loadbalancer.NETWORKROLE_ROLE_LISTENERS_AND_TARGETS),
NetworkId: &opts.NetworkID,
},
},
Expand All @@ -268,17 +266,17 @@ func lbSpecFromService(
if listenerNetwork := service.Annotations[listenerNetworkAnnotation]; listenerNetwork != "" {
lb.Networks = []loadbalancer.Network{
{
Role: new(string(lbLegacy.NETWORKROLE_TARGETS)),
Role: new(loadbalancer.NETWORKROLE_ROLE_TARGETS),
NetworkId: &opts.NetworkID,
}, {
Role: new(string(lbLegacy.NETWORKROLE_LISTENERS)),
Role: new(loadbalancer.NETWORKROLE_ROLE_LISTENERS),
NetworkId: &listenerNetwork,
},
}
} else {
lb.Networks = []loadbalancer.Network{
{
Role: new(string(lbLegacy.NETWORKROLE_LISTENERS_AND_TARGETS)),
Role: new(loadbalancer.NETWORKROLE_ROLE_LISTENERS_AND_TARGETS),
NetworkId: &opts.NetworkID,
},
}
Expand Down Expand Up @@ -503,22 +501,22 @@ func lbSpecFromService(
name = fmt.Sprintf("port-%s-%d", strings.ToLower(string(port.Protocol)), port.Port)
}

var protocol lbLegacy.ListenerProtocol
var protocol loadbalancer.ListenerProtocol
var tcpOptions *loadbalancer.OptionsTCP
var udpOptions *loadbalancer.OptionsUDP

switch port.Protocol {
case corev1.ProtocolTCP:
if proxyProtocolEnableForPort(tcpProxyProtocolEnabled, tcpProxyProtocolPortFilter, port.Port) {
protocol = lbLegacy.LISTENERPROTOCOL_TCP_PROXY
protocol = loadbalancer.LISTENERPROTOCOL_PROTOCOL_TCP_PROXY
} else {
protocol = lbLegacy.LISTENERPROTOCOL_TCP
protocol = loadbalancer.LISTENERPROTOCOL_PROTOCOL_TCP
}
tcpOptions = &loadbalancer.OptionsTCP{
IdleTimeout: new(fmt.Sprintf("%.0fs", tcpIdleTimeout.Seconds())),
}
case corev1.ProtocolUDP:
protocol = lbLegacy.LISTENERPROTOCOL_UDP
protocol = loadbalancer.LISTENERPROTOCOL_PROTOCOL_UDP
udpOptions = &loadbalancer.OptionsUDP{
IdleTimeout: new(fmt.Sprintf("%.0fs", udpIdleTimeout.Seconds())),
}
Expand All @@ -530,7 +528,7 @@ func lbSpecFromService(
DisplayName: &name,
Port: new(port.Port),
TargetPool: &name,
Protocol: new(string(protocol)),
Protocol: new(protocol),
Tcp: tcpOptions,
Udp: udpOptions,
})
Expand Down Expand Up @@ -597,8 +595,7 @@ type resultImmutableChanged struct {
// compareLBwithSpec checks whether the load balancer fulfills the specification.
// If immutableChanged is not nil then spec differs from lb such that an update will fail.
// Otherwise, fulfills will indicate whether an update is necessary.
//
//nolint:staticcheck // Temporary workaround: v2api OpenAPI generator currently misses enum constants.

func compareLBwithSpec(lb *loadbalancer.LoadBalancer, spec *loadbalancer.CreateLoadBalancerPayload) (fulfills bool, immutableChanged *resultImmutableChanged) { //nolint:gocyclo,funlen,lll // It is long but not complex.
// If a mutable property has changed we must still check the rest of the object because if there is an immutable change it must always be returned.
fulfills = true
Expand Down Expand Up @@ -666,13 +663,13 @@ func compareLBwithSpec(lb *loadbalancer.LoadBalancer, spec *loadbalancer.CreateL
if !cmp.PtrValEqual(x.TargetPool, y.TargetPool) {
fulfills = false
}
if (cmp.UnpackPtr(x.Protocol) == string(lbLegacy.LISTENERPROTOCOL_TCP) || cmp.UnpackPtr(x.Protocol) == string(lbLegacy.LISTENERPROTOCOL_TCP_PROXY)) &&
if (cmp.UnpackPtr(x.Protocol) == loadbalancer.LISTENERPROTOCOL_PROTOCOL_TCP || cmp.UnpackPtr(x.Protocol) == loadbalancer.LISTENERPROTOCOL_PROTOCOL_TCP_PROXY) &&
!cmp.PtrValEqualFn(x.Tcp, y.Tcp, func(a, b loadbalancer.OptionsTCP) bool {
return cmp.PtrValEqual(a.IdleTimeout, b.IdleTimeout)
}) {
fulfills = false
}
if cmp.UnpackPtr(x.Protocol) == string(lbLegacy.LISTENERPROTOCOL_UDP) && !cmp.PtrValEqualFn(x.Udp, y.Udp, func(a, b loadbalancer.OptionsUDP) bool {
if cmp.UnpackPtr(x.Protocol) == loadbalancer.LISTENERPROTOCOL_PROTOCOL_UDP && !cmp.PtrValEqualFn(x.Udp, y.Udp, func(a, b loadbalancer.OptionsUDP) bool {
return cmp.PtrValEqual(a.IdleTimeout, b.IdleTimeout)
}) {
fulfills = false
Expand Down
50 changes: 23 additions & 27 deletions pkg/ccm/loadbalancer_spec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,12 @@ import (
"github.com/onsi/gomega/types"
stackitconfig "github.com/stackitcloud/cloud-provider-stackit/pkg/stackit/config"

//nolint:staticcheck // Temporary workaround: v2api OpenAPI generator currently misses enum constants.
lbLegacy "github.com/stackitcloud/stackit-sdk-go/services/loadbalancer"
loadbalancer "github.com/stackitcloud/stackit-sdk-go/services/loadbalancer/v2api"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/utils/ptr"
)

//nolint:staticcheck // Temporary workaround: v2api OpenAPI generator currently misses enum constants
var _ = Describe("lbSpecFromService", func() {
const (
externalAddress = "123.124.88.99"
Expand Down Expand Up @@ -227,15 +224,15 @@ var _ = Describe("lbSpecFromService", func() {
"Listeners": ConsistOf(
MatchFields(IgnoreExtras, Fields{
"DisplayName": PointTo(Equal("http")),
"Protocol": PointTo(Equal(string(lbLegacy.LISTENERPROTOCOL_TCP_PROXY))),
"Protocol": PointTo(Equal(loadbalancer.LISTENERPROTOCOL_PROTOCOL_TCP_PROXY)),
}),
MatchFields(IgnoreExtras, Fields{
"DisplayName": PointTo(Equal("http-alt")),
"Protocol": PointTo(Equal(string(lbLegacy.LISTENERPROTOCOL_TCP_PROXY))),
"Protocol": PointTo(Equal(loadbalancer.LISTENERPROTOCOL_PROTOCOL_TCP_PROXY)),
}),
MatchFields(IgnoreExtras, Fields{
"DisplayName": PointTo(Equal("dns")),
"Protocol": PointTo(Equal(string(lbLegacy.LISTENERPROTOCOL_UDP))),
"Protocol": PointTo(Equal(loadbalancer.LISTENERPROTOCOL_PROTOCOL_UDP)),
}),
),
})))
Expand All @@ -262,15 +259,15 @@ var _ = Describe("lbSpecFromService", func() {
"Listeners": ConsistOf(
MatchFields(IgnoreExtras, Fields{
"DisplayName": PointTo(Equal("http")),
"Protocol": PointTo(Equal(string(lbLegacy.LISTENERPROTOCOL_TCP_PROXY))),
"Protocol": PointTo(Equal(loadbalancer.LISTENERPROTOCOL_PROTOCOL_TCP_PROXY)),
}),
MatchFields(IgnoreExtras, Fields{
"DisplayName": PointTo(Equal("http-alt")),
"Protocol": PointTo(Equal(string(lbLegacy.LISTENERPROTOCOL_TCP_PROXY))),
"Protocol": PointTo(Equal(loadbalancer.LISTENERPROTOCOL_PROTOCOL_TCP_PROXY)),
}),
MatchFields(IgnoreExtras, Fields{
"DisplayName": PointTo(Equal("https")),
"Protocol": PointTo(Equal(string(lbLegacy.LISTENERPROTOCOL_TCP))),
"Protocol": PointTo(Equal(loadbalancer.LISTENERPROTOCOL_PROTOCOL_TCP)),
}),
),
})))
Expand All @@ -295,7 +292,7 @@ var _ = Describe("lbSpecFromService", func() {
"Listeners": ConsistOf(
MatchFields(IgnoreExtras, Fields{
"DisplayName": PointTo(Equal("http")),
"Protocol": PointTo(Equal(string(lbLegacy.LISTENERPROTOCOL_TCP))),
"Protocol": PointTo(Equal(loadbalancer.LISTENERPROTOCOL_PROTOCOL_TCP)),
}),
),
})))
Expand Down Expand Up @@ -375,13 +372,13 @@ var _ = Describe("lbSpecFromService", func() {
Expect(spec.Listeners).To(ConsistOf(
MatchFields(IgnoreExtras, Fields{
"DisplayName": PointTo(Equal("http")),
"Protocol": PointTo(Equal(string(lbLegacy.LISTENERPROTOCOL_TCP))),
"Protocol": PointTo(Equal(loadbalancer.LISTENERPROTOCOL_PROTOCOL_TCP)),
"Port": PointTo(BeNumerically("==", 80)),
"TargetPool": PointTo(Equal("http")),
}),
MatchFields(IgnoreExtras, Fields{
"DisplayName": PointTo(Equal("dns")),
"Protocol": PointTo(Equal(string(lbLegacy.LISTENERPROTOCOL_UDP))),
"Protocol": PointTo(Equal(loadbalancer.LISTENERPROTOCOL_PROTOCOL_UDP)),
"Port": PointTo(BeNumerically("==", 53)),
"TargetPool": PointTo(Equal("dns")),
}),
Expand Down Expand Up @@ -649,7 +646,7 @@ var _ = Describe("lbSpecFromService", func() {
}),
MatchFields(IgnoreExtras, Fields{
"DisplayName": PointTo(Equal("my-tcp-proxy-port")),
"Protocol": PointTo(Equal(string(lbLegacy.LISTENERPROTOCOL_TCP_PROXY))),
"Protocol": PointTo(Equal(loadbalancer.LISTENERPROTOCOL_PROTOCOL_TCP_PROXY)),
"Tcp": PointTo(MatchFields(IgnoreExtras, Fields{
"IdleTimeout": PointTo(Equal("900s")),
})),
Expand Down Expand Up @@ -1160,7 +1157,7 @@ var _ = Describe("lbSpecFromService", func() {
Expect(err).NotTo(HaveOccurred())
Expect(spec.Networks).To(ConsistOf(MatchFields(IgnoreExtras, Fields{
"NetworkId": PointTo(Equal("my-network")),
"Role": PointTo(Equal(string(lbLegacy.NETWORKROLE_LISTENERS_AND_TARGETS))),
"Role": PointTo(Equal(loadbalancer.NETWORKROLE_ROLE_LISTENERS_AND_TARGETS)),
})))
})

Expand All @@ -1176,11 +1173,11 @@ var _ = Describe("lbSpecFromService", func() {
Expect(spec.Networks).To(ConsistOf(
MatchFields(IgnoreExtras, Fields{
"NetworkId": PointTo(Equal("my-network")),
"Role": PointTo(Equal(string(lbLegacy.NETWORKROLE_TARGETS))),
"Role": PointTo(Equal(loadbalancer.NETWORKROLE_ROLE_TARGETS)),
}),
MatchFields(IgnoreExtras, Fields{
"NetworkId": PointTo(Equal("my-listener-network")),
"Role": PointTo(Equal(string(lbLegacy.NETWORKROLE_LISTENERS))),
"Role": PointTo(Equal(loadbalancer.NETWORKROLE_ROLE_LISTENERS)),
}),
))
})
Expand Down Expand Up @@ -1224,7 +1221,6 @@ type compareLBwithSpecTest struct {
spec *loadbalancer.CreateLoadBalancerPayload
}

//nolint:staticcheck // Temporary workaround: v2api OpenAPI generator currently misses enum constants
var _ = DescribeTable("compareLBwithSpec",
func(t *compareLBwithSpecTest) {
fulfills, immutableChanged := compareLBwithSpec(t.lb, t.spec)
Expand Down Expand Up @@ -1429,15 +1425,15 @@ var _ = DescribeTable("compareLBwithSpec",
PrivateNetworkOnly: new(true),
},
Listeners: []loadbalancer.Listener{
{Protocol: new(string(lbLegacy.LISTENERPROTOCOL_TCP))},
{Protocol: new(loadbalancer.LISTENERPROTOCOL_PROTOCOL_TCP)},
},
},
spec: &loadbalancer.CreateLoadBalancerPayload{
Options: &loadbalancer.LoadBalancerOptions{
PrivateNetworkOnly: new(true),
},
Listeners: []loadbalancer.Listener{
{Protocol: new(string(lbLegacy.LISTENERPROTOCOL_TCP_PROXY))},
{Protocol: new(loadbalancer.LISTENERPROTOCOL_PROTOCOL_TCP_PROXY)},
},
},
}),
Expand All @@ -1449,7 +1445,7 @@ var _ = DescribeTable("compareLBwithSpec",
},
Listeners: []loadbalancer.Listener{
{
Protocol: new(string(lbLegacy.LISTENERPROTOCOL_TCP)),
Protocol: new(loadbalancer.LISTENERPROTOCOL_PROTOCOL_TCP),
Tcp: &loadbalancer.OptionsTCP{
IdleTimeout: new("60s"),
},
Expand All @@ -1462,7 +1458,7 @@ var _ = DescribeTable("compareLBwithSpec",
},
Listeners: []loadbalancer.Listener{
{
Protocol: new(string(lbLegacy.LISTENERPROTOCOL_TCP)),
Protocol: new(loadbalancer.LISTENERPROTOCOL_PROTOCOL_TCP),
Tcp: &loadbalancer.OptionsTCP{
IdleTimeout: new("120s"),
},
Expand All @@ -1478,7 +1474,7 @@ var _ = DescribeTable("compareLBwithSpec",
},
Listeners: []loadbalancer.Listener{
{
Protocol: new(string(lbLegacy.LISTENERPROTOCOL_UDP)),
Protocol: new(loadbalancer.LISTENERPROTOCOL_PROTOCOL_UDP),
Udp: &loadbalancer.OptionsUDP{
IdleTimeout: new("60s"),
},
Expand All @@ -1491,7 +1487,7 @@ var _ = DescribeTable("compareLBwithSpec",
},
Listeners: []loadbalancer.Listener{
{
Protocol: new(string(lbLegacy.LISTENERPROTOCOL_UDP)),
Protocol: new(loadbalancer.LISTENERPROTOCOL_PROTOCOL_UDP),
Udp: &loadbalancer.OptionsUDP{
IdleTimeout: new("120s"),
},
Expand All @@ -1507,7 +1503,7 @@ var _ = DescribeTable("compareLBwithSpec",
},
Listeners: []loadbalancer.Listener{
{
Protocol: new(string(lbLegacy.LISTENERPROTOCOL_TCP_PROXY)),
Protocol: new(loadbalancer.LISTENERPROTOCOL_PROTOCOL_TCP_PROXY),
Tcp: &loadbalancer.OptionsTCP{
IdleTimeout: new("60s"),
},
Expand All @@ -1520,7 +1516,7 @@ var _ = DescribeTable("compareLBwithSpec",
},
Listeners: []loadbalancer.Listener{
{
Protocol: new(string(lbLegacy.LISTENERPROTOCOL_TCP_PROXY)),
Protocol: new(loadbalancer.LISTENERPROTOCOL_PROTOCOL_TCP_PROXY),
Tcp: &loadbalancer.OptionsTCP{
IdleTimeout: new("120s"),
},
Expand Down Expand Up @@ -1595,7 +1591,7 @@ var _ = DescribeTable("compareLBwithSpec",
},
Networks: []loadbalancer.Network{
{
Role: new(string(lbLegacy.NETWORKROLE_LISTENERS)),
Role: new(loadbalancer.NETWORKROLE_ROLE_LISTENERS),
},
},
},
Expand All @@ -1605,7 +1601,7 @@ var _ = DescribeTable("compareLBwithSpec",
},
Networks: []loadbalancer.Network{
{
Role: new(string(lbLegacy.NETWORKROLE_TARGETS)),
Role: new(loadbalancer.NETWORKROLE_ROLE_TARGETS),
},
},
},
Expand Down
Loading