Skip to content

Commit ad2a82d

Browse files
add hotplug vi
Signed-off-by: yaroslavborbat <[email protected]>
1 parent 92ef5fb commit ad2a82d

File tree

27 files changed

+933
-1992
lines changed

27 files changed

+933
-1992
lines changed

api/Taskfile.dist.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -87,4 +87,4 @@ tasks:
8787
- go install -mod=readonly sigs.k8s.io/controller-tools/cmd/controller-gen@v{{ .CONTROLLER_GEN_VERSION }}
8888
status:
8989
- |
90-
ls $GOPATH/bin/controller-gen
90+
$GOPATH/bin/controller-gen --version | grep -q "v{{ .CONTROLLER_GEN_VERSION }}"

api/client/kubeclient/client.go

+2
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ type VirtualMachineInterface interface {
8383
Freeze(ctx context.Context, name string, opts v1alpha2.VirtualMachineFreeze) error
8484
Unfreeze(ctx context.Context, name string) error
8585
Migrate(ctx context.Context, name string, opts v1alpha2.VirtualMachineMigrate) error
86+
AddVolume(ctx context.Context, name string, opts v1alpha2.VirtualMachineAddVolume) error
87+
RemoveVolume(ctx context.Context, name string, opts v1alpha2.VirtualMachineRemoveVolume) error
8688
}
8789

8890
type client struct {

api/client/kubeclient/vm.go

+26
Original file line numberDiff line numberDiff line change
@@ -149,3 +149,29 @@ func (v vm) Migrate(ctx context.Context, name string, opts v1alpha2.VirtualMachi
149149
}
150150
return v.restClient.Put().AbsPath(path).Body(body).Do(ctx).Error()
151151
}
152+
153+
func (v vm) AddVolume(ctx context.Context, name string, opts v1alpha2.VirtualMachineAddVolume) error {
154+
path := fmt.Sprintf(subresourceURLTpl, v.namespace, v.resource, name, "addvolume")
155+
156+
return v.restClient.
157+
Put().
158+
AbsPath(path).
159+
Param("name", opts.Name).
160+
Param("volumeKind", opts.VolumeKind).
161+
Param("pvcName", opts.PVCName).
162+
Param("image", opts.Image).
163+
Param("isCdrom", strconv.FormatBool(opts.IsCdrom)).
164+
Do(ctx).
165+
Error()
166+
}
167+
168+
func (v vm) RemoveVolume(ctx context.Context, name string, opts v1alpha2.VirtualMachineRemoveVolume) error {
169+
path := fmt.Sprintf(subresourceURLTpl, v.namespace, v.resource, name, "removevolume")
170+
171+
return v.restClient.
172+
Put().
173+
AbsPath(path).
174+
Param("name", opts.Name).
175+
Do(ctx).
176+
Error()
177+
}

api/core/v1alpha2/virtual_machine_block_disk_attachment.go api/core/v1alpha2/virtual_machine_block_device_attachment.go

+6-2
Original file line numberDiff line numberDiff line change
@@ -72,18 +72,22 @@ type VirtualMachineBlockDeviceAttachmentStatus struct {
7272
type VMBDAObjectRef struct {
7373
// The type of the block device. Options are:
7474
// * `VirtualDisk` — use `VirtualDisk` as the disk. This type is always mounted in RW mode.
75+
// * `VirtualImage` — use `VirtualImage` as the disk. This type is always mounted in RO mode.
76+
// * `ClusterVirtualImage` - use `ClusterVirtualImage` as the disk. This type is always mounted in RO mode.
7577
Kind VMBDAObjectRefKind `json:"kind,omitempty"`
7678
// The name of block device to attach.
7779
Name string `json:"name,omitempty"`
7880
}
7981

8082
// VMBDAObjectRefKind defines the type of the block device.
8183
//
82-
// +kubebuilder:validation:Enum={VirtualDisk}
84+
// +kubebuilder:validation:Enum={VirtualDisk,VirtualImage,ClusterVirtualImage}
8385
type VMBDAObjectRefKind string
8486

8587
const (
86-
VMBDAObjectRefKindVirtualDisk VMBDAObjectRefKind = "VirtualDisk"
88+
VMBDAObjectRefKindVirtualDisk VMBDAObjectRefKind = "VirtualDisk"
89+
VMBDAObjectRefKindVirtualImage VMBDAObjectRefKind = "VirtualImage"
90+
VMBDAObjectRefKindClusterVirtualImage VMBDAObjectRefKind = "ClusterVirtualImage"
8791
)
8892

8993
// BlockDeviceAttachmentPhase defines current status of resource:

api/pkg/apiserver/api/generated/openapi/zz_generated.openapi.go

+45-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/subresources/types.go

+9-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ limitations under the License.
1616

1717
package subresources
1818

19-
import metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
19+
import (
20+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
21+
)
2022

2123
// +genclient
2224
// +genclient:readonly
@@ -51,6 +53,11 @@ type VirtualMachinePortForward struct {
5153

5254
type VirtualMachineAddVolume struct {
5355
metav1.TypeMeta
56+
Name string
57+
VolumeKind string
58+
PVCName string
59+
Image string
60+
IsCdrom bool
5461
}
5562

5663
// +genclient
@@ -59,6 +66,7 @@ type VirtualMachineAddVolume struct {
5966

6067
type VirtualMachineRemoveVolume struct {
6168
metav1.TypeMeta
69+
Name string
6270
}
6371

6472
// +genclient

api/subresources/v1alpha2/types.go

+6
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,11 @@ type VirtualMachinePortForward struct {
5555

5656
type VirtualMachineAddVolume struct {
5757
metav1.TypeMeta `json:",inline"`
58+
Name string `json:"name"`
59+
VolumeKind string `json:"volumeKind"`
60+
PVCName string `json:"pvcName"`
61+
Image string `json:"image"`
62+
IsCdrom bool `json:"isCdrom"`
5863
}
5964

6065
// +genclient
@@ -64,6 +69,7 @@ type VirtualMachineAddVolume struct {
6469

6570
type VirtualMachineRemoveVolume struct {
6671
metav1.TypeMeta `json:",inline"`
72+
Name string `json:"name"`
6773
}
6874

6975
// +genclient

api/subresources/v1alpha2/zz_generated.conversion.go

+54
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crds/doc-ru-virtualmachineblockdeviceattachments.yaml

+2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ spec:
1616
description: |
1717
Тип блочного устройства. Возможны следующие варианты:
1818
* `VirtualDisk` — использовать `VirtualDisk` в качестве диска. Этот тип всегда монтируется в режиме RW.
19+
* `VirtualImage` — использовать `VirtualImage` в качестве диска. Этот тип всегда монтируется в режиме RO.
20+
* `ClusterVirtualImage` - использовать `ClusterVirtualImage` в качестве диска. Этот тип всегда монтируется в режиме RO.
1921
name:
2022
description: |
2123
Имя блочного устройства

crds/virtualmachineblockdeviceattachments.yaml

+4
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,12 @@ spec:
7171
description: |-
7272
The type of the block device. Options are:
7373
* `VirtualDisk` — use `VirtualDisk` as the disk. This type is always mounted in RW mode.
74+
* `VirtualImage` — use `VirtualImage` as the disk. This type is always mounted in RO mode.
75+
* `ClusterVirtualImage` - use `ClusterVirtualImage` as the disk. This type is always mounted in RO mode.
7476
enum:
7577
- VirtualDisk
78+
- VirtualImage
79+
- ClusterVirtualImage
7680
type: string
7781
name:
7882
description: The name of block device to attach.

0 commit comments

Comments
 (0)