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
4 changes: 0 additions & 4 deletions pkg/ccm/instances.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,6 @@ type Instances struct {
region string
}

type InstancesOpts struct {
API string `yaml:"api"`
}

func NewInstance(client stackit.NodeClient, projectID, region string) (*Instances, error) {
return &Instances{
iaasClient: client,
Expand Down
11 changes: 3 additions & 8 deletions pkg/ccm/loadbalancer.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"strings"
"time"

stackitconfig "github.com/stackitcloud/cloud-provider-stackit/pkg/stackit/config"
"github.com/stackitcloud/stackit-sdk-go/services/loadbalancer"
corev1 "k8s.io/api/core/v1"
"k8s.io/client-go/tools/record"
Expand Down Expand Up @@ -41,20 +42,14 @@ type LoadBalancer struct {
client stackit.LoadbalancerClient
recorder record.EventRecorder // set in CloudControllerManager.Initialize
projectID string
opts LoadBalancerOpts
opts stackitconfig.LoadBalancerOpts
// metricsRemoteWrite setting this enables remote writing of metrics and nil means it is disabled
metricsRemoteWrite *MetricsRemoteWrite
}

type LoadBalancerOpts struct {
API string `yaml:"api"`
NetworkID string `yaml:"networkId"`
ExtraLabels map[string]string `yaml:"extraLabels"`
}

var _ cloudprovider.LoadBalancer = (*LoadBalancer)(nil)

func NewLoadBalancer(client stackit.LoadbalancerClient, projectID string, opts LoadBalancerOpts, metricsRemoteWrite *MetricsRemoteWrite) (*LoadBalancer, error) { //nolint:lll // looks weird when shortened
func NewLoadBalancer(client stackit.LoadbalancerClient, projectID string, opts stackitconfig.LoadBalancerOpts, metricsRemoteWrite *MetricsRemoteWrite) (*LoadBalancer, error) { //nolint:lll // looks weird when shortened
// LoadBalancer.recorder is set in CloudControllerManager.Initialize
return &LoadBalancer{
client: client,
Expand Down
3 changes: 2 additions & 1 deletion pkg/ccm/loadbalancer_spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"strings"
"time"

stackitconfig "github.com/stackitcloud/cloud-provider-stackit/pkg/stackit/config"
"github.com/stackitcloud/stackit-sdk-go/services/loadbalancer"
corev1 "k8s.io/api/core/v1"

Expand Down Expand Up @@ -241,7 +242,7 @@ func getPlanID(service *corev1.Service) (planID *string, msgs []string, err erro
func lbSpecFromService( //nolint:funlen,gocyclo // It is long but not complex.
service *corev1.Service,
nodes []*corev1.Node,
opts LoadBalancerOpts,
opts stackitconfig.LoadBalancerOpts,
observability *loadbalancer.LoadbalancerOptionObservability,
) (*loadbalancer.CreateLoadBalancerPayload, []Event, error) {
lb := &loadbalancer.CreateLoadBalancerPayload{
Expand Down
5 changes: 3 additions & 2 deletions pkg/ccm/loadbalancer_spec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
. "github.com/onsi/gomega"
. "github.com/onsi/gomega/gstruct"
"github.com/onsi/gomega/types"
stackitconfig "github.com/stackitcloud/cloud-provider-stackit/pkg/stackit/config"

"github.com/stackitcloud/stackit-sdk-go/services/loadbalancer"
corev1 "k8s.io/api/core/v1"
Expand All @@ -24,7 +25,7 @@ var _ = Describe("lbSpecFromService", func() {
httpAlt corev1.ServicePort
https corev1.ServicePort
dns corev1.ServicePort
lbOpts LoadBalancerOpts
lbOpts stackitconfig.LoadBalancerOpts
)
BeforeEach(func() {
http = corev1.ServicePort{
Expand All @@ -47,7 +48,7 @@ var _ = Describe("lbSpecFromService", func() {
Port: 53,
Protocol: corev1.ProtocolUDP,
}
lbOpts = LoadBalancerOpts{NetworkID: "my-network"}
lbOpts = stackitconfig.LoadBalancerOpts{NetworkID: "my-network"}
})

Context("internal load balancer", func() {
Expand Down
5 changes: 3 additions & 2 deletions pkg/ccm/loadbalancer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
stackitconfig "github.com/stackitcloud/cloud-provider-stackit/pkg/stackit/config"
"github.com/stackitcloud/stackit-sdk-go/services/loadbalancer"
"go.uber.org/mock/gomock"
corev1 "k8s.io/api/core/v1"
Expand All @@ -30,13 +31,13 @@ var _ = Describe("LoadBalancer", func() {
loadBalancer *LoadBalancer
clusterName string
projectID string
lbOpts LoadBalancerOpts
lbOpts stackitconfig.LoadBalancerOpts
)

BeforeEach(func() {
clusterName = "my-cluster"
projectID = "my-project"
lbOpts = LoadBalancerOpts{NetworkID: "my-network"}
lbOpts = stackitconfig.LoadBalancerOpts{NetworkID: "my-network"}

ctrl := gomock.NewController(GinkgoT())
mockClient = stackit.NewMockLoadbalancerClient(ctrl)
Expand Down
27 changes: 10 additions & 17 deletions pkg/ccm/stackit.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"io"
"os"

stackitconfig "github.com/stackitcloud/cloud-provider-stackit/pkg/stackit/config"
sdkconfig "github.com/stackitcloud/stackit-sdk-go/core/config"
"github.com/stackitcloud/stackit-sdk-go/services/iaas"
"github.com/stackitcloud/stackit-sdk-go/services/loadbalancer"
Expand All @@ -19,7 +20,6 @@ import (

"github.com/stackitcloud/cloud-provider-stackit/pkg/metrics"
"github.com/stackitcloud/cloud-provider-stackit/pkg/stackit"
"github.com/stackitcloud/cloud-provider-stackit/pkg/stackit/metadata"
)

const (
Expand All @@ -42,13 +42,6 @@ type CloudControllerManager struct {
instances *Instances
}

type Config struct {
Global stackit.GlobalOpts `yaml:"global"`
Metadata metadata.Opts `yaml:"metadata"`
LoadBalancer LoadBalancerOpts `yaml:"loadBalancer"`
Instances InstancesOpts `yaml:"instances"`
}

func init() {
cloudprovider.RegisterCloudProvider(ProviderName, func(config io.Reader) (cloudprovider.Interface, error) {
cfg, err := GetConfig(config)
Expand Down Expand Up @@ -79,8 +72,8 @@ func init() {
})
}

func GetConfig(reader io.Reader) (Config, error) {
var cfg Config
func GetConfig(reader io.Reader) (stackitconfig.CCMConfig, error) {
var cfg stackitconfig.CCMConfig

content, err := io.ReadAll(reader)
if err != nil {
Expand Down Expand Up @@ -124,21 +117,21 @@ func BuildObservability() (*MetricsRemoteWrite, error) {
return nil, fmt.Errorf("missing from env: %q", missingKeys)
}

// NewCloudControllerManager creates a new instance of the stackit struct from a config struct
func NewCloudControllerManager(cfg *Config, obs *MetricsRemoteWrite) (*CloudControllerManager, error) {
// NewCloudControllerManager creates a new instance of the stackit struct from a stackitconfig struct
func NewCloudControllerManager(cfg *stackitconfig.CCMConfig, obs *MetricsRemoteWrite) (*CloudControllerManager, error) {
lbOpts := []sdkconfig.ConfigurationOption{
sdkconfig.WithHTTPClient(metrics.NewInstrumentedHTTPClient()),
}

if cfg.LoadBalancer.API != "" {
lbOpts = append(lbOpts, sdkconfig.WithEndpoint(cfg.LoadBalancer.API))
if cfg.Global.APIEndpoints.LoadBalancerAPI != "" {
lbOpts = append(lbOpts, sdkconfig.WithEndpoint(cfg.Global.APIEndpoints.LoadBalancerAPI))
}

// The token is only provided by the 'gardener-extension-provider-stackit' in case of emergency access.
// In those cases, the [cfg.LoadBalancerAPI.URL] will also be different (direct API URL instead of the API Gateway)
lbEmergencyAPIToken := os.Getenv(stackitLoadBalancerEmergencyAPIToken)
if lbEmergencyAPIToken != "" {
klog.Warningf("Using emergency token for loadbalancer api on host: %s", cfg.LoadBalancer.API)
klog.Warningf("Using emergency token for loadbalancer api on host: %s", cfg.Global.APIEndpoints.LoadBalancerAPI)
lbOpts = append(lbOpts, sdkconfig.WithToken(lbEmergencyAPIToken))
}

Expand All @@ -155,8 +148,8 @@ func NewCloudControllerManager(cfg *Config, obs *MetricsRemoteWrite) (*CloudCont
sdkconfig.WithHTTPClient(metrics.NewInstrumentedHTTPClient()),
}

if cfg.Instances.API != "" {
iaasOpts = append(iaasOpts, sdkconfig.WithEndpoint(cfg.Instances.API))
if cfg.Global.APIEndpoints.IaasAPI != "" {
iaasOpts = append(iaasOpts, sdkconfig.WithEndpoint(cfg.Global.APIEndpoints.IaasAPI))
}

iaasInnerClient, err := iaas.NewAPIClient(iaasOpts...)
Expand Down
12 changes: 7 additions & 5 deletions pkg/ccm/stackit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
stackitconfig "github.com/stackitcloud/cloud-provider-stackit/pkg/stackit/config"
)

var _ = Describe("GetConfig", func() {
Expand All @@ -14,19 +15,20 @@ var _ = Describe("GetConfig", func() {
global:
projectId: "test-project"
region: "eu01"
apiEndpoints:
loadBalancerApi: "https://load-balancer.api.eu01.stackit.cloud"
metadata:
searchOrder: "metadataService,configDrive"
loadBalancer:
api: "https://load-balancer.api.eu01.stackit.cloud"
networkId: "test-network"
`

config, err := GetConfig(strings.NewReader(validYAML))
Expect(err).NotTo(HaveOccurred())
Expect(config.Global.ProjectID).To(Equal("test-project"))
Expect(config.Global.Region).To(Equal("eu01"))
Expect(config.Global.APIEndpoints.LoadBalancerAPI).To(Equal("https://load-balancer.api.eu01.stackit.cloud"))
Expect(config.Metadata.SearchOrder).To(Equal("metadataService,configDrive"))
Expect(config.LoadBalancer.API).To(Equal("https://load-balancer.api.eu01.stackit.cloud"))
Expect(config.LoadBalancer.NetworkID).To(Equal("test-network"))
})

Expand All @@ -43,8 +45,8 @@ loadBalancer:
Expect(err).NotTo(HaveOccurred())
Expect(config.Global.ProjectID).To(Equal("my-project"))
Expect(config.Global.Region).To(Equal("eu01"))
Expect(config.Global.APIEndpoints.LoadBalancerAPI).To(BeEmpty())
Expect(config.LoadBalancer.NetworkID).To(Equal("my-network"))
Expect(config.LoadBalancer.API).To(BeEmpty())
})

It("should handle configuration with extra labels", func() {
Expand Down Expand Up @@ -82,7 +84,7 @@ global:

config, err := GetConfig(strings.NewReader(emptyYAML))
Expect(err).NotTo(HaveOccurred())
Expect(config).To(Equal(Config{}))
Expect(config).To(Equal(stackitconfig.CCMConfig{}))
})

It("should return error for invalid YAML structure", func() {
Expand Down Expand Up @@ -133,6 +135,6 @@ loadBalancer:

config, err := GetConfig(emptyReader)
Expect(err).NotTo(HaveOccurred())
Expect(config).To(Equal(Config{}))
Expect(config).To(Equal(stackitconfig.CCMConfig{}))
})
})
3 changes: 2 additions & 1 deletion pkg/csi/blockstorage/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (

"github.com/container-storage-interface/spec/lib/go/csi"
"github.com/stackitcloud/cloud-provider-stackit/pkg/stackit"
stackitconfig "github.com/stackitcloud/cloud-provider-stackit/pkg/stackit/config"
corev1 "k8s.io/client-go/listers/core/v1"
"k8s.io/klog/v2"

Expand Down Expand Up @@ -138,7 +139,7 @@ func (d *Driver) SetupControllerService(instance stackit.IaasClient) {
d.cs = NewControllerServer(d, instance)
}

func (d *Driver) SetupNodeService(mountProvider mount.IMount, metadataProvider metadata.IMetadata, opts stackit.BlockStorageOpts) {
func (d *Driver) SetupNodeService(mountProvider mount.IMount, metadataProvider metadata.IMetadata, opts stackitconfig.BlockStorageOpts) {
klog.Info("Providing node service")
d.ns = NewNodeServer(d, mountProvider, metadataProvider, opts)
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/csi/blockstorage/nodeserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"github.com/container-storage-interface/spec/lib/go/csi"
"github.com/kubernetes-csi/csi-lib-utils/protosanitizer"
"github.com/stackitcloud/cloud-provider-stackit/pkg/csi/util"
stackitconfig "github.com/stackitcloud/cloud-provider-stackit/pkg/stackit/config"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
"k8s.io/klog/v2"
Expand All @@ -35,15 +36,14 @@ import (
sharedcsi "github.com/stackitcloud/cloud-provider-stackit/pkg/csi"
"github.com/stackitcloud/cloud-provider-stackit/pkg/csi/util/blockdevice"
"github.com/stackitcloud/cloud-provider-stackit/pkg/csi/util/mount"
"github.com/stackitcloud/cloud-provider-stackit/pkg/stackit"
"github.com/stackitcloud/cloud-provider-stackit/pkg/stackit/metadata"
)

type nodeServer struct {
Driver *Driver
Mount mount.IMount
Metadata metadata.IMetadata
Opts stackit.BlockStorageOpts
Opts stackitconfig.BlockStorageOpts
csi.UnimplementedNodeServer
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/csi/blockstorage/nodeserver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"github.com/container-storage-interface/spec/lib/go/csi"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"github.com/stackitcloud/cloud-provider-stackit/pkg/stackit"
stackitconfig "github.com/stackitcloud/cloud-provider-stackit/pkg/stackit/config"
"go.uber.org/mock/gomock"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
Expand Down Expand Up @@ -42,7 +42,7 @@ var _ = Describe("NodeServer", func() {
d,
mountMock,
metadataMock,
stackit.BlockStorageOpts{},
stackitconfig.BlockStorageOpts{},
)
})

Expand Down
3 changes: 2 additions & 1 deletion pkg/csi/blockstorage/sanity_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/google/uuid"
"github.com/kubernetes-csi/csi-test/v5/pkg/sanity"
. "github.com/onsi/ginkgo/v2"
stackitconfig "github.com/stackitcloud/cloud-provider-stackit/pkg/stackit/config"
mountutils "k8s.io/mount-utils"
exec "k8s.io/utils/exec/testing"

Expand Down Expand Up @@ -437,7 +438,7 @@ var _ = Describe("CSI sanity test", Ordered, func() {

// --- Driver Setup & Run ---
driver.SetupControllerService(iaasClient)
driver.SetupNodeService(mountMock, metadataMock, stackit.BlockStorageOpts{})
driver.SetupNodeService(mountMock, metadataMock, stackitconfig.BlockStorageOpts{})

go func() {
defer GinkgoRecover()
Expand Down
3 changes: 2 additions & 1 deletion pkg/csi/blockstorage/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (

"github.com/stackitcloud/cloud-provider-stackit/pkg/csi/util/mount"
"github.com/stackitcloud/cloud-provider-stackit/pkg/stackit"
stackitconfig "github.com/stackitcloud/cloud-provider-stackit/pkg/stackit/config"
"github.com/stackitcloud/cloud-provider-stackit/pkg/stackit/metadata"

"github.com/container-storage-interface/spec/lib/go/csi"
Expand Down Expand Up @@ -56,7 +57,7 @@ func NewIdentityServer(d *Driver) *identityServer {
}
}

func NewNodeServer(d *Driver, mountProvider mount.IMount, metadataProvider metadata.IMetadata, opts stackit.BlockStorageOpts) *nodeServer { //nolint:lll // looks weird when shortened
func NewNodeServer(d *Driver, mountProvider mount.IMount, metadataProvider metadata.IMetadata, opts stackitconfig.BlockStorageOpts) *nodeServer { //nolint:lll // looks weird when shortened
return &nodeServer{
Driver: d,
Mount: mountProvider,
Expand Down
Loading