Skip to content

Commit 077b4a2

Browse files
authored
Merge pull request kubernetes-sigs#2072 from arghya88/validate-filter-in-sg
🐛Validate that additional security groups can not have filters
2 parents 7636198 + 627104a commit 077b4a2

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

api/v1alpha3/awsmachine_webhook.go

+12
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ func (r *AWSMachine) ValidateCreate() error {
5353
allErrs = append(allErrs, r.validateRootVolume()...)
5454
allErrs = append(allErrs, r.validateNonRootVolumes()...)
5555
allErrs = append(allErrs, isValidSSHKey(r.Spec.SSHKeyName)...)
56+
allErrs = append(allErrs, r.validateAdditionalSecurityGroups()...)
5657

5758
return aggregateObjErrors(r.GroupVersionKind().GroupKind(), r.Name, allErrs)
5859
}
@@ -183,3 +184,14 @@ func (r *AWSMachine) Default() {
183184
r.Spec.CloudInit.SecureSecretsBackend = SecretBackendSecretsManager
184185
}
185186
}
187+
188+
func (r *AWSMachine) validateAdditionalSecurityGroups() field.ErrorList {
189+
var allErrs field.ErrorList
190+
191+
for _, additionalSecurityGroups := range r.Spec.AdditionalSecurityGroups {
192+
if len(additionalSecurityGroups.Filters) > 0 {
193+
allErrs = append(allErrs, field.Forbidden(field.NewPath("spec.additionalSecurityGroups"), "filters are not implemented for security groups and will be removed in a future release"))
194+
}
195+
}
196+
return allErrs
197+
}

api/v1alpha3/awsmachine_webhook_test.go

+18
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,24 @@ func TestAWSMachine_ValidateCreate(t *testing.T) {
138138
},
139139
wantErr: false,
140140
},
141+
{
142+
name: "additional security groups should not have filters",
143+
machine: &AWSMachine{
144+
Spec: AWSMachineSpec{
145+
AdditionalSecurityGroups: []AWSResourceReference{
146+
{
147+
Filters: []Filter{
148+
{
149+
Name: "example-name",
150+
Values: []string{"example-value"},
151+
},
152+
},
153+
},
154+
},
155+
},
156+
},
157+
wantErr: true,
158+
},
141159
}
142160
for _, tt := range tests {
143161
t.Run(tt.name, func(t *testing.T) {

0 commit comments

Comments
 (0)