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
11 changes: 3 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -124,21 +124,16 @@ verify-image-stackit-csi-plugin: image-stackit-csi-plugin
@docker run -v ./tools/csi-deps-check.sh:/tools/csi-deps-check.sh --entrypoint=/tools/csi-deps-check.sh $(REGISTRY)/$(REPO)/stackit-csi-plugin-dev:$(VERSION)

# generate mock types for the following services (space-separated list)
MOCK_SERVICES := iaas

.PHONY: mocks
mocks: $(MOCKGEN)
# clean mocks
@find . -name '*_mock.go' -delete || true
# generate mocks
@go mod download
@for service in $(MOCK_SERVICES); do \
INTERFACES=`go doc -all github.com/stackitcloud/stackit-sdk-go/services/$$service | grep '^type Api.* interface' | sed -n 's/^type \(.*\) interface.*/\1/p' | paste -sd,`,DefaultApi; \
$(MOCKGEN) -destination ./pkg/mock/$$service/$$service.go -package $$service github.com/stackitcloud/stackit-sdk-go/services/$$service $$INTERFACES; \
done

# API mocks
@$(MOCKGEN) -destination ./pkg/mock/loadbalancer/loadbalancer.go -package loadbalancer github.com/stackitcloud/stackit-sdk-go/services/loadbalancer/v2api DefaultAPI
@$(MOCKGEN) -destination ./pkg/mock/iaas/iaas.go -package iaas github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api DefaultAPI

# client mocks
@$(MOCKGEN) -destination ./pkg/stackit/iaas_mock.go -package stackit ./pkg/stackit IaasClient
@$(MOCKGEN) -destination ./pkg/stackit/loadbalancer_mock.go -package stackit ./pkg/stackit LoadbalancerClient
@$(MOCKGEN) -destination ./pkg/stackit/server_mock.go -package stackit ./pkg/stackit NodeClient
Expand Down
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ require (
github.com/prometheus/client_golang v1.23.2
github.com/spf13/cobra v1.10.2
github.com/spf13/pflag v1.0.10
github.com/stackitcloud/stackit-sdk-go/core v0.24.0
github.com/stackitcloud/stackit-sdk-go/services/iaas v1.3.5
github.com/stackitcloud/stackit-sdk-go/core v0.25.0
github.com/stackitcloud/stackit-sdk-go/services/iaas v1.10.1
github.com/stackitcloud/stackit-sdk-go/services/loadbalancer v1.11.1
go.uber.org/mock v0.6.0
golang.org/x/sync v0.20.0
Expand Down Expand Up @@ -91,7 +91,7 @@ require (
github.com/prometheus/client_model v0.6.2 // indirect
github.com/prometheus/common v0.66.1 // indirect
github.com/prometheus/procfs v0.16.1 // indirect
github.com/stackitcloud/stackit-sdk-go/services/resourcemanager v0.18.5 // indirect
github.com/stackitcloud/stackit-sdk-go/services/resourcemanager v0.22.1 // indirect
github.com/stoewer/go-strcase v1.3.1 // indirect
github.com/stretchr/objx v0.5.3 // indirect
github.com/x448/float16 v0.8.4 // indirect
Expand Down
12 changes: 6 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -186,14 +186,14 @@ github.com/spf13/pflag v1.0.10 h1:4EBh2KAYBwaONj6b2Ye1GiHfwjqyROoF4RwYO+vPwFk=
github.com/spf13/pflag v1.0.10/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
github.com/stackitcloud/cloud-provider v0.35.1-ske-1 h1:Oo71mALP7hh50wAeGOogng2sAsi7AUre4177WS2n9NE=
github.com/stackitcloud/cloud-provider v0.35.1-ske-1/go.mod h1:zGF/i9YuBODKxj7szGMMIz4DRnjsDy5mg2JU+XbbULA=
github.com/stackitcloud/stackit-sdk-go/core v0.24.0 h1:kHCcezCJ5OGSP7RRuGOxD5rF2wejpkEiRr/OdvNcuPQ=
github.com/stackitcloud/stackit-sdk-go/core v0.24.0/go.mod h1:osMglDby4csGZ5sIfhNyYq1bS1TxIdPY88+skE/kkmI=
github.com/stackitcloud/stackit-sdk-go/services/iaas v1.3.5 h1:W57+XRa8wTLsi5CV9Tqa7mGgt/PvlRM//RurXSmvII8=
github.com/stackitcloud/stackit-sdk-go/services/iaas v1.3.5/go.mod h1:lTWjW57eAq1bwfM6nsNinhoBr3MHFW/GaFasdAsYfDM=
github.com/stackitcloud/stackit-sdk-go/core v0.25.0 h1:ra3VEk684MNoq741g+xbZrKjZzhyztq5liUAwwew4DY=
github.com/stackitcloud/stackit-sdk-go/core v0.25.0/go.mod h1:WU1hhxnjXw2EV7CYa1nlEvNpMiRY6CvmIOaHuL3pOaA=
github.com/stackitcloud/stackit-sdk-go/services/iaas v1.10.1 h1:cnuhSWcd2MxG/LWkJgxTZCbtLCBLNSB31/iGfCj7rUw=
github.com/stackitcloud/stackit-sdk-go/services/iaas v1.10.1/go.mod h1:Qa7486Y17g07N/9HbAVEVPcPZ+e1l3y7F9I7j5nKewY=
github.com/stackitcloud/stackit-sdk-go/services/loadbalancer v1.11.1 h1:8hLLCP4n9w3K3dqJaKF1PnMpX4qjR8UQL3gDr80hgDI=
github.com/stackitcloud/stackit-sdk-go/services/loadbalancer v1.11.1/go.mod h1:vqTjmecQ4+oVWzeo9tCOUZ3TrpIIzM+C0apC7cdAD0Y=
github.com/stackitcloud/stackit-sdk-go/services/resourcemanager v0.18.5 h1:MZ5aTO2NQ1Jecmi67ByGskve5nKXHl91fE+z+vFjxt4=
github.com/stackitcloud/stackit-sdk-go/services/resourcemanager v0.18.5/go.mod h1:CJLmdqWvJm5/3+lXPDKu8k4WXs2UG8euGoqQX5xE79k=
github.com/stackitcloud/stackit-sdk-go/services/resourcemanager v0.22.1 h1:J7EqPLrdfEWhEw5bH3StHbKtrSwJ6Gdjw5RwzsHXGf0=
github.com/stackitcloud/stackit-sdk-go/services/resourcemanager v0.22.1/go.mod h1:hczoIYoLKu7vL+iunL1AlhQ2MqQXckPlqiozrqdZrWQ=
github.com/stoewer/go-strcase v1.3.1 h1:iS0MdW+kVTxgMoE1LAZyMiYJFKlOzLooE4MxjirtkAs=
github.com/stoewer/go-strcase v1.3.1/go.mod h1:fAH5hQ5pehh+j3nZfvwdk2RgEgQjAoM8wodgtPmh1xo=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
Expand Down
21 changes: 12 additions & 9 deletions pkg/ccm/instances.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (

"github.com/stackitcloud/cloud-provider-stackit/pkg/labels"
"github.com/stackitcloud/cloud-provider-stackit/pkg/stackit"
"github.com/stackitcloud/stackit-sdk-go/services/iaas"
iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api"

corev1 "k8s.io/api/core/v1"
cloudprovider "k8s.io/cloud-provider"
Expand Down Expand Up @@ -105,27 +105,30 @@ func (i *Instances) InstanceMetadata(ctx context.Context, node *corev1.Node) (*c
if len(server.GetNics()) == 0 {
return nil, fmt.Errorf("server has no network interfaces")
}
for _, nic := range server.GetNics() {
if ipv4, ok := nic.GetIpv4Ok(); ok {

nics := server.GetNics()
for i := range nics {
nic := &nics[i]
if nic.HasIpv4() {
addToNodeAddresses(&addresses,
corev1.NodeAddress{
Address: ipv4,
Address: nic.GetIpv4(),
Type: corev1.NodeInternalIP,
})
}

if ipv6, ok := nic.GetIpv6Ok(); ok {
if nic.HasIpv6() {
addToNodeAddresses(&addresses,
corev1.NodeAddress{
Address: ipv6,
Address: nic.GetIpv6(),
Type: corev1.NodeInternalIP,
})
}

if publicIP, ok := nic.GetPublicIpOk(); ok {
if nic.HasPublicIp() {
addToNodeAddresses(&addresses,
corev1.NodeAddress{
Address: publicIP,
Address: nic.GetPublicIp(),
Type: corev1.NodeExternalIP,
})
}
Expand Down Expand Up @@ -214,7 +217,7 @@ func getServerByName(ctx context.Context, client stackit.NodeClient, name, proje
// TODO: Implement field selector for ListServers so we don't have to do the following
for i := range serverList {
server := serverList[i]
if serverName, ok := server.GetNameOk(); ok && serverName == name {
if server.GetName() == name {
return &server, nil
}
}
Expand Down
20 changes: 10 additions & 10 deletions pkg/ccm/instances_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
. "github.com/onsi/gomega"

"github.com/stackitcloud/cloud-provider-stackit/pkg/stackit"
"github.com/stackitcloud/stackit-sdk-go/services/iaas"
iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api"

"go.uber.org/mock/gomock"
corev1 "k8s.io/api/core/v1"
Expand Down Expand Up @@ -82,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: new("foo"),
Name: "foo",
},
}, nil)

Expand All @@ -97,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: new("foo"),
Name: "foo",
}, nil)

node := &corev1.Node{
Expand All @@ -114,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: new("foo"),
Name: "foo",
}, nil)

node := &corev1.Node{
Expand All @@ -131,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: new("foo"),
Name: "foo",
}, nil)

node := &corev1.Node{
Expand Down Expand Up @@ -177,7 +177,7 @@ 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: new("foo"),
Name: "foo",
Status: new(instanceStopping),
},
}, nil)
Expand All @@ -193,7 +193,7 @@ 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: new("foo"),
Name: "foo",
Status: new("ACTIVE"),
}, nil)

Expand Down Expand Up @@ -238,10 +238,10 @@ var _ = Describe("Node Controller", func() {
It("successfully get all the metadata values", func() {
nodeMockClient.EXPECT().ListServers(gomock.Any(), projectID, region).Return(&[]iaas.Server{
{
Name: new("foo"),
Name: "foo",
Id: new(serverID),
MachineType: new("flatcar"),
Nics: &[]iaas.ServerNetwork{
MachineType: "flatcar",
Nics: []iaas.ServerNetwork{
{
Ipv4: new("10.10.100.24"),
},
Expand Down
2 changes: 1 addition & 1 deletion pkg/ccm/stackit.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (

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"
iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api"
loadbalancer "github.com/stackitcloud/stackit-sdk-go/services/loadbalancer/v2api"
"gopkg.in/yaml.v3"
corev1 "k8s.io/api/core/v1"
Expand Down
46 changes: 23 additions & 23 deletions pkg/csi/blockstorage/controllerserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (
"github.com/go-viper/mapstructure/v2"
"github.com/kubernetes-csi/csi-lib-utils/protosanitizer"
"github.com/stackitcloud/cloud-provider-stackit/pkg/csi/util"
"github.com/stackitcloud/stackit-sdk-go/services/iaas"
iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
"google.golang.org/protobuf/types/known/timestamppb"
Expand Down Expand Up @@ -130,7 +130,7 @@ func (cs *controllerServer) CreateVolume(ctx context.Context, req *csi.CreateVol
if *vols[0].Status != stackit.VolumeAvailableStatus {
return nil, status.Error(codes.Internal, fmt.Sprintf("Volume %s is not in available state", *vols[0].Id))
}
klog.V(4).Infof("Volume %s already exists in Availability Zone: %s of size %d GiB", *vols[0].Id, *vols[0].AvailabilityZone, *vols[0].Size)
klog.V(4).Infof("Volume %s already exists in Availability Zone: %s of size %d GiB", *vols[0].Id, vols[0].AvailabilityZone, *vols[0].Size)
return getCreateVolumeResponse(&vols[0]), nil
} else if len(vols) > 1 {
klog.V(3).Infof("found multiple existing volumes with selected name (%s) during create", volName)
Expand Down Expand Up @@ -175,8 +175,8 @@ func (cs *controllerServer) CreateVolume(ctx context.Context, req *csi.CreateVol
if err != nil {
return nil, status.Errorf(codes.Internal, "Failed to retrieve the source volume of snapshot %s: %v", sourceSnapshotID, err)
}
if *snapshotVolSrc.AvailabilityZone != volAvailability {
return nil, status.Errorf(codes.ResourceExhausted, "Volume must be in the same availability zone as source Snapshot. Got %s Required: %s", volAvailability, *snapshotVolSrc.AvailabilityZone)
if snapshotVolSrc.AvailabilityZone != volAvailability {
return nil, status.Errorf(codes.ResourceExhausted, "Volume must be in the same availability zone as source Snapshot. Got %s Required: %s", volAvailability, snapshotVolSrc.AvailabilityZone)
}
}

Expand Down Expand Up @@ -208,8 +208,8 @@ func (cs *controllerServer) CreateVolume(ctx context.Context, req *csi.CreateVol
}
return nil, status.Errorf(codes.Internal, "Failed to retrieve the source volume %s: %v", sourceVolID, err)
}
if volAvailability != *sourceVolume.AvailabilityZone {
return nil, status.Errorf(codes.ResourceExhausted, "Volume must be in the same availability zone as source Volume. Got %s Required: %s", volAvailability, *sourceVolume.AvailabilityZone)
if volAvailability != sourceVolume.AvailabilityZone {
return nil, status.Errorf(codes.ResourceExhausted, "Volume must be in the same availability zone as source Volume. Got %s Required: %s", volAvailability, sourceVolume.AvailabilityZone)
}
volumeSourceType = stackit.VolumeSource
}
Expand All @@ -218,7 +218,7 @@ func (cs *controllerServer) CreateVolume(ctx context.Context, req *csi.CreateVol
Name: new(volName),
PerformanceClass: volParams.PerformanceClass,
Size: new(volSizeGB),
AvailabilityZone: new(volAvailability),
AvailabilityZone: volAvailability,
//TODO: IaaS API does not allow dots or slashes. Additionally we would like to actually use metadata/annotations
//Labels: new(util.ConvertMapStringToInterface(properties)),
}
Expand All @@ -233,8 +233,8 @@ func (cs *controllerServer) CreateVolume(ctx context.Context, req *csi.CreateVol
volumeSourceID := determineSourceIDForSourceType(volumeSourceType, sourceSnapshotID, sourceVolID)
klog.V(4).Infof("Creating volume from %s source", volumeSourceType)
opts.Source = &iaas.VolumeSource{
Id: new(volumeSourceID),
Type: new(string(volumeSourceType)),
Id: volumeSourceID,
Type: string(volumeSourceType),
}
}

Expand Down Expand Up @@ -272,7 +272,7 @@ func (cs *controllerServer) CreateVolume(ctx context.Context, req *csi.CreateVol
return nil, status.Error(codes.Internal, fmt.Sprintf("CreateVolume Volume %s failed getting available in time: %v", *vol.Id, err))
}

klog.V(4).Infof("CreateVolume: Successfully created volume %s in Availability Zone: %s of size %d GiB", *vol.Id, *vol.AvailabilityZone, *vol.Size)
klog.V(4).Infof("CreateVolume: Successfully created volume %s in Availability Zone: %s of size %d GiB", *vol.Id, vol.AvailabilityZone, *vol.Size)

return getCreateVolumeResponse(vol), nil
}
Expand All @@ -289,10 +289,10 @@ func setVolumeEncryptionParameters(opts *iaas.CreateVolumePayload, volParams *st
}

encryptionConfig := &iaas.VolumeEncryptionParameter{
KekKeyId: volParams.KMSKeyID,
KekKeyVersion: new(int64(kmsKeyVersionInt)),
KekKeyringId: volParams.KMSKeyringID,
ServiceAccount: volParams.KMSServiceAccount,
KekKeyId: *volParams.KMSKeyID,
KekKeyVersion: int64(kmsKeyVersionInt),
KekKeyringId: *volParams.KMSKeyringID,
ServiceAccount: *volParams.KMSServiceAccount,
}

if volParams.KMSProjectID != nil {
Expand Down Expand Up @@ -571,7 +571,7 @@ func (cs *controllerServer) CreateSnapshot(ctx context.Context, req *csi.CreateS
Snapshot: &csi.Snapshot{
SnapshotId: *snap.Id,
SizeBytes: *snap.Size * util.GIBIBYTE,
SourceVolumeId: *snap.VolumeId,
SourceVolumeId: snap.VolumeId,
CreationTime: ctime,
ReadyToUse: true,
},
Expand Down Expand Up @@ -643,7 +643,7 @@ func (cs *controllerServer) createSnapshot(ctx context.Context, cloud stackit.Ia
// Verify a snapshot with the provided name doesn't already exist for this tenant
if len(snapshots) == 1 {
snap := &snapshots[0]
if *snap.VolumeId != volumeID {
if snap.VolumeId != volumeID {
return nil, status.Error(codes.AlreadyExists, "Snapshot with given name already exists, with different source volume ID")
}

Expand Down Expand Up @@ -754,7 +754,7 @@ func (cs *controllerServer) ListSnapshots(ctx context.Context, req *csi.ListSnap
Snapshot: &csi.Snapshot{
SizeBytes: *snap.Size * util.GIBIBYTE,
SnapshotId: *snap.Id,
SourceVolumeId: *snap.VolumeId,
SourceVolumeId: snap.VolumeId,
CreationTime: ctime,
ReadyToUse: true,
},
Expand Down Expand Up @@ -798,7 +798,7 @@ func (cs *controllerServer) ListSnapshots(ctx context.Context, req *csi.ListSnap
Snapshot: &csi.Snapshot{
SizeBytes: *v.Size * util.GIBIBYTE,
SnapshotId: *v.Id,
SourceVolumeId: *v.VolumeId,
SourceVolumeId: v.VolumeId,
CreationTime: ctime,
ReadyToUse: true,
},
Expand Down Expand Up @@ -967,15 +967,15 @@ func getCreateVolumeResponse(vol *iaas.Volume) *csi.CreateVolumeResponse {
volCnx := map[string]string{}

if vol.Source != nil {
volumeSourceType = stackit.VolumeSourceTypes(*vol.Source.Type)
volumeSourceType = stackit.VolumeSourceTypes(vol.Source.Type)
switch volumeSourceType {
case stackit.VolumeSource:
volCnx[ResizeRequired] = "true"

volsrc = &csi.VolumeContentSource{
Type: &csi.VolumeContentSource_Volume{
Volume: &csi.VolumeContentSource_VolumeSource{
VolumeId: *vol.Source.Id,
VolumeId: vol.Source.Id,
},
},
}
Expand All @@ -985,7 +985,7 @@ func getCreateVolumeResponse(vol *iaas.Volume) *csi.CreateVolumeResponse {
volsrc = &csi.VolumeContentSource{
Type: &csi.VolumeContentSource_Snapshot{
Snapshot: &csi.VolumeContentSource_SnapshotSource{
SnapshotId: *vol.Source.Id,
SnapshotId: vol.Source.Id,
},
},
}
Expand All @@ -995,7 +995,7 @@ func getCreateVolumeResponse(vol *iaas.Volume) *csi.CreateVolumeResponse {
volsrc = &csi.VolumeContentSource{
Type: &csi.VolumeContentSource_Snapshot{
Snapshot: &csi.VolumeContentSource_SnapshotSource{
SnapshotId: *vol.Source.Id,
SnapshotId: vol.Source.Id,
},
},
}
Expand All @@ -1004,7 +1004,7 @@ func getCreateVolumeResponse(vol *iaas.Volume) *csi.CreateVolumeResponse {

accessibleTopology := []*csi.Topology{
{
Segments: map[string]string{topologyKey: ptr.Deref(vol.AvailabilityZone, "")},
Segments: map[string]string{topologyKey: vol.AvailabilityZone},
},
}

Expand Down
Loading