Skip to content

Commit b5a3246

Browse files
committed
CFE:1065 add webhook validation for placementGroupPartition
Signed-off-by: chiragkyal <[email protected]>
1 parent d33aa94 commit b5a3246

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

pkg/webhooks/machine_webhook.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -746,6 +746,17 @@ func validateAWS(m *machinev1beta1.Machine, config *admissionConfig) (bool, []st
746746
)
747747
}
748748

749+
if providerSpec.PlacementGroupName == "" && providerSpec.PlacementGroupPartition != 0 {
750+
errs = append(
751+
errs,
752+
field.Invalid(
753+
field.NewPath("providerSpec", "placementGroupPartition"),
754+
providerSpec.PlacementGroupPartition,
755+
"providerSpec.placementGroupPartition is set but providerSpec.placementGroupName is empty",
756+
),
757+
)
758+
}
759+
749760
duplicatedTags := getDuplicatedTags(providerSpec.Tags)
750761
if len(duplicatedTags) > 0 {
751762
warnings = append(warnings, fmt.Sprintf("providerSpec.tags: duplicated tag names (%s): only the first value will be used.", strings.Join(duplicatedTags, ",")))

pkg/webhooks/machine_webhook_test.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2133,6 +2133,30 @@ func TestValidateAWSProviderSpec(t *testing.T) {
21332133
expectedOk: false,
21342134
expectedError: "providerSpec.tenancy: Invalid value: \"invalid\": Invalid providerSpec.tenancy, the only allowed options are: default, dedicated, host",
21352135
},
2136+
{
2137+
testCase: "fail if placementGroupPartition is set, but placementGroupName is empty",
2138+
modifySpec: func(p *machinev1beta1.AWSMachineProviderConfig) {
2139+
p.PlacementGroupName = ""
2140+
p.PlacementGroupPartition = 2
2141+
},
2142+
expectedOk: false,
2143+
expectedError: "providerSpec.placementGroupPartition: Invalid value: 2: providerSpec.placementGroupPartition is set but providerSpec.placementGroupName is empty",
2144+
},
2145+
{
2146+
testCase: "allow if only placementGroupName is set",
2147+
modifySpec: func(p *machinev1beta1.AWSMachineProviderConfig) {
2148+
p.PlacementGroupName = "placement-group"
2149+
},
2150+
expectedOk: true,
2151+
},
2152+
{
2153+
testCase: "allow if both placementGroupName and placementGroupPartition are set",
2154+
modifySpec: func(p *machinev1beta1.AWSMachineProviderConfig) {
2155+
p.PlacementGroupName = "placement-group"
2156+
p.PlacementGroupPartition = 2
2157+
},
2158+
expectedOk: true,
2159+
},
21362160
{
21372161
testCase: "with no iam instance profile",
21382162
modifySpec: func(p *machinev1beta1.AWSMachineProviderConfig) {

0 commit comments

Comments
 (0)