Skip to content

Commit f35b019

Browse files
authored
Merge pull request #2239 from k8s-infra-cherrypick-robot/cherry-pick-2237-to-release-0.11
[release-0.11] 🐛 Fix support for `OpenStackMachine.Spec.SecurityGroups`
2 parents 2c82caa + 55bfc3b commit f35b019

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

controllers/openstackmachine_controller.go

+3
Original file line numberDiff line numberDiff line change
@@ -527,6 +527,9 @@ func openStackMachineSpecToOpenStackServerSpec(openStackMachineSpec *infrav1.Ope
527527
},
528528
}
529529
}
530+
if len(openStackMachineSpec.SecurityGroups) > 0 {
531+
serverPorts[i].SecurityGroups = append(serverPorts[i].SecurityGroups, openStackMachineSpec.SecurityGroups...)
532+
}
530533
}
531534
openStackServerSpec.Ports = serverPorts
532535

controllers/openstackmachine_controller_test.go

+37
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,21 @@ func TestOpenStackMachineSpecToOpenStackServerSpec(t *testing.T) {
7676
},
7777
},
7878
}
79+
portOptsWithAdditionalSecurityGroup := []infrav1.PortOpts{
80+
{
81+
Network: &infrav1.NetworkParam{
82+
ID: ptr.To(openStackCluster.Status.Network.ID),
83+
},
84+
SecurityGroups: []infrav1.SecurityGroupParam{
85+
{
86+
ID: ptr.To(openStackCluster.Status.WorkerSecurityGroup.ID),
87+
},
88+
{
89+
ID: ptr.To(extraSecurityGroupUUID),
90+
},
91+
},
92+
},
93+
}
7994
image := infrav1.ImageParam{Filter: &infrav1.ImageFilter{Name: ptr.To("my-image")}}
8095
tags := []string{"tag1", "tag2"}
8196
userData := &corev1.LocalObjectReference{Name: "server-data-secret"}
@@ -101,6 +116,28 @@ func TestOpenStackMachineSpecToOpenStackServerSpec(t *testing.T) {
101116
UserDataRef: userData,
102117
},
103118
},
119+
{
120+
name: "Test a OpenStackMachineSpec to OpenStackServerSpec conversion with an additional security group",
121+
spec: &infrav1.OpenStackMachineSpec{
122+
Flavor: ptr.To(flavorName),
123+
Image: image,
124+
SSHKeyName: sshKeyName,
125+
SecurityGroups: []infrav1.SecurityGroupParam{
126+
{
127+
ID: ptr.To(extraSecurityGroupUUID),
128+
},
129+
},
130+
},
131+
want: &infrav1alpha1.OpenStackServerSpec{
132+
Flavor: ptr.To(flavorName),
133+
IdentityRef: identityRef,
134+
Image: image,
135+
SSHKeyName: sshKeyName,
136+
Ports: portOptsWithAdditionalSecurityGroup,
137+
Tags: tags,
138+
UserDataRef: userData,
139+
},
140+
},
104141
}
105142
for i := range tests {
106143
tt := tests[i]

0 commit comments

Comments
 (0)