@@ -27,7 +27,6 @@ import (
2727 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2828 "k8s.io/utils/ptr"
2929 "sigs.k8s.io/cluster-api/util/conditions"
30- "sigs.k8s.io/controller-runtime/pkg/client"
3130
3231 infrav1alpha1 "github.com/ionos-cloud/cluster-api-provider-proxmox/api/v1alpha1"
3332 "github.com/ionos-cloud/cluster-api-provider-proxmox/internal/inject"
@@ -72,7 +71,7 @@ func TestReconcileBootstrapData_NoNetworkConfig_UpdateStatus(t *testing.T) {
7271 machineScope .SetVirtualMachine (vm )
7372 machineScope .ProxmoxMachine .Status .IPAddresses = map [string ]infrav1alpha1.IPAddress {infrav1alpha1 .DefaultNetworkDevice : {IPV4 : "10.10.10.10" }}
7473 createIP4AddressResource (t , kubeClient , machineScope , infrav1alpha1 .DefaultNetworkDevice , "10.10.10.10" )
75- createBootstrapSecret (t , kubeClient , machineScope )
74+ createBootstrapSecret (t , kubeClient , machineScope , cloudinit . FormatCloudConfig )
7675
7776 requeue , err := reconcileBootstrapData (context .Background (), machineScope )
7877 require .NoError (t , err )
@@ -100,7 +99,7 @@ func TestReconcileBootstrapData_UpdateStatus(t *testing.T) {
10099 machineScope .ProxmoxMachine .Status .IPAddresses = map [string ]infrav1alpha1.IPAddress {infrav1alpha1 .DefaultNetworkDevice : {IPV4 : "10.10.10.10" }, "net1" : {IPV4 : "10.100.10.10" }}
101100 createIP4AddressResource (t , kubeClient , machineScope , infrav1alpha1 .DefaultNetworkDevice , "10.10.10.10" )
102101 createIP4AddressResource (t , kubeClient , machineScope , "net1" , "10.100.10.10" )
103- createBootstrapSecret (t , kubeClient , machineScope )
102+ createBootstrapSecret (t , kubeClient , machineScope , cloudinit . FormatCloudConfig )
104103 getISOInjector = func (_ * proxmox.VirtualMachine , _ []byte , _ , _ cloudinit.Renderer ) isoInjector {
105104 return FakeISOInjector {}
106105 }
@@ -119,7 +118,7 @@ func TestReconcileBootstrapData_BadInjector(t *testing.T) {
119118 machineScope .SetVirtualMachine (vm )
120119 machineScope .ProxmoxMachine .Status .IPAddresses = map [string ]infrav1alpha1.IPAddress {infrav1alpha1 .DefaultNetworkDevice : {IPV4 : "10.10.10.10" }}
121120 createIP4AddressResource (t , kubeClient , machineScope , infrav1alpha1 .DefaultNetworkDevice , "10.10.10.10" )
122- createBootstrapSecret (t , kubeClient , machineScope )
121+ createBootstrapSecret (t , kubeClient , machineScope , cloudinit . FormatCloudConfig )
123122
124123 getISOInjector = func (_ * proxmox.VirtualMachine , _ []byte , _ , _ cloudinit.Renderer ) isoInjector {
125124 return FakeISOInjector {Error : errors .New ("bad FakeISOInjector" )}
@@ -336,7 +335,7 @@ func TestReconcileBootstrapData_DualStack(t *testing.T) {
336335 createIP4AddressResource (t , kubeClient , machineScope , infrav1alpha1 .DefaultNetworkDevice , "10.10.10.10" )
337336 createIP6AddressResource (t , kubeClient , machineScope , infrav1alpha1 .DefaultNetworkDevice , "2001:db8::2" )
338337
339- createBootstrapSecret (t , kubeClient , machineScope )
338+ createBootstrapSecret (t , kubeClient , machineScope , cloudinit . FormatCloudConfig )
340339 getISOInjector = func (_ * proxmox.VirtualMachine , _ []byte , _ , _ cloudinit.Renderer ) isoInjector {
341340 return FakeISOInjector {}
342341 }
@@ -388,7 +387,7 @@ func TestReconcileBootstrapData_DualStack_AdditionalDevices(t *testing.T) {
388387 createIP6AddressResource (t , kubeClient , machineScope , infrav1alpha1 .DefaultNetworkDevice , "2001:db8::2" )
389388 createIP4AddressResource (t , kubeClient , machineScope , "net1" , "10.0.0.10" )
390389 createIP6AddressResource (t , kubeClient , machineScope , "net1" , "2001:db8::9" )
391- createBootstrapSecret (t , kubeClient , machineScope )
390+ createBootstrapSecret (t , kubeClient , machineScope , cloudinit . FormatCloudConfig )
392391 getISOInjector = func (_ * proxmox.VirtualMachine , _ []byte , _ , _ cloudinit.Renderer ) isoInjector {
393392 return FakeISOInjector {}
394393 }
@@ -433,7 +432,7 @@ func TestReconcileBootstrapData_VirtualDevices_VRF(t *testing.T) {
433432 createIP4AddressResource (t , kubeClient , machineScope , infrav1alpha1 .DefaultNetworkDevice , "10.10.10.10" )
434433 createIP4AddressResource (t , kubeClient , machineScope , "net1" , "10.100.10.10" )
435434
436- createBootstrapSecret (t , kubeClient , machineScope )
435+ createBootstrapSecret (t , kubeClient , machineScope , cloudinit . FormatCloudConfig )
437436 getISOInjector = func (_ * proxmox.VirtualMachine , _ []byte , _ , _ cloudinit.Renderer ) isoInjector {
438437 return FakeISOInjector {}
439438 }
@@ -479,7 +478,7 @@ func TestReconcileBootstrapDataMissingNetworkConfig(t *testing.T) {
479478 machineScope .SetVirtualMachine (vm )
480479
481480 machineScope .ProxmoxMachine .Status .IPAddresses = map [string ]infrav1alpha1.IPAddress {infrav1alpha1 .DefaultNetworkDevice : {IPV4 : "10.10.10.10" }}
482- createBootstrapSecret (t , kubeClient , machineScope )
481+ createBootstrapSecret (t , kubeClient , machineScope , cloudinit . FormatCloudConfig )
483482
484483 requeue , err := reconcileBootstrapData (context .Background (), machineScope )
485484 require .Error (t , err )
@@ -489,16 +488,17 @@ func TestReconcileBootstrapDataMissingNetworkConfig(t *testing.T) {
489488 require .True (t , conditions .GetReason (machineScope .ProxmoxMachine , infrav1alpha1 .VMProvisionedCondition ) == infrav1alpha1 .WaitingForStaticIPAllocationReason )
490489}
491490
492- func TestReconcileBootstrapData_Formats (t * testing.T ) {
491+ func TestReconcileBootstrapData_Format_CloudConfig (t * testing.T ) {
493492 machineScope , _ , kubeClient := setupReconcilerTest (t )
494493
495494 vm := newVMWithNets ("virtio=A6:23:64:4D:84:CB,bridge=vmbr0" )
496495 vm .VirtualMachineConfig .SMBios1 = biosUUID
497496 machineScope .SetVirtualMachine (vm )
498497 machineScope .ProxmoxMachine .Status .IPAddresses = map [string ]infrav1alpha1.IPAddress {infrav1alpha1 .DefaultNetworkDevice : {IPV4 : "10.10.10.10" }}
499498 createIP4AddressResource (t , kubeClient , machineScope , infrav1alpha1 .DefaultNetworkDevice , "10.10.10.10" )
500- createBootstrapSecret (t , kubeClient , machineScope )
499+ createBootstrapSecret (t , kubeClient , machineScope , cloudinit . FormatCloudConfig )
501500 machineScope .SetVirtualMachine (vm )
501+
502502 getISOInjector = func (_ * proxmox.VirtualMachine , _ []byte , _ , _ cloudinit.Renderer ) isoInjector {
503503 return FakeISOInjector {}
504504 }
@@ -514,21 +514,32 @@ func TestReconcileBootstrapData_Formats(t *testing.T) {
514514 require .Equal (t , cloudinit .FormatCloudConfig , ptr .Deref (format , "" ))
515515 require .Equal (t , []byte ("data" ), data )
516516 require .Nil (t , err )
517+ }
517518
518- // test explicitly setting format to ignition
519- var dataSecret corev1.Secret
520- err = kubeClient .Get (context .Background (), client.ObjectKey {Namespace : machineScope .Machine .Namespace , Name : ptr .Deref (machineScope .Machine .Spec .Bootstrap .DataSecretName , "" )}, & dataSecret )
521- require .NoError (t , err )
522- dataSecret .Data ["format" ] = []byte (ignition .FormatIgnition )
523- require .NoError (t , kubeClient .Update (context .Background (), & dataSecret ))
519+ func TestReconcileBootstrapData_Format_Ignition (t * testing.T ) {
520+ machineScope , _ , kubeClient := setupReconcilerTest (t )
521+
522+ vm := newVMWithNets ("virtio=A6:23:64:4D:84:CB,bridge=vmbr0" )
523+ vm .VirtualMachineConfig .SMBios1 = biosUUID
524+ machineScope .SetVirtualMachine (vm )
525+ machineScope .ProxmoxMachine .Status .IPAddresses = map [string ]infrav1alpha1.IPAddress {infrav1alpha1 .DefaultNetworkDevice : {IPV4 : "10.10.10.10" }}
526+ createIP4AddressResource (t , kubeClient , machineScope , infrav1alpha1 .DefaultNetworkDevice , "10.10.10.10" )
527+ createBootstrapSecret (t , kubeClient , machineScope , ignition .FormatIgnition )
528+ machineScope .SetVirtualMachine (vm )
529+
530+ getIgnitionISOInjector = func (_ * proxmox.VirtualMachine , _ cloudinit.Renderer , _ * ignition.Enricher ) isoInjector {
531+ return FakeIgnitionISOInjector {}
532+ }
533+ t .Cleanup (func () { getISOInjector = defaultISOInjector })
524534
525- _ , err = reconcileBootstrapData (context .Background (), machineScope )
535+ requeue , err : = reconcileBootstrapData (context .Background (), machineScope )
526536 require .NoError (t , err )
537+ require .False (t , requeue )
527538 require .True (t , * machineScope .ProxmoxMachine .Status .BootstrapDataProvided )
528539
529- data , format , err = getBootstrapData (context .Background (), machineScope )
540+ data , format , err : = getBootstrapData (context .Background (), machineScope )
530541 require .Equal (t , ignition .FormatIgnition , ptr .Deref (format , "" ))
531- require .Equal (t , []byte ("data " ), data )
542+ require .Equal (t , []byte ("{ \" ignition \" :{ \" version \" : \" 2.3.0 \" }} " ), data )
532543 require .Nil (t , err )
533544}
534545
0 commit comments