Skip to content

Commit 0df0e90

Browse files
committed
Server: Allow attaching volumes
Add a new mutable `volumes` fields in the server resource spec, allowing to control volumes attached to the server.
1 parent 1fe3c62 commit 0df0e90

File tree

24 files changed

+892
-37
lines changed

24 files changed

+892
-37
lines changed

api/v1alpha1/server_types.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,27 @@ type ServerPortSpec struct {
6060
PortRef *KubernetesNameRef `json:"portRef,omitempty"`
6161
}
6262

63+
// +kubebuilder:validation:MinProperties:=1
64+
type ServerVolumeSpec struct {
65+
// volumeRef is a reference to a Volume object. Server creation will wait for
66+
// this volume to be created and available.
67+
// +required
68+
VolumeRef KubernetesNameRef `json:"volumeRef"`
69+
70+
// device is the name of the device, such as `/dev/vdb`.
71+
// Omit for auto-assignment
72+
// +kubebuilder:validation:MaxLength:=255
73+
// +optional
74+
Device *string `json:"device,omitempty"`
75+
}
76+
77+
type ServerVolumeStatus struct {
78+
// id is the ID of a volume attached to the server.
79+
// +kubebuilder:validation:MaxLength:=1024
80+
// +optional
81+
ID string `json:"id,omitempty"`
82+
}
83+
6384
// ServerResourceSpec contains the desired state of a server
6485
type ServerResourceSpec struct {
6586
// name will be the name of the created resource. If not specified, the
@@ -92,6 +113,12 @@ type ServerResourceSpec struct {
92113
// +kubebuilder:validation:XValidation:rule="self == oldSelf",message="ports is immutable"
93114
Ports []ServerPortSpec `json:"ports"`
94115

116+
// volumes is a list of volumes attached to the server.
117+
// +kubebuilder:validation:MaxItems:=32
118+
// +listType=atomic
119+
// +optional
120+
Volumes []ServerVolumeSpec `json:"volumes,omitempty"`
121+
95122
// serverGroupRef is a reference to a ServerGroup object. The server
96123
// will be created in the server group.
97124
// +optional
@@ -155,6 +182,12 @@ type ServerResourceStatus struct {
155182
// +optional
156183
ServerGroups []string `json:"serverGroups,omitempty"`
157184

185+
// volumes contains the volumes attached to the server.
186+
// +kubebuilder:validation:MaxItems:=32
187+
// +listType=atomic
188+
// +optional
189+
Volumes []ServerVolumeStatus `json:"volumes,omitempty"`
190+
158191
// tags is the list of tags on the resource.
159192
// +kubebuilder:validation:MaxItems:=32
160193
// +kubebuilder:validation:items:MaxLength=1024

api/v1alpha1/volume_types.go

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,27 @@ type VolumeFilter struct {
7171
Size *int32 `json:"size,omitempty"`
7272
}
7373

74+
type VolumeAttachmentStatus struct {
75+
// attachmentID represents the attachment UUID.
76+
// +kubebuilder:validation:MaxLength=1024
77+
// +optional
78+
AttachmentID string `json:"attachmentID"`
79+
80+
// serverID is the UUID of the server to which the volume is attached.
81+
// +kubebuilder:validation:MaxLength=1024
82+
// +optional
83+
ServerID string `json:"serverID"`
84+
85+
// device is the name of the device in the instance.
86+
// +kubebuilder:validation:MaxLength=1024
87+
// +optional
88+
Device string `json:"device"`
89+
90+
// attachedAt shows the date and time when the resource was attached. The date and time stamp format is ISO 8601.
91+
// +optional
92+
AttachedAt *metav1.Time `json:"attachedAt"`
93+
}
94+
7495
// VolumeResourceStatus represents the observed state of the resource.
7596
type VolumeResourceStatus struct {
7697
// name is a Human-readable name for the resource. Might not be unique.
@@ -97,8 +118,11 @@ type VolumeResourceStatus struct {
97118
// +optional
98119
AvailabilityZone string `json:"availabilityZone,omitempty"`
99120

100-
// Instances onto which the volume is attached.
101-
// Attachments []Attachment `json:"attachments"`
121+
// attachments is a list of attachments for the volume.
122+
// +kubebuilder:validation:MaxItems:=32
123+
// +listType=atomic
124+
// +optional
125+
Attachments []VolumeAttachmentStatus `json:"attachments"`
102126

103127
// volumeType is the name of associated the volume type.
104128
// +kubebuilder:validation:MaxLength=1024

api/v1alpha1/zz_generated.deepcopy.go

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

0 commit comments

Comments
 (0)