@@ -25,6 +25,8 @@ import (
2525 "k8s.io/apimachinery/pkg/runtime"
2626 "k8s.io/utils/pointer"
2727 "sigs.k8s.io/cluster-api/api/v1alpha3"
28+ bootstrapv1a2 "sigs.k8s.io/cluster-api/bootstrap/kubeadm/api/v1alpha2"
29+ bootstrapv1a3 "sigs.k8s.io/cluster-api/bootstrap/kubeadm/api/v1alpha3"
2830 utilconversion "sigs.k8s.io/cluster-api/util/conversion"
2931)
3032
@@ -112,18 +114,27 @@ func TestConvertMachine(t *testing.T) {
112114 g := NewWithT (t )
113115
114116 t .Run ("to hub" , func (t * testing.T ) {
115- t .Run ("should convert the Spec.ClusterName from label " , func (t * testing.T ) {
117+ t .Run ("should convert all fields correctly " , func (t * testing.T ) {
116118 src := & Machine {
117119 ObjectMeta : metav1.ObjectMeta {
118120 Labels : map [string ]string {
119121 MachineClusterLabelName : "test-cluster" ,
120122 },
121123 },
124+ Spec : MachineSpec {
125+ Bootstrap : Bootstrap {
126+ ConfigRef : & corev1.ObjectReference {
127+ Kind : kubeadmConfigKind ,
128+ APIVersion : bootstrapv1a2 .GroupVersion .String (),
129+ },
130+ },
131+ },
122132 }
123133 dst := & v1alpha3.Machine {}
124134
125135 g .Expect (src .ConvertTo (dst )).To (Succeed ())
126136 g .Expect (dst .Spec .ClusterName ).To (Equal ("test-cluster" ))
137+ g .Expect (dst .Spec .Bootstrap .ConfigRef .APIVersion ).To (Equal (bootstrapv1a3 .GroupVersion .String ()))
127138 })
128139 })
129140
@@ -161,19 +172,32 @@ func TestConvertMachineSet(t *testing.T) {
161172 g := NewWithT (t )
162173
163174 t .Run ("to hub" , func (t * testing.T ) {
164- t .Run ("should convert the Spec.ClusterName from label " , func (t * testing.T ) {
175+ t .Run ("should convert all fields correctly " , func (t * testing.T ) {
165176 src := & MachineSet {
166177 ObjectMeta : metav1.ObjectMeta {
167178 Labels : map [string ]string {
168179 MachineClusterLabelName : "test-cluster" ,
169180 },
170181 },
182+ Spec : MachineSetSpec {
183+ Template : MachineTemplateSpec {
184+ Spec : MachineSpec {
185+ Bootstrap : Bootstrap {
186+ ConfigRef : & corev1.ObjectReference {
187+ Kind : kubeadmConfigKind ,
188+ APIVersion : bootstrapv1a2 .GroupVersion .String (),
189+ },
190+ },
191+ },
192+ },
193+ },
171194 }
172195 dst := & v1alpha3.MachineSet {}
173196
174197 g .Expect (src .ConvertTo (dst )).To (Succeed ())
175198 g .Expect (dst .Spec .ClusterName ).To (Equal ("test-cluster" ))
176199 g .Expect (dst .Spec .Template .Spec .ClusterName ).To (Equal ("test-cluster" ))
200+ g .Expect (dst .Spec .Template .Spec .Bootstrap .ConfigRef .APIVersion ).To (Equal (bootstrapv1a3 .GroupVersion .String ()))
177201 })
178202 })
179203
@@ -210,19 +234,33 @@ func TestConvertMachineDeployment(t *testing.T) {
210234 g := NewWithT (t )
211235
212236 t .Run ("to hub" , func (t * testing.T ) {
213- t .Run ("should convert the Spec.ClusterName from label " , func (t * testing.T ) {
237+ t .Run ("should convert all fields correctly " , func (t * testing.T ) {
214238 src := & MachineDeployment {
215239 ObjectMeta : metav1.ObjectMeta {
216240 Labels : map [string ]string {
217241 MachineClusterLabelName : "test-cluster" ,
218242 },
219243 },
244+ Spec : MachineDeploymentSpec {
245+ Paused : true ,
246+ Template : MachineTemplateSpec {
247+ Spec : MachineSpec {
248+ Bootstrap : Bootstrap {
249+ ConfigRef : & corev1.ObjectReference {
250+ Kind : kubeadmConfigTemplateKind ,
251+ APIVersion : bootstrapv1a2 .GroupVersion .String (),
252+ },
253+ },
254+ },
255+ },
256+ },
220257 }
221258 dst := & v1alpha3.MachineDeployment {}
222259
223260 g .Expect (src .ConvertTo (dst )).To (Succeed ())
224261 g .Expect (dst .Spec .ClusterName ).To (Equal ("test-cluster" ))
225262 g .Expect (dst .Spec .Template .Spec .ClusterName ).To (Equal ("test-cluster" ))
263+ g .Expect (dst .Spec .Template .Spec .Bootstrap .ConfigRef .APIVersion ).To (Equal (bootstrapv1a3 .GroupVersion .String ()))
226264 })
227265 })
228266
@@ -244,7 +282,6 @@ func TestConvertMachineDeployment(t *testing.T) {
244282 }
245283 src .Status .SetTypedPhase (v1alpha3 .MachineDeploymentPhaseRunning )
246284 dst := & MachineDeployment {}
247-
248285 g .Expect (dst .ConvertFrom (src )).To (Succeed ())
249286 restored := & v1alpha3.MachineDeployment {}
250287 g .Expect (dst .ConvertTo (restored )).To (Succeed ())
0 commit comments