Skip to content

Commit 00485cd

Browse files
rybnicowikkyk
authored andcommitted
Add test TestReconcileBootstrapDataFormats
1 parent cab54fe commit 00485cd

File tree

1 file changed

+45
-12
lines changed

1 file changed

+45
-12
lines changed

internal/service/vmservice/bootstrap_test.go

Lines changed: 45 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ 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"
3031

3132
infrav1alpha1 "github.com/ionos-cloud/cluster-api-provider-proxmox/api/v1alpha1"
3233
"github.com/ionos-cloud/cluster-api-provider-proxmox/internal/inject"
@@ -178,18 +179,7 @@ func TestGetBootstrapData_MissingSecretValue(t *testing.T) {
178179
secret.Data["value"] = []byte("notdata")
179180
require.NoError(t, client.Update(context.Background(), secret))
180181

181-
// test defaulting of format to cloud-config
182-
data, format, err := getBootstrapData(context.Background(), machineScope)
183-
require.Equal(t, cloudinit.FormatCloudConfig, ptr.Deref(format, ""))
184-
require.Equal(t, []byte("notdata"), data)
185-
require.Nil(t, err)
186-
187-
// test explicitly setting format to ignition
188-
secret.Data["format"] = []byte(ignition.FormatIgnition)
189-
require.NoError(t, client.Update(context.Background(), secret))
190-
191-
data, format, err = getBootstrapData(context.Background(), machineScope)
192-
require.Equal(t, ignition.FormatIgnition, ptr.Deref(format, ""))
182+
data, _, err = getBootstrapData(context.Background(), machineScope)
193183
require.Equal(t, []byte("notdata"), data)
194184
require.Nil(t, err)
195185
}
@@ -499,6 +489,49 @@ func TestReconcileBootstrapDataMissingNetworkConfig(t *testing.T) {
499489
require.True(t, conditions.GetReason(machineScope.ProxmoxMachine, infrav1alpha1.VMProvisionedCondition) == infrav1alpha1.WaitingForStaticIPAllocationReason)
500490
}
501491

492+
func TestReconcileBootstrapData_Formats(t *testing.T) {
493+
machineScope, _, kubeClient := setupReconcilerTest(t)
494+
495+
vm := newVMWithNets("virtio=A6:23:64:4D:84:CB,bridge=vmbr0")
496+
vm.VirtualMachineConfig.SMBios1 = biosUUID
497+
machineScope.SetVirtualMachine(vm)
498+
machineScope.ProxmoxMachine.Status.IPAddresses = map[string]infrav1alpha1.IPAddress{infrav1alpha1.DefaultNetworkDevice: {IPV4: "10.10.10.10"}}
499+
createIP4AddressResource(t, kubeClient, machineScope, infrav1alpha1.DefaultNetworkDevice, "10.10.10.10")
500+
createBootstrapSecret(t, kubeClient, machineScope)
501+
machineScope.SetVirtualMachine(vm)
502+
getISOInjector = func(_ *proxmox.VirtualMachine, _ []byte, _, _ cloudinit.Renderer) isoInjector {
503+
return FakeISOInjector{}
504+
}
505+
t.Cleanup(func() { getISOInjector = defaultISOInjector })
506+
507+
// test defaulting of format to cloud-config
508+
requeue, err := reconcileBootstrapData(context.Background(), machineScope)
509+
require.NoError(t, err)
510+
require.False(t, requeue)
511+
require.True(t, *machineScope.ProxmoxMachine.Status.BootstrapDataProvided)
512+
513+
data, format, err := getBootstrapData(context.Background(), machineScope)
514+
require.Equal(t, cloudinit.FormatCloudConfig, ptr.Deref(format, ""))
515+
require.Equal(t, []byte("data"), data)
516+
require.Nil(t, err)
517+
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))
524+
525+
_, err = reconcileBootstrapData(context.Background(), machineScope)
526+
require.NoError(t, err)
527+
require.True(t, *machineScope.ProxmoxMachine.Status.BootstrapDataProvided)
528+
529+
data, format, err = getBootstrapData(context.Background(), machineScope)
530+
require.Equal(t, ignition.FormatIgnition, ptr.Deref(format, ""))
531+
require.Equal(t, []byte("data"), data)
532+
require.Nil(t, err)
533+
}
534+
502535
func TestDefaultISOInjector(t *testing.T) {
503536
injector := defaultISOInjector(newRunningVM(), []byte("data"), cloudinit.NewMetadata(biosUUID, "test", "1.2.3", true), cloudinit.NewNetworkConfig(nil))
504537

0 commit comments

Comments
 (0)