Skip to content

Commit

Permalink
More Matt (the revenge)
Browse files Browse the repository at this point in the history
  • Loading branch information
mdbooth committed Jan 17, 2024
1 parent b1ac242 commit d4a3641
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 38 deletions.
75 changes: 70 additions & 5 deletions api/v1alpha7/conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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
// }
//
5 changes: 5 additions & 0 deletions api/v1alpha7/zz_generated.conversion.go

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

33 changes: 0 additions & 33 deletions test/helpers/fuzz_mutate.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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))
}
})
Expand Down

0 comments on commit d4a3641

Please sign in to comment.