Skip to content

Commit

Permalink
WIP - AllNodes security groups API
Browse files Browse the repository at this point in the history
  • Loading branch information
EmilienM committed Jan 16, 2024
1 parent 47b87c8 commit ebb6cc6
Show file tree
Hide file tree
Showing 17 changed files with 925 additions and 85 deletions.
4 changes: 4 additions & 0 deletions api/v1alpha5/conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -522,3 +522,7 @@ func Convert_v1alpha5_Bastion_To_v1alpha8_Bastion(in *Bastion, out *infrav1.Bast
in.Instance.FloatingIP = out.FloatingIP
return nil
}

func Convert_v1alpha8_SecurityGroupRule_To_v1alpha5_SecurityGroupRule(in *infrav1.SecurityGroupRule, out *SecurityGroupRule, s conversion.Scope) error {
return autoConvert_v1alpha8_SecurityGroupRule_To_v1alpha5_SecurityGroupRule(in, out, s)
}
4 changes: 2 additions & 2 deletions api/v1alpha5/conversion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func TestConvertFrom(t *testing.T) {
Spec: OpenStackClusterSpec{},
ObjectMeta: metav1.ObjectMeta{
Annotations: map[string]string{
"cluster.x-k8s.io/conversion-data": "{\"spec\":{\"allowAllInClusterTraffic\":false,\"apiServerLoadBalancer\":{},\"cloudName\":\"\",\"controlPlaneEndpoint\":{\"host\":\"\",\"port\":0},\"disableAPIServerFloatingIP\":false,\"disableExternalNetwork\":false,\"externalNetwork\":{},\"managedSecurityGroups\":false,\"network\":{},\"subnet\":{}},\"status\":{\"ready\":false}}",
"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}}",
},
},
},
Expand All @@ -64,7 +64,7 @@ func TestConvertFrom(t *testing.T) {
Spec: OpenStackClusterTemplateSpec{},
ObjectMeta: metav1.ObjectMeta{
Annotations: map[string]string{
"cluster.x-k8s.io/conversion-data": "{\"spec\":{\"template\":{\"spec\":{\"allowAllInClusterTraffic\":false,\"apiServerLoadBalancer\":{},\"cloudName\":\"\",\"controlPlaneEndpoint\":{\"host\":\"\",\"port\":0},\"disableAPIServerFloatingIP\":false,\"disableExternalNetwork\":false,\"externalNetwork\":{},\"managedSecurityGroups\":false,\"network\":{},\"subnet\":{}}}}}",
"cluster.x-k8s.io/conversion-data": "{\"spec\":{\"template\":{\"spec\":{\"allowAllInClusterTraffic\":false,\"apiServerLoadBalancer\":{},\"cloudName\":\"\",\"controlPlaneEndpoint\":{\"host\":\"\",\"port\":0},\"disableAPIServerFloatingIP\":false,\"disableExternalNetwork\":false,\"externalNetwork\":{},\"network\":{},\"subnet\":{}}}}}",
},
},
},
Expand Down
95 changes: 80 additions & 15 deletions api/v1alpha5/zz_generated.conversion.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 33 additions & 0 deletions api/v1alpha6/conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,10 @@ func restorev1alpha8ClusterStatus(previous *infrav1.OpenStackClusterStatus, dst
if previous.Bastion != nil {
dst.Bastion.ReferencedResources = previous.Bastion.ReferencedResources
}

if previous.AllNodesSecurityGroup != nil {
dst.AllNodesSecurityGroup = previous.AllNodesSecurityGroup
}
}

func restorev1alpha6ClusterSpec(previous *OpenStackClusterSpec, dst *OpenStackClusterSpec) {
Expand Down Expand Up @@ -128,6 +132,11 @@ var v1alpha6OpenStackClusterRestorer = conversion.RestorerFor[*OpenStackCluster]
}

var v1alpha8OpenStackClusterRestorer = conversion.RestorerFor[*infrav1.OpenStackCluster]{
"managedSecurityGroups": conversion.UnconditionalFieldRestorer(
func(c *infrav1.OpenStackCluster) **infrav1.SecurityGroupsSpec {
return &c.Spec.ManagedSecurityGroups
},
),
"externalNetwork": conversion.UnconditionalFieldRestorer(
func(c *infrav1.OpenStackCluster) *infrav1.NetworkFilter {
return &c.Spec.ExternalNetwork
Expand Down Expand Up @@ -208,6 +217,11 @@ var v1alpha6OpenStackClusterTemplateRestorer = conversion.RestorerFor[*OpenStack
}

var v1alpha8OpenStackClusterTemplateRestorer = conversion.RestorerFor[*infrav1.OpenStackClusterTemplate]{
"managedSecurityGroups": conversion.UnconditionalFieldRestorer(
func(c *infrav1.OpenStackClusterTemplate) **infrav1.SecurityGroupsSpec {
return &c.Spec.Template.Spec.ManagedSecurityGroups
},
),
"externalNetwork": conversion.UnconditionalFieldRestorer(
func(c *infrav1.OpenStackClusterTemplate) *infrav1.NetworkFilter {
return &c.Spec.Template.Spec.ExternalNetwork
Expand Down Expand Up @@ -486,6 +500,10 @@ func Convert_v1alpha8_OpenStackClusterSpec_To_v1alpha6_OpenStackClusterSpec(in *
out.ExternalNetworkID = in.ExternalNetwork.ID
}

if in.ManagedSecurityGroups != nil && in.ManagedSecurityGroups.Enabled {
out.ManagedSecurityGroups = true
}

return nil
}

Expand All @@ -501,6 +519,12 @@ func Convert_v1alpha6_OpenStackClusterSpec_To_v1alpha8_OpenStackClusterSpec(in *
}
}

if in.ManagedSecurityGroups {
out.ManagedSecurityGroups = &infrav1.SecurityGroupsSpec{
Enabled: true,
}
}

return nil
}

Expand Down Expand Up @@ -780,3 +804,12 @@ func Convert_v1alpha8_Bastion_To_v1alpha6_Bastion(in *infrav1.Bastion, out *Bast
out.Instance.FloatingIP = in.FloatingIP
return nil
}

func Convert_v1alpha8_SecurityGroupRule_To_v1alpha6_SecurityGroupRule(in *infrav1.SecurityGroupRule, out *SecurityGroupRule, s apiconversion.Scope) error {
err := autoConvert_v1alpha8_SecurityGroupRule_To_v1alpha6_SecurityGroupRule(in, out, s)
if err != nil {
return err
}

return nil
}
95 changes: 80 additions & 15 deletions api/v1alpha6/zz_generated.conversion.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit ebb6cc6

Please sign in to comment.