Skip to content

Commit ed9940d

Browse files
committed
♻️ refacto: switch to SDKv3
1 parent 4dd4253 commit ed9940d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+1272
-1367
lines changed

Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ BUILD_ENV := "buildenv/cloud-provider-osc:0.0"
2121
BUILD_ENV_RUN := "build-cloud-provider-osc"
2222
DEPLOY_NAME := "k8s-osc-ccm"
2323

24-
SOURCES := $(shell find ./cloud-controller-manager -name '*.go')
24+
SOURCES := $(shell find ./ccm -name '*.go')
2525
GOOS ?= $(shell go env GOOS)
2626
VERSION ?= $(shell git describe --tags --always --dirty)
2727
LDFLAGS := "-w -s -X 'github.com/outscale/cloud-provider-osc/cloud-controller-manager/utils.version=$(VERSION)'"
@@ -63,7 +63,7 @@ build: $(SOURCES)
6363
CGO_ENABLED=0 GOOS=$(GOOS) go build $(GO_ADD_OPTIONS) \
6464
-ldflags $(LDFLAGS) \
6565
-o osc-cloud-controller-manager \
66-
cloud-controller-manager/cmd/osc-cloud-controller-manager/main.go
66+
ccm/cmd/osc-cloud-controller-manager/main.go
6767

6868
.PHONY: verify
6969
verify: verify-fmt vet
@@ -82,7 +82,7 @@ mock-generate:
8282

8383
.PHONY: test
8484
test:
85-
CGO_ENABLED=0 OSC_ACCESS_KEY=test OSC_SECRET_KEY=test go test -count=1 -v ./cloud-controller-manager/... ./deploy/...
85+
CGO_ENABLED=0 OSC_ACCESS_KEY=test OSC_SECRET_KEY=test go test -count=1 -v ./ccm/... ./deploy/...
8686

8787

8888
.PHONY: build-image

REUSE.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
version = 1
66

77
[[annotations]]
8-
path = ["*", "cloud-controller-manager/**", "tests/**", ".github/**", "deploy/**"]
8+
path = ["*", "ccm/**", "tests/**", ".github/**", "deploy/**"]
99
SPDX-FileCopyrightText = "2025 Outscale SAS <[email protected]>"
1010
SPDX-License-Identifier = "BSD-3-Clause"
1111

cloud-controller-manager/osc/cloud/annotations.go renamed to ccm/cloud/annotations.go

File renamed without changes.

cloud-controller-manager/osc/cloud/cloud.go renamed to ccm/cloud/cloud.go

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,10 @@ import (
1010
"fmt"
1111
"slices"
1212

13-
"github.com/outscale/cloud-provider-osc/cloud-controller-manager/osc/oapi"
14-
"github.com/outscale/cloud-provider-osc/cloud-controller-manager/utils"
15-
"github.com/outscale/osc-sdk-go/v2"
13+
"github.com/outscale/cloud-provider-osc/ccm/oapi"
14+
"github.com/outscale/goutils/k8s/tags"
15+
"github.com/outscale/osc-sdk-go/v3/pkg/osc"
16+
"github.com/samber/lo"
1617
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1718
clientset "k8s.io/client-go/kubernetes"
1819
"k8s.io/klog/v2"
@@ -51,16 +52,16 @@ func New(ctx context.Context, clusterID string) (*Cloud, error) {
5152
} else {
5253
// primary cluster ID (CAPOSC v1)
5354
c.clusterID = []string{self.ClusterID()}
54-
if self.SubnetID != "" {
55+
if self.SubnetID != nil {
5556
// alternate cluster ID (CAPOSC v0)
5657
subs, err := api.OAPI().ReadSubnets(ctx, osc.ReadSubnetsRequest{
57-
Filters: &osc.FiltersSubnet{SubnetIds: &[]string{self.SubnetID}},
58+
Filters: &osc.FiltersSubnet{SubnetIds: &[]string{*self.SubnetID}},
5859
})
5960
if err != nil {
6061
return nil, fmt.Errorf("error finding self subnets: %w", err)
6162
}
6263
if len(subs) == 1 {
63-
clusterID := getClusterIDFromTags(subs[0].GetTags())
64+
clusterID := tags.GetClusterID(subs[0].Tags)
6465
if clusterID != "" && !slices.Contains(c.clusterID, clusterID) {
6566
c.clusterID = append(c.clusterID, clusterID)
6667
}
@@ -101,8 +102,8 @@ func (c *Cloud) Initialize(ctx context.Context, kube clientset.Interface) {
101102
logger.V(3).Info("Inferred cluster ID: " + string(ns.UID))
102103
}
103104

104-
func (c *Cloud) sameCluster(tags []osc.ResourceTag) bool {
105-
return slices.Contains(c.clusterID, getClusterIDFromTags(tags))
105+
func (c *Cloud) sameCluster(t []osc.ResourceTag) bool {
106+
return slices.Contains(c.clusterID, tags.GetClusterID(t))
106107
}
107108

108109
func (c *Cloud) mainSGTagKey() string {
@@ -116,11 +117,11 @@ func (c *Cloud) clusterIDTagKey() string {
116117
if len(c.clusterID) == 0 {
117118
return ""
118119
}
119-
return clusterIDTagKey(c.clusterID[0])
120+
return tags.ClusterIDKey(c.clusterID[0])
120121
}
121122

122123
func (c *Cloud) clusterIDTagKeys() []string {
123-
return utils.Map(c.clusterID, func(c string) (string, bool) {
124-
return clusterIDTagKey(c), true
124+
return lo.Map(c.clusterID, func(c string, _ int) string {
125+
return tags.ClusterIDKey(c)
125126
})
126127
}

0 commit comments

Comments
 (0)