Skip to content

Commit a1c30a8

Browse files
Merge pull request #1266 from nutanix-cloud-native/nutanix-gpu-datadisks
CORS-3546: Nutanix: add gpus and dataDisks support
2 parents 3a817c7 + fcc35cd commit a1c30a8

19 files changed

+818
-24
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ require (
1010
github.com/google/uuid v1.6.0
1111
github.com/onsi/ginkgo/v2 v2.17.1
1212
github.com/onsi/gomega v1.32.0
13-
github.com/openshift/api v0.0.0-20240708071937-c9a91940bf0f
13+
github.com/openshift/api v0.0.0-20240731195412-e863d9f8a215
1414
github.com/openshift/client-go v0.0.0-20240528061634-b054aa794d87
1515
github.com/openshift/library-go v0.0.0-20240116081341-964bcb3f545c
1616
github.com/prometheus/client_golang v1.18.0

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -476,8 +476,8 @@ github.com/onsi/ginkgo/v2 v2.17.1 h1:V++EzdbhI4ZV4ev0UTIj0PzhzOcReJFyJaLjtSF55M8
476476
github.com/onsi/ginkgo/v2 v2.17.1/go.mod h1:llBI3WDLL9Z6taip6f33H76YcWtJv+7R3HigUjbIBOs=
477477
github.com/onsi/gomega v1.32.0 h1:JRYU78fJ1LPxlckP6Txi/EYqJvjtMrDC04/MM5XRHPk=
478478
github.com/onsi/gomega v1.32.0/go.mod h1:a4x4gW6Pz2yK1MAmvluYme5lvYTn61afQ2ETw/8n4Lg=
479-
github.com/openshift/api v0.0.0-20240708071937-c9a91940bf0f h1:NmJAlN2fPnL86aq5BbEQJ62v/D16LzIaaQ0Qn72s87E=
480-
github.com/openshift/api v0.0.0-20240708071937-c9a91940bf0f/go.mod h1:OOh6Qopf21pSzqNVCB5gomomBXb8o5sGKZxG2KNpaXM=
479+
github.com/openshift/api v0.0.0-20240731195412-e863d9f8a215 h1:NY9X6aNRa3PKTRj9nTncCoGRbdwiis2CL1T3miXxjoc=
480+
github.com/openshift/api v0.0.0-20240731195412-e863d9f8a215/go.mod h1:OOh6Qopf21pSzqNVCB5gomomBXb8o5sGKZxG2KNpaXM=
481481
github.com/openshift/client-go v0.0.0-20240528061634-b054aa794d87 h1:JtLhaGpSEconE+1IKmIgCOof/Len5ceG6H1pk43yv5U=
482482
github.com/openshift/client-go v0.0.0-20240528061634-b054aa794d87/go.mod h1:3IPD4U0qyovZS4EFady2kqY32m8lGcbs/Wx+yprg9z8=
483483
github.com/openshift/library-go v0.0.0-20240116081341-964bcb3f545c h1:gLylEQQryG+A6nqWYIwE1wUzn1eFUmthjADvflMWKnM=

pkg/webhooks/machine_webhook.go

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1665,12 +1665,124 @@ func validateNutanix(m *machinev1beta1.Machine, config *admissionConfig) (bool,
16651665
}
16661666
}
16671667

1668+
// validate gpus if configured
1669+
if len(providerSpec.GPUs) > 0 {
1670+
fldPath := field.NewPath("providerSpec", "gpus")
1671+
for _, gpu := range providerSpec.GPUs {
1672+
switch gpu.Type {
1673+
case machinev1.NutanixGPUIdentifierDeviceID:
1674+
if gpu.DeviceID == nil {
1675+
errs = append(errs, field.Required(fldPath.Child("deviceID"), "missing gpu deviceID"))
1676+
}
1677+
case machinev1.NutanixGPUIdentifierName:
1678+
if gpu.Name == nil || *gpu.Name == "" {
1679+
errs = append(errs, field.Required(fldPath.Child("name"), "missing gpu name"))
1680+
}
1681+
default:
1682+
errMsg := fmt.Sprintf("invalid gpu identifier type, the valid types: %q, %q.", machinev1.NutanixGPUIdentifierDeviceID, machinev1.NutanixGPUIdentifierName)
1683+
errs = append(errs, field.Invalid(fldPath.Child("type"), gpu.Type, errMsg))
1684+
}
1685+
}
1686+
}
1687+
1688+
// validate dataDisks if configured
1689+
if len(providerSpec.DataDisks) > 0 {
1690+
for _, fldErr := range validateNutanixDataDisks(providerSpec.DataDisks) {
1691+
errs = append(errs, fldErr)
1692+
}
1693+
}
1694+
16681695
if len(errs) > 0 {
16691696
return false, warnings, errs
16701697
}
16711698
return true, warnings, nil
16721699
}
16731700

1701+
func validateNutanixDataDisks(disks []machinev1.NutanixVMDisk) (fldErrs []*field.Error) {
1702+
fldPath := field.NewPath("providerSpec", "dataDisks")
1703+
var errMsg string
1704+
1705+
for _, disk := range disks {
1706+
// validate the minimum diskSize of 1Gi
1707+
diskSizeBytes := disk.DiskSize.Value()
1708+
if diskSizeBytes < 1024*1024*1024 {
1709+
fldErrs = append(fldErrs, field.Invalid(fldPath.Child("diskSize"), fmt.Sprintf("%v bytes", diskSizeBytes), "The minimum diskSize is 1Gi bytes."))
1710+
}
1711+
1712+
if disk.DeviceProperties != nil {
1713+
switch disk.DeviceProperties.DeviceType {
1714+
case machinev1.NutanixDiskDeviceTypeDisk:
1715+
switch disk.DeviceProperties.AdapterType {
1716+
case machinev1.NutanixDiskAdapterTypeSCSI, machinev1.NutanixDiskAdapterTypeIDE, machinev1.NutanixDiskAdapterTypePCI, machinev1.NutanixDiskAdapterTypeSATA, machinev1.NutanixDiskAdapterTypeSPAPR:
1717+
// valid configuration
1718+
default:
1719+
// invalid configuration
1720+
fldErrs = append(fldErrs, field.Invalid(fldPath.Child("deviceProperties", "adapterType"), disk.DeviceProperties.AdapterType,
1721+
fmt.Sprintf("invalid adapter type for the %q device type, the valid values: %q, %q, %q, %q, %q.",
1722+
machinev1.NutanixDiskDeviceTypeDisk, machinev1.NutanixDiskAdapterTypeSCSI, machinev1.NutanixDiskAdapterTypeIDE,
1723+
machinev1.NutanixDiskAdapterTypePCI, machinev1.NutanixDiskAdapterTypeSATA, machinev1.NutanixDiskAdapterTypeSPAPR)))
1724+
}
1725+
case machinev1.NutanixDiskDeviceTypeCDROM:
1726+
switch disk.DeviceProperties.AdapterType {
1727+
case machinev1.NutanixDiskAdapterTypeIDE, machinev1.NutanixDiskAdapterTypeSATA:
1728+
// valid configuration
1729+
default:
1730+
// invalid configuration
1731+
fldErrs = append(fldErrs, field.Invalid(fldPath.Child("deviceProperties", "adapterType"), disk.DeviceProperties.AdapterType,
1732+
fmt.Sprintf("invalid adapter type for the %q device type, the valid values: %q, %q.",
1733+
machinev1.NutanixDiskDeviceTypeCDROM, machinev1.NutanixDiskAdapterTypeIDE, machinev1.NutanixDiskAdapterTypeSATA)))
1734+
}
1735+
default:
1736+
fldErrs = append(fldErrs, field.Invalid(fldPath.Child("deviceProperties", "deviceType"), disk.DeviceProperties.DeviceType,
1737+
fmt.Sprintf("invalid device type, the valid types: %q, %q.", machinev1.NutanixDiskDeviceTypeDisk, machinev1.NutanixDiskDeviceTypeCDROM)))
1738+
}
1739+
1740+
if disk.DeviceProperties.DeviceIndex < 0 {
1741+
fldErrs = append(fldErrs, field.Invalid(fldPath.Child("deviceProperties", "deviceIndex"),
1742+
disk.DeviceProperties.DeviceIndex, "invalid device index, the valid values are non-negative integers."))
1743+
}
1744+
}
1745+
1746+
if disk.StorageConfig != nil {
1747+
if disk.StorageConfig.DiskMode != machinev1.NutanixDiskModeStandard && disk.StorageConfig.DiskMode != machinev1.NutanixDiskModeFlash {
1748+
fldErrs = append(fldErrs, field.Invalid(fldPath.Child("storageConfig", "diskMode"), disk.StorageConfig.DiskMode,
1749+
fmt.Sprintf("invalid disk mode, the valid values: %q, %q.", machinev1.NutanixDiskModeStandard, machinev1.NutanixDiskModeFlash)))
1750+
}
1751+
1752+
storageContainerRef := disk.StorageConfig.StorageContainer
1753+
if storageContainerRef != nil {
1754+
switch storageContainerRef.Type {
1755+
case machinev1.NutanixIdentifierUUID:
1756+
if storageContainerRef.UUID == nil || *storageContainerRef.UUID == "" {
1757+
fldErrs = append(fldErrs, field.Required(fldPath.Child("storageConfig", "storageContainer", "uuid"), "missing storageContainer uuid."))
1758+
}
1759+
default:
1760+
errMsg = fmt.Sprintf("invalid storageContainer reference type, the valid values: %q.", machinev1.NutanixIdentifierUUID)
1761+
fldErrs = append(fldErrs, field.Invalid(fldPath.Child("storageConfig", "storageContainer", "type"), storageContainerRef.Type, errMsg))
1762+
}
1763+
}
1764+
}
1765+
1766+
if disk.DataSource != nil {
1767+
switch disk.DataSource.Type {
1768+
case machinev1.NutanixIdentifierUUID:
1769+
if disk.DataSource.UUID == nil || *disk.DataSource.UUID == "" {
1770+
fldErrs = append(fldErrs, field.Required(fldPath.Child("dataSource", "uuid"), "missing disk dataSource uuid."))
1771+
}
1772+
case machinev1.NutanixIdentifierName:
1773+
if disk.DataSource.Name == nil || *disk.DataSource.Name == "" {
1774+
fldErrs = append(fldErrs, field.Required(fldPath.Child("dataSource", "name"), "missing disk dataSource name."))
1775+
}
1776+
default:
1777+
errMsg := fmt.Sprintf("invalid disk dataSource reference type, the valid values: %q, %q.", machinev1.NutanixIdentifierUUID, machinev1.NutanixIdentifierName)
1778+
fldErrs = append(fldErrs, field.Invalid(fldPath.Child("dataSource", "type"), disk.DataSource.Type, errMsg))
1779+
}
1780+
}
1781+
}
1782+
1783+
return fldErrs
1784+
}
1785+
16741786
func validateNutanixResourceIdentifier(resource string, identifier machinev1.NutanixResourceIdentifier) *field.Error {
16751787
parentPath := field.NewPath("providerSpec")
16761788
if identifier.Type == machinev1.NutanixIdentifierName {

pkg/webhooks/machine_webhook_test.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5058,6 +5058,22 @@ func TestValidateNutanixProviderSpec(t *testing.T) {
50585058
expectedOk: false,
50595059
expectedError: "providerSpec.categories.value: Invalid value: \"val0123456789012345678901234567890123456789012345678901234567890123456789\": value must be a string with length between 1 and 64.",
50605060
},
5061+
{
5062+
testCase: "with invalid gpu reference type provided",
5063+
modifySpec: func(p *machinev1.NutanixMachineProviderConfig) {
5064+
p.GPUs = append(p.GPUs, machinev1.NutanixGPU{Type: "invalid"})
5065+
},
5066+
expectedOk: false,
5067+
expectedError: "providerSpec.gpus.type: Invalid value: \"invalid\": invalid gpu identifier type, the valid types: \"DeviceID\", \"Name\".",
5068+
},
5069+
{
5070+
testCase: "with too small diskSize provided",
5071+
modifySpec: func(p *machinev1.NutanixMachineProviderConfig) {
5072+
p.DataDisks = append(p.DataDisks, machinev1.NutanixVMDisk{DiskSize: resource.MustParse("500Mi")})
5073+
},
5074+
expectedOk: false,
5075+
expectedError: "providerSpec.dataDisks.diskSize: Invalid value: \"524288000 bytes\": The minimum diskSize is 1Gi bytes.",
5076+
},
50615077
{
50625078
testCase: "with all required fields it succeeds",
50635079
expectedOk: true,

vendor/github.com/openshift/api/config/v1alpha1/types_cluster_image_policy.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/openshift/api/config/v1alpha1/types_image_policy.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/openshift/api/config/v1alpha1/zz_generated.featuregated-crd-manifests.yaml

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/openshift/api/features.md

Lines changed: 5 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)