Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ require (
github.com/metal3-io/cluster-api-provider-metal3/api v0.0.0-20230131153742-d668fd7a03f0
github.com/onsi/ginkgo/v2 v2.8.0
github.com/onsi/gomega v1.26.0
github.com/openshift/api v0.0.0-20230201213816-61d971884921
github.com/openshift/api v0.0.0-20230210183623-c7a709d557d0
github.com/openshift/client-go v0.0.0-20230120202327-72f107311084
github.com/openshift/library-go v0.0.0-20230130232623-47904dd9ff5a
github.com/operator-framework/operator-sdk v0.5.1-0.20190301204940-c2efe6f74e7b
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -640,8 +640,8 @@ github.com/onsi/gomega v0.0.0-20170829124025-dcabb60a477c/go.mod h1:C1qb7wdrVGGV
github.com/onsi/gomega v1.7.0/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY=
github.com/onsi/gomega v1.26.0 h1:03cDLK28U6hWvCAns6NeydX3zIm4SF3ci69ulidS32Q=
github.com/onsi/gomega v1.26.0/go.mod h1:r+zV744Re+DiYCIPRlYOTxn0YkOLcAnW8k1xXdMPGhM=
github.com/openshift/api v0.0.0-20230201213816-61d971884921 h1:19XfhG/rG4oxNOQ1PNtHIjW23z2+QNHC6lH1VZWhSWY=
github.com/openshift/api v0.0.0-20230201213816-61d971884921/go.mod h1:ctXNyWanKEjGj8sss1KjjHQ3ENKFm33FFnS5BKaIPh4=
github.com/openshift/api v0.0.0-20230210183623-c7a709d557d0 h1:892oS23LBMlo4g6p1aspGmG4vGCakGOvN0jCPT4rtpw=
github.com/openshift/api v0.0.0-20230210183623-c7a709d557d0/go.mod h1:ctXNyWanKEjGj8sss1KjjHQ3ENKFm33FFnS5BKaIPh4=
github.com/openshift/client-go v0.0.0-20230120202327-72f107311084 h1:66uaqNwA+qYyQDwsMWUfjjau8ezmg1dzCqub13KZOcE=
github.com/openshift/client-go v0.0.0-20230120202327-72f107311084/go.mod h1:M3h9m001PWac3eAudGG3isUud6yBjr5XpzLYLLTlHKo=
github.com/openshift/library-go v0.0.0-20230130232623-47904dd9ff5a h1:OzF7I7mAzO4SBo5eO5CWoCTgMDydN/Tf2/Rq8YbMpT0=
Expand Down
42 changes: 42 additions & 0 deletions pkg/webhooks/machine_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -1484,6 +1484,32 @@ func validateNutanix(m *machinev1beta1.Machine, config *admissionConfig) (bool,
}
}

// validate bootType
if err = validateNutanixBootType(providerSpec.BootType); err != nil {
errs = append(errs, err)
}

// validate project if configured
if len(providerSpec.Project.Type) != 0 {
if err := validateNutanixResourceIdentifier("project", providerSpec.Project); err != nil {
errs = append(errs, err)
}
}

// validate categories if configured
if len(providerSpec.Categories) > 0 {
for _, category := range providerSpec.Categories {
if len(category.Key) < 1 || len(category.Key) > 64 {
err = field.Invalid(field.NewPath("providerSpec", "categories", "key"), category.Key, "key must be a string with length between 1 and 64.")
errs = append(errs, err)
}
if len(category.Value) < 1 || len(category.Value) > 64 {
err = field.Invalid(field.NewPath("providerSpec", "categories", "value"), category.Value, "value must be a string with length between 1 and 64.")
errs = append(errs, err)
}
}
}

if len(errs) > 0 {
return false, warnings, utilerrors.NewAggregate(errs)
}
Expand All @@ -1507,6 +1533,22 @@ func validateNutanixResourceIdentifier(resource string, identifier machinev1.Nut
return nil
}

func validateNutanixBootType(bootType machinev1.NutanixBootType) error {
parentPath := field.NewPath("providerSpec")
// verify the bootType configurations
// Type bootType field is optional, and valid values include: "", Legacy, UEFI, SecureBoot
switch bootType {
case "", machinev1.NutanixLegacyBoot, machinev1.NutanixUEFIBoot, machinev1.NutanixSecureBoot:
// valid bootType
default:
errMsg := fmt.Sprintf("valid bootType values are: \"\", %q, %q, %q.",
machinev1.NutanixLegacyBoot, machinev1.NutanixUEFIBoot, machinev1.NutanixSecureBoot)
return field.Invalid(parentPath.Child("bootType"), bootType, errMsg)
}

return nil
}

func isAzureGovCloud(platformStatus *osconfigv1.PlatformStatus) bool {
return platformStatus != nil && platformStatus.Azure != nil &&
platformStatus.Azure.CloudName != osconfigv1.AzurePublicCloud
Expand Down
17 changes: 17 additions & 0 deletions pkg/webhooks/machine_webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4691,6 +4691,23 @@ func TestValidateNutanixProviderSpec(t *testing.T) {
expectedOk: false,
expectedError: "providerSpec.credentialsSecret: Required value: credentialsSecret must be provided",
},
{
testCase: "with invalid bootType provided",
modifySpec: func(p *machinev1.NutanixMachineProviderConfig) {
p.BootType = "invalid"
},
expectedOk: false,
expectedError: fmt.Sprintf("providerSpec.bootType: Invalid value: \"invalid\": valid bootType values are: \"\", %q, %q, %q.", machinev1.NutanixLegacyBoot, machinev1.NutanixUEFIBoot, machinev1.NutanixSecureBoot),
},
{
testCase: "with invalid categories provided",
modifySpec: func(p *machinev1.NutanixMachineProviderConfig) {
p.Categories = append(p.Categories, machinev1.NutanixCategory{Key: "key1",
Value: "val0123456789012345678901234567890123456789012345678901234567890123456789"})
},
expectedOk: false,
expectedError: "providerSpec.categories.value: Invalid value: \"val0123456789012345678901234567890123456789012345678901234567890123456789\": value must be a string with length between 1 and 64.",
},
{
testCase: "with all required fields it succeeds",
expectedOk: true,
Expand Down

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

Loading