From 7df1bd6893e91e20f25e99d9570fdb6b20a207ea Mon Sep 17 00:00:00 2001 From: Sagar Muchhal Date: Wed, 15 Nov 2023 04:23:15 -0800 Subject: [PATCH] Adds new field for min hardware version Adds a new field to set the minimum hardware version on the VSphereMachine Spec. This field is used to a similar field in the VMOperator's VirtualMachineSpec. Signed-off-by: Sagar Muchhal --- apis/vmware/v1beta1/vspheremachine_types.go | 10 +- ...mware.com_clustervirtualmachineimages.yaml | 25 +- ...ator.vmware.com_virtualmachineclasses.yaml | 4 +- ...rator.vmware.com_virtualmachineimages.yaml | 25 +- ...are.com_virtualmachinepublishrequests.yaml | 12 +- ...vmoperator.vmware.com_virtualmachines.yaml | 244 ++++++------------ ...tor.vmware.com_virtualmachineservices.yaml | 4 +- ...com_virtualmachinesetresourcepolicies.yaml | 4 +- ....com_virtualmachinewebconsolerequests.yaml | 9 + ...ture.cluster.x-k8s.io_vspheremachines.yaml | 8 +- ...ster.x-k8s.io_vspheremachinetemplates.yaml | 8 +- go.mod | 2 +- go.sum | 4 +- pkg/services/vmoperator/vmopmachine.go | 10 + pkg/util/vmx.go | 9 +- 15 files changed, 166 insertions(+), 212 deletions(-) diff --git a/apis/vmware/v1beta1/vspheremachine_types.go b/apis/vmware/v1beta1/vspheremachine_types.go index 3252a5cbf3..b35b8b6226 100644 --- a/apis/vmware/v1beta1/vspheremachine_types.go +++ b/apis/vmware/v1beta1/vspheremachine_types.go @@ -36,7 +36,7 @@ type VSphereMachineVolume struct { // VSphereMachineSpec defines the desired state of VSphereMachine. type VSphereMachineSpec struct { - // ProviderID is the virtual machine's BIOS UUID formated as + // ProviderID is the virtual machine's BIOS UUID formatted as // vsphere://12345678-1234-1234-1234-123456789abc. // This is required at runtime by CAPI. Do not remove this field. // +optional @@ -79,6 +79,14 @@ type VSphereMachineSpec struct { // +optional // +kubebuilder:default=hard PowerOffMode VirtualMachinePowerOpMode `json:"powerOffMode,omitempty"` + + // MinHardwareVersion specifies the desired minimum hardware version + // for this VM. Setting this field will ensure that the hardware version + // of the VM is at least set to the specified value. + // The expected format of the field is vmx-15. + // + // +optional + MinHardwareVersion string `json:"minHardwareVersion,omitempty"` } // VSphereMachineStatus defines the observed state of VSphereMachine. diff --git a/config/deployments/integration-tests/crds/vmoperator.vmware.com_clustervirtualmachineimages.yaml b/config/deployments/integration-tests/crds/vmoperator.vmware.com_clustervirtualmachineimages.yaml index ea35382090..0c1383a7e0 100644 --- a/config/deployments/integration-tests/crds/vmoperator.vmware.com_clustervirtualmachineimages.yaml +++ b/config/deployments/integration-tests/crds/vmoperator.vmware.com_clustervirtualmachineimages.yaml @@ -20,14 +20,8 @@ spec: scope: Cluster versions: - additionalPrinterColumns: - - jsonPath: .spec.providerRef.name - name: Provider-Name - type: string - - jsonPath: .status.contentLibraryRef.name - name: Content-Library-Name - type: string - jsonPath: .status.imageName - name: Image-Name + name: Display-Name type: string - jsonPath: .spec.productInfo.version name: Version @@ -256,7 +250,7 @@ spec: eg: bios, efi.' type: string imageName: - description: ImageName describes the display name of this VirtualMachineImage. + description: ImageName describes the display name of this image. type: string imageSupported: description: 'ImageSupported indicates whether the VirtualMachineImage @@ -275,12 +269,12 @@ spec: type: object type: object served: true - storage: true + storage: false subresources: status: {} - additionalPrinterColumns: - jsonPath: .status.name - name: Image Name + name: Display Name type: string - jsonPath: .status.productInfo.version name: Image Version @@ -439,8 +433,7 @@ spec: format: int32 type: integer name: - description: Name describes the observed, "friendly" name for this - image. + description: Name describes the display name of this image. type: string osInfo: description: "OSInfo describes the observed operating system information @@ -509,9 +502,15 @@ spec: of this image is a Content Library, this will be the version of the corresponding Content Library item. type: string + providerItemID: + description: ProviderItemID describes the ID of the provider item + that this image corresponds to. If the provider of this image is + a Content Library, this ID will be that of the corresponding Content + Library item. + type: string type: object type: object served: true - storage: false + storage: true subresources: status: {} diff --git a/config/deployments/integration-tests/crds/vmoperator.vmware.com_virtualmachineclasses.yaml b/config/deployments/integration-tests/crds/vmoperator.vmware.com_virtualmachineclasses.yaml index 0da38d49fd..de7a2a5efb 100644 --- a/config/deployments/integration-tests/crds/vmoperator.vmware.com_virtualmachineclasses.yaml +++ b/config/deployments/integration-tests/crds/vmoperator.vmware.com_virtualmachineclasses.yaml @@ -214,7 +214,7 @@ spec: type: object type: object served: true - storage: true + storage: false subresources: status: {} - additionalPrinterColumns: @@ -498,6 +498,6 @@ spec: type: object type: object served: true - storage: false + storage: true subresources: status: {} diff --git a/config/deployments/integration-tests/crds/vmoperator.vmware.com_virtualmachineimages.yaml b/config/deployments/integration-tests/crds/vmoperator.vmware.com_virtualmachineimages.yaml index 4aa803d57e..6548fe9c41 100644 --- a/config/deployments/integration-tests/crds/vmoperator.vmware.com_virtualmachineimages.yaml +++ b/config/deployments/integration-tests/crds/vmoperator.vmware.com_virtualmachineimages.yaml @@ -18,14 +18,8 @@ spec: scope: Cluster versions: - additionalPrinterColumns: - - jsonPath: .spec.providerRef.name - name: Provider-Name - type: string - - jsonPath: .status.contentLibraryRef.name - name: Content-Library-Name - type: string - jsonPath: .status.imageName - name: Image-Name + name: Display-Name type: string - jsonPath: .spec.productInfo.version name: Version @@ -256,7 +250,7 @@ spec: eg: bios, efi.' type: string imageName: - description: ImageName describes the display name of this VirtualMachineImage. + description: ImageName describes the display name of this image. type: string imageSupported: description: 'ImageSupported indicates whether the VirtualMachineImage @@ -275,12 +269,12 @@ spec: type: object type: object served: true - storage: true + storage: false subresources: status: {} - additionalPrinterColumns: - jsonPath: .status.name - name: Image Name + name: Display Name type: string - jsonPath: .status.productInfo.version name: Image Version @@ -442,8 +436,7 @@ spec: format: int32 type: integer name: - description: Name describes the observed, "friendly" name for this - image. + description: Name describes the display name of this image. type: string osInfo: description: "OSInfo describes the observed operating system information @@ -512,9 +505,15 @@ spec: of this image is a Content Library, this will be the version of the corresponding Content Library item. type: string + providerItemID: + description: ProviderItemID describes the ID of the provider item + that this image corresponds to. If the provider of this image is + a Content Library, this ID will be that of the corresponding Content + Library item. + type: string type: object type: object served: true - storage: false + storage: true subresources: status: {} diff --git a/config/deployments/integration-tests/crds/vmoperator.vmware.com_virtualmachinepublishrequests.yaml b/config/deployments/integration-tests/crds/vmoperator.vmware.com_virtualmachinepublishrequests.yaml index 1ab7d62a53..40475305e8 100644 --- a/config/deployments/integration-tests/crds/vmoperator.vmware.com_virtualmachinepublishrequests.yaml +++ b/config/deployments/integration-tests/crds/vmoperator.vmware.com_virtualmachinepublishrequests.yaml @@ -89,8 +89,8 @@ spec: published object. type: string name: - description: "Name is the name of the published object. \n - If the spec.target.location.apiVersion equals imageregistry.vmware.com/v1alpha1 + description: "Name is the display name of the published object. + \n If the spec.target.location.apiVersion equals imageregistry.vmware.com/v1alpha1 and the spec.target.location.kind equals ContentLibrary, then this should be the name that will show up in vCenter Content Library, not the custom resource name in the namespace. @@ -256,8 +256,8 @@ spec: published object. type: string name: - description: "Name is the name of the published object. \n - If the spec.target.location.apiVersion equals imageregistry.vmware.com/v1alpha1 + description: "Name is the display name of the published object. + \n If the spec.target.location.apiVersion equals imageregistry.vmware.com/v1alpha1 and the spec.target.location.kind equals ContentLibrary, then this should be the name that will show up in vCenter Content Library, not the custom resource name in the namespace. @@ -291,7 +291,7 @@ spec: type: object type: object served: true - storage: true + storage: false subresources: status: {} - name: v1alpha2 @@ -594,6 +594,6 @@ spec: type: object type: object served: true - storage: false + storage: true subresources: status: {} diff --git a/config/deployments/integration-tests/crds/vmoperator.vmware.com_virtualmachines.yaml b/config/deployments/integration-tests/crds/vmoperator.vmware.com_virtualmachines.yaml index 1a5a0dc3dc..d1d38f8ff5 100644 --- a/config/deployments/integration-tests/crds/vmoperator.vmware.com_virtualmachines.yaml +++ b/config/deployments/integration-tests/crds/vmoperator.vmware.com_virtualmachines.yaml @@ -104,6 +104,33 @@ spec: be introspected to discover identifying attributes that may help users to identify the desired image to use. type: string + minHardwareVersion: + description: "MinHardwareVersion specifies the desired minimum hardware + version for this VM. \n Usually the VM's hardware version is derived + from: 1. the VirtualMachineClass used to deploy the VM provided + by the ClassName field 2. the datacenter/cluster/host default hardware + version Setting this field will ensure that the hardware version + of the VM is at least set to the specified value. To enforce this, + it will override the value from the VirtualMachineClass. \n This + field is never updated to reflect the derived hardware version. + Instead, VirtualMachineStatus.HardwareVersion surfaces the observed + hardware version. \n Please note, setting this field's value to + N ensures a VM's hardware version is equal to or greater than N. + For example, if a VM's observed hardware version is 10 and this + field's value is 13, then the VM will be upgraded to hardware version + 13. However, if the observed hardware version is 17 and this field's + value is 13, no change will occur. \n Several features are hardware + version dependent, for example: \n * NVMe Controllers \t\t + >= 14 * Dynamic Direct Path I/O devices >= 17 \n Please refer to + https://kb.vmware.com/s/article/1003746 for a list of VM hardware + versions. \n It is important to remember that a VM's hardware version + may not be downgraded and upgrading a VM deployed from an image + based on an older hardware version to a more recent one may result + in unpredictable behavior. In other words, please be careful when + choosing to upgrade a VM to a newer hardware version." + format: int32 + minimum: 13 + type: integer networkInterfaces: description: NetworkInterfaces describes a list of VirtualMachineNetworkInterfaces to be configured on the VirtualMachine instance. Each of these VirtualMachineNetworkInterfaces @@ -494,6 +521,12 @@ spec: - type type: object type: array + hardwareVersion: + description: "HardwareVersion describes the VirtualMachine resource's + observed hardware version. \n Please refer to VirtualMachineSpec.MinHardwareVersion + for more information on the topic of a VM's hardware version." + format: int32 + type: integer host: description: Host describes the hostname or IP address of the infrastructure host that the VirtualMachine is executing on. @@ -592,7 +625,7 @@ spec: type: object type: object served: true - storage: true + storage: false subresources: status: {} - additionalPrinterColumns: @@ -1240,7 +1273,7 @@ spec: description: GUIRunOnce is a representation of the Sysprep GuiRunOnce key. properties: - commmands: + commands: description: Commands is a list of commands to run at first user logon, after guest customization. items: @@ -1445,8 +1478,8 @@ spec: items: description: KeyValueOrSecretKeySelectorPair is useful when wanting to realize a map as a list of key/value pairs - where each value could also referenced data stored in - a Secret resource. + where each value could also reference data stored in a + Secret resource. properties: key: description: Key is the key part of the key/value pair. @@ -1500,7 +1533,7 @@ spec: type: object type: object className: - description: "Class describes the name of the VirtualMachineClass + description: "ClassName describes the name of the VirtualMachineClass resource used to deploy this VM. \n This field is optional in the cases where there exists a sensible default value, such as when there is a single VirtualMachineClass resource available in the @@ -1518,87 +1551,45 @@ spec: default value, such as when there is a single VirtualMachineImage resource available in the same Namespace as the VM being deployed." type: string + minHardwareVersion: + description: "MinHardwareVersion specifies the desired minimum hardware + version for this VM. \n Usually the VM's hardware version is derived + from: 1. the VirtualMachineClass used to deploy the VM provided + by the ClassName field 2. the datacenter/cluster/host default hardware + version Setting this field will ensure that the hardware version + of the VM is at least set to the specified value. To enforce this, + it will override the value from the VirtualMachineClass. \n This + field is never updated to reflect the derived hardware version. + Instead, VirtualMachineStatus.HardwareVersion surfaces the observed + hardware version. \n Please note, setting this field's value to + N ensures a VM's hardware version is equal to or greater than N. + For example, if a VM's observed hardware version is 10 and this + field's value is 13, then the VM will be upgraded to hardware version + 13. However, if the observed hardware version is 17 and this field's + value is 13, no change will occur. \n Several features are hardware + version dependent, for example: \n * NVMe Controllers \t\t + >= 14 * Dynamic Direct Path I/O devices >= 17 \n Please refer to + https://kb.vmware.com/s/article/1003746 for a list of VM hardware + versions. \n It is important to remember that a VM's hardware version + may not be downgraded and upgrading a VM deployed from an image + based on an older hardware version to a more recent one may result + in unpredictable behavior. In other words, please be careful when + choosing to upgrade a VM to a newer hardware version." + format: int32 + minimum: 13 + type: integer network: description: "Network describes the desired network configuration for the VM. \n Please note this value may be omitted entirely and the VM will be assigned a single, virtual network interface that is connected to the Namespace's default network." properties: - addresses: - description: "Addresses is an optional list of IP4 or IP6 addresses - to assign to the VM. \n Please note this field is only supported - if the connected network supports manual IP allocation. \n Please - note IP4 and IP6 addresses must include the network prefix length, - ex. 192.168.0.10/24 or 2001:db8:101::a/64. \n Please note this - field may not contain IP4 addresses if DHCP4 is set to true - or IP6 addresses if DHCP6 is set to true. \n Please note if - the Interfaces field is non-empty then this field is ignored - and should be specified on the elements in the Interfaces list." - items: - type: string - type: array - deviceName: - description: "DeviceName describes the unique name of this network - interface, used to distinguish it from other network interfaces - attached to this VM. \n This value is also used to rename the - device inside the guest when the bootstrap provider is CloudInit. - Please note it is up to the user to ensure the provided device - name does not conflict with any other devices inside the guest, - ex. dvd, cdrom, sda, etc. \n Please note if the Interfaces field - is non-empty then this field is ignored and should be specified - on the elements in the Interfaces list. \n If the Interfaces - field is empty and this field is not specified, then the default - interface's name will be eth0." - pattern: ^\w\w+$ - type: string - dhcp4: - description: "DHCP4 indicates whether or not to use DHCP for IP4 - networking. \n Please note this field is only supported if the - network connection supports DHCP. \n Please note this field - is mutually exclusive with IP4 addresses in the Addresses field - and the Gateway4 field. \n Please note if the Interfaces field - is non-empty then this field is ignored and should be specified - on the elements in the Interfaces list." - type: boolean - dhcp6: - description: "DHCP6 indicates whether or not to use DHCP for IP6 - networking. \n Please note this field is only supported if the - network connection supports DHCP. \n Please note this field - is mutually exclusive with IP4 addresses in the Addresses field - and the Gateway6 field. \n Please note if the Interfaces field - is non-empty then this field is ignored and should be specified - on the elements in the Interfaces list." - type: boolean disabled: description: "Disabled is a flag that indicates whether or not to disable networking for this VM. \n When set to true, the VM is not configured with a default interface nor any specified from the Interfaces field." type: boolean - gateway4: - description: "Gateway4 is the default, IP4 gateway for this VM. - \n Please note this field is only supported if the network connection - supports manual IP allocation. \n If the network connection - supports manual IP allocation and the Addresses field includes - at least one IP4 address, then this field is required. \n Please - note the IP address must include the network prefix length, - ex. 192.168.0.1/24. \n Please note this field is mutually exclusive - with DHCP4. \n Please note if the Interfaces field is non-empty - then this field is ignored and should be specified on the elements - in the Interfaces list." - type: string - gateway6: - description: "Gateway6 is the primary IP6 gateway for this VM. - \n Please note this field is only supported if the network connection - supports manual IP allocation. \n If the network connection - supports manual IP allocation and the Addresses field includes - at least one IP4 address, then this field is required. \n Please - note the IP address must include the network prefix length, - ex. 2001:db8:101::1/64. \n Please note this field is mutually - exclusive with DHCP6. \n Please note if the Interfaces field - is non-empty then this field is ignored and should be specified - on the elements in the Interfaces list." - type: string hostName: description: "HostName is the value the guest uses as its host name. If omitted then the name of the VM will be used. \n Please @@ -1607,9 +1598,9 @@ spec: type: string interfaces: description: "Interfaces is the list of network interfaces used - by this VM. \n Please note this field is mutually exclusive - with the following fields: DeviceName, Network, Addresses, DHCP4, - DHCP6, Gateway4, Gateway6, MTU, Nameservers, Routes, and SearchDomains." + by this VM. \n If the Interfaces field is empty and the Disabled + field is false, then a default interface with the name eth0 + will be created." items: description: VirtualMachineNetworkInterfaceSpec describes the desired state of a VM's network interface. @@ -1640,7 +1631,7 @@ spec: description: "DHCP6 indicates whether or not this interface uses DHCP for IP6 networking. \n Please note this field is only supported if the network connection supports DHCP. - \n Please note this field is mutually exclusive with IP4 + \n Please note this field is mutually exclusive with IP6 addresses in the Addresses field and the Gateway6 field." type: boolean gateway4: @@ -1658,7 +1649,7 @@ spec: interface. \n Please note this field is only supported if the network connection supports manual IP allocation. \n If the network connection supports manual IP allocation - and the Addresses field includes at least one IP4 address, + and the Addresses field includes at least one IP6 address, then this field is required. \n Please note the IP address must include the network prefix length, ex. 2001:db8:101::1/64. \n Please note this field is mutually exclusive with DHCP6." @@ -1729,10 +1720,10 @@ spec: format: int32 type: integer to: - description: To is an IP4 address. + description: To is an IP4 or IP6 address. type: string via: - description: Via is an IP4 address. + description: Via is an IP4 or IP6 address. type: string required: - metric @@ -1756,89 +1747,6 @@ spec: x-kubernetes-list-map-keys: - name x-kubernetes-list-type: map - mtu: - description: "MTU is the Maximum Transmission Unit size in bytes. - \n Please note this feature is available only with the following - bootstrap providers: CloudInit. \n Please note if the Interfaces - field is non-empty then this field is ignored and should be - specified on the elements in the Interfaces list." - format: int64 - type: integer - nameservers: - description: "Nameservers is a list of IP4 and/or IP6 addresses - used as DNS nameservers. \n Please note this feature is available - only with the following bootstrap providers: CloudInit, LinuxPrep, - and Sysprep (except for RawSysprep). \n Please note that Linux - allows only three nameservers (https://linux.die.net/man/5/resolv.conf). - \n Please note if the Interfaces field is non-empty then this - field is ignored and should be specified on the elements in - the Interfaces list." - items: - type: string - type: array - network: - description: "Network is the optional name of the network resource - to which this VM is connected. \n Please note if the Interfaces - field is non-empty then this field is ignored. \n If networking - is not disabled, no interfaces are defined, and this value is - omitted, then the VM will be provided a single virtual network - interface and connected to the Namespace's default network." - properties: - apiVersion: - description: 'APIVersion defines the versioned schema of this - representation of an object. Servers should convert recognized - schemas to the latest internal value, and may reject unrecognized - values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources' - type: string - kind: - description: 'Kind is a string value representing the REST - resource this object represents. Servers may infer this - from the endpoint the client submits requests to. Cannot - be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds' - type: string - name: - description: 'Name refers to a unique resource in the current - namespace. More info: http://kubernetes.io/docs/user-guide/identifiers#names' - type: string - required: - - name - type: object - routes: - description: "Routes is a list of optional, static routes. \n - Please note this feature is available only with the following - bootstrap providers: CloudInit. \n Please note if the Interfaces - field is non-empty then this field is ignored and should be - specified on the elements in the Interfaces list." - items: - description: VirtualMachineNetworkRouteSpec defines a static - route for a guest. - properties: - metric: - description: Metric is the weight/priority of the route. - format: int32 - type: integer - to: - description: To is an IP4 address. - type: string - via: - description: Via is an IP4 address. - type: string - required: - - metric - - to - - via - type: object - type: array - searchDomains: - description: "SearchDomains is a list of search domains used when - resolving IP addresses with DNS. \n Please note this feature - is available only with the following bootstrap providers: CloudInit, - LinuxPrep, and Sysprep (except for RawSysprep). \n Please note - if the Interfaces field is non-empty then this field is ignored - and should be specified on the elements in the Interfaces list." - items: - type: string - type: array type: object nextRestartTime: description: "NextRestartTime may be used to restart the VM, in accordance @@ -2205,6 +2113,12 @@ spec: - type type: object type: array + hardwareVersion: + description: "HardwareVersion describes the VirtualMachine resource's + observed hardware version. \n Please refer to VirtualMachineSpec.MinHardwareVersion + for more information on the topic of a VM's hardware version." + format: int32 + type: integer host: description: Host describes the hostname or IP address of the infrastructure host where the VM is executed. @@ -2708,6 +2622,6 @@ spec: type: object type: object served: true - storage: false + storage: true subresources: status: {} diff --git a/config/deployments/integration-tests/crds/vmoperator.vmware.com_virtualmachineservices.yaml b/config/deployments/integration-tests/crds/vmoperator.vmware.com_virtualmachineservices.yaml index 8a442c4bb9..a41610b085 100644 --- a/config/deployments/integration-tests/crds/vmoperator.vmware.com_virtualmachineservices.yaml +++ b/config/deployments/integration-tests/crds/vmoperator.vmware.com_virtualmachineservices.yaml @@ -174,7 +174,7 @@ spec: type: object type: object served: true - storage: true + storage: false subresources: status: {} - additionalPrinterColumns: @@ -322,6 +322,6 @@ spec: type: object type: object served: true - storage: false + storage: true subresources: status: {} diff --git a/config/deployments/integration-tests/crds/vmoperator.vmware.com_virtualmachinesetresourcepolicies.yaml b/config/deployments/integration-tests/crds/vmoperator.vmware.com_virtualmachinesetresourcepolicies.yaml index 92755f5faf..b20bb26b0e 100644 --- a/config/deployments/integration-tests/crds/vmoperator.vmware.com_virtualmachinesetresourcepolicies.yaml +++ b/config/deployments/integration-tests/crds/vmoperator.vmware.com_virtualmachinesetresourcepolicies.yaml @@ -123,7 +123,7 @@ spec: type: object type: object served: true - storage: true + storage: false subresources: status: {} - name: v1alpha2 @@ -221,6 +221,6 @@ spec: type: object type: object served: true - storage: false + storage: true subresources: status: {} diff --git a/config/deployments/integration-tests/crds/vmoperator.vmware.com_virtualmachinewebconsolerequests.yaml b/config/deployments/integration-tests/crds/vmoperator.vmware.com_virtualmachinewebconsolerequests.yaml index 7e243b0a3d..4da6fb2cf4 100644 --- a/config/deployments/integration-tests/crds/vmoperator.vmware.com_virtualmachinewebconsolerequests.yaml +++ b/config/deployments/integration-tests/crds/vmoperator.vmware.com_virtualmachinewebconsolerequests.yaml @@ -40,8 +40,13 @@ spec: description: Name is the name of a VM in the same Namespace as this web console request. type: string + publicKey: + description: PublicKey is used to encrypt the status.response. This + is expected to be a RSA OAEP public key in X.509 PEM format. + type: string required: - name + - publicKey type: object status: description: VirtualMachineWebConsoleRequestStatus describes the observed @@ -64,6 +69,10 @@ spec: by Go's https://pkg.go.dev/net#ResolveIPAddr and https://pkg.go.dev/net#ParseIP functions." type: string + response: + description: Response will be the authenticated ticket corresponding + to this web console request. + type: string type: object type: object served: true diff --git a/config/supervisor/crd/vmware.infrastructure.cluster.x-k8s.io_vspheremachines.yaml b/config/supervisor/crd/vmware.infrastructure.cluster.x-k8s.io_vspheremachines.yaml index acc2e5c611..a28498b8bd 100644 --- a/config/supervisor/crd/vmware.infrastructure.cluster.x-k8s.io_vspheremachines.yaml +++ b/config/supervisor/crd/vmware.infrastructure.cluster.x-k8s.io_vspheremachines.yaml @@ -62,6 +62,12 @@ spec: description: ImageName is the name of the base image used when specifying the underlying virtual machine type: string + minHardwareVersion: + description: MinHardwareVersion specifies the desired minimum hardware + version for this VM. Setting this field will ensure that the hardware + version of the VM is at least set to the specified value. The expected + format of the field is vmx-15. + type: string powerOffMode: default: hard description: "PowerOffMode describes the desired behavior when powering @@ -79,7 +85,7 @@ spec: - trySoft type: string providerID: - description: ProviderID is the virtual machine's BIOS UUID formated + description: ProviderID is the virtual machine's BIOS UUID formatted as vsphere://12345678-1234-1234-1234-123456789abc. This is required at runtime by CAPI. Do not remove this field. type: string diff --git a/config/supervisor/crd/vmware.infrastructure.cluster.x-k8s.io_vspheremachinetemplates.yaml b/config/supervisor/crd/vmware.infrastructure.cluster.x-k8s.io_vspheremachinetemplates.yaml index 746107b352..4c0fa434bb 100644 --- a/config/supervisor/crd/vmware.infrastructure.cluster.x-k8s.io_vspheremachinetemplates.yaml +++ b/config/supervisor/crd/vmware.infrastructure.cluster.x-k8s.io_vspheremachinetemplates.yaml @@ -58,6 +58,12 @@ spec: description: ImageName is the name of the base image used when specifying the underlying virtual machine type: string + minHardwareVersion: + description: MinHardwareVersion specifies the desired minimum + hardware version for this VM. Setting this field will ensure + that the hardware version of the VM is at least set to the + specified value. The expected format of the field is vmx-15. + type: string powerOffMode: default: hard description: "PowerOffMode describes the desired behavior @@ -77,7 +83,7 @@ spec: type: string providerID: description: ProviderID is the virtual machine's BIOS UUID - formated as vsphere://12345678-1234-1234-1234-123456789abc. + formatted as vsphere://12345678-1234-1234-1234-123456789abc. This is required at runtime by CAPI. Do not remove this field. type: string diff --git a/go.mod b/go.mod index 202f156293..0a0dce3037 100644 --- a/go.mod +++ b/go.mod @@ -14,7 +14,7 @@ require ( github.com/spf13/cobra v1.8.0 github.com/stretchr/testify v1.8.4 github.com/vmware-tanzu/net-operator-api v0.0.0-20210401185409-b0dc6c297707 - github.com/vmware-tanzu/vm-operator/api v1.8.2 + github.com/vmware-tanzu/vm-operator/api v1.8.3-0.20231114230806-852c1641447a github.com/vmware-tanzu/vm-operator/external/ncp v0.0.0-20211209213435-0f4ab286f64f github.com/vmware-tanzu/vm-operator/external/tanzu-topology v0.0.0-20211209213435-0f4ab286f64f github.com/vmware/govmomi v0.33.1 diff --git a/go.sum b/go.sum index 9c4f4574ee..fac7b1996b 100644 --- a/go.sum +++ b/go.sum @@ -657,8 +657,8 @@ github.com/valyala/fastjson v1.6.4 h1:uAUNq9Z6ymTgGhcm0UynUAB6tlbakBrz6CQFax3BXV github.com/valyala/fastjson v1.6.4/go.mod h1:CLCAqky6SMuOcxStkYQvblddUtoRxhYMGLrsQns1aXY= github.com/vmware-tanzu/net-operator-api v0.0.0-20210401185409-b0dc6c297707 h1:2onys8tWlQh7DFiOz6+68AwJdW9EBOEv6RTKzwh1x7A= github.com/vmware-tanzu/net-operator-api v0.0.0-20210401185409-b0dc6c297707/go.mod h1:pDB0pUiFYufuP3lUkQX9fZ67PYnKvqBpDcJN3mSrw5U= -github.com/vmware-tanzu/vm-operator/api v1.8.2 h1:7cZHVusqAmAMFWvsiU7X5xontxdjasknI/sVfe0p0Z4= -github.com/vmware-tanzu/vm-operator/api v1.8.2/go.mod h1:vauVboD3sQxP+pb28TnI9wfrj+0nH2zSEc9Q7AzWJ54= +github.com/vmware-tanzu/vm-operator/api v1.8.3-0.20231114230806-852c1641447a h1:4HHk5t/lSogK3xi/+myTJ6p2/5B5p3gEMQhrilvnUB0= +github.com/vmware-tanzu/vm-operator/api v1.8.3-0.20231114230806-852c1641447a/go.mod h1:SXaSFtnw2502Tzy0bfQVHrvbFDijR96r1ihUYQWPOK8= github.com/vmware-tanzu/vm-operator/external/ncp v0.0.0-20211209213435-0f4ab286f64f h1:RUuS5lh25citvQoXmDSfxJ1BB72LXOjD5cXvJETJ7Cc= github.com/vmware-tanzu/vm-operator/external/ncp v0.0.0-20211209213435-0f4ab286f64f/go.mod h1:5rqRJ9zGR+KnKbkGx373WgN8xJpvAj99kHnfoDYRO5I= github.com/vmware-tanzu/vm-operator/external/tanzu-topology v0.0.0-20211209213435-0f4ab286f64f h1:wwYUf16/g8bLywQMQJB5VHbDtuf6aOFH24Ar2/yA7+I= diff --git a/pkg/services/vmoperator/vmopmachine.go b/pkg/services/vmoperator/vmopmachine.go index 0fe424cfe5..dcc94a4556 100644 --- a/pkg/services/vmoperator/vmopmachine.go +++ b/pkg/services/vmoperator/vmopmachine.go @@ -270,6 +270,15 @@ func (v VmopMachineService) reconcileVMOperatorVM(ctx context.Context, superviso dataSecretName = *dsn } + var minHardwareVersion int32 + if version := supervisorMachineCtx.VSphereMachine.Spec.MinHardwareVersion; version != "" { + hwVersion, err := infrautilv1.ParseHardwareVersion(version) + if err != nil { + return err + } + minHardwareVersion = int32(hwVersion) + } + _, err := ctrlutil.CreateOrPatch(ctx, v.Client, vmOperatorVM, func() error { // Define a new VM Operator virtual machine. // NOTE: Set field-by-field in order to preserve changes made directly @@ -284,6 +293,7 @@ func (v VmopMachineService) reconcileVMOperatorVM(ctx context.Context, superviso Transport: vmoprv1.VirtualMachineMetadataCloudInitTransport, } vmOperatorVM.Spec.PowerOffMode = vmoprv1.VirtualMachinePowerOpMode(supervisorMachineCtx.VSphereMachine.Spec.PowerOffMode) + vmOperatorVM.Spec.MinHardwareVersion = minHardwareVersion // VMOperator supports readiness probe and will add/remove endpoints to a // VirtualMachineService based on the outcome of the readiness check. diff --git a/pkg/util/vmx.go b/pkg/util/vmx.go index 82240b31c4..c53de60c91 100644 --- a/pkg/util/vmx.go +++ b/pkg/util/vmx.go @@ -25,12 +25,12 @@ import ( // and returns whether the first version is less than the second. // It returns an error if an invalid vmx version is passed. func LessThan(version1, version2 string) (bool, error) { - v1, err := getIntVersion(version1) + v1, err := ParseHardwareVersion(version1) if err != nil { return false, err } - v2, err := getIntVersion(version2) + v2, err := ParseHardwareVersion(version2) if err != nil { return false, err } @@ -38,7 +38,10 @@ func LessThan(version1, version2 string) (bool, error) { return v1 < v2, nil } -func getIntVersion(version string) (int, error) { +// ParseHardwareVersion returns the virtual machine hardware version from the input. +// It expects the input formatted as vmx-17, where the trailing number is +// virtual machine hardware version. +func ParseHardwareVersion(version string) (int, error) { versionStr := strings.TrimPrefix(version, "vmx-") return strconv.Atoi(versionStr) }