Skip to content

Commit 59034d8

Browse files
mdboothEmilienM
authored andcommitted
Matt made a dump in the codebase
1 parent cb63ffe commit 59034d8

17 files changed

+520
-640
lines changed

api/v1alpha5/conversion.go

Lines changed: 72 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,28 @@ var _ ctrlconversion.Convertible = &OpenStackCluster{}
3030

3131
const trueString = "true"
3232

33+
// legacyCalicoSecurityGroupRules are the legacy security group rules for calico
34+
// that need to be applied to the control plane and worker security groups when
35+
// managed security groups are enabled and upgrading from v1alpha7 to v1alpha8.
36+
var legacyCalicoSecurityGroupRules = []infrav1.SecurityGroupRuleSpec{
37+
{
38+
Description: "BGP (calico)",
39+
Direction: "ingress",
40+
EtherType: "IPv4",
41+
PortRangeMin: 179,
42+
PortRangeMax: 179,
43+
Protocol: "tcp",
44+
RemoteManagedGroups: []infrav1.ManagedSecurityGroupName{"controlplane", "worker"},
45+
},
46+
{
47+
Description: "IP-in-IP (calico)",
48+
Direction: "ingress",
49+
EtherType: "IPv4",
50+
Protocol: "4",
51+
RemoteManagedGroups: []infrav1.ManagedSecurityGroupName{"controlplane", "worker"},
52+
},
53+
}
54+
3355
func (r *OpenStackCluster) ConvertTo(dstRaw ctrlconversion.Hub) error {
3456
dst := dstRaw.(*infrav1.OpenStackCluster)
3557

@@ -196,6 +218,10 @@ func Convert_v1alpha8_OpenStackClusterSpec_To_v1alpha5_OpenStackClusterSpec(in *
196218
out.ExternalNetworkID = in.ExternalNetwork.ID
197219
}
198220

221+
if in.ManagedSecurityGroups.Enabled {
222+
out.ManagedSecurityGroups = true
223+
}
224+
199225
return nil
200226
}
201227

@@ -211,6 +237,13 @@ func Convert_v1alpha5_OpenStackClusterSpec_To_v1alpha8_OpenStackClusterSpec(in *
211237
}
212238
}
213239

240+
if in.ManagedSecurityGroups {
241+
out.ManagedSecurityGroups = infrav1.SecurityGroupsSpec{
242+
Enabled: true,
243+
AllNodesSecurityGroupRules: legacyCalicoSecurityGroupRules,
244+
}
245+
}
246+
214247
return nil
215248
}
216249

@@ -523,6 +556,43 @@ func Convert_v1alpha5_Bastion_To_v1alpha8_Bastion(in *Bastion, out *infrav1.Bast
523556
return nil
524557
}
525558

526-
func Convert_v1alpha8_SecurityGroupRule_To_v1alpha5_SecurityGroupRule(in *infrav1.SecurityGroupRule, out *SecurityGroupRule, s conversion.Scope) error {
527-
return autoConvert_v1alpha8_SecurityGroupRule_To_v1alpha5_SecurityGroupRule(in, out, s)
559+
func Convert_v1alpha8_SecurityGroupStatus_To_v1alpha5_SecurityGroup(in *infrav1.SecurityGroupStatus, out *SecurityGroup, s conversion.Scope) error { //nolint:revive
560+
out.ID = in.ID
561+
out.Name = in.Name
562+
out.Rules = make([]SecurityGroupRule, len(in.Rules))
563+
for i, rule := range in.Rules {
564+
out.Rules[i] = SecurityGroupRule{
565+
ID: rule.ID,
566+
Description: rule.Description,
567+
Direction: rule.Direction,
568+
EtherType: rule.EtherType,
569+
PortRangeMin: rule.PortRangeMin,
570+
PortRangeMax: rule.PortRangeMax,
571+
Protocol: rule.Protocol,
572+
RemoteGroupID: rule.RemoteGroupID,
573+
RemoteIPPrefix: rule.RemoteIPPrefix,
574+
}
575+
}
576+
return nil
577+
}
578+
579+
func Convert_v1alpha5_SecurityGroup_To_v1alpha8_SecurityGroupStatus(in *SecurityGroup, out *infrav1.SecurityGroupStatus, s conversion.Scope) error { //nolint:revive
580+
out.ID = in.ID
581+
out.Name = in.Name
582+
out.Rules = make([]infrav1.SecurityGroupRuleStatus, len(in.Rules))
583+
for i, rule := range in.Rules {
584+
out.Rules[i] = infrav1.SecurityGroupRuleStatus{
585+
ID: rule.ID,
586+
Description: rule.Description,
587+
Direction: rule.Direction,
588+
EtherType: rule.EtherType,
589+
PortRangeMin: rule.PortRangeMin,
590+
PortRangeMax: rule.PortRangeMax,
591+
Protocol: rule.Protocol,
592+
RemoteGroupID: rule.RemoteGroupID,
593+
RemoteIPPrefix: rule.RemoteIPPrefix,
594+
}
595+
}
596+
597+
return nil
528598
}

api/v1alpha5/conversion_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ func TestConvertFrom(t *testing.T) {
4949
Spec: OpenStackClusterSpec{},
5050
ObjectMeta: metav1.ObjectMeta{
5151
Annotations: map[string]string{
52-
"cluster.x-k8s.io/conversion-data": "{\"spec\":{\"allowAllInClusterTraffic\":false,\"apiServerLoadBalancer\":{},\"cloudName\":\"\",\"controlPlaneEndpoint\":{\"host\":\"\",\"port\":0},\"disableAPIServerFloatingIP\":false,\"disableExternalNetwork\":false,\"externalNetwork\":{},\"network\":{},\"subnet\":{}},\"status\":{\"ready\":false}}",
52+
"cluster.x-k8s.io/conversion-data": "{\"spec\":{\"allowAllInClusterTraffic\":false,\"apiServerLoadBalancer\":{},\"cloudName\":\"\",\"controlPlaneEndpoint\":{\"host\":\"\",\"port\":0},\"disableAPIServerFloatingIP\":false,\"disableExternalNetwork\":false,\"externalNetwork\":{},\"managedSecurityGroups\":{},\"network\":{},\"subnet\":{}},\"status\":{\"ready\":false}}",
5353
},
5454
},
5555
},
@@ -64,7 +64,7 @@ func TestConvertFrom(t *testing.T) {
6464
Spec: OpenStackClusterTemplateSpec{},
6565
ObjectMeta: metav1.ObjectMeta{
6666
Annotations: map[string]string{
67-
"cluster.x-k8s.io/conversion-data": "{\"spec\":{\"template\":{\"spec\":{\"allowAllInClusterTraffic\":false,\"apiServerLoadBalancer\":{},\"cloudName\":\"\",\"controlPlaneEndpoint\":{\"host\":\"\",\"port\":0},\"disableAPIServerFloatingIP\":false,\"disableExternalNetwork\":false,\"externalNetwork\":{},\"network\":{},\"subnet\":{}}}}}",
67+
"cluster.x-k8s.io/conversion-data": "{\"spec\":{\"template\":{\"spec\":{\"allowAllInClusterTraffic\":false,\"apiServerLoadBalancer\":{},\"cloudName\":\"\",\"controlPlaneEndpoint\":{\"host\":\"\",\"port\":0},\"disableAPIServerFloatingIP\":false,\"disableExternalNetwork\":false,\"externalNetwork\":{},\"managedSecurityGroups\":{},\"network\":{},\"subnet\":{}}}}}",
6868
},
6969
},
7070
},

api/v1alpha5/zz_generated.conversion.go

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

0 commit comments

Comments
 (0)