Skip to content

Commit

Permalink
Merge pull request #2239 from k8s-infra-cherrypick-robot/cherry-pick-…
Browse files Browse the repository at this point in the history
…2237-to-release-0.11

[release-0.11] 🐛 Fix support for `OpenStackMachine.Spec.SecurityGroups`
  • Loading branch information
k8s-ci-robot authored Nov 5, 2024
2 parents 2c82caa + 55bfc3b commit f35b019
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
3 changes: 3 additions & 0 deletions controllers/openstackmachine_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -527,6 +527,9 @@ func openStackMachineSpecToOpenStackServerSpec(openStackMachineSpec *infrav1.Ope
},
}
}
if len(openStackMachineSpec.SecurityGroups) > 0 {
serverPorts[i].SecurityGroups = append(serverPorts[i].SecurityGroups, openStackMachineSpec.SecurityGroups...)
}
}
openStackServerSpec.Ports = serverPorts

Expand Down
37 changes: 37 additions & 0 deletions controllers/openstackmachine_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,21 @@ func TestOpenStackMachineSpecToOpenStackServerSpec(t *testing.T) {
},
},
}
portOptsWithAdditionalSecurityGroup := []infrav1.PortOpts{
{
Network: &infrav1.NetworkParam{
ID: ptr.To(openStackCluster.Status.Network.ID),
},
SecurityGroups: []infrav1.SecurityGroupParam{
{
ID: ptr.To(openStackCluster.Status.WorkerSecurityGroup.ID),
},
{
ID: ptr.To(extraSecurityGroupUUID),
},
},
},
}
image := infrav1.ImageParam{Filter: &infrav1.ImageFilter{Name: ptr.To("my-image")}}
tags := []string{"tag1", "tag2"}
userData := &corev1.LocalObjectReference{Name: "server-data-secret"}
Expand All @@ -101,6 +116,28 @@ func TestOpenStackMachineSpecToOpenStackServerSpec(t *testing.T) {
UserDataRef: userData,
},
},
{
name: "Test a OpenStackMachineSpec to OpenStackServerSpec conversion with an additional security group",
spec: &infrav1.OpenStackMachineSpec{
Flavor: ptr.To(flavorName),
Image: image,
SSHKeyName: sshKeyName,
SecurityGroups: []infrav1.SecurityGroupParam{
{
ID: ptr.To(extraSecurityGroupUUID),
},
},
},
want: &infrav1alpha1.OpenStackServerSpec{
Flavor: ptr.To(flavorName),
IdentityRef: identityRef,
Image: image,
SSHKeyName: sshKeyName,
Ports: portOptsWithAdditionalSecurityGroup,
Tags: tags,
UserDataRef: userData,
},
},
}
for i := range tests {
tt := tests[i]
Expand Down

0 comments on commit f35b019

Please sign in to comment.