Skip to content

Commit

Permalink
fix(vmbda): allow wffc hotplugs
Browse files Browse the repository at this point in the history
1. vmbda condition BlockDeviceReady waits until the disk is wffc or ready, after which it performs a hot plug to the virtual machine (from this moment the disk is considered attached to the virtual machine)
2. vd does not allow editing the spec if the disk is attached to the virtual machine or Ready
3. vmbda CRD gen2
4. vmbda uses condition builder to manage conditions

Signed-off-by: Isteb4k <[email protected]>
  • Loading branch information
Isteb4k authored Sep 18, 2024
1 parent a2a0254 commit e155f4e
Show file tree
Hide file tree
Showing 12 changed files with 431 additions and 250 deletions.
47 changes: 37 additions & 10 deletions api/core/v1alpha2/virtual_machine_block_disk_attachment.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,26 @@ const (
VMBDAResource = "virtualmachineblockdeviceattachments"
)

// VirtualMachineBlockDeviceAttachment is a disk ready to be bound by a VM
// VirtualMachineBlockDeviceAttachment provides a hot plug for connecting a disk to a virtual machine.
//
// +kubebuilder:object:root=true
// +kubebuilder:metadata:labels={heritage=deckhouse,module=virtualization}
// +kubebuilder:subresource:status
// +kubebuilder:resource:categories={all,virtualization},scope=Namespaced,shortName={vmbda,vmbdas},singular=virtualmachineblockdeviceattachment
// +kubebuilder:printcolumn:name="PHASE",type="string",JSONPath=".status.phase",description="VirtualMachineBlockDeviceAttachment phase."
// +kubebuilder:printcolumn:name="VIRTUAL MACHINE NAME",type="string",JSONPath=".status.virtualMachineName",description="The name of the virtual machine to which this disk is attached."
// +kubebuilder:printcolumn:name="AGE",type="date",JSONPath=".metadata.creationTimestamp",description="Time of creation resource."
// +genclient
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
type VirtualMachineBlockDeviceAttachment struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Spec VirtualMachineBlockDeviceAttachmentSpec `json:"spec"`
Status VirtualMachineBlockDeviceAttachmentStatus `json:"status"`
Status VirtualMachineBlockDeviceAttachmentStatus `json:"status,omitempty"`
}

// VirtualMachineBlockDeviceAttachmentList contains a list of VirtualMachineBlockDeviceAttachment
// VirtualMachineBlockDeviceAttachmentList contains a list of VirtualMachineBlockDeviceAttachment.
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
type VirtualMachineBlockDeviceAttachmentList struct {
metav1.TypeMeta `json:",inline"`
Expand All @@ -45,27 +53,46 @@ type VirtualMachineBlockDeviceAttachmentList struct {
}

type VirtualMachineBlockDeviceAttachmentSpec struct {
// The name of the virtual machine to which the disk or image should be connected.
VirtualMachineName string `json:"virtualMachineName"`
BlockDeviceRef VMBDAObjectRef `json:"blockDeviceRef"`
}

type VirtualMachineBlockDeviceAttachmentStatus struct {
Phase BlockDeviceAttachmentPhase `json:"phase,omitempty"`
// The name of the virtual machine to which this disk is attached.
VirtualMachineName string `json:"virtualMachineName,omitempty"`
// Contains details of the current state of this API Resource.
Conditions []metav1.Condition `json:"conditions,omitempty"`
// The generation last processed by the controller
ObservedGeneration int64 `json:"observedGeneration,omitempty"`
}

type VMBDAObjectRef struct {
// The type of the block device. Options are:
// * `VirtualDisk` — use `VirtualDisk` as the disk. This type is always mounted in RW mode.
Kind VMBDAObjectRefKind `json:"kind,omitempty"`
Name string `json:"name,omitempty"`
// The name of block device to attach.
Name string `json:"name,omitempty"`
}

// VMBDAObjectRefKind defines the type of the block device.
//
// +kubebuilder:validation:Enum={VirtualDisk}
type VMBDAObjectRefKind string

const (
VMBDAObjectRefKindVirtualDisk VMBDAObjectRefKind = "VirtualDisk"
)

type VirtualMachineBlockDeviceAttachmentStatus struct {
Phase BlockDeviceAttachmentPhase `json:"phase,omitempty"`
Conditions []metav1.Condition `json:"conditions,omitempty"`
ObservedGeneration int64 `json:"observedGeneration,omitempty"`
}

// BlockDeviceAttachmentPhase defines current status of resource:
// * Pending — the resource has been created and is on a waiting queue.
// * InProgress — the disk is in the process of being attached.
// * Attached — the disk is attached to virtual machine.
// * Failed — there was a problem with attaching the disk.
// * Terminating — the process of resource deletion is in progress.
//
// +kubebuilder:validation:Enum={Pending,InProgress,Attached,Failed,Terminating}
type BlockDeviceAttachmentPhase string

const (
Expand Down
30 changes: 26 additions & 4 deletions api/core/v1alpha2/vmbdacondition/condition.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ limitations under the License.
package vmbdacondition

// Type represents the various condition types for the `VirtualMachineBlockDeviceAttachment`.
type Type = string
type Type string

const (
// BlockDeviceReadyType indicates that the block device (for example, a `VirtualDisk`) is ready to be hot-plugged.
Expand All @@ -30,24 +30,30 @@ const (

type (
// BlockDeviceReadyReason represents the various reasons for the `BlockDeviceReady` condition type.
BlockDeviceReadyReason = string
BlockDeviceReadyReason string
// VirtualMachineReadyReason represents the various reasons for the `VirtualMachineReady` condition type.
VirtualMachineReadyReason = string
VirtualMachineReadyReason string
// AttachedReason represents the various reasons for the `Attached` condition type.
AttachedReason = string
AttachedReason string
)

const (
// BlockDeviceReadyUnknown represents unknown condition state.
BlockDeviceReadyUnknown BlockDeviceReadyReason = "Unknown"
// BlockDeviceReady signifies that the block device is ready to be hot-plugged, allowing the hot-plug process to start.
BlockDeviceReady BlockDeviceReadyReason = "BlockDeviceReady"
// BlockDeviceNotReady signifies that the block device is not ready, preventing the hot-plug process from starting.
BlockDeviceNotReady BlockDeviceReadyReason = "BlockDeviceNotReady"

// VirtualMachineReadyUnknown represents unknown condition state.
VirtualMachineReadyUnknown VirtualMachineReadyReason = "Unknown"
// VirtualMachineReady signifies that the virtual machine is ready for hot-plugging a disk, allowing the hot-plug process to start.
VirtualMachineReady VirtualMachineReadyReason = "VirtualMachineReady"
// VirtualMachineNotReady signifies that the virtual machine is not ready, preventing the hot-plug process from starting.
VirtualMachineNotReady VirtualMachineReadyReason = "VirtualMachineNotReady"

// AttachedUnknown represents unknown condition state.
AttachedUnknown BlockDeviceReadyReason = "Unknown"
// Attached signifies that the virtual disk is successfully hot-plugged into the virtual machine.
Attached AttachedReason = "Attached"
// NotAttached signifies that the virtual disk is not yet hot-plugged into the virtual machine.
Expand All @@ -60,3 +66,19 @@ const (
// Only the one that was created or started sooner can be processed.
Conflict AttachedReason = "Conflict"
)

func (t Type) String() string {
return string(t)
}

func (t BlockDeviceReadyReason) String() string {
return string(t)
}

func (t VirtualMachineReadyReason) String() string {
return string(t)
}

func (t AttachedReason) String() string {
return string(t)
}
9 changes: 8 additions & 1 deletion api/core/v1alpha2/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

59 changes: 40 additions & 19 deletions api/pkg/apiserver/api/generated/openapi/zz_generated.openapi.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion api/scripts/update-codegen.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ function source::settings {
MODULE="github.com/deckhouse/virtualization/api"
PREFIX_GROUP="virtualization.deckhouse.io_"
# TODO: Temporary filter until all CRDs become auto-generated.
ALLOWED_RESOURCE_GEN_CRD=("VirtualMachineClass" "ExampleKind1" "ExampleKind2")
ALLOWED_RESOURCE_GEN_CRD=("VirtualMachineClass" "VirtualMachineBlockDeviceAttachment" "ExampleKind1" "ExampleKind2")
source "${CODEGEN_PKG}/kube_codegen.sh"
}

Expand Down
4 changes: 1 addition & 3 deletions crds/doc-ru-virtualmachineblockdeviceattachments.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ spec:
kind:
description: |
Тип блочного устройства. Возможны следующие варианты:
* `VirtualDisk` — использовать `VirtualDisk` в качестве диска. Этот тип всегда монтируется в режиме RW.
name:
description: |
Expand Down Expand Up @@ -46,12 +45,11 @@ spec:
phase:
description: |
Фаза ресурса:
* Pending — ресурс был создан и находится в очереди ожидания.
* InProgress — диск в процессе подключения к ВМ.
* Attached — диск подключен к ВМ.
* Failed — возникла проблема с подключением диска.
* Terminating - ресурс находится в процессе удаления.
* Terminating ресурс находится в процессе удаления.
virtualMachineName:
description: |
Имя виртуальной машины, к которой подключен этот диск.
Expand Down
Loading

0 comments on commit e155f4e

Please sign in to comment.