Skip to content

Commit

Permalink
Update CD-ROM API fields and related webhook code
Browse files Browse the repository at this point in the history
  • Loading branch information
dilyar85 committed Aug 8, 2024
1 parent d21ed40 commit 0b2c08d
Show file tree
Hide file tree
Showing 16 changed files with 454 additions and 170 deletions.
29 changes: 18 additions & 11 deletions api/v1alpha3/virtualmachine_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,9 +276,10 @@ type VirtualMachineImageRef struct {
type VirtualMachineCdromSpec struct {
// +kubebuilder:validation:Pattern="^[a-z0-9]{2,}$"

// Name describes the unique and immutable name of this CD-ROM device.
// If omitted or empty, the controller will generate it as "cdrom" + "num",
// where "num" is the device's index in the spec.cdrom list.
// Name consist of at least two lowercase letters or digits of this CD-ROM.
// It must be unique among all CD-ROM devices attached to the VM.
//
// This field is immutable when the VM is powered on.
Name string `json:"name"`

// Image describes the reference to an ISO type VirtualMachineImage or
Expand All @@ -303,8 +304,11 @@ type VirtualMachineCdromSpec struct {
// disconnected from the VM. If the CD-ROM device already exists, it is
// updated to a disconnected state.
//
// Please note that disconnecting a CD-ROM during guest OS installation may
// not work since the CD-ROM might be locked by the guest OS.
//
// Defaults to true if omitted.
Connected bool `json:"connected,omitempty"`
Connected *bool `json:"connected,omitempty"`

// +optional
// +kubebuilder:default=true
Expand All @@ -313,7 +317,7 @@ type VirtualMachineCdromSpec struct {
// may be used to connect/disconnect the CD-ROM device.
//
// Defaults to true if omitted.
AllowGuestControl bool `json:"allowGuestControl,omitempty"`
AllowGuestControl *bool `json:"allowGuestControl,omitempty"`
}

// VirtualMachineSpec defines the desired state of a VirtualMachine.
Expand All @@ -326,7 +330,9 @@ type VirtualMachineSpec struct {
//
// Each CD-ROM device requires a reference to an ISO-type
// VirtualMachineImage or ClusterVirtualMachineImage resource as backing.
// More than one CD-ROM device with the backing image is disallowed.
//
// Multiple CD-ROM devices using the same backing image, regardless of image
// kinds (namespace or cluster scope), are not allowed.
//
// CD-ROM devices can be added, updated, or removed when the VM is powered
// off. When the VM is powered on, only the connection state of existing
Expand Down Expand Up @@ -590,18 +596,19 @@ type VirtualMachineSpec struct {
//
// The logic that determines the guest ID is as follows:
//
// 1. If this field is set, then its value is used.
// 2. Otherwise, if the VirtualMachineClass used to deploy the VM contains a
// non-empty guest ID, then it is used.
// 3. Finally, if this field is still undetermined, and the VM is deployed
// from an OVF template that defines a guest ID, then that value is used.
// If this field is set, then its value is used.
// Otherwise, if the VM is deployed from an OVF template that defines a
// guest ID, then that value is used.
// The guest ID from VirtualMachineClass used to deploy the VM is ignored.
//
// Please refer to https://bit.ly/4elnjP3 for a complete list of supported
// guest operating system identifiers.
//
// Please note that this field is immutable after the VM is powered on.
// To change the guest ID after the VM is powered on, the VM must be powered
// off and then powered on again with the updated guest ID spec.
//
// This field is required when the VM has any CD-ROM devices attached.
GuestID string `json:"guestID,omitempty"`
}

Expand Down
14 changes: 13 additions & 1 deletion api/v1alpha3/zz_generated.deepcopy.go

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

Original file line number Diff line number Diff line change
Expand Up @@ -993,7 +993,10 @@ spec:
Each CD-ROM device requires a reference to an ISO-type
VirtualMachineImage or ClusterVirtualMachineImage resource as backing.
More than one CD-ROM device with the backing image is disallowed.
Multiple CD-ROM devices using the same backing image, regardless of image
kinds (namespace or cluster scope), are not allowed.
CD-ROM devices can be added, updated, or removed when the VM is powered
Expand Down Expand Up @@ -1028,6 +1031,10 @@ spec:
updated to a disconnected state.
Please note that disconnecting a CD-ROM during guest OS installation may
not work since the CD-ROM might be locked by the guest OS.
Defaults to true if omitted.
type: boolean
image:
Expand Down Expand Up @@ -1059,9 +1066,11 @@ spec:
type: object
name:
description: |-
Name describes the unique and immutable name of this CD-ROM device.
If omitted or empty, the controller will generate it as "cdrom" + "num",
where "num" is the device's index in the spec.cdrom list.
Name consist of at least two lowercase letters or digits of this CD-ROM.
It must be unique among all CD-ROM devices attached to the VM.
This field is immutable when the VM is powered on.
pattern: ^[a-z0-9]{2,}$
type: string
required:
Expand Down Expand Up @@ -1091,11 +1100,10 @@ spec:
The logic that determines the guest ID is as follows:
1. If this field is set, then its value is used.
2. Otherwise, if the VirtualMachineClass used to deploy the VM contains a
non-empty guest ID, then it is used.
3. Finally, if this field is still undetermined, and the VM is deployed
from an OVF template that defines a guest ID, then that value is used.
If this field is set, then its value is used.
Otherwise, if the VM is deployed from an OVF template that defines a
guest ID, then that value is used.
The guest ID from VirtualMachineClass used to deploy the VM is ignored.
Please refer to https://bit.ly/4elnjP3 for a complete list of supported
Expand All @@ -1105,6 +1113,9 @@ spec:
Please note that this field is immutable after the VM is powered on.
To change the guest ID after the VM is powered on, the VM must be powered
off and then powered on again with the updated guest ID spec.
This field is required when the VM has any CD-ROM devices attached.
type: string
image:
description: |-
Expand Down
29 changes: 20 additions & 9 deletions config/crd/bases/vmoperator.vmware.com_virtualmachines.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3980,7 +3980,10 @@ spec:
Each CD-ROM device requires a reference to an ISO-type
VirtualMachineImage or ClusterVirtualMachineImage resource as backing.
More than one CD-ROM device with the backing image is disallowed.
Multiple CD-ROM devices using the same backing image, regardless of image
kinds (namespace or cluster scope), are not allowed.
CD-ROM devices can be added, updated, or removed when the VM is powered
Expand Down Expand Up @@ -4015,6 +4018,10 @@ spec:
updated to a disconnected state.
Please note that disconnecting a CD-ROM during guest OS installation may
not work since the CD-ROM might be locked by the guest OS.
Defaults to true if omitted.
type: boolean
image:
Expand Down Expand Up @@ -4046,9 +4053,11 @@ spec:
type: object
name:
description: |-
Name describes the unique and immutable name of this CD-ROM device.
If omitted or empty, the controller will generate it as "cdrom" + "num",
where "num" is the device's index in the spec.cdrom list.
Name consist of at least two lowercase letters or digits of this CD-ROM.
It must be unique among all CD-ROM devices attached to the VM.
This field is immutable when the VM is powered on.
pattern: ^[a-z0-9]{2,}$
type: string
required:
Expand Down Expand Up @@ -4078,11 +4087,10 @@ spec:
The logic that determines the guest ID is as follows:
1. If this field is set, then its value is used.
2. Otherwise, if the VirtualMachineClass used to deploy the VM contains a
non-empty guest ID, then it is used.
3. Finally, if this field is still undetermined, and the VM is deployed
from an OVF template that defines a guest ID, then that value is used.
If this field is set, then its value is used.
Otherwise, if the VM is deployed from an OVF template that defines a
guest ID, then that value is used.
The guest ID from VirtualMachineClass used to deploy the VM is ignored.
Please refer to https://bit.ly/4elnjP3 for a complete list of supported
Expand All @@ -4092,6 +4100,9 @@ spec:
Please note that this field is immutable after the VM is powered on.
To change the guest ID after the VM is powered on, the VM must be powered
off and then powered on again with the updated guest ID spec.
This field is required when the VM has any CD-ROM devices attached.
type: string
image:
description: |-
Expand Down
47 changes: 37 additions & 10 deletions docs/ref/api/v1alpha3.md
Original file line number Diff line number Diff line change
Expand Up @@ -692,9 +692,11 @@ _Appears in:_

| Field | Description |
| --- | --- |
| `name` _string_ | Name describes the unique and immutable name of this CD-ROM device.
If omitted or empty, the controller will generate it as "cdrom" + "num",
where "num" is the device's index in the spec.cdrom list. |
| `name` _string_ | Name consist of at least two lowercase letters or digits of this CD-ROM.
It must be unique among all CD-ROM devices attached to the VM.


This field is immutable when the VM is powered on. |
| `image` _[VirtualMachineImageRef](#virtualmachineimageref)_ | Image describes the reference to an ISO type VirtualMachineImage or
ClusterVirtualMachineImage resource used as the backing for the CD-ROM.
If the image kind is omitted, it defaults to VirtualMachineImage.
Expand All @@ -717,6 +719,10 @@ disconnected from the VM. If the CD-ROM device already exists, it is
updated to a disconnected state.


Please note that disconnecting a CD-ROM during guest OS installation may
not work since the CD-ROM might be locked by the guest OS.


Defaults to true if omitted. |
| `allowGuestControl` _boolean_ | AllowGuestControl describes whether or not a web console connection
may be used to connect/disconnect the CD-ROM device.
Expand Down Expand Up @@ -822,6 +828,21 @@ _Appears in:_



### VirtualMachineImageDiskInfo



VirtualMachineImageDiskInfo describes information about any disks associated with
this image.

_Appears in:_
- [VirtualMachineImageStatus](#virtualmachineimagestatus)

| Field | Description |
| --- | --- |
| `capacity` _[Quantity](#quantity)_ | Capacity is the virtual disk capacity in bytes. |
| `size` _[Quantity](#quantity)_ | Size is the estimated populated size of the virtual disk in bytes. |

### VirtualMachineImageOSInfo


Expand Down Expand Up @@ -942,6 +963,7 @@ image. |
| `vmwareSystemProperties` _KeyValuePair array_ | VMwareSystemProperties describes the observed VMware system properties defined for
this image. |
| `productInfo` _[VirtualMachineImageProductInfo](#virtualmachineimageproductinfo)_ | ProductInfo describes the observed product information for this image. |
| `disks` _[VirtualMachineImageDiskInfo](#virtualmachineimagediskinfo) array_ | Disks describes the observed disk information for this image. |
| `providerContentVersion` _string_ | ProviderContentVersion describes the content version from the provider item
that this image corresponds to. If the provider of this image is a Content
Library, this will be the version of the corresponding Content Library item. |
Expand Down Expand Up @@ -2090,7 +2112,10 @@ _Appears in:_

Each CD-ROM device requires a reference to an ISO-type
VirtualMachineImage or ClusterVirtualMachineImage resource as backing.
More than one CD-ROM device with the backing image is disallowed.


Multiple CD-ROM devices using the same backing image, regardless of image
kinds (namespace or cluster scope), are not allowed.


CD-ROM devices can be added, updated, or removed when the VM is powered
Expand Down Expand Up @@ -2303,11 +2328,10 @@ default value for spec.bootstrap.cloudInit.instanceID if it is omitted. |
The logic that determines the guest ID is as follows:


1. If this field is set, then its value is used.
2. Otherwise, if the VirtualMachineClass used to deploy the VM contains a
non-empty guest ID, then it is used.
3. Finally, if this field is still undetermined, and the VM is deployed
from an OVF template that defines a guest ID, then that value is used.
If this field is set, then its value is used.
Otherwise, if the VM is deployed from an OVF template that defines a
guest ID, then that value is used.
The guest ID from VirtualMachineClass used to deploy the VM is ignored.


Please refer to https://bit.ly/4elnjP3 for a complete list of supported
Expand All @@ -2316,7 +2340,10 @@ guest operating system identifiers.

Please note that this field is immutable after the VM is powered on.
To change the guest ID after the VM is powered on, the VM must be powered
off and then powered on again with the updated guest ID spec. |
off and then powered on again with the updated guest ID spec.


This field is required when the VM has any CD-ROM devices attached. |

### VirtualMachineStatus

Expand Down
4 changes: 2 additions & 2 deletions pkg/providers/vsphere/session/session_vm_update_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1553,8 +1553,8 @@ var _ = Describe("UpdateVirtualMachine", func() {
Name: vmiName,
Kind: vmiKind,
},
AllowGuestControl: true,
Connected: true,
AllowGuestControl: &[]bool{true}[0],
Connected: &[]bool{true}[0],
},
}
})
Expand Down
4 changes: 2 additions & 2 deletions pkg/providers/vsphere/vmprovider_vm_utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,10 +207,10 @@ func vmUtilTests() {
)

BeforeEach(func() {
nsVMImage = builder.DummyVirtualMachineImage(builder.DummyVMIID)
nsVMImage = builder.DummyVirtualMachineImage(builder.DummyVMIName)
nsVMImage.Namespace = vmCtx.VM.Namespace
conditions.MarkTrue(nsVMImage, vmopv1.ReadyConditionType)
clusterVMImage = builder.DummyClusterVirtualMachineImage(builder.DummyVMIID)
clusterVMImage = builder.DummyClusterVirtualMachineImage(builder.DummyCVMIName)
conditions.MarkTrue(clusterVMImage, vmopv1.ReadyConditionType)
})

Expand Down
18 changes: 9 additions & 9 deletions pkg/util/vsphere/vm/cdrom.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func UpdateCdromDeviceChanges(
for _, specCdrom := range vmCtx.VM.Spec.Cdrom {
imageRef := specCdrom.Image
// Sync the content library file if needed to connect the CD-ROM device.
syncFile := specCdrom.Connected
syncFile := *specCdrom.Connected
bFileName, err := getBackingFileNameByImageRef(vmCtx, libManager, k8sClient, syncFile, imageRef)
if err != nil {
return nil, fmt.Errorf("error getting backing file name by image ref %s: %w", imageRef, err)
Expand Down Expand Up @@ -122,7 +122,7 @@ func UpdateConfigSpecCdromDeviceConnection(
for _, specCdrom := range cdromSpec {
imageRef := specCdrom.Image
// Sync the content library file if needed to connect the CD-ROM device.
syncFile := specCdrom.Connected
syncFile := *specCdrom.Connected
bFileName, err := getBackingFileNameByImageRef(vmCtx, libManager, k8sClient, syncFile, imageRef)
if err != nil {
return fmt.Errorf("error getting backing file name by image ref %s: %w", imageRef, err)
Expand Down Expand Up @@ -265,9 +265,9 @@ func createNewCdrom(
VirtualDevice: vimtypes.VirtualDevice{
Backing: backing,
Connectable: &vimtypes.VirtualDeviceConnectInfo{
AllowGuestControl: cdromSpec.AllowGuestControl,
StartConnected: cdromSpec.Connected,
Connected: cdromSpec.Connected,
AllowGuestControl: *cdromSpec.AllowGuestControl,
StartConnected: *cdromSpec.Connected,
Connected: *cdromSpec.Connected,
},
},
}
Expand Down Expand Up @@ -378,10 +378,10 @@ func updateCurCdromsConnectionState(
for b, spec := range backingFileNameToCdromSpec {
if cdrom, ok := backingFileNameToCdrom[b]; ok {
if c := cdrom.GetVirtualDevice().Connectable; c != nil &&
(c.Connected != spec.Connected || c.AllowGuestControl != spec.AllowGuestControl) {
c.StartConnected = spec.Connected
c.Connected = spec.Connected
c.AllowGuestControl = spec.AllowGuestControl
(c.Connected != *spec.Connected || c.AllowGuestControl != *spec.AllowGuestControl) {
c.StartConnected = *spec.Connected
c.Connected = *spec.Connected
c.AllowGuestControl = *spec.AllowGuestControl

deviceChanges = append(deviceChanges, &vimtypes.VirtualDeviceConfigSpec{
Device: cdrom,
Expand Down
Loading

0 comments on commit 0b2c08d

Please sign in to comment.