Skip to content

Commit 14b0591

Browse files
committed
Restrict name format of ScalewayMachine and ScalewayCluster
1 parent 724affc commit 14b0591

File tree

8 files changed

+21
-62
lines changed

8 files changed

+21
-62
lines changed

api/v1alpha1/scalewaycluster_types.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,8 @@ type NetworkStatus struct {
230230
// +kubebuilder:storageversion
231231

232232
// ScalewayCluster is the Schema for the scalewayclusters API.
233+
// +kubebuilder:validation:XValidation:rule="self.metadata.name.size() <= 63",message="name must be between 1 and 63 characters"
234+
// +kubebuilder:validation:XValidation:rule="self.metadata.name.matches('^[a-z0-9]([-a-z0-9]*[a-z0-9])?$')",message="name must be a valid DNS label"
233235
type ScalewayCluster struct {
234236
metav1.TypeMeta `json:",inline"`
235237
metav1.ObjectMeta `json:"metadata,omitempty"`

api/v1alpha1/scalewaymachine_types.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,8 @@ type ScalewayMachineStatus struct {
100100
// +kubebuilder:storageversion
101101

102102
// ScalewayMachine is the Schema for the scalewaymachines API.
103+
// +kubebuilder:validation:XValidation:rule="self.metadata.name.size() <= 63",message="name must be between 1 and 63 characters"
104+
// +kubebuilder:validation:XValidation:rule="self.metadata.name.matches('^[a-z0-9]([-a-z0-9]*[a-z0-9])?$')",message="name must be a valid DNS label"
103105
type ScalewayMachine struct {
104106
metav1.TypeMeta `json:",inline"`
105107
metav1.ObjectMeta `json:"metadata,omitempty"`

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,11 @@ spec:
364364
type: boolean
365365
type: object
366366
type: object
367+
x-kubernetes-validations:
368+
- message: name must be between 1 and 63 characters
369+
rule: self.metadata.name.size() <= 63
370+
- message: name must be a valid DNS label
371+
rule: self.metadata.name.matches('^[a-z0-9]([-a-z0-9]*[a-z0-9])?$')
367372
served: true
368373
storage: true
369374
subresources:

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,11 @@ spec:
181181
required:
182182
- spec
183183
type: object
184+
x-kubernetes-validations:
185+
- message: name must be between 1 and 63 characters
186+
rule: self.metadata.name.size() <= 63
187+
- message: name must be a valid DNS label
188+
rule: self.metadata.name.matches('^[a-z0-9]([-a-z0-9]*[a-z0-9])?$')
184189
served: true
185190
storage: true
186191
subresources:

internal/scope/cluster.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,13 +83,17 @@ func (c *Cluster) Close(ctx context.Context) error {
8383
// ResourceNameName returns the name/prefix that resources created for the cluster should have.
8484
// It is possible to provide additional suffixes that will be appended to the name with a leading "-".
8585
func (c *Cluster) ResourceName(suffixes ...string) string {
86-
return truncateString(strings.Join(append([]string{c.ScalewayCluster.Name}, suffixes...), "-"), 128)
86+
return strings.Join(append([]string{c.ScalewayCluster.Name}, suffixes...), "-")
8787
}
8888

8989
// ResourceTags returns the tags that resources created for the cluster should have.
9090
// It is possible to provide additional tags that will be added to the default tags.
9191
func (c *Cluster) ResourceTags(additional ...string) []string {
92-
return append([]string{fmt.Sprintf("caps-scalewaycluster=%s", c.ScalewayCluster.Name)}, additional...)
92+
return append(
93+
[]string{
94+
fmt.Sprintf("caps-namespace=%s", c.ScalewayCluster.Namespace),
95+
fmt.Sprintf("caps-scalewaycluster=%s", c.ScalewayCluster.Name),
96+
}, additional...)
9397
}
9498

9599
// HasPrivateNetwork returns true if the cluster has a Private Network.

internal/scope/machine.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ func (m *Machine) Close(ctx context.Context) error {
7373

7474
// ResourceNameName returns the name that resources created for the machine should have.
7575
func (m *Machine) ResourceName() string {
76-
return truncateString(m.ScalewayMachine.Name, 63)
76+
return m.ScalewayMachine.Name
7777
}
7878

7979
// ResourceTags returns the tags that resources created for the machine should have.

internal/scope/scope.go

Lines changed: 0 additions & 12 deletions
This file was deleted.

internal/scope/scope_test.go

Lines changed: 0 additions & 47 deletions
This file was deleted.

0 commit comments

Comments
 (0)