Skip to content

Commit a18c400

Browse files
committed
use iaas v2 api
Signed-off-by: Felix Breuer <f.breuer94@gmail.com>
1 parent eb02b2a commit a18c400

21 files changed

Lines changed: 1829 additions & 7955 deletions

File tree

Makefile

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ check: $(GOIMPORTS) $(GOLANGCI_LINT) $(HELM) ## Runs golangci-lint, gofmt/goimpo
110110
@bash $(GARDENER_HACK_DIR)/check-charts.sh ./charts
111111

112112
# generate mock types for the following services from the SDK (space-separated list)
113-
SDK_MOCK_SERVICES := iaas dns
113+
SDK_MOCK_SERVICES := dns
114114

115115
.PHONY: generate-mocks
116116
generate-mocks: $(MOCKGEN)
@@ -120,7 +120,13 @@ generate-mocks: $(MOCKGEN)
120120
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; \
121121
$(MOCKGEN) -destination ./pkg/stackit/client/mock/$$service/$$service.go -package $$service github.com/stackitcloud/stackit-sdk-go/services/$$service $$INTERFACES; \
122122
done
123-
@$(MOCKGEN) -destination ./pkg/stackit/client/mock/loadbalancer/loadbalancer.go -package loadbalancer github.com/stackitcloud/stackit-sdk-go/services/loadbalancer/v2api DefaultAPI
123+
124+
@$(MOCKGEN) -destination ./pkg/stackit/client/mock/loadbalancer/loadbalancer.go -package loadbalancer -imports loadbalancerv2api=github.com/stackitcloud/stackit-sdk-go/services/loadbalancer/v2api github.com/stackitcloud/stackit-sdk-go/services/loadbalancer/v2api DefaultAPI
125+
@$(MOCKGEN) -destination ./pkg/stackit/client/mock/iaas/iaas.go -package iaas -imports iaasv2api=github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api DefaultAPI
126+
127+
@$(MOCKGEN) -destination ./pkg/stackit/client/mock/mocks.go -package client github.com/stackitcloud/gardener-extension-provider-stackit/v2/pkg/stackit/client Factory,DNSClient
128+
@$(MOCKGEN) -destination ./pkg/stackit/client/mock/iaas_mock.go -package client github.com/stackitcloud/gardener-extension-provider-stackit/v2/pkg/stackit/client IaaSClient
129+
@$(MOCKGEN) -destination ./pkg/stackit/client/mock/loadbalancing_mock.go -package client github.com/stackitcloud/gardener-extension-provider-stackit/v2/pkg/stackit/client LoadBalancingClient
124130

125131
.PHONY: generate
126132
generate: $(CONTROLLER_GEN) $(GEN_CRD_API_REFERENCE_DOCS) $(HELM) $(MOCKGEN) $(YQ) $(YAML2JSON) $(GOIMPORTS) generate-mocks ## Generates the controller-registration, other code-gen, the imagename constants as well as executes go:generate directives

pkg/controller/bastion/actuator.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
extensionsv1alpha1 "github.com/gardener/gardener/pkg/apis/extensions/v1alpha1"
1111
"github.com/gardener/gardener/pkg/controllerutils/reconciler"
1212
"github.com/go-logr/logr"
13-
iaaswait "github.com/stackitcloud/stackit-sdk-go/services/iaas/wait"
13+
iaaswait "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api/wait"
1414
corev1 "k8s.io/api/core/v1"
1515
"k8s.io/apimachinery/pkg/runtime"
1616
"k8s.io/apimachinery/pkg/runtime/serializer"

pkg/controller/bastion/resources.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import (
55
"fmt"
66

77
"github.com/go-logr/logr"
8-
"github.com/stackitcloud/stackit-sdk-go/services/iaas"
8+
iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api"
99

1010
stackitclient "github.com/stackitcloud/gardener-extension-provider-stackit/v2/pkg/stackit/client"
1111
)

pkg/controller/bastion/resources_public_ip.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@ import (
55
"fmt"
66

77
"github.com/go-logr/logr"
8-
"github.com/stackitcloud/stackit-sdk-go/services/iaas"
9-
"k8s.io/utils/ptr"
8+
iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api"
109

1110
"github.com/stackitcloud/gardener-extension-provider-stackit/v2/pkg/stackit"
1211
)
@@ -15,7 +14,7 @@ func (r *Resources) reconcilePublicIP(ctx context.Context, log logr.Logger) erro
1514
if r.PublicIP == nil {
1615
var err error
1716
r.PublicIP, err = r.IaaS.CreatePublicIp(ctx, iaas.CreatePublicIPPayload{
18-
Labels: new(stackit.ToLabels(r.Labels)),
17+
Labels: stackit.ToLabels(r.Labels),
1918
})
2019
if err != nil {
2120
return fmt.Errorf("error creating public IP: %w", err)
@@ -24,7 +23,7 @@ func (r *Resources) reconcilePublicIP(ctx context.Context, log logr.Logger) erro
2423
log.Info("Created public IP", "publicIP", r.PublicIP.GetId())
2524
}
2625

27-
if networkInterface := ptr.Deref(r.PublicIP.GetNetworkInterface(), ""); networkInterface != "" {
26+
if networkInterface := r.PublicIP.GetNetworkInterface(); networkInterface != "" {
2827
log.V(1).Info("Public IP is already associated with network interface", "publicIP", r.PublicIP.GetId(), "networkInterface", networkInterface)
2928
return nil
3029
}

pkg/controller/bastion/resources_security_group.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66
"net/netip"
77

88
"github.com/go-logr/logr"
9-
"github.com/stackitcloud/stackit-sdk-go/services/iaas"
9+
iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api"
1010

1111
"github.com/stackitcloud/gardener-extension-provider-stackit/v2/pkg/stackit"
1212
stackitclient "github.com/stackitcloud/gardener-extension-provider-stackit/v2/pkg/stackit/client"
@@ -20,8 +20,8 @@ func (r *Resources) reconcileSecurityGroup(ctx context.Context, log logr.Logger)
2020
if r.SecurityGroup == nil {
2121
var err error
2222
r.SecurityGroup, err = r.IaaS.CreateSecurityGroup(ctx, iaas.CreateSecurityGroupPayload{
23-
Name: new(r.ResourceName),
24-
Labels: new(stackit.ToLabels(r.Labels)),
23+
Name: r.ResourceName,
24+
Labels: stackit.ToLabels(r.Labels),
2525

2626
Description: new("Security group for Bastion " + r.Bastion.Name),
2727
})
@@ -61,7 +61,7 @@ func (o *Options) determineWantedSecurityGroupRules() ([]iaas.SecurityGroupRule,
6161
// DHCP tells us our IP and the route to the metadata server
6262
Description: new("Allow DHCP requests"),
6363

64-
Direction: new(stackit.DirectionEgress),
64+
Direction: stackit.DirectionEgress,
6565
Ethertype: new(stackit.EtherTypeIPv4),
6666
Protocol: new(stackit.ProtocolUDP),
6767
PortRange: iaas.NewPortRange(68, 67),
@@ -71,7 +71,7 @@ func (o *Options) determineWantedSecurityGroupRules() ([]iaas.SecurityGroupRule,
7171
{
7272
Description: new("Allow egress to metadata server"),
7373

74-
Direction: new(stackit.DirectionEgress),
74+
Direction: stackit.DirectionEgress,
7575
Ethertype: new(stackit.EtherTypeIPv4),
7676
Protocol: new(stackit.ProtocolTCP),
7777
PortRange: iaas.NewPortRange(80, 80),
@@ -81,7 +81,7 @@ func (o *Options) determineWantedSecurityGroupRules() ([]iaas.SecurityGroupRule,
8181
{
8282
Description: new(fmt.Sprintf("Allow egress from Bastion %s to %s worker nodes", o.Bastion.Name, o.TechnicalID)),
8383

84-
Direction: new(stackit.DirectionEgress),
84+
Direction: stackit.DirectionEgress,
8585
Ethertype: new(stackit.EtherTypeIPv4),
8686
Protocol: new(stackit.ProtocolTCP),
8787
PortRange: portRangeSSH,
@@ -95,7 +95,7 @@ func (o *Options) determineWantedSecurityGroupRules() ([]iaas.SecurityGroupRule,
9595
rules = append(rules, iaas.SecurityGroupRule{
9696
Description: new(fmt.Sprintf("Allow ingress to Bastion %s from world", o.Bastion.Name)),
9797

98-
Direction: new(stackit.DirectionIngress),
98+
Direction: stackit.DirectionIngress,
9999
Ethertype: new(stackit.EtherTypeIPv4),
100100
Protocol: new(stackit.ProtocolTCP),
101101
PortRange: portRangeSSH,
@@ -120,7 +120,7 @@ func (o *Options) determineWantedSecurityGroupRules() ([]iaas.SecurityGroupRule,
120120
rules = append(rules, iaas.SecurityGroupRule{
121121
Description: new(fmt.Sprintf("Allow ingress to Bastion %s from %s", o.Bastion.Name, normalizedCIDR)),
122122

123-
Direction: new(stackit.DirectionIngress),
123+
Direction: stackit.DirectionIngress,
124124
Ethertype: new(etherType),
125125
Protocol: new(stackit.ProtocolTCP),
126126
PortRange: portRangeSSH,
@@ -137,7 +137,7 @@ func (r *Resources) reconcileWorkerSecurityGroupRule(ctx context.Context, log lo
137137
wantedRule := iaas.SecurityGroupRule{
138138
Description: new(fmt.Sprintf("Allow ingress to shoot worker nodes from Bastion %s", r.Bastion.Name)),
139139

140-
Direction: new(stackit.DirectionIngress),
140+
Direction: stackit.DirectionIngress,
141141
Ethertype: new(stackit.EtherTypeIPv4),
142142
Protocol: new(stackit.ProtocolTCP),
143143
PortRange: portRangeSSH,

pkg/controller/bastion/resources_security_group_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66
extensionsv1alpha1 "github.com/gardener/gardener/pkg/apis/extensions/v1alpha1"
77
. "github.com/onsi/ginkgo/v2"
88
. "github.com/onsi/gomega"
9-
"github.com/stackitcloud/stackit-sdk-go/services/iaas"
9+
iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api"
1010
networkingv1 "k8s.io/api/networking/v1"
1111
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1212

@@ -47,7 +47,7 @@ var _ = Describe("Security Group", func() {
4747
iaas.SecurityGroupRule{
4848
Description: new(fmt.Sprintf("Allow ingress to Bastion %s from %s", o.Bastion.Name, "1.2.3.4/32")),
4949

50-
Direction: new(stackit.DirectionIngress),
50+
Direction: stackit.DirectionIngress,
5151
Ethertype: new(stackit.EtherTypeIPv4),
5252
Protocol: new(stackit.ProtocolTCP),
5353
PortRange: iaas.NewPortRange(22, 22),
@@ -57,7 +57,7 @@ var _ = Describe("Security Group", func() {
5757
iaas.SecurityGroupRule{
5858
Description: new(fmt.Sprintf("Allow ingress to Bastion %s from %s", o.Bastion.Name, "2001:db8:1::/48")),
5959

60-
Direction: new(stackit.DirectionIngress),
60+
Direction: stackit.DirectionIngress,
6161
Ethertype: new(stackit.EtherTypeIPv6),
6262
Protocol: new(stackit.ProtocolTCP),
6363
PortRange: iaas.NewPortRange(22, 22),
@@ -74,7 +74,7 @@ var _ = Describe("Security Group", func() {
7474
iaas.SecurityGroupRule{
7575
Description: new(fmt.Sprintf("Allow ingress to Bastion %s from world", o.Bastion.Name)),
7676

77-
Direction: new(stackit.DirectionIngress),
77+
Direction: stackit.DirectionIngress,
7878
Ethertype: new(stackit.EtherTypeIPv4),
7979
Protocol: new(stackit.ProtocolTCP),
8080
PortRange: iaas.NewPortRange(22, 22),

pkg/controller/bastion/resources_server.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import (
55
"fmt"
66

77
"github.com/go-logr/logr"
8-
"github.com/stackitcloud/stackit-sdk-go/services/iaas"
8+
iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api"
99

1010
"github.com/stackitcloud/gardener-extension-provider-stackit/v2/pkg/stackit"
1111
)
@@ -18,24 +18,24 @@ func (r *Resources) reconcileServer(ctx context.Context, log logr.Logger) error
1818

1919
var err error
2020
r.Server, err = r.IaaS.CreateServer(ctx, iaas.CreateServerPayload{
21-
Name: new(r.ResourceName),
22-
Labels: new(stackit.ToLabels(r.Labels)),
21+
Name: r.ResourceName,
22+
Labels: stackit.ToLabels(r.Labels),
2323

2424
AvailabilityZone: new(r.AvailabilityZone),
25-
MachineType: new(r.MachineType),
26-
BootVolume: &iaas.ServerBootVolume{
25+
MachineType: r.MachineType,
26+
BootVolume: &iaas.BootVolume{
2727
DeleteOnTermination: new(true),
2828
Source: iaas.NewBootVolumeSource(r.ImageID, "image"),
2929
// TODO: make size and performance class configurable
3030
Size: new(int64(10)),
3131
},
3232

33-
SecurityGroups: new([]string{r.SecurityGroup.GetId()}),
34-
Networking: new(iaas.CreateServerNetworkingAsCreateServerPayloadAllOfNetworking(&iaas.CreateServerNetworking{
33+
SecurityGroups: []string{r.SecurityGroup.GetId()},
34+
Networking: iaas.CreateServerNetworkingAsCreateServerPayloadAllOfNetworking(&iaas.CreateServerNetworking{
3535
NetworkId: new(r.NetworkID),
36-
})),
36+
}),
3737

38-
UserData: new(r.Bastion.Spec.UserData),
38+
UserData: new(string(r.Bastion.Spec.UserData)),
3939
})
4040
if err != nil {
4141
return fmt.Errorf("error creating server: %w", err)

pkg/controller/bastion/resources_test.go

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
"github.com/go-logr/logr"
99
. "github.com/onsi/ginkgo/v2"
1010
. "github.com/onsi/gomega"
11-
"github.com/stackitcloud/stackit-sdk-go/services/iaas"
11+
iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api"
1212
"go.uber.org/mock/gomock"
1313
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1414

@@ -47,10 +47,10 @@ var _ = Describe("Bastion Resources", func() {
4747
resources.ResourceName = "test-resource"
4848
resources.Labels = map[string]string{"test-labels-key": "test-labels-value"}
4949

50-
expectedSecurityGroup := []iaas.SecurityGroup{{Name: new("test-security-group")}}
50+
expectedSecurityGroup := []iaas.SecurityGroup{{Name: "test-security-group"}}
5151
mockIaaS.EXPECT().GetSecurityGroupByName(ctx, resources.ResourceName).Return(expectedSecurityGroup, nil)
5252

53-
expectedServer := []iaas.Server{{Name: new("test-server")}}
53+
expectedServer := []iaas.Server{{Name: "test-server"}}
5454
mockIaaS.EXPECT().GetServerByName(ctx, resources.ResourceName).Return(expectedServer, nil)
5555

5656
expectedPublicIP := []iaas.PublicIp{{Id: new("test-ip")}}
@@ -157,7 +157,7 @@ var _ = Describe("Bastion Resources", func() {
157157
}
158158
resources.PublicIP = &iaas.PublicIp{
159159
Id: new("test-public-ip"),
160-
NetworkInterface: iaas.NewNullableString(new("test-interface")),
160+
NetworkInterface: *iaas.NewNullableString(new("test-interface")),
161161
}
162162

163163
err := resources.reconcilePublicIP(ctx, logger)
@@ -222,23 +222,23 @@ var _ = Describe("Bastion Resources", func() {
222222
resources.SecurityGroup = &iaas.SecurityGroup{Id: new("test-security-group")}
223223

224224
expectedPayload := iaas.CreateServerPayload{
225-
Name: new("test-resource"),
226-
Labels: new(stackit.ToLabels(map[string]string{
225+
Name: "test-resource",
226+
Labels: stackit.ToLabels(map[string]string{
227227
"test-label-key": "test-label-value",
228-
})),
228+
}),
229229
AvailabilityZone: new("test-az"),
230-
MachineType: new("test-machine"),
231-
BootVolume: &iaas.ServerBootVolume{
230+
MachineType: "test-machine",
231+
BootVolume: &iaas.BootVolume{
232232
DeleteOnTermination: new(true),
233233
Source: iaas.NewBootVolumeSource("test-image", "image"),
234234
Size: new(int64(10)),
235235
},
236-
SecurityGroups: new([]string{"test-security-group"}),
237-
Networking: new(iaas.CreateServerNetworkingAsCreateServerPayloadAllOfNetworking(&iaas.CreateServerNetworking{
236+
SecurityGroups: []string{"test-security-group"},
237+
Networking: iaas.CreateServerNetworkingAsCreateServerPayloadAllOfNetworking(&iaas.CreateServerNetworking{
238238
NetworkId: new("test-network"),
239-
})),
239+
}),
240240

241-
UserData: new([]byte{1, 2, 3, 4}),
241+
UserData: new(string([]byte{1, 2, 3, 4})),
242242
}
243243
expectedServer := &iaas.Server{
244244
Id: new("test-server"),
@@ -292,8 +292,8 @@ var _ = Describe("Bastion Resources", func() {
292292
}
293293

294294
expectedPayload := iaas.CreateSecurityGroupPayload{
295-
Name: new("test-resource"),
296-
Labels: new(stackit.ToLabels(map[string]string{"test-labels-key": "test-labels-value"})),
295+
Name: "test-resource",
296+
Labels: stackit.ToLabels(map[string]string{"test-labels-key": "test-labels-value"}),
297297
Description: new("Security group for Bastion test-bastion"),
298298
}
299299
expectedSecurityGroup := &iaas.SecurityGroup{

pkg/controller/infrastructure/openstack/infraflow/reconcile.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -523,7 +523,7 @@ func (fctx *FlowContext) ensureStackitSSHKeyPair(ctx context.Context) error {
523523
return err
524524
}
525525
if keyPair != nil {
526-
publicKey := ptr.Deref(keyPair.PublicKey, "")
526+
publicKey := keyPair.PublicKey
527527
// if the public keys are matching then return early. In all other cases we should be creating (or replacing) the keypair with a new one.
528528
if publicKey != "" && publicKey == string(fctx.infra.Spec.SSHPublicKey) {
529529
fctx.state.Set(NameKeyPair, *keyPair.Name)

0 commit comments

Comments
 (0)