Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Checkup: Randomize ConfigMap name #66

Merged
merged 2 commits into from
Apr 8, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 17 additions & 10 deletions pkg/internal/checkup/checkup.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,16 @@ const (
)

func New(client kubeVirtVMIClient, namespace string, checkupConfig config.Config, executor testExecutor) *Checkup {
const randomStringLen = 5
randomSuffix := k8srand.String(randomStringLen)

vmiUnderTestCMName := vmiUnderTestConfigMapName(randomSuffix)

return &Checkup{
client: client,
namespace: namespace,
vmUnderTestConfigMap: newVMUnderTestConfigMap(checkupConfig),
vmi: newRealtimeVMI(checkupConfig),
vmUnderTestConfigMap: newVMUnderTestConfigMap(vmiUnderTestCMName, checkupConfig),
vmi: newRealtimeVMI(vmiUnderTestName(randomSuffix), checkupConfig, vmiUnderTestCMName),
executor: executor,
cfg: checkupConfig,
}
Expand Down Expand Up @@ -227,17 +232,17 @@ func (c *Checkup) waitForVMIDeletion(ctx context.Context) error {
return nil
}

func newVMUnderTestConfigMap(checkupConfig config.Config) *corev1.ConfigMap {
func newVMUnderTestConfigMap(name string, checkupConfig config.Config) *corev1.ConfigMap {
vmUnderTestConfigData := map[string]string{
config.BootScriptName: generateBootScript(),
}
return configmap.New(VMUnderTestConfigMapNamePrefix,
return configmap.New(name,
checkupConfig.PodName,
checkupConfig.PodUID,
vmUnderTestConfigData)
}

func newRealtimeVMI(checkupConfig config.Config) *kvcorev1.VirtualMachineInstance {
func newRealtimeVMI(name string, checkupConfig config.Config, configMapName string) *kvcorev1.VirtualMachineInstance {
const (
CPUSocketsCount = 1
CPUCoresCount = 4
Expand All @@ -250,7 +255,7 @@ func newRealtimeVMI(checkupConfig config.Config) *kvcorev1.VirtualMachineInstanc
configVolumeName = "realtime-config"
)

return vmi.New(randomizeName(VMINamePrefix),
return vmi.New(name,
vmi.WithOwnerReference(checkupConfig.PodName, checkupConfig.PodUID),
vmi.WithoutCRIOCPULoadBalancing(),
vmi.WithoutCRIOCPUQuota(),
Expand All @@ -264,7 +269,7 @@ func newRealtimeVMI(checkupConfig config.Config) *kvcorev1.VirtualMachineInstanc
vmi.WithNodeSelector(checkupConfig.VMUnderTestTargetNodeName),
vmi.WithContainerDisk(rootDiskName, checkupConfig.VMUnderTestContainerDiskImage),
vmi.WithVirtIODisk(rootDiskName),
vmi.WithConfigMapVolume(configVolumeName, VMUnderTestConfigMapNamePrefix),
vmi.WithConfigMapVolume(configVolumeName, configMapName),
vmi.WithConfigMapDisk(configVolumeName, configDiskSerial),
vmi.WithCloudInitNoCloudVolume(cloudInitDiskName,
vmi.CloudInit(realtimeVMIBootCommands(configDiskSerial))),
Expand Down Expand Up @@ -314,10 +319,12 @@ func realtimeVMIBootCommands(configDiskSerial string) []string {
}
}

func randomizeName(prefix string) string {
const randomStringLen = 5
func vmiUnderTestName(suffix string) string {
return VMINamePrefix + "-" + suffix
}

return fmt.Sprintf("%s-%s", prefix, k8srand.String(randomStringLen))
func vmiUnderTestConfigMapName(suffix string) string {
return VMUnderTestConfigMapNamePrefix + "-" + suffix
}

func ObjectFullName(namespace, name string) string {
Expand Down
Loading