Skip to content

Commit

Permalink
Checkup: Randomize ConfigMap name
Browse files Browse the repository at this point in the history
Currently, the ConfigMap that is used to inject the boot script
to the VM under test has a constant name.

This prevents running multiple instances of the checkup
in one namespace simultaneously.

Randomize the name, so the checkup could have multiple simultaneously
running instances in a single namespace.

Signed-off-by: Orel Misan <omisan@redhat.com>
  • Loading branch information
orelmisan committed Apr 8, 2024
1 parent bee6c3a commit c965f01
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions pkg/internal/checkup/checkup.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,13 @@ func New(client kubeVirtVMIClient, namespace string, checkupConfig config.Config
const randomStringLen = 5
randomSuffix := k8srand.String(randomStringLen)

vmiUnderTestCMName := vmiUnderTestConfigMapName(randomSuffix)

return &Checkup{
client: client,
namespace: namespace,
vmUnderTestConfigMap: newVMUnderTestConfigMap(checkupConfig),
vmi: newRealtimeVMI(vmiUnderTestName(randomSuffix), checkupConfig),
vmUnderTestConfigMap: newVMUnderTestConfigMap(vmiUnderTestCMName, checkupConfig),
vmi: newRealtimeVMI(vmiUnderTestName(randomSuffix), checkupConfig, vmiUnderTestCMName),
executor: executor,
cfg: checkupConfig,
}
Expand Down Expand Up @@ -230,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(name string, checkupConfig config.Config) *kvcorev1.VirtualMachineInstance {
func newRealtimeVMI(name string, checkupConfig config.Config, configMapName string) *kvcorev1.VirtualMachineInstance {
const (
CPUSocketsCount = 1
CPUCoresCount = 4
Expand All @@ -267,7 +269,7 @@ func newRealtimeVMI(name string, checkupConfig config.Config) *kvcorev1.VirtualM
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 @@ -321,6 +323,10 @@ func vmiUnderTestName(suffix string) string {
return VMINamePrefix + "-" + suffix
}

func vmiUnderTestConfigMapName(suffix string) string {
return VMUnderTestConfigMapNamePrefix + "-" + suffix
}

func ObjectFullName(namespace, name string) string {
return fmt.Sprintf("%s/%s", namespace, name)
}

0 comments on commit c965f01

Please sign in to comment.