Skip to content

Commit 905f97e

Browse files
committed
update placementGroupPartition to use pointer
Signed-off-by: chiragkyal <[email protected]>
1 parent f88ae50 commit 905f97e

File tree

2 files changed

+34
-28
lines changed

2 files changed

+34
-28
lines changed

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
},

0 commit comments

Comments
 (0)