diff --git a/api/v1alpha7/conversion.go b/api/v1alpha7/conversion.go index d9e50a44d5..11183b77e6 100644 --- a/api/v1alpha7/conversion.go +++ b/api/v1alpha7/conversion.go @@ -50,7 +50,30 @@ var ( var _ ctrlconversion.Convertible = &OpenStackCluster{} -var v1alpha7OpenStackClusterRestorer = conversion.RestorerFor[*OpenStackCluster]{} +func restorev1alpha7SecurityGroup(previous *SecurityGroup, dst *SecurityGroup) { + if previous == nil || dst == nil { + return + } + + for i, rule := range previous.Rules { + dst.Rules[i].SecurityGroupID = rule.SecurityGroupID + } +} + +func restorev1alpha7OpenStackClusterStatus(previous *OpenStackClusterStatus, dst *OpenStackClusterStatus) { + restorev1alpha7SecurityGroup(previous.ControlPlaneSecurityGroup, dst.ControlPlaneSecurityGroup) + restorev1alpha7SecurityGroup(previous.WorkerSecurityGroup, dst.WorkerSecurityGroup) + restorev1alpha7SecurityGroup(previous.BastionSecurityGroup, dst.BastionSecurityGroup) +} + +var v1alpha7OpenStackClusterRestorer = conversion.RestorerFor[*OpenStackCluster]{ + "status": conversion.HashedFieldRestorer( + func(c *OpenStackCluster) *OpenStackClusterStatus { + return &c.Status + }, + restorev1alpha7OpenStackClusterStatus, + ), +} var v1alpha8OpenStackClusterRestorer = conversion.RestorerFor[*infrav1.OpenStackCluster]{ "bastion": conversion.HashedFieldRestorer( @@ -456,11 +479,53 @@ func Convert_v1alpha8_OpenStackClusterSpec_To_v1alpha7_OpenStackClusterSpec(in * return nil } -func Convert_v1alpha8_SecurityGroupRule_To_v1alpha7_SecurityGroupRule(in *infrav1.SecurityGroupRuleSpec, out *SecurityGroupRule, s apiconversion.Scope) error { - err := autoConvert_v1alpha8_SecurityGroupRule_To_v1alpha7_SecurityGroupRule(in, out, s) - if err != nil { - return err +func Convert_v1alpha8_SecurityGroupStatus_To_v1alpha7_SecurityGroup(in *infrav1.SecurityGroupStatus, out *SecurityGroup, s apiconversion.Scope) error { + out.ID = in.ID + out.Name = in.Name + out.Rules = make([]SecurityGroupRule, len(in.Rules)) + for i, rule := range in.Rules { + out.Rules[i] = SecurityGroupRule{ + ID: rule.ID, + Description: rule.Description, + Direction: rule.Direction, + EtherType: rule.EtherType, + PortRangeMin: rule.PortRangeMin, + PortRangeMax: rule.PortRangeMax, + Protocol: rule.Protocol, + RemoteGroupID: rule.RemoteGroupID, + RemoteIPPrefix: rule.RemoteIPPrefix, + } + } + return nil +} + +func Convert_v1alpha7_SecurityGroup_To_v1alpha8_SecurityGroupStatus(in *SecurityGroup, out *infrav1.SecurityGroupStatus, s apiconversion.Scope) error { + out.ID = in.ID + out.Name = in.Name + out.Rules = make([]infrav1.SecurityGroupRuleStatus, len(in.Rules)) + for i, rule := range in.Rules { + out.Rules[i] = infrav1.SecurityGroupRuleStatus{ + ID: rule.ID, + Description: rule.Description, + Direction: rule.Direction, + EtherType: rule.EtherType, + PortRangeMin: rule.PortRangeMin, + PortRangeMax: rule.PortRangeMax, + Protocol: rule.Protocol, + RemoteGroupID: rule.RemoteGroupID, + RemoteIPPrefix: rule.RemoteIPPrefix, + } } return nil } + +// func Convert_v1alpha8_SecurityGroupRule_To_v1alpha7_SecurityGroupRule(in *infrav1.SecurityGroupRuleSpec, out *SecurityGroupRule, s apiconversion.Scope) error { +// err := autoConvert_v1alpha8_SecurityGroupRule_To_v1alpha7_SecurityGroupRule(in, out, s) +// if err != nil { +// return err +// } +// +// return nil +// } +// diff --git a/api/v1alpha7/zz_generated.conversion.go b/api/v1alpha7/zz_generated.conversion.go index 49427b6e6f..6a6f17bd05 100644 --- a/api/v1alpha7/zz_generated.conversion.go +++ b/api/v1alpha7/zz_generated.conversion.go @@ -429,6 +429,11 @@ func RegisterConversions(s *runtime.Scheme) error { }); err != nil { return err } + if err := s.AddConversionFunc((*v1alpha8.SecurityGroupStatus)(nil), (*SecurityGroup)(nil), func(a, b interface{}, scope conversion.Scope) error { + return Convert_v1alpha8_SecurityGroupStatus_To_v1alpha7_SecurityGroup(a.(*v1alpha8.SecurityGroupStatus), b.(*SecurityGroup), scope) + }); err != nil { + return err + } return nil } diff --git a/test/helpers/fuzz_mutate.go b/test/helpers/fuzz_mutate.go index 5e3f95b25b..bcdac36d15 100644 --- a/test/helpers/fuzz_mutate.go +++ b/test/helpers/fuzz_mutate.go @@ -25,7 +25,6 @@ import ( apiequality "k8s.io/apimachinery/pkg/api/equality" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/client-go/kubernetes/scheme" - infrav1 "sigs.k8s.io/cluster-api-provider-openstack/api/v1alpha8" utilconversion "sigs.k8s.io/cluster-api/util/conversion" "sigs.k8s.io/controller-runtime/pkg/conversion" ) @@ -71,38 +70,6 @@ func FuzzMutateTestFunc(input FuzzMutateTestFuncInput) func(*testing.T) { input.HubAfterMutation(hubAfter) } - if !apiequality.Semantic.DeepEqual(hubBefore, hubAfter) { - var clusterBefore, clusterAfter *infrav1.OpenStackCluster - clusterBefore, ok := hubBefore.(*infrav1.OpenStackCluster) - if ok { - clusterAfter = hubAfter.(*infrav1.OpenStackCluster) - } - - g.Expect(apiequality.Semantic.DeepEqual(clusterBefore.Spec.Bastion, clusterAfter.Spec.Bastion)).To(gomega.BeTrue(), cmp.Diff(clusterBefore.Spec.Bastion, clusterAfter.Spec.Bastion)) - g.Expect(apiequality.Semantic.DeepEqual(clusterBefore.Spec, clusterAfter.Spec)).To(gomega.BeTrue(), cmp.Diff(clusterBefore.Spec, clusterAfter.Spec)) - - g.Expect(apiequality.Semantic.DeepEqual(clusterBefore.Status.Ready, clusterAfter.Status.Ready)).To(gomega.BeTrue(), cmp.Diff(clusterBefore.Status.Ready, clusterAfter.Status.Ready)) - g.Expect(apiequality.Semantic.DeepEqual(clusterBefore.Status.Network, clusterAfter.Status.Network)).To(gomega.BeTrue(), cmp.Diff(clusterBefore.Status.Network, clusterAfter.Status.Network)) - g.Expect(apiequality.Semantic.DeepEqual(clusterBefore.Status.ExternalNetwork, clusterAfter.Status.ExternalNetwork)).To(gomega.BeTrue(), cmp.Diff(clusterBefore.Status.ExternalNetwork, clusterAfter.Status.ExternalNetwork)) - g.Expect(apiequality.Semantic.DeepEqual(clusterBefore.Status.Router, clusterAfter.Status.Router)).To(gomega.BeTrue(), cmp.Diff(clusterBefore.Status.Router, clusterAfter.Status.Router)) - g.Expect(apiequality.Semantic.DeepEqual(clusterBefore.Status.APIServerLoadBalancer, clusterAfter.Status.APIServerLoadBalancer)).To(gomega.BeTrue(), cmp.Diff(clusterBefore.Status.APIServerLoadBalancer, clusterAfter.Status.APIServerLoadBalancer)) - g.Expect(apiequality.Semantic.DeepEqual(clusterBefore.Status.FailureDomains, clusterAfter.Status.FailureDomains)).To(gomega.BeTrue(), cmp.Diff(clusterBefore.Status.FailureDomains, clusterAfter.Status.FailureDomains)) - g.Expect(apiequality.Semantic.DeepEqual(clusterBefore.Status.ControlPlaneSecurityGroup, clusterAfter.Status.ControlPlaneSecurityGroup)).To(gomega.BeTrue(), cmp.Diff(clusterBefore.Status.ControlPlaneSecurityGroup, clusterAfter.Status.ControlPlaneSecurityGroup)) - - if !apiequality.Semantic.DeepEqual(clusterBefore.Status.WorkerSecurityGroup, clusterAfter.Status.WorkerSecurityGroup) { - g.Expect(apiequality.Semantic.DeepEqual(clusterBefore.Status.WorkerSecurityGroup, clusterAfter.Status.WorkerSecurityGroup)).To(gomega.BeTrue(), cmp.Diff(clusterBefore.Status.WorkerSecurityGroup, clusterAfter.Status.WorkerSecurityGroup)) - } - - g.Expect(apiequality.Semantic.DeepEqual(clusterBefore.Status.WorkerSecurityGroup, clusterAfter.Status.WorkerSecurityGroup)).To(gomega.BeTrue(), cmp.Diff(clusterBefore.Status.WorkerSecurityGroup, clusterAfter.Status.WorkerSecurityGroup)) - g.Expect(apiequality.Semantic.DeepEqual(clusterBefore.Status.BastionSecurityGroup, clusterAfter.Status.BastionSecurityGroup)).To(gomega.BeTrue(), cmp.Diff(clusterBefore.Status.BastionSecurityGroup, clusterAfter.Status.BastionSecurityGroup)) - g.Expect(apiequality.Semantic.DeepEqual(clusterBefore.Status.Bastion, clusterAfter.Status.Bastion)).To(gomega.BeTrue(), cmp.Diff(clusterBefore.Status.Bastion, clusterAfter.Status.Bastion)) - g.Expect(apiequality.Semantic.DeepEqual(clusterBefore.Status.FailureReason, clusterAfter.Status.FailureReason)).To(gomega.BeTrue(), cmp.Diff(clusterBefore.Status.FailureReason, clusterAfter.Status.FailureReason)) - g.Expect(apiequality.Semantic.DeepEqual(clusterBefore.Status.FailureMessage, clusterAfter.Status.FailureMessage)).To(gomega.BeTrue(), cmp.Diff(clusterBefore.Status.FailureMessage, clusterAfter.Status.FailureMessage)) - - g.Expect(apiequality.Semantic.DeepEqual(clusterBefore.Status, clusterAfter.Status)).To(gomega.BeTrue(), cmp.Diff(clusterBefore.Status, clusterAfter.Status)) - g.Expect(apiequality.Semantic.DeepEqual(clusterBefore.ObjectMeta, clusterAfter.ObjectMeta)).To(gomega.BeTrue(), cmp.Diff(clusterBefore.ObjectMeta, clusterAfter.ObjectMeta)) - g.Expect(apiequality.Semantic.DeepEqual(clusterBefore.TypeMeta, clusterAfter.TypeMeta)).To(gomega.BeTrue(), cmp.Diff(clusterBefore.TypeMeta, clusterAfter.TypeMeta)) - } g.Expect(apiequality.Semantic.DeepEqual(hubBefore, hubAfter)).To(gomega.BeTrue(), cmp.Diff(hubBefore, hubAfter)) } })