Skip to content

Commit 9f7f5ff

Browse files
committed
Implement ScalewayMachine
1 parent 2d06db3 commit 9f7f5ff

27 files changed

+2345
-180
lines changed

.golangci.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ linters:
3939
alias: apierrors
4040
- pkg: k8s.io/apimachinery/pkg/util/errors
4141
alias: utilerrors
42+
- pkg: github.com/scaleway/cluster-api-provider-scaleway/internal/service/scaleway/lb/util
43+
alias: lbutil
4244
exclusions:
4345
generated: lax
4446
rules:

api/v1alpha1/scalewaymachine_types.go

Lines changed: 81 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,100 @@ package v1alpha1
22

33
import (
44
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
5+
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
56
)
67

7-
// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN!
8-
// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized.
8+
const MachineFinalizer = "scalewaycluster.infrastructure.cluster.x-k8s.io/sm-protection"
99

1010
// ScalewayMachineSpec defines the desired state of ScalewayMachine.
11+
// +kubebuilder:validation:XValidation:rule="has(self.rootVolume) == has(oldSelf.rootVolume)",message="rootVolume cannot be added or removed"
12+
// +kubebuilder:validation:XValidation:rule="has(self.publicNetwork) == has(oldSelf.publicNetwork)",message="publicNetwork cannot be added or removed"
1113
type ScalewayMachineSpec struct {
12-
// INSERT ADDITIONAL SPEC FIELDS - desired state of cluster
13-
// Important: Run "make" to regenerate code after modifying this file
14+
// ProviderID must match the provider ID as seen on the node object corresponding to this machine.
15+
// +kubebuilder:validation:XValidation:rule="self == oldSelf",message="Value is immutable"
16+
// +optional
17+
ProviderID *string `json:"providerID,omitempty"`
1418

15-
// Foo is an example field of ScalewayMachine. Edit scalewaymachine_types.go to remove/update
16-
Foo string `json:"foo,omitempty"`
19+
// CommercialType of instance (e.g. PRO2-S).
20+
// +kubebuilder:default="PRO2-S"
21+
// +kubebuilder:validation:XValidation:rule="self == oldSelf",message="Value is immutable"
22+
CommercialType string `json:"commercialType"`
23+
24+
// Image ID, Name or Label to use to create the instance.
25+
// +kubebuilder:validation:XValidation:rule="self == oldSelf",message="Value is immutable"
26+
Image ImageSpec `json:"image"`
27+
28+
// RootVolume defines the characteristics of the system (root) volume.
29+
// +kubebuilder:validation:XValidation:rule="self == oldSelf",message="Value is immutable"
30+
// +optional
31+
RootVolume *RootVolumeSpec `json:"rootVolume,omitempty"`
32+
33+
// PublicNetwork allows attaching public IPs to the instance.
34+
// +kubebuilder:validation:XValidation:rule="self == oldSelf",message="Value is immutable"
35+
// +optional
36+
PublicNetwork *PublicNetworkSpec `json:"publicNetwork,omitempty"`
37+
}
38+
39+
// RootVolumeSpec defines the characteristics of the system (root) volume.
40+
type RootVolumeSpec struct {
41+
// Size of the root volume in GB. Defaults to 20 GB.
42+
// +kubebuilder:default=20
43+
// +kubebuilder:validation:Minimum=8
44+
// +optional
45+
Size *int64 `json:"size,omitempty"`
46+
47+
// Type of the root volume. Can be local or block. Note that not all types
48+
// of instances support local volumes.
49+
// +kubebuilder:validation:Enum=local;block
50+
// +kubebuilder:default="block"
51+
// +optional
52+
Type *string `json:"type,omitempty"`
53+
54+
// IOPS is the number of IOPS requested for the disk. This is only applicable for block volumes.
55+
// +optional
56+
IOPS *int64 `json:"iops,omitempty"`
57+
}
58+
59+
// PublicNetworkSpec allows enabling the attachment of public IPs to the instance.
60+
type PublicNetworkSpec struct {
61+
// EnableIPv4 defines whether server has IPv4 address enabled.
62+
// +optional
63+
EnableIPv4 *bool `json:"enableIPv4,omitempty"`
64+
// EnableIPv6 defines whether server has IPv6 addresses enabled.
65+
// +optional
66+
EnableIPv6 *bool `json:"enableIPv6,omitempty"`
67+
}
68+
69+
// ImageSpec contains an ID, Name or Label to use to create the instance.
70+
// +kubebuilder:validation:XValidation:rule="(has(self.id) ? 1 : 0) + (has(self.name) ? 1 : 0) + (has(self.label) ? 1 : 0) == 1",message="exactly one of id, name or label must be set"
71+
type ImageSpec struct {
72+
// ID of the image.
73+
ID *string `json:"id,omitempty"`
74+
// Name of the image.
75+
Name *string `json:"name,omitempty"`
76+
// Label of the image.
77+
Label *string `json:"label,omitempty"`
1778
}
1879

1980
// ScalewayMachineStatus defines the observed state of ScalewayMachine.
2081
type ScalewayMachineStatus struct {
21-
// INSERT ADDITIONAL STATUS FIELD - define observed state of cluster
22-
// Important: Run "make" to regenerate code after modifying this file
82+
// Addresses contains the associated addresses for the machine.
83+
// +optional
84+
Addresses []clusterv1.MachineAddress `json:"addresses,omitempty"`
85+
86+
// Ready denotes that the Scaleway machine infrastructure is fully provisioned.
87+
// NOTE: this field is part of the Cluster API contract and it is used to orchestrate provisioning.
88+
// The value of this field is never updated after provisioning is completed. Please use conditions
89+
// to check the operational state of the infra machine.
90+
// +optional
91+
Ready bool `json:"ready"`
2392
}
2493

2594
// +kubebuilder:object:root=true
2695
// +kubebuilder:subresource:status
96+
// +kubebuilder:printcolumn:name="CommercialType",type="string",JSONPath=".spec.commercialType",description="Instance commercial type"
97+
// +kubebuilder:printcolumn:name="ProviderID",type="string",JSONPath=".spec.providerID",description="Node provider ID"
98+
// +kubebuilder:printcolumn:name="Ready",type="boolean",JSONPath=".status.ready",description="Indicates whether the Scaleway machine is ready"
2799
// +kubebuilder:resource:path=scalewaymachines,scope=Namespaced,categories=cluster-api,shortName=sm
28100
// +kubebuilder:storageversion
29101

@@ -32,6 +104,7 @@ type ScalewayMachine struct {
32104
metav1.TypeMeta `json:",inline"`
33105
metav1.ObjectMeta `json:"metadata,omitempty"`
34106

107+
// +kubebuilder:validation:Required
35108
Spec ScalewayMachineSpec `json:"spec,omitempty"`
36109
Status ScalewayMachineStatus `json:"status,omitempty"`
37110
}

api/v1alpha1/zz_generated.deepcopy.go

Lines changed: 109 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cmd/main.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -192,10 +192,7 @@ func main() {
192192
setupLog.Error(err, "unable to create controller", "controller", "ScalewayCluster")
193193
os.Exit(1)
194194
}
195-
if err = (&controller.ScalewayMachineReconciler{
196-
Client: mgr.GetClient(),
197-
Scheme: mgr.GetScheme(),
198-
}).SetupWithManager(mgr); err != nil {
195+
if err = controller.NewScalewayMachineReconciler(mgr.GetClient()).SetupWithManager(mgr); err != nil {
199196
setupLog.Error(err, "unable to create controller", "controller", "ScalewayMachine")
200197
os.Exit(1)
201198
}

0 commit comments

Comments
 (0)