Skip to content

Commit

Permalink
Webhook validation for vgpuProfile
Browse files Browse the repository at this point in the history
  • Loading branch information
birksl committed May 31, 2024
1 parent bc85b61 commit 7a1af63
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 170 deletions.
3 changes: 3 additions & 0 deletions apis/v1beta1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,16 +251,19 @@ type PCIDeviceSpec struct {
// DeviceID is the device ID of a virtual machine's PCI, in integer.
// Defaults to the eponymous property value in the template from which the
// virtual machine is cloned.
// Mutually exclusive with VGPUProfile.
// +kubebuilder:validation:Required
DeviceID *int32 `json:"deviceId,omitempty"`
// VendorId is the vendor ID of a virtual machine's PCI, in integer.
// Defaults to the eponymous property value in the template from which the
// virtual machine is cloned.
// Mutually exclusive with VGPUProfile.
// +kubebuilder:validation:Required
VendorID *int32 `json:"vendorId,omitempty"`
// VGPUProfile is the profile name of a virtual machine's vGPU, in string.
// Defaults to the eponymous property value in the template from which the
// virtual machine is cloned.
// Mutually exclusive with DeviceID and VendorID.
// +kubebuilder:validation:Required
VGPUProfile string `json:"vgpuProfile,omitempty"`
// CustomLabel is the hardware label of a virtual machine's PCI device.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1221,18 +1221,21 @@ spec:
description: DeviceID is the device ID of a virtual machine's
PCI, in integer. Defaults to the eponymous property value
in the template from which the virtual machine is cloned.
Mutually exclusive with VGPUProfile.
format: int32
type: integer
vendorId:
description: VendorId is the vendor ID of a virtual machine's
PCI, in integer. Defaults to the eponymous property value
in the template from which the virtual machine is cloned.
Mutually exclusive with VGPUProfile.
format: int32
type: integer
vgpuProfile:
description: VGPUProfile is the VGPUProfile of a virtual machine's
description: VGPUProfile is the profile name of a virtual machine's
vGPU, in string. Defaults to the eponymous property value
in the template from which the virtual machine is cloned.
Mutually exclusive with DeviceID and VendorID.
type: string
type: object
type: array
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1133,21 +1133,22 @@ spec:
description: DeviceID is the device ID of a virtual
machine's PCI, in integer. Defaults to the eponymous
property value in the template from which the virtual
machine is cloned.
machine is cloned. Mutually exclusive with VGPUProfile.
format: int32
type: integer
vendorId:
description: VendorId is the vendor ID of a virtual
machine's PCI, in integer. Defaults to the eponymous
property value in the template from which the virtual
machine is cloned.
machine is cloned. Mutually exclusive with VGPUProfile.
format: int32
type: integer
vgpuProfile:
description: VGPUProfile is the VGPUProfile of a virtual
description: VGPUProfile is the profile name of a virtual
machine's vGPU, in string. Defaults to the eponymous
property value in the template from which the virtual
machine is cloned.
machine is cloned. Mutually exclusive with DeviceID
and VendorID.
type: string
type: object
type: array
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1267,18 +1267,21 @@ spec:
description: DeviceID is the device ID of a virtual machine's
PCI, in integer. Defaults to the eponymous property value
in the template from which the virtual machine is cloned.
Mutually exclusive with VGPUProfile.
format: int32
type: integer
vendorId:
description: VendorId is the vendor ID of a virtual machine's
PCI, in integer. Defaults to the eponymous property value
in the template from which the virtual machine is cloned.
Mutually exclusive with VGPUProfile.
format: int32
type: integer
vgpuProfile:
description: VGPUProfile is the VGPUProfile of a virtual machine's
description: VGPUProfile is the profile name of a virtual machine's
vGPU, in string. Defaults to the eponymous property value
in the template from which the virtual machine is cloned.
Mutually exclusive with DeviceID and VendorID.
type: string
type: object
type: array
Expand Down
7 changes: 7 additions & 0 deletions internal/webhooks/vspheremachinetemplate.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,13 @@ func (webhook *VSphereMachineTemplateWebhook) ValidateCreate(_ context.Context,
allErrs = append(allErrs, field.Invalid(field.NewPath("spec", "template", "spec", "guestSoftPowerOffTimeout"), spec.GuestSoftPowerOffTimeout, "should be greater than 0"))
}
}
for _, device := range spec.PciDevices {
hasVGPU := device.VGPUProfile != ""
hasPCI := device.DeviceID != nil && device.VendorID != nil
if (hasPCI && hasVGPU) || (!hasPCI && !hasVGPU) {
allErrs = append(allErrs, field.Invalid(field.NewPath("spec", "template", "spec", "pciDevices"), spec.PciDevices, "should have either deviceID + vendorID or vgpuProfile"))
}
}
return nil, AggregateObjErrors(obj.GroupVersionKind().GroupKind(), obj.Name, allErrs)
}

Expand Down
163 changes: 0 additions & 163 deletions test/e2e/config/vsphere-dev.yaml

This file was deleted.

1 change: 0 additions & 1 deletion test/e2e/config/vsphere.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,6 @@ variables:
# These IDs correspond to Tesla T4s, they are the decimal representation of the hex values.
DEVICE_ID: 7864
VENDOR_ID: 4318
PROFILE_NAME: grid_v100d-4c
# CAPV feature flags
EXP_NODE_ANTI_AFFINITY: "true"
CAPI_DIAGNOSTICS_ADDRESS: ":8080"
Expand Down

0 comments on commit 7a1af63

Please sign in to comment.