Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(vmbda): add hotplug virtual image #536

Merged
merged 11 commits into from
Jan 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion api/Taskfile.dist.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,4 @@ tasks:
- go install -mod=readonly sigs.k8s.io/controller-tools/cmd/controller-gen@v{{ .CONTROLLER_GEN_VERSION }}
status:
- |
ls $GOPATH/bin/controller-gen
$GOPATH/bin/controller-gen --version | grep -q "v{{ .CONTROLLER_GEN_VERSION }}"
2 changes: 2 additions & 0 deletions api/client/kubeclient/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ type VirtualMachineInterface interface {
Freeze(ctx context.Context, name string, opts v1alpha2.VirtualMachineFreeze) error
Unfreeze(ctx context.Context, name string) error
Migrate(ctx context.Context, name string, opts v1alpha2.VirtualMachineMigrate) error
AddVolume(ctx context.Context, name string, opts v1alpha2.VirtualMachineAddVolume) error
RemoveVolume(ctx context.Context, name string, opts v1alpha2.VirtualMachineRemoveVolume) error
}

type client struct {
Expand Down
24 changes: 24 additions & 0 deletions api/client/kubeclient/vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,3 +149,27 @@ func (v vm) Migrate(ctx context.Context, name string, opts v1alpha2.VirtualMachi
}
return v.restClient.Put().AbsPath(path).Body(body).Do(ctx).Error()
}

func (v vm) AddVolume(ctx context.Context, name string, opts v1alpha2.VirtualMachineAddVolume) error {
path := fmt.Sprintf(subresourceURLTpl, v.namespace, v.resource, name, "addvolume")
return v.restClient.
Put().
AbsPath(path).
Param("name", opts.Name).
Param("volumeKind", opts.VolumeKind).
Param("pvcName", opts.PVCName).
Param("image", opts.Image).
Param("isCdrom", strconv.FormatBool(opts.IsCdrom)).
Do(ctx).
Error()
}

func (v vm) RemoveVolume(ctx context.Context, name string, opts v1alpha2.VirtualMachineRemoveVolume) error {
path := fmt.Sprintf(subresourceURLTpl, v.namespace, v.resource, name, "removevolume")
return v.restClient.
Put().
AbsPath(path).
Param("name", opts.Name).
Do(ctx).
Error()
}
Original file line number Diff line number Diff line change
Expand Up @@ -72,18 +72,22 @@ type VirtualMachineBlockDeviceAttachmentStatus struct {
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.
// * `VirtualImage` — use `VirtualImage` as the disk. This type is always mounted in RO mode.
// * `ClusterVirtualImage` - use `ClusterVirtualImage` as the disk. This type is always mounted in RO mode.
Kind VMBDAObjectRefKind `json:"kind,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}
// +kubebuilder:validation:Enum={VirtualDisk,VirtualImage,ClusterVirtualImage}
type VMBDAObjectRefKind string

const (
VMBDAObjectRefKindVirtualDisk VMBDAObjectRefKind = "VirtualDisk"
VMBDAObjectRefKindVirtualDisk VMBDAObjectRefKind = "VirtualDisk"
VMBDAObjectRefKindVirtualImage VMBDAObjectRefKind = "VirtualImage"
VMBDAObjectRefKindClusterVirtualImage VMBDAObjectRefKind = "ClusterVirtualImage"
)

// BlockDeviceAttachmentPhase defines current status of resource:
Expand Down
46 changes: 45 additions & 1 deletion 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.

10 changes: 9 additions & 1 deletion api/subresources/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ limitations under the License.

package subresources

import metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// +genclient
// +genclient:readonly
Expand Down Expand Up @@ -51,6 +53,11 @@ type VirtualMachinePortForward struct {

type VirtualMachineAddVolume struct {
metav1.TypeMeta
Name string
VolumeKind string
PVCName string
Image string
IsCdrom bool
}

// +genclient
Expand All @@ -59,6 +66,7 @@ type VirtualMachineAddVolume struct {

type VirtualMachineRemoveVolume struct {
metav1.TypeMeta
Name string
}

// +genclient
Expand Down
6 changes: 6 additions & 0 deletions api/subresources/v1alpha2/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ type VirtualMachinePortForward struct {

type VirtualMachineAddVolume struct {
metav1.TypeMeta `json:",inline"`
Name string `json:"name"`
VolumeKind string `json:"volumeKind"`
PVCName string `json:"pvcName"`
Image string `json:"image"`
IsCdrom bool `json:"isCdrom"`
}

// +genclient
Expand All @@ -64,6 +69,7 @@ type VirtualMachineAddVolume struct {

type VirtualMachineRemoveVolume struct {
metav1.TypeMeta `json:",inline"`
Name string `json:"name"`
}

// +genclient
Expand Down
54 changes: 54 additions & 0 deletions api/subresources/v1alpha2/zz_generated.conversion.go

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

2 changes: 2 additions & 0 deletions crds/doc-ru-virtualmachineblockdeviceattachments.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ spec:
description: |
Тип блочного устройства. Возможны следующие варианты:
* `VirtualDisk` — использовать `VirtualDisk` в качестве диска. Этот тип всегда монтируется в режиме RW.
* `VirtualImage` — использовать `VirtualImage` в качестве диска. Этот тип всегда монтируется в режиме RO.
* `ClusterVirtualImage` - использовать `ClusterVirtualImage` в качестве диска. Этот тип всегда монтируется в режиме RO.
name:
description: |
Имя блочного устройства
Expand Down
4 changes: 4 additions & 0 deletions crds/virtualmachineblockdeviceattachments.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,12 @@ spec:
description: |-
The type of the block device. Options are:
* `VirtualDisk` — use `VirtualDisk` as the disk. This type is always mounted in RW mode.
* `VirtualImage` — use `VirtualImage` as the disk. This type is always mounted in RO mode.
* `ClusterVirtualImage` - use `ClusterVirtualImage` as the disk. This type is always mounted in RO mode.
enum:
- VirtualDisk
- VirtualImage
- ClusterVirtualImage
type: string
name:
description: The name of block device to attach.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ func main() {
}

vmbdaLogger := logger.NewControllerLogger(vmbda.ControllerName, logLevel, logOutput, logDebugVerbosity, logDebugControllerList)
if _, err = vmbda.NewController(ctx, mgr, vmbdaLogger, controllerNamespace); err != nil {
if _, err = vmbda.NewController(ctx, mgr, virtClient, vmbdaLogger, controllerNamespace); err != nil {
log.Error(err.Error())
os.Exit(1)
}
Expand Down
Loading
Loading