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
10 changes: 8 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ check: $(GOIMPORTS) $(GOLANGCI_LINT) $(HELM) ## Runs golangci-lint, gofmt/goimpo
@bash $(GARDENER_HACK_DIR)/check-charts.sh ./charts

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

.PHONY: generate-mocks
generate-mocks: $(MOCKGEN)
Expand All @@ -120,7 +120,13 @@ generate-mocks: $(MOCKGEN)
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/stackit/client/mock/$$service/$$service.go -package $$service github.com/stackitcloud/stackit-sdk-go/services/$$service $$INTERFACES; \
done
@$(MOCKGEN) -destination ./pkg/stackit/client/mock/loadbalancer/loadbalancer.go -package loadbalancer github.com/stackitcloud/stackit-sdk-go/services/loadbalancer/v2api DefaultAPI

@$(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
@$(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

@$(MOCKGEN) -destination ./pkg/stackit/client/mock/mocks.go -package client github.com/stackitcloud/gardener-extension-provider-stackit/v2/pkg/stackit/client Factory,DNSClient
@$(MOCKGEN) -destination ./pkg/stackit/client/mock/iaas_mock.go -package client github.com/stackitcloud/gardener-extension-provider-stackit/v2/pkg/stackit/client IaaSClient
@$(MOCKGEN) -destination ./pkg/stackit/client/mock/loadbalancing_mock.go -package client github.com/stackitcloud/gardener-extension-provider-stackit/v2/pkg/stackit/client LoadBalancingClient

.PHONY: generate
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
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ require (
github.com/stackitcloud/stackit-sdk-go/core v0.23.0
github.com/stackitcloud/stackit-sdk-go/services/authorization v0.14.1
github.com/stackitcloud/stackit-sdk-go/services/dns v0.17.6
github.com/stackitcloud/stackit-sdk-go/services/iaas v1.3.5
github.com/stackitcloud/stackit-sdk-go/services/iaas v1.7.0
github.com/stackitcloud/stackit-sdk-go/services/loadbalancer v1.11.0
github.com/stackitcloud/stackit-sdk-go/services/resourcemanager v0.20.1
github.com/stackitcloud/stackit-sdk-go/services/serviceaccount v0.15.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -471,8 +471,8 @@ github.com/stackitcloud/stackit-sdk-go/services/authorization v0.14.1 h1:9qIh4vs
github.com/stackitcloud/stackit-sdk-go/services/authorization v0.14.1/go.mod h1:hZc0FvlEhN8zmlORsKLBjBep6iYAY/QLnoV1rDnY69A=
github.com/stackitcloud/stackit-sdk-go/services/dns v0.17.6 h1:GBRb49x5Nax/oQQaaf2F3kKwv8DQQOL0TQOC0C/v/Ew=
github.com/stackitcloud/stackit-sdk-go/services/dns v0.17.6/go.mod h1:IX9iL3MigDZUmzwswTJMfYvyi118KAHrFMfjJUy5NYk=
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/services/iaas v1.7.0 h1:WyOC7tEazOPF9PwlExsycYvhm2l9OcjGQfZHDAckVIc=
github.com/stackitcloud/stackit-sdk-go/services/iaas v1.7.0/go.mod h1:78hDXs5sEokK2sAaBSn79kodytszmDYEAuMS56kPHIw=
github.com/stackitcloud/stackit-sdk-go/services/loadbalancer v1.11.0 h1:81q4OIt54bw4Of5UP/sqXTgT8LkzeY+uHIgSvzQQl3w=
github.com/stackitcloud/stackit-sdk-go/services/loadbalancer v1.11.0/go.mod h1:hjXxEkJ247sa9IxoACRK8oUvly7Hux2qnIw7rj4c6xs=
github.com/stackitcloud/stackit-sdk-go/services/resourcemanager v0.20.1 h1:IvZqEXjRjXrkjY0aSZFZ5zccOr2ZB+fj+N8AG46ajC4=
Expand Down
2 changes: 1 addition & 1 deletion pkg/controller/bastion/actuator.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
extensionsv1alpha1 "github.com/gardener/gardener/pkg/apis/extensions/v1alpha1"
"github.com/gardener/gardener/pkg/controllerutils/reconciler"
"github.com/go-logr/logr"
iaaswait "github.com/stackitcloud/stackit-sdk-go/services/iaas/wait"
iaaswait "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api/wait"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/serializer"
Expand Down
2 changes: 1 addition & 1 deletion pkg/controller/bastion/resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"fmt"

"github.com/go-logr/logr"
"github.com/stackitcloud/stackit-sdk-go/services/iaas"
iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api"

stackitclient "github.com/stackitcloud/gardener-extension-provider-stackit/v2/pkg/stackit/client"
)
Expand Down
7 changes: 3 additions & 4 deletions pkg/controller/bastion/resources_public_ip.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ import (
"fmt"

"github.com/go-logr/logr"
"github.com/stackitcloud/stackit-sdk-go/services/iaas"
"k8s.io/utils/ptr"
iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api"

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

if networkInterface := ptr.Deref(r.PublicIP.GetNetworkInterface(), ""); networkInterface != "" {
if networkInterface := r.PublicIP.GetNetworkInterface(); networkInterface != "" {
log.V(1).Info("Public IP is already associated with network interface", "publicIP", r.PublicIP.GetId(), "networkInterface", networkInterface)
return nil
}
Expand Down
18 changes: 9 additions & 9 deletions pkg/controller/bastion/resources_security_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"net/netip"

"github.com/go-logr/logr"
"github.com/stackitcloud/stackit-sdk-go/services/iaas"
iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api"

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

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

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

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

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

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

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

Direction: new(stackit.DirectionIngress),
Direction: stackit.DirectionIngress,
Ethertype: new(stackit.EtherTypeIPv4),
Protocol: new(stackit.ProtocolTCP),
PortRange: portRangeSSH,
Expand Down
8 changes: 4 additions & 4 deletions pkg/controller/bastion/resources_security_group_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
extensionsv1alpha1 "github.com/gardener/gardener/pkg/apis/extensions/v1alpha1"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"github.com/stackitcloud/stackit-sdk-go/services/iaas"
iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api"
networkingv1 "k8s.io/api/networking/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

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

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

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

Direction: new(stackit.DirectionIngress),
Direction: stackit.DirectionIngress,
Ethertype: new(stackit.EtherTypeIPv4),
Protocol: new(stackit.ProtocolTCP),
PortRange: iaas.NewPortRange(22, 22),
Expand Down
18 changes: 9 additions & 9 deletions pkg/controller/bastion/resources_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"fmt"

"github.com/go-logr/logr"
"github.com/stackitcloud/stackit-sdk-go/services/iaas"
iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api"

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

var err error
r.Server, err = r.IaaS.CreateServer(ctx, iaas.CreateServerPayload{
Name: new(r.ResourceName),
Labels: new(stackit.ToLabels(r.Labels)),
Name: r.ResourceName,
Labels: stackit.ToLabels(r.Labels),

AvailabilityZone: new(r.AvailabilityZone),
MachineType: new(r.MachineType),
BootVolume: &iaas.ServerBootVolume{
MachineType: r.MachineType,
BootVolume: &iaas.BootVolume{
DeleteOnTermination: new(true),
Source: iaas.NewBootVolumeSource(r.ImageID, "image"),
// TODO: make size and performance class configurable
Size: new(int64(10)),
},

SecurityGroups: new([]string{r.SecurityGroup.GetId()}),
Networking: new(iaas.CreateServerNetworkingAsCreateServerPayloadAllOfNetworking(&iaas.CreateServerNetworking{
SecurityGroups: []string{r.SecurityGroup.GetId()},
Networking: iaas.CreateServerNetworkingAsCreateServerPayloadAllOfNetworking(&iaas.CreateServerNetworking{
NetworkId: new(r.NetworkID),
})),
}),

UserData: new(r.Bastion.Spec.UserData),
UserData: new(string(r.Bastion.Spec.UserData)),
})
if err != nil {
return fmt.Errorf("error creating server: %w", err)
Expand Down
30 changes: 15 additions & 15 deletions pkg/controller/bastion/resources_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/go-logr/logr"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"github.com/stackitcloud/stackit-sdk-go/services/iaas"
iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api"
"go.uber.org/mock/gomock"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

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

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

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

expectedPublicIP := []iaas.PublicIp{{Id: new("test-ip")}}
Expand Down Expand Up @@ -157,7 +157,7 @@ var _ = Describe("Bastion Resources", func() {
}
resources.PublicIP = &iaas.PublicIp{
Id: new("test-public-ip"),
NetworkInterface: iaas.NewNullableString(new("test-interface")),
NetworkInterface: *iaas.NewNullableString(new("test-interface")),
}

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

expectedPayload := iaas.CreateServerPayload{
Name: new("test-resource"),
Labels: new(stackit.ToLabels(map[string]string{
Name: "test-resource",
Labels: stackit.ToLabels(map[string]string{
"test-label-key": "test-label-value",
})),
}),
AvailabilityZone: new("test-az"),
MachineType: new("test-machine"),
BootVolume: &iaas.ServerBootVolume{
MachineType: "test-machine",
BootVolume: &iaas.BootVolume{
DeleteOnTermination: new(true),
Source: iaas.NewBootVolumeSource("test-image", "image"),
Size: new(int64(10)),
},
SecurityGroups: new([]string{"test-security-group"}),
Networking: new(iaas.CreateServerNetworkingAsCreateServerPayloadAllOfNetworking(&iaas.CreateServerNetworking{
SecurityGroups: []string{"test-security-group"},
Networking: iaas.CreateServerNetworkingAsCreateServerPayloadAllOfNetworking(&iaas.CreateServerNetworking{
NetworkId: new("test-network"),
})),
}),

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

expectedPayload := iaas.CreateSecurityGroupPayload{
Name: new("test-resource"),
Labels: new(stackit.ToLabels(map[string]string{"test-labels-key": "test-labels-value"})),
Name: "test-resource",
Labels: stackit.ToLabels(map[string]string{"test-labels-key": "test-labels-value"}),
Description: new("Security group for Bastion test-bastion"),
}
expectedSecurityGroup := &iaas.SecurityGroup{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,7 @@ func (fctx *FlowContext) ensureStackitSSHKeyPair(ctx context.Context) error {
return err
}
if keyPair != nil {
publicKey := ptr.Deref(keyPair.PublicKey, "")
publicKey := keyPair.PublicKey
// 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.
if publicKey != "" && publicKey == string(fctx.infra.Spec.SSHPublicKey) {
fctx.state.Set(NameKeyPair, *keyPair.Name)
Expand Down
Loading