Skip to content

Commit 1e81d50

Browse files
committed
Reduce the Bastion status to only fields which are used
The Instance type's only remaining use was to report the status of the Bastion. Most of the fields weren't used, but were still polluting the API. This change makes the intended use of the type explicit, and reduces it to only the fields which are actually used.
1 parent 091e2a7 commit 1e81d50

13 files changed

+130
-596
lines changed

api/v1alpha5/conversion.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,3 +229,25 @@ func Convert_v1alpha5_PortOpts_To_v1alpha7_PortOpts(in *PortOpts, out *infrav1.P
229229
// SecurityGroups have been removed in v1alpha7.
230230
return autoConvert_v1alpha5_PortOpts_To_v1alpha7_PortOpts(in, out, s)
231231
}
232+
233+
func Convert_v1alpha5_Instance_To_v1alpha7_BastionStatus(in *Instance, out *infrav1.BastionStatus, _ conversion.Scope) error {
234+
// BastionStatus is the same as Instance with unused fields removed
235+
out.ID = in.ID
236+
out.Name = in.Name
237+
out.SSHKeyName = in.SSHKeyName
238+
out.State = infrav1.InstanceState(in.State)
239+
out.IP = in.IP
240+
out.FloatingIP = in.FloatingIP
241+
return nil
242+
}
243+
244+
func Convert_v1alpha7_BastionStatus_To_v1alpha5_Instance(in *infrav1.BastionStatus, out *Instance, _ conversion.Scope) error {
245+
// BastionStatus is the same as Instance with unused fields removed
246+
out.ID = in.ID
247+
out.Name = in.Name
248+
out.SSHKeyName = in.SSHKeyName
249+
out.State = InstanceState(in.State)
250+
out.IP = in.IP
251+
out.FloatingIP = in.FloatingIP
252+
return nil
253+
}

api/v1alpha5/zz_generated.conversion.go

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

api/v1alpha6/conversion.go

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -133,11 +133,6 @@ func restorev1alpha7ClusterStatus(previous *infrav1.OpenStackClusterStatus, dst
133133
if previous.Network != nil && previous.Network.PortOpts != nil {
134134
dst.Network.PortOpts.PropagateUplinkStatus = previous.Network.PortOpts.PropagateUplinkStatus
135135
}
136-
// PropagateUplinkStatus has been added in v1alpha7.
137-
// We restore the whole Networks since they are anyway immutable.
138-
if previous.Bastion != nil && previous.Bastion.Networks != nil {
139-
dst.Bastion.Networks = previous.Bastion.Networks
140-
}
141136
}
142137

143138
var _ ctrlconversion.Convertible = &OpenStackCluster{}
@@ -425,3 +420,25 @@ func Convert_v1alpha7_PortOpts_To_v1alpha6_PortOpts(in *infrav1.PortOpts, out *P
425420
// value specs and propagate uplink status have been added in v1alpha7 but have no equivalent in v1alpha5
426421
return autoConvert_v1alpha7_PortOpts_To_v1alpha6_PortOpts(in, out, s)
427422
}
423+
424+
func Convert_v1alpha6_Instance_To_v1alpha7_BastionStatus(in *Instance, out *infrav1.BastionStatus, _ conversion.Scope) error {
425+
// BastionStatus is the same as Instance with unused fields removed
426+
out.ID = in.ID
427+
out.Name = in.Name
428+
out.SSHKeyName = in.SSHKeyName
429+
out.State = infrav1.InstanceState(in.State)
430+
out.IP = in.IP
431+
out.FloatingIP = in.FloatingIP
432+
return nil
433+
}
434+
435+
func Convert_v1alpha7_BastionStatus_To_v1alpha6_Instance(in *infrav1.BastionStatus, out *Instance, _ conversion.Scope) error {
436+
// BastionStatus is the same as Instance with unused fields removed
437+
out.ID = in.ID
438+
out.Name = in.Name
439+
out.SSHKeyName = in.SSHKeyName
440+
out.State = InstanceState(in.State)
441+
out.IP = in.IP
442+
out.FloatingIP = in.FloatingIP
443+
return nil
444+
}

api/v1alpha6/conversion_test.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,12 @@ package v1alpha6
1919
import (
2020
"testing"
2121

22+
fuzz "github.com/google/gofuzz"
2223
"github.com/onsi/gomega"
24+
"k8s.io/apimachinery/pkg/api/apitesting/fuzzer"
2325
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2426
runtime "k8s.io/apimachinery/pkg/runtime"
27+
runtimeserializer "k8s.io/apimachinery/pkg/runtime/serializer"
2528
utilconversion "sigs.k8s.io/cluster-api/util/conversion"
2629
ctrlconversion "sigs.k8s.io/controller-runtime/pkg/conversion"
2730

@@ -36,10 +39,35 @@ func TestFuzzyConversion(t *testing.T) {
3639
delete(obj.GetAnnotations(), utilconversion.DataAnnotation)
3740
}
3841

42+
fuzzerFuncs := func(_ runtimeserializer.CodecFactory) []interface{} {
43+
return []interface{}{
44+
func(instance *Instance, c fuzz.Continue) {
45+
c.FuzzNoCustom(instance)
46+
47+
// None of the following fields have ever been set in v1alpha6
48+
instance.Trunk = false
49+
instance.FailureDomain = ""
50+
instance.SecurityGroups = nil
51+
instance.Networks = nil
52+
instance.Subnet = ""
53+
instance.Tags = nil
54+
instance.Image = ""
55+
instance.ImageUUID = ""
56+
instance.Flavor = ""
57+
instance.UserData = ""
58+
instance.Metadata = nil
59+
instance.ConfigDrive = nil
60+
instance.RootVolume = nil
61+
instance.ServerGroupID = ""
62+
},
63+
}
64+
}
65+
3966
t.Run("for OpenStackCluster", utilconversion.FuzzTestFunc(utilconversion.FuzzTestFuncInput{
4067
Hub: &infrav1.OpenStackCluster{},
4168
Spoke: &OpenStackCluster{},
4269
HubAfterMutation: ignoreDataAnnotation,
70+
FuzzerFuncs: []fuzzer.FuzzerFuncs{fuzzerFuncs},
4371
}))
4472

4573
t.Run("for OpenStackClusterTemplate", utilconversion.FuzzTestFunc(utilconversion.FuzzTestFuncInput{

api/v1alpha6/zz_generated.conversion.go

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

0 commit comments

Comments
 (0)