diff --git a/pkg/internal/checkup/checkup.go b/pkg/internal/checkup/checkup.go index d3c63d5f..dc529063 100644 --- a/pkg/internal/checkup/checkup.go +++ b/pkg/internal/checkup/checkup.go @@ -23,6 +23,7 @@ import ( "context" "fmt" "log" + "strings" "time" corev1 "k8s.io/api/core/v1" @@ -189,11 +190,6 @@ func newRealtimeVMI(checkupConfig config.Config) *kvcorev1.VirtualMachineInstanc guestMemory = "4Gi" rootDiskName = "rootdisk" cloudInitDiskName = "cloudinitdisk" - userData = `#cloud-config -password: redhat -chpasswd: - expire: false -user: user` ) return vmi.New(randomizeName(VMINamePrefix), @@ -210,7 +206,7 @@ user: user` vmi.WithNodeSelector(checkupConfig.VMUnderTestTargetNodeName), vmi.WithContainerDisk(rootDiskName, checkupConfig.VMUnderTestContainerDiskImage), vmi.WithVirtIODisk(rootDiskName), - vmi.WithCloudInitNoCloudVolume(cloudInitDiskName, userData), + vmi.WithCloudInitNoCloudVolume(cloudInitDiskName, CloudInit(config.VMIUsername, config.VMIPassword)), vmi.WithVirtIODisk(cloudInitDiskName), ) } @@ -224,3 +220,14 @@ func randomizeName(prefix string) string { func ObjectFullName(namespace, name string) string { return fmt.Sprintf("%s/%s", namespace, name) } + +func CloudInit(username, password string) string { + sb := strings.Builder{} + sb.WriteString("#cloud-config\n") + sb.WriteString(fmt.Sprintf("user: %s\n", username)) + sb.WriteString(fmt.Sprintf("password: %s\n", password)) + sb.WriteString("chpasswd:\n") + sb.WriteString(" expire: false") + + return sb.String() +} diff --git a/pkg/internal/checkup/checkup_test.go b/pkg/internal/checkup/checkup_test.go index 5f6e4e38..d1d6985e 100644 --- a/pkg/internal/checkup/checkup_test.go +++ b/pkg/internal/checkup/checkup_test.go @@ -215,6 +215,17 @@ func TestRunFailure(t *testing.T) { assert.Equal(t, expectedResults, actualResults) } +func TestCloudInitString(t *testing.T) { + actualString := checkup.CloudInit("user", "password") + expectedString := `#cloud-config +user: user +password: password +chpasswd: + expire: false` + + assert.Equal(t, expectedString, actualString) +} + type executorStub struct { executeErr error }