Skip to content

Commit 43b4efe

Browse files
committed
♻️ refacto: switch to SDKv3
1 parent 14b0d1b commit 43b4efe

File tree

22 files changed

+509
-530
lines changed

22 files changed

+509
-530
lines changed

cloud-controller-manager/osc/cloud/loadbalancer.go

Lines changed: 120 additions & 111 deletions
Large diffs are not rendered by default.

cloud-controller-manager/osc/cloud/tags.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package cloud
33
import (
44
"strings"
55

6-
"github.com/outscale/osc-sdk-go/v2"
6+
"github.com/outscale/osc-sdk-go/v3/pkg/osc"
77
)
88

99
const (
@@ -43,17 +43,17 @@ const (
4343

4444
func getLBUClusterID(tags []osc.ResourceTag) string {
4545
for _, t := range tags {
46-
if strings.HasPrefix(t.GetKey(), ClusterIDTagKeyPrefix) {
47-
return strings.TrimPrefix(t.GetKey(), ClusterIDTagKeyPrefix)
46+
if strings.HasPrefix(t.Key, ClusterIDTagKeyPrefix) {
47+
return strings.TrimPrefix(t.Key, ClusterIDTagKeyPrefix)
4848
}
4949
}
5050
return ""
5151
}
5252

5353
func getLBUServiceName(tags []osc.ResourceTag) string {
5454
for _, t := range tags {
55-
if t.GetKey() == ServiceNameTagKey {
56-
return t.GetValue()
55+
if t.Key == ServiceNameTagKey {
56+
return t.Value
5757
}
5858
}
5959
return ""

cloud-controller-manager/osc/cloud/utils.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import (
44
"slices"
55
"strings"
66

7-
"github.com/outscale/osc-sdk-go/v2"
7+
"github.com/outscale/osc-sdk-go/v3/pkg/osc"
88
)
99

1010
func hasTag(tags []osc.ResourceTag, k string, v ...string) bool {

cloud-controller-manager/osc/cloud/vm.go

Lines changed: 32 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@ import (
66
"net/url"
77
"strings"
88

9-
"github.com/aws/aws-sdk-go/aws"
10-
"github.com/outscale/osc-sdk-go/v2"
9+
"github.com/outscale/osc-sdk-go/v3/pkg/osc"
1110
v1 "k8s.io/api/core/v1"
1211
"k8s.io/apimachinery/pkg/types"
1312
cloudprovider "k8s.io/cloud-provider"
@@ -22,8 +21,7 @@ type VM struct {
2221
NodeName types.NodeName
2322
AvailabilityZone string
2423
Region string
25-
NetID string
26-
SubnetID string
24+
SubnetID *string
2725
VmType string
2826

2927
cloudVm *osc.Vm
@@ -32,18 +30,14 @@ type VM struct {
3230
// FromOscVm creates a new awsInstance object
3331
func FromOscVm(vm *osc.Vm) *VM {
3432
v := &VM{
35-
ID: vm.GetVmId(),
36-
NodeName: mapInstanceToNodeName(vm),
37-
VmType: vm.GetVmType(),
38-
NetID: vm.GetNetId(),
39-
SubnetID: vm.GetSubnetId(),
40-
41-
cloudVm: vm,
42-
}
43-
if vm.Placement != nil {
44-
v.AvailabilityZone = vm.Placement.GetSubregionName()
45-
v.Region = v.AvailabilityZone[:len(v.AvailabilityZone)-1]
46-
}
33+
ID: vm.VmId,
34+
NodeName: mapInstanceToNodeName(vm),
35+
VmType: vm.VmType,
36+
SubnetID: vm.SubnetId,
37+
AvailabilityZone: vm.Placement.SubregionName,
38+
cloudVm: vm,
39+
}
40+
v.Region = v.AvailabilityZone[:len(v.AvailabilityZone)-1]
4741
return v
4842
}
4943

@@ -56,57 +50,52 @@ func (vm *VM) NodeAddresses() []v1.NodeAddress {
5650
addresses := []v1.NodeAddress{}
5751

5852
// handle internal network interfaces
59-
if len(vm.cloudVm.GetNics()) > 0 {
60-
for _, networkInterface := range vm.cloudVm.GetNics() {
53+
if len(vm.cloudVm.Nics) > 0 {
54+
for _, networkInterface := range vm.cloudVm.Nics {
6155
// skip network interfaces that are not currently in use
62-
if *networkInterface.State != "in-use" {
56+
if networkInterface.State != "in-use" {
6357
continue
6458
}
6559

66-
for _, internalIP := range networkInterface.GetPrivateIps() {
67-
if ipAddress := internalIP.GetPrivateIp(); ipAddress != "" {
68-
addresses = append(addresses, v1.NodeAddress{Type: v1.NodeInternalIP, Address: ipAddress})
69-
}
60+
for _, internalIP := range networkInterface.PrivateIps {
61+
addresses = append(addresses, v1.NodeAddress{Type: v1.NodeInternalIP, Address: internalIP.PrivateIp})
7062
}
7163
}
7264
} else {
73-
ipAddress := vm.cloudVm.GetPrivateIp()
74-
if ipAddress != "" {
75-
addresses = append(addresses, v1.NodeAddress{Type: v1.NodeInternalIP, Address: ipAddress})
76-
}
65+
addresses = append(addresses, v1.NodeAddress{Type: v1.NodeInternalIP, Address: vm.cloudVm.PrivateIp})
7766
}
78-
publicIPAddress := vm.cloudVm.GetPublicIp()
79-
if publicIPAddress != "" {
80-
addresses = append(addresses, v1.NodeAddress{Type: v1.NodeExternalIP, Address: publicIPAddress})
67+
publicIPAddress := vm.cloudVm.PublicIp
68+
if publicIPAddress != nil {
69+
addresses = append(addresses, v1.NodeAddress{Type: v1.NodeExternalIP, Address: *publicIPAddress})
8170
}
82-
privateDNSName := aws.StringValue(vm.cloudVm.PrivateDnsName)
83-
if privateDNSName != "" {
84-
addresses = append(addresses, v1.NodeAddress{Type: v1.NodeInternalDNS, Address: privateDNSName})
85-
addresses = append(addresses, v1.NodeAddress{Type: v1.NodeHostName, Address: privateDNSName})
71+
privateDNSName := vm.cloudVm.PrivateDnsName
72+
if privateDNSName != nil {
73+
addresses = append(addresses, v1.NodeAddress{Type: v1.NodeInternalDNS, Address: *privateDNSName})
74+
addresses = append(addresses, v1.NodeAddress{Type: v1.NodeHostName, Address: *privateDNSName})
8675
}
87-
publicDNSName := aws.StringValue(vm.cloudVm.PublicDnsName)
88-
if publicDNSName != "" {
89-
addresses = append(addresses, v1.NodeAddress{Type: v1.NodeExternalDNS, Address: publicDNSName})
76+
publicDNSName := vm.cloudVm.PublicDnsName
77+
if publicDNSName != nil {
78+
addresses = append(addresses, v1.NodeAddress{Type: v1.NodeExternalDNS, Address: *publicDNSName})
9079
}
9180

9281
return addresses
9382
}
9483

9584
func (vm *VM) IsStopped() bool {
96-
return vm.cloudVm.GetState() == "stopped"
85+
return vm.cloudVm.State == "stopped"
9786
}
9887

9988
func (vm *VM) IsTerminated() bool {
100-
return vm.cloudVm.GetState() == "terminated"
89+
return vm.cloudVm.State == "terminated"
10190
}
10291

10392
// InstanceID returns the instance ID
10493
func (vm *VM) InstanceID() string {
105-
return "/" + vm.cloudVm.Placement.GetSubregionName() + "/" + vm.cloudVm.GetVmId()
94+
return "/" + vm.cloudVm.Placement.SubregionName + "/" + vm.cloudVm.VmId
10695
}
10796

10897
func (vm *VM) ClusterID() string {
109-
for _, t := range vm.cloudVm.GetTags() {
98+
for _, t := range vm.cloudVm.Tags {
11099
if strings.HasPrefix(t.Key, ClusterIDTagKeyPrefix) {
111100
return strings.TrimPrefix(t.Key, ClusterIDTagKeyPrefix)
112101
}
@@ -158,7 +147,7 @@ func (c *Cloud) GetVMsByNodeName(ctx context.Context, nodeNames ...string) ([]VM
158147
vms := make([]VM, 0, len(nodeNames))
159148
for _, nodeName := range nodeNames {
160149
for _, sdkVM := range sdkVMs {
161-
if hasTag(sdkVM.GetTags(), TagVmNodeName, nodeName) ||
150+
if hasTag(sdkVM.Tags, TagVmNodeName, nodeName) ||
162151
mapInstanceToNodeName(&sdkVM) == types.NodeName(nodeName) {
163152
vms = append(vms, *FromOscVm(&sdkVM))
164153
}
@@ -225,7 +214,7 @@ func (c *Cloud) GetVMsByID(ctx context.Context, vmIDs ...string) ([]VM, error) {
225214

226215
// mapInstanceToNodeName maps an OSC instance to a k8s NodeName, by extracting the PrivateDNSName
227216
func mapInstanceToNodeName(i *osc.Vm) types.NodeName {
228-
return types.NodeName(aws.StringValue(i.PrivateDnsName))
217+
return types.NodeName(*i.PrivateDnsName)
229218
}
230219

231220
func ParseProviderID(providerID string) (subregion, vmID string, err error) {

0 commit comments

Comments
 (0)