Skip to content

Commit

Permalink
checkup: Add boot script to VMs' configmaps
Browse files Browse the repository at this point in the history
Currently the VM guests are configured on a service added on the
customize-vm script created in the image building process.
There is no real need for the script to run on that context, and it is
easier to manage if it runs as part of the cloud-init context.
This commits:
- copies the script to a checkup function.
- adds the boot script to the traffic-gen and vmi-under-test VMs
- mounts the script with the correct permissions.

Signed-off-by: Ram Lavi <[email protected]>
  • Loading branch information
RamLavi committed Jan 25, 2024
1 parent 5633c4d commit 9dfcf78
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
7 changes: 6 additions & 1 deletion pkg/internal/checkup/checkup.go
Original file line number Diff line number Diff line change
Expand Up @@ -317,11 +317,15 @@ func ObjectFullName(namespace, name string) string {
}

func newVMIUnderTestConfigMap(name string, checkupConfig config.Config) *k8scorev1.ConfigMap {
vmiUnderTestConfigData := map[string]string{
config.BootScriptName: generateBootScript(),
}

return configmap.New(
name,
checkupConfig.PodName,
checkupConfig.PodUID,
nil,
vmiUnderTestConfigData,
)
}

Expand All @@ -333,6 +337,7 @@ func newTrafficGenConfigMap(name string, checkupConfig config.Config) *k8scorev1
trex.CfgFileName: trexConfig.GenerateCfgFile(),
trex.StreamPyFileName: trexConfig.GenerateStreamPyFile(),
trex.StreamPeerParamsPyFileName: trexConfig.GenerateStreamAddrPyFile(),
config.BootScriptName: generateBootScript(),
}
return configmap.New(
name,
Expand Down
25 changes: 25 additions & 0 deletions pkg/internal/checkup/vmi.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,27 @@ func Affinity(nodeName, ownerUID string) *k8scorev1.Affinity {
return &affinity
}

func generateBootScript() string {
const isolatedCores = "2-7"
sb := strings.Builder{}

sb.WriteString("#!/bin/bash\n")
sb.WriteString("set -e\n")
sb.WriteString("\n")
sb.WriteString("checkup_tuned_adm_set_marker_full_path=" + config.BootScriptTunedAdmSetMarkerFileFullPath + "\n")
sb.WriteString("driverctl set-override " + config.VMIEastNICPCIAddress + " vfio-pci\n")
sb.WriteString("driverctl set-override " + config.VMIWestNICPCIAddress + " vfio-pci\n")
sb.WriteString("\n")
sb.WriteString("if [ ! -f \"$checkup_tuned_adm_set_marker_full_path\" ]; then\n")
sb.WriteString(" echo \"isolated_cores=" + isolatedCores + "\" > /etc/tuned/cpu-partitioning-variables.conf\n")
sb.WriteString(" tuned-adm profile cpu-partitioning\n\n")
sb.WriteString(" touch $checkup_tuned_adm_set_marker_full_path\n")
sb.WriteString(" reboot\n")
sb.WriteString("fi\n")

return sb.String()
}

func CloudInit(username, password string, bootCommands []string) string {
sb := strings.Builder{}
sb.WriteString("#cloud-config\n")
Expand Down Expand Up @@ -162,6 +183,8 @@ func trafficGenBootCommands(configDiskSerial string) []string {
fmt.Sprintf("cp %s /etc", path.Join(configMountDirectory, trex.CfgFileName)),
fmt.Sprintf("mkdir -p %s", trex.StreamsPyPath),
fmt.Sprintf("cp %s/*.py %s", configMountDirectory, trex.StreamsPyPath),
fmt.Sprintf("cp %s %s", path.Join(configMountDirectory, config.BootScriptName), config.BootScriptBinDirectory),
fmt.Sprintf("chmod 744 %s", path.Join(config.BootScriptBinDirectory, config.BootScriptName)),
}
}

Expand All @@ -171,5 +194,7 @@ func vmiUnderTestBootCommands(configDiskSerial string) []string {
return []string{
fmt.Sprintf("mkdir %s", configMountDirectory),
fmt.Sprintf("mount /dev/$(lsblk --nodeps -no name,serial | grep %s | cut -f1 -d' ') %s", configDiskSerial, configMountDirectory),
fmt.Sprintf("cp %s %s", path.Join(configMountDirectory, config.BootScriptName), config.BootScriptBinDirectory),
fmt.Sprintf("chmod 744 %s", path.Join(config.BootScriptBinDirectory, config.BootScriptName)),
}
}
4 changes: 4 additions & 0 deletions pkg/internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ const (

VMIEastNICPCIAddress = "0000:06:00.0"
VMIWestNICPCIAddress = "0000:07:00.0"

BootScriptName = "dpdk-checkup-boot.sh"
BootScriptBinDirectory = "/usr/bin/"
BootScriptTunedAdmSetMarkerFileFullPath = "/var/dpdk-checkup-tuned-adm-set-marker"
)

var (
Expand Down

0 comments on commit 9dfcf78

Please sign in to comment.