Skip to content

Commit 8cb403d

Browse files
committed
Add projectID field in ScalewayCluster
1 parent 9f7f5ff commit 8cb403d

File tree

6 files changed

+30
-14
lines changed

6 files changed

+30
-14
lines changed

api/v1alpha1/scalewaycluster_types.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,14 @@ const ClusterFinalizer = "scalewaycluster.infrastructure.cluster.x-k8s.io/sc-pro
1010
// ScalewayClusterSpec defines the desired state of ScalewayCluster.
1111
// +kubebuilder:validation:XValidation:rule="!has(oldSelf.controlPlaneEndpoint) || has(self.controlPlaneEndpoint)", message="controlPlaneEndpoint is required once set"
1212
type ScalewayClusterSpec struct {
13+
// ProjectID is the Scaleway project ID where the cluster will be created.
14+
// +kubebuilder:validation:XValidation:rule="self == oldSelf",message="Value is immutable"
15+
// +kubebuilder:validation:Pattern:="^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$"
16+
ProjectID string `json:"projectID"`
17+
1318
// Region represents the region where the cluster will be hosted.
1419
// +kubebuilder:validation:XValidation:rule="self == oldSelf",message="Value is immutable"
15-
// +kubebuilder:validation:MinLength=1
16-
// +kubebuilder:validation:MaxLength=10
20+
// +kubebuilder:validation:Pattern:="^[a-z]{2}-[a-z]{3}$"
1721
Region string `json:"region"`
1822

1923
// Network contains network related options for the cluster.

config/crd/bases/infrastructure.cluster.x-k8s.io_scalewayclusters.yaml

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -280,11 +280,18 @@ spec:
280280
- message: privateNetwork is required when publicGateways is set
281281
rule: '!has(self.publicGateways) || has(self.privateNetwork) &&
282282
self.privateNetwork.enabled'
283+
projectID:
284+
description: ProjectID is the Scaleway project ID where the cluster
285+
will be created.
286+
pattern: ^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$
287+
type: string
288+
x-kubernetes-validations:
289+
- message: Value is immutable
290+
rule: self == oldSelf
283291
region:
284292
description: Region represents the region where the cluster will be
285293
hosted.
286-
maxLength: 10
287-
minLength: 1
294+
pattern: ^[a-z]{2}-[a-z]{3}$
288295
type: string
289296
x-kubernetes-validations:
290297
- message: Value is immutable
@@ -296,6 +303,7 @@ spec:
296303
The following key is optional: SCW_API_URL.
297304
type: string
298305
required:
306+
- projectID
299307
- region
300308
- scalewaySecretName
301309
type: object

config/crd/bases/infrastructure.cluster.x-k8s.io_scalewayclustertemplates.yaml

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -281,11 +281,18 @@ spec:
281281
is set
282282
rule: '!has(self.publicGateways) || has(self.privateNetwork)
283283
&& self.privateNetwork.enabled'
284+
projectID:
285+
description: ProjectID is the Scaleway project ID where the
286+
cluster will be created.
287+
pattern: ^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$
288+
type: string
289+
x-kubernetes-validations:
290+
- message: Value is immutable
291+
rule: self == oldSelf
284292
region:
285293
description: Region represents the region where the cluster
286294
will be hosted.
287-
maxLength: 10
288-
minLength: 1
295+
pattern: ^[a-z]{2}-[a-z]{3}$
289296
type: string
290297
x-kubernetes-validations:
291298
- message: Value is immutable
@@ -297,6 +304,7 @@ spec:
297304
The following key is optional: SCW_API_URL.
298305
type: string
299306
required:
307+
- projectID
300308
- region
301309
- scalewaySecretName
302310
type: object

internal/controller/scalewaycluster_controller_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ var _ = Describe("ScalewayCluster Controller", func() {
3737
Namespace: "default",
3838
},
3939
Spec: infrav1.ScalewayClusterSpec{
40-
Region: string(scw.RegionFrPar),
40+
ProjectID: "11111111-1111-1111-1111-111111111111",
41+
Region: string(scw.RegionFrPar),
4142
},
4243
}
4344
Expect(k8sClient.Create(ctx, resource)).To(Succeed())

internal/scope/cluster.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ func NewCluster(ctx context.Context, params *ClusterParams) (*Cluster, error) {
5252
return nil, fmt.Errorf("failed to get ScalewaySecret: %w", err)
5353
}
5454

55-
c, err := scwClient.New(region, secret.Data)
55+
c, err := scwClient.New(region, params.ScalewayCluster.Spec.ProjectID, secret.Data)
5656
if err != nil {
5757
return nil, fmt.Errorf("failed to create Scaleway client from ScalewaySecret: %w", err)
5858
}

internal/service/scaleway/client/client.go

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ type Client struct {
3535

3636
// New returns a new Scaleway client based on the provided region and secretData.
3737
// The secret data must contain a default projectID and credentials.
38-
func New(region scw.Region, secretData map[string][]byte) (*Client, error) {
38+
func New(region scw.Region, projectID string, secretData map[string][]byte) (*Client, error) {
3939
accessKey := string(secretData[scw.ScwAccessKeyEnv])
4040
if accessKey == "" {
4141
return nil, fmt.Errorf("field %s is missing in secret", scw.ScwAccessKeyEnv)
@@ -46,11 +46,6 @@ func New(region scw.Region, secretData map[string][]byte) (*Client, error) {
4646
return nil, fmt.Errorf("field %s is missing in secret", scw.ScwSecretKeyEnv)
4747
}
4848

49-
projectID := string(secretData[scw.ScwDefaultProjectIDEnv])
50-
if projectID == "" {
51-
return nil, fmt.Errorf("field %s is missing in secret", scw.ScwDefaultProjectIDEnv)
52-
}
53-
5449
opts := []scw.ClientOption{
5550
scw.WithAuth(accessKey, secretKey),
5651
scw.WithDefaultProjectID(projectID),

0 commit comments

Comments
 (0)