Skip to content

Commit 87e406c

Browse files
committed
Rename managedSecurityGroups.allNodesSecurityGroupRules
Rename `spec.managedSecurityGroups.allNodesSecurityGroupRules` to `spec.managedSecurityGroups.clusterNodesSecurityGroupRules` to clarify that these rules apply only to cluster nodes (control plane and workers), and not to other managed resources such as the bastion host.
1 parent aa3b922 commit 87e406c

17 files changed

Lines changed: 270 additions & 101 deletions

api/v1beta1/conversion.go

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,46 @@ func Convert_v1beta2_OpenStackClusterSpec_To_v1beta1_OpenStackClusterSpec(
430430
return nil
431431
}
432432

433+
func Convert_v1beta1_ManagedSecurityGroups_To_v1beta2_ManagedSecurityGroups(
434+
in *ManagedSecurityGroups,
435+
out *infrav1.ManagedSecurityGroups,
436+
s apiconversion.Scope,
437+
) error {
438+
if err := autoConvert_v1beta1_ManagedSecurityGroups_To_v1beta2_ManagedSecurityGroups(in, out, s); err != nil {
439+
return err
440+
}
441+
442+
if len(in.AllNodesSecurityGroupRules) > 0 {
443+
out.ClusterNodesSecurityGroupRules = make([]infrav1.SecurityGroupRuleSpec, len(in.AllNodesSecurityGroupRules))
444+
for i := range in.AllNodesSecurityGroupRules {
445+
if err := Convert_v1beta1_SecurityGroupRuleSpec_To_v1beta2_SecurityGroupRuleSpec(&in.AllNodesSecurityGroupRules[i], &out.ClusterNodesSecurityGroupRules[i], s); err != nil {
446+
return err
447+
}
448+
}
449+
}
450+
return nil
451+
}
452+
453+
func Convert_v1beta2_ManagedSecurityGroups_To_v1beta1_ManagedSecurityGroups(
454+
in *infrav1.ManagedSecurityGroups,
455+
out *ManagedSecurityGroups,
456+
s apiconversion.Scope,
457+
) error {
458+
if err := autoConvert_v1beta2_ManagedSecurityGroups_To_v1beta1_ManagedSecurityGroups(in, out, s); err != nil {
459+
return err
460+
}
461+
462+
if len(in.ClusterNodesSecurityGroupRules) > 0 {
463+
out.AllNodesSecurityGroupRules = make([]SecurityGroupRuleSpec, len(in.ClusterNodesSecurityGroupRules))
464+
for i := range in.ClusterNodesSecurityGroupRules {
465+
if err := Convert_v1beta2_SecurityGroupRuleSpec_To_v1beta1_SecurityGroupRuleSpec(&in.ClusterNodesSecurityGroupRules[i], &out.AllNodesSecurityGroupRules[i], s); err != nil {
466+
return err
467+
}
468+
}
469+
}
470+
return nil
471+
}
472+
433473
// LegacyCalicoSecurityGroupRules returns a list of security group rules for calico
434474
// that need to be applied to the control plane and worker security groups when
435475
// managed security groups are enabled and upgrading to v1beta1.

api/v1beta1/conversion_test.go

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1115,3 +1115,104 @@ func TestOpenStackCluster_RoundTrip_ManagedRouter(t *testing.T) {
11151115
})
11161116
}
11171117
}
1118+
1119+
func TestOpenStackCluster_RoundTrip_ManagedSecurityGroups_ClusterNodesRules(t *testing.T) {
1120+
tests := []struct {
1121+
name string
1122+
in OpenStackCluster
1123+
}{
1124+
{
1125+
name: "single rule",
1126+
in: OpenStackCluster{
1127+
Spec: OpenStackClusterSpec{
1128+
ManagedSecurityGroups: &ManagedSecurityGroups{
1129+
AllNodesSecurityGroupRules: []SecurityGroupRuleSpec{
1130+
{
1131+
Name: "allow-http",
1132+
Direction: "ingress",
1133+
},
1134+
},
1135+
},
1136+
},
1137+
},
1138+
},
1139+
{
1140+
name: "multiple rules",
1141+
in: OpenStackCluster{
1142+
Spec: OpenStackClusterSpec{
1143+
ManagedSecurityGroups: &ManagedSecurityGroups{
1144+
AllNodesSecurityGroupRules: []SecurityGroupRuleSpec{
1145+
{
1146+
Name: "allow-http",
1147+
Direction: "ingress",
1148+
},
1149+
{
1150+
Name: "allow-https",
1151+
Direction: "ingress",
1152+
},
1153+
},
1154+
},
1155+
},
1156+
},
1157+
},
1158+
{
1159+
name: "mixed with other node rules",
1160+
in: OpenStackCluster{
1161+
Spec: OpenStackClusterSpec{
1162+
ManagedSecurityGroups: &ManagedSecurityGroups{
1163+
AllNodesSecurityGroupRules: []SecurityGroupRuleSpec{
1164+
{Name: "all-nodes-rule", Direction: "ingress"},
1165+
},
1166+
ControlPlaneNodesSecurityGroupRules: []SecurityGroupRuleSpec{
1167+
{Name: "cp-rule", Direction: "egress"},
1168+
},
1169+
WorkerNodesSecurityGroupRules: []SecurityGroupRuleSpec{
1170+
{Name: "worker-rule", Direction: "ingress"},
1171+
},
1172+
},
1173+
},
1174+
},
1175+
},
1176+
{
1177+
name: "no AllNodesSecurityGroupRules — field stays nil",
1178+
in: OpenStackCluster{
1179+
Spec: OpenStackClusterSpec{
1180+
ManagedSecurityGroups: &ManagedSecurityGroups{
1181+
AllowAllInClusterTraffic: true,
1182+
},
1183+
},
1184+
},
1185+
},
1186+
{
1187+
name: "no ManagedSecurityGroups at all",
1188+
in: OpenStackCluster{},
1189+
},
1190+
}
1191+
1192+
for _, tt := range tests {
1193+
t.Run(tt.name, func(t *testing.T) {
1194+
g := NewWithT(t)
1195+
1196+
hub := &infrav1.OpenStackCluster{}
1197+
g.Expect(tt.in.ConvertTo(hub)).To(Succeed())
1198+
1199+
// Verify intermediate v1beta2 state
1200+
if tt.in.Spec.ManagedSecurityGroups == nil {
1201+
g.Expect(hub.Spec.ManagedSecurityGroups).To(BeNil())
1202+
} else {
1203+
g.Expect(hub.Spec.ManagedSecurityGroups).NotTo(BeNil())
1204+
g.Expect(hub.Spec.ManagedSecurityGroups.ClusterNodesSecurityGroupRules).To(HaveLen(len(tt.in.Spec.ManagedSecurityGroups.AllNodesSecurityGroupRules)))
1205+
for i, rule := range tt.in.Spec.ManagedSecurityGroups.AllNodesSecurityGroupRules {
1206+
g.Expect(hub.Spec.ManagedSecurityGroups.ClusterNodesSecurityGroupRules[i].Name).To(Equal(rule.Name))
1207+
g.Expect(hub.Spec.ManagedSecurityGroups.ClusterNodesSecurityGroupRules[i].Direction).To(Equal(rule.Direction))
1208+
}
1209+
}
1210+
1211+
restored := &OpenStackCluster{}
1212+
g.Expect(restored.ConvertFrom(hub)).To(Succeed())
1213+
1214+
// Verify full round-trip
1215+
g.Expect(restored.Spec.ManagedSecurityGroups).To(Equal(tt.in.Spec.ManagedSecurityGroups))
1216+
})
1217+
}
1218+
}

api/v1beta1/zz_generated.conversion.go

Lines changed: 30 additions & 24 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/v1beta2/openstackcluster_types.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -307,13 +307,13 @@ type ManagedNetwork struct {
307307

308308
// ManagedSecurityGroups defines the desired state of security groups and rules for the cluster.
309309
type ManagedSecurityGroups struct {
310-
// allNodesSecurityGroupRules defines the rules that should be applied to all nodes.
310+
// clusterNodesSecurityGroupRules defines the rules that should be applied to all cluster nodes, excluding the bastion host.
311311
// +patchMergeKey=name
312312
// +patchStrategy=merge
313313
// +listType=map
314314
// +listMapKey=name
315315
// +optional
316-
AllNodesSecurityGroupRules []SecurityGroupRuleSpec `json:"allNodesSecurityGroupRules,omitempty" patchStrategy:"merge" patchMergeKey:"name"`
316+
ClusterNodesSecurityGroupRules []SecurityGroupRuleSpec `json:"clusterNodesSecurityGroupRules,omitempty" patchStrategy:"merge" patchMergeKey:"name"`
317317

318318
// controlPlaneNodesSecurityGroupRules defines the rules that should be applied to control plane nodes.
319319
// +patchMergeKey=name

api/v1beta2/zz_generated.deepcopy.go

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cmd/models-schema/zz_generated.openapi.go

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/crd/bases/infrastructure.cluster.x-k8s.io_openstackclusters.yaml

Lines changed: 9 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/crd/bases/infrastructure.cluster.x-k8s.io_openstackclustertemplates.yaml

Lines changed: 10 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

controllers/openstackcluster_controller_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1195,7 +1195,7 @@ var _ = Describe("OpenStackCluster controller", func() {
11951195
DisableAPIServerFloatingIP: ptr.To(true),
11961196
APIServerFixedIP: ptr.To("192.168.0.10"),
11971197
ManagedSecurityGroups: &infrav1.ManagedSecurityGroups{
1198-
AllNodesSecurityGroupRules: []infrav1.SecurityGroupRuleSpec{
1198+
ClusterNodesSecurityGroupRules: []infrav1.SecurityGroupRuleSpec{
11991199
{
12001200
Direction: "ingress",
12011201
Protocol: ptr.To("tcp"),
@@ -1271,7 +1271,7 @@ var _ = Describe("OpenStackCluster controller", func() {
12711271
DisableAPIServerFloatingIP: ptr.To(true),
12721272
APIServerFixedIP: ptr.To("192.168.0.10"),
12731273
ManagedSecurityGroups: &infrav1.ManagedSecurityGroups{
1274-
AllNodesSecurityGroupRules: []infrav1.SecurityGroupRuleSpec{
1274+
ClusterNodesSecurityGroupRules: []infrav1.SecurityGroupRuleSpec{
12751275
{
12761276
Direction: "ingress",
12771277
Protocol: ptr.To("tcp"),

0 commit comments

Comments
 (0)