-
Notifications
You must be signed in to change notification settings - Fork 261
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
🐛 Don't apply worker SG to control plane machines #1785
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -89,8 +89,9 @@ func getDefaultOpenStackMachine() *infrav1.OpenStackMachine { | |
ServerMetadata: map[string]string{ | ||
"test-metadata": "test-value", | ||
}, | ||
ConfigDrive: pointer.Bool(true), | ||
ServerGroupID: serverGroupUUID, | ||
ConfigDrive: pointer.Bool(true), | ||
SecurityGroups: []infrav1.SecurityGroupFilter{}, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: I think you're setting SecurityGroups to an empty list to avoid appending to nil here? If so, you don't need to do that: nil is a valid empty slice. Appending to it will create a slice in the same way that a new slice is created if you exceed the capacity of the existing slice: https://go.dev/play/p/Nhln2sbvEGD It's also safe and idiomatic to iterate over a nil slice in a for loop: https://go.dev/play/p/E5aqZHV51L0. This means, e.g. you don't need to write an additional guard like: if (slice != nil) {
for _, elem := range slice {
...
}
} There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good to know, but the reason I did this is dumber: I had set the instance spec There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not worth a respin just for this imho. |
||
ServerGroupID: serverGroupUUID, | ||
}, | ||
} | ||
} | ||
|
@@ -105,10 +106,11 @@ func getDefaultInstanceSpec() *compute.InstanceSpec { | |
Metadata: map[string]string{ | ||
"test-metadata": "test-value", | ||
}, | ||
ConfigDrive: *pointer.Bool(true), | ||
FailureDomain: *pointer.String(failureDomain), | ||
ServerGroupID: serverGroupUUID, | ||
Tags: []string{"test-tag"}, | ||
ConfigDrive: *pointer.Bool(true), | ||
FailureDomain: *pointer.String(failureDomain), | ||
ServerGroupID: serverGroupUUID, | ||
SecurityGroups: []infrav1.SecurityGroupFilter{}, | ||
Tags: []string{"test-tag"}, | ||
} | ||
} | ||
|
||
|
@@ -165,6 +167,44 @@ func Test_machineToInstanceSpec(t *testing.T) { | |
return i | ||
}, | ||
}, | ||
{ | ||
name: "Control plane security group not applied to worker", | ||
openStackCluster: func() *infrav1.OpenStackCluster { | ||
c := getDefaultOpenStackCluster() | ||
c.Spec.ManagedSecurityGroups = true | ||
c.Status.WorkerSecurityGroup = nil | ||
return c | ||
}, | ||
machine: getDefaultMachine, | ||
openStackMachine: getDefaultOpenStackMachine, | ||
wantInstanceSpec: func() *compute.InstanceSpec { | ||
i := getDefaultInstanceSpec() | ||
i.SecurityGroups = []infrav1.SecurityGroupFilter{} | ||
return i | ||
}, | ||
}, | ||
{ | ||
name: "Worker security group not applied to control plane", | ||
openStackCluster: func() *infrav1.OpenStackCluster { | ||
c := getDefaultOpenStackCluster() | ||
c.Spec.ManagedSecurityGroups = true | ||
c.Status.ControlPlaneSecurityGroup = nil | ||
return c | ||
}, | ||
machine: func() *clusterv1.Machine { | ||
m := getDefaultMachine() | ||
m.Labels = map[string]string{ | ||
clusterv1.MachineControlPlaneLabel: "true", | ||
} | ||
return m | ||
}, | ||
openStackMachine: getDefaultOpenStackMachine, | ||
wantInstanceSpec: func() *compute.InstanceSpec { | ||
i := getDefaultInstanceSpec() | ||
i.SecurityGroups = []infrav1.SecurityGroupFilter{} | ||
return i | ||
}, | ||
}, | ||
{ | ||
name: "Extra security group", | ||
openStackCluster: func() *infrav1.OpenStackCluster { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think in practise this would mean we're in some unusual state and we shouldn't reconcile at all until ControlPlaneSecurityGroup is set. However:
So I'm happy to merge this.