Skip to content

Commit 80301b1

Browse files
Merge pull request #1267 from chiragkyal/use-pointer
OCPBUGS-36469: Update validation for placementGroupPartition to honour it as pointer
2 parents e959540 + 905f97e commit 80301b1

22 files changed

+103
-92
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-20240613141850-76a71dac36a0
13+
github.com/openshift/api v0.0.0-20240708071937-c9a91940bf0f
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-20240613141850-76a71dac36a0 h1:Kn16YZDBGwetg+pMQ0u0/3aOxRXQJi/1lu6rIlK+1So=
480-
github.com/openshift/api v0.0.0-20240613141850-76a71dac36a0/go.mod h1:OOh6Qopf21pSzqNVCB5gomomBXb8o5sGKZxG2KNpaXM=
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=
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: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -746,28 +746,30 @@ func validateAWS(m *machinev1beta1.Machine, config *admissionConfig) (bool, []st
746746
)
747747
}
748748

749-
// placementGroupPartition must be between 1 and 7 if it's not 0 (default).
750-
if providerSpec.PlacementGroupPartition < 0 || providerSpec.PlacementGroupPartition > 7 {
751-
errs = append(
752-
errs,
753-
field.Invalid(
754-
field.NewPath("providerSpec", "placementGroupPartition"),
755-
providerSpec.PlacementGroupPartition,
756-
"placementGroupPartition must be between 1 and 7",
757-
),
758-
)
759-
}
760-
761-
// If placementGroupPartition is not 0 (default), placementGroupName must be set.
762-
if providerSpec.PlacementGroupName == "" && providerSpec.PlacementGroupPartition != 0 {
763-
errs = append(
764-
errs,
765-
field.Invalid(
766-
field.NewPath("providerSpec", "placementGroupPartition"),
767-
providerSpec.PlacementGroupPartition,
768-
"providerSpec.placementGroupPartition is set but providerSpec.placementGroupName is empty",
769-
),
770-
)
749+
if providerSpec.PlacementGroupPartition != nil {
750+
partition := *providerSpec.PlacementGroupPartition
751+
// placementGroupPartition must be between 1 and 7
752+
if partition < 1 || partition > 7 {
753+
errs = append(
754+
errs,
755+
field.Invalid(
756+
field.NewPath("providerSpec", "placementGroupPartition"),
757+
partition,
758+
"providerSpec.placementGroupPartition must be between 1 and 7",
759+
),
760+
)
761+
}
762+
// placementGroupName must be set
763+
if providerSpec.PlacementGroupName == "" {
764+
errs = append(
765+
errs,
766+
field.Invalid(
767+
field.NewPath("providerSpec", "placementGroupPartition"),
768+
partition,
769+
"providerSpec.placementGroupPartition is set but providerSpec.placementGroupName is empty",
770+
),
771+
)
772+
}
771773
}
772774

773775
duplicatedTags := getDuplicatedTags(providerSpec.Tags)

pkg/webhooks/machine_webhook_test.go

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2137,7 +2137,8 @@ func TestValidateAWSProviderSpec(t *testing.T) {
21372137
testCase: "fail if placementGroupPartition is set, but placementGroupName is empty",
21382138
modifySpec: func(p *machinev1beta1.AWSMachineProviderConfig) {
21392139
p.PlacementGroupName = ""
2140-
p.PlacementGroupPartition = 2
2140+
partition := int32(2)
2141+
p.PlacementGroupPartition = &partition
21412142
},
21422143
expectedOk: false,
21432144
expectedError: "providerSpec.placementGroupPartition: Invalid value: 2: providerSpec.placementGroupPartition is set but providerSpec.placementGroupName is empty",
@@ -2146,19 +2147,21 @@ func TestValidateAWSProviderSpec(t *testing.T) {
21462147
testCase: "fail if placementGroupPartition is outside 1-7 range (lower)",
21472148
modifySpec: func(p *machinev1beta1.AWSMachineProviderConfig) {
21482149
p.PlacementGroupName = "placement-group"
2149-
p.PlacementGroupPartition = -1
2150+
partition := int32(0)
2151+
p.PlacementGroupPartition = &partition
21502152
},
21512153
expectedOk: false,
2152-
expectedError: "providerSpec.placementGroupPartition: Invalid value: -1: placementGroupPartition must be between 1 and 7",
2154+
expectedError: "providerSpec.placementGroupPartition: Invalid value: 0: providerSpec.placementGroupPartition must be between 1 and 7",
21532155
},
21542156
{
21552157
testCase: "fail if placementGroupPartition is outside 1-7 range (upper)",
21562158
modifySpec: func(p *machinev1beta1.AWSMachineProviderConfig) {
21572159
p.PlacementGroupName = "placement-group"
2158-
p.PlacementGroupPartition = 8
2160+
partition := int32(8)
2161+
p.PlacementGroupPartition = &partition
21592162
},
21602163
expectedOk: false,
2161-
expectedError: "providerSpec.placementGroupPartition: Invalid value: 8: placementGroupPartition must be between 1 and 7",
2164+
expectedError: "providerSpec.placementGroupPartition: Invalid value: 8: providerSpec.placementGroupPartition must be between 1 and 7",
21622165
},
21632166
{
21642167
testCase: "allow if only placementGroupName is set",
@@ -2171,7 +2174,8 @@ func TestValidateAWSProviderSpec(t *testing.T) {
21712174
testCase: "allow if correct placementGroupName and placementGroupPartition are set",
21722175
modifySpec: func(p *machinev1beta1.AWSMachineProviderConfig) {
21732176
p.PlacementGroupName = "placement-group"
2174-
p.PlacementGroupPartition = 2
2177+
partition := int32(2)
2178+
p.PlacementGroupPartition = &partition
21752179
},
21762180
expectedOk: true,
21772181
},

vendor/github.com/openshift/api/config/v1/types_cluster_version.go

Lines changed: 0 additions & 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/v1/types_feature.go

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

vendor/github.com/openshift/api/config/v1/types_tlssecurityprofile.go

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

vendor/github.com/openshift/api/config/v1/zz_generated.crd-manifests/0000_00_cluster-version-operator_01_clusterversions-CustomNoUpgrade.crd.yaml

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

vendor/github.com/openshift/api/config/v1/zz_generated.crd-manifests/0000_00_cluster-version-operator_01_clusterversions-Default.crd.yaml

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

vendor/github.com/openshift/api/config/v1/zz_generated.crd-manifests/0000_00_cluster-version-operator_01_clusterversions-DevPreviewNoUpgrade.crd.yaml

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

0 commit comments

Comments
 (0)