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: Introduce vmi under test configmap #219

Merged
merged 2 commits into from
Jan 25, 2024
Merged
Show file tree
Hide file tree
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
73 changes: 49 additions & 24 deletions pkg/internal/checkup/checkup.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,34 +54,38 @@ type testExecutor interface {
}

type Checkup struct {
client kubeVirtVMIClient
namespace string
params config.Config
vmiUnderTest *kvcorev1.VirtualMachineInstance
trafficGen *kvcorev1.VirtualMachineInstance
trafficGenConfigMap *k8scorev1.ConfigMap
results status.Results
executor testExecutor
client kubeVirtVMIClient
namespace string
params config.Config
vmiUnderTest *kvcorev1.VirtualMachineInstance
trafficGen *kvcorev1.VirtualMachineInstance
trafficGenConfigMap *k8scorev1.ConfigMap
vmiUnderTestConfigMap *k8scorev1.ConfigMap
results status.Results
executor testExecutor
}

const (
TrafficGenConfigMapNamePrefix = "dpdk-traffic-gen-config"
TrafficGenConfigMapNamePrefix = "dpdk-traffic-gen-config"
vmiUnderTestConfigMapNamePrefix = "vmi-under-test-config"
)

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

trafficGenCMName := trafficGenConfigMapName(randomSuffix)
vmiUnderTestCMName := vmiUnderTestConfigMapName(randomSuffix)

return &Checkup{
client: client,
namespace: namespace,
params: checkupConfig,
vmiUnderTest: newVMIUnderTest(vmiUnderTestName(randomSuffix), checkupConfig),
trafficGen: newTrafficGen(trafficGenName(randomSuffix), checkupConfig, trafficGenCMName),
trafficGenConfigMap: newTrafficGenConfigMap(trafficGenCMName, checkupConfig),
executor: executor,
client: client,
namespace: namespace,
params: checkupConfig,
vmiUnderTest: newVMIUnderTest(vmiUnderTestName(randomSuffix), checkupConfig, vmiUnderTestCMName),
vmiUnderTestConfigMap: newVMIUnderTestConfigMap(vmiUnderTestCMName, checkupConfig),
trafficGen: newTrafficGen(trafficGenName(randomSuffix), checkupConfig, trafficGenCMName),
trafficGenConfigMap: newTrafficGenConfigMap(trafficGenCMName, checkupConfig),
executor: executor,
}
}

Expand All @@ -93,7 +97,11 @@ func (c *Checkup) Setup(ctx context.Context) (setupErr error) {
const errMessagePrefix = "setup"
var err error

if err = c.createTrafficGenCM(setupCtx); err != nil {
if err = c.createConfigmap(setupCtx, c.trafficGenConfigMap); err != nil {
return fmt.Errorf("%s: %w", errMessagePrefix, err)
}

if err = c.createConfigmap(setupCtx, c.vmiUnderTestConfigMap); err != nil {
return fmt.Errorf("%s: %w", errMessagePrefix, err)
}

Expand Down Expand Up @@ -178,7 +186,11 @@ func (c *Checkup) Teardown(ctx context.Context) error {
teardownErrors = append(teardownErrors, fmt.Sprintf("%s: %v", errMessagePrefix, err))
}

if err := c.deleteTrafficGenCM(ctx); err != nil {
if err := c.deleteConfigmap(ctx, c.trafficGenConfigMap); err != nil {
teardownErrors = append(teardownErrors, fmt.Sprintf("%s: %v", errMessagePrefix, err))
}

if err := c.deleteConfigmap(ctx, c.vmiUnderTestConfigMap); err != nil {
teardownErrors = append(teardownErrors, fmt.Sprintf("%s: %v", errMessagePrefix, err))
}

Expand All @@ -201,17 +213,17 @@ func (c *Checkup) Results() status.Results {
return c.results
}

func (c *Checkup) createTrafficGenCM(ctx context.Context) error {
log.Printf("Creating ConfigMap %q...", ObjectFullName(c.namespace, c.trafficGenConfigMap.Name))
func (c *Checkup) createConfigmap(ctx context.Context, configMap *k8scorev1.ConfigMap) error {
log.Printf("Creating ConfigMap %q...", ObjectFullName(c.namespace, configMap.Name))

_, err := c.client.CreateConfigMap(ctx, c.namespace, c.trafficGenConfigMap)
_, err := c.client.CreateConfigMap(ctx, c.namespace, configMap)
return err
}

func (c *Checkup) deleteTrafficGenCM(ctx context.Context) error {
log.Printf("Deleting ConfigMap %q...", ObjectFullName(c.namespace, c.trafficGenConfigMap.Name))
func (c *Checkup) deleteConfigmap(ctx context.Context, configMap *k8scorev1.ConfigMap) error {
log.Printf("Deleting ConfigMap %q...", ObjectFullName(c.namespace, configMap.Name))

return c.client.DeleteConfigMap(ctx, c.namespace, c.trafficGenConfigMap.Name)
return c.client.DeleteConfigMap(ctx, c.namespace, configMap.Name)
}

func (c *Checkup) createVMI(ctx context.Context, vmiToCreate *kvcorev1.VirtualMachineInstance) error {
Expand Down Expand Up @@ -304,6 +316,15 @@ func ObjectFullName(namespace, name string) string {
return fmt.Sprintf("%s/%s", namespace, name)
}

func newVMIUnderTestConfigMap(name string, checkupConfig config.Config) *k8scorev1.ConfigMap {
return configmap.New(
name,
checkupConfig.PodName,
checkupConfig.PodUID,
nil,
)
}

func newTrafficGenConfigMap(name string, checkupConfig config.Config) *k8scorev1.ConfigMap {
trexConfig := trex.NewConfig(checkupConfig)
trafficGenConfigData := map[string]string{
Expand Down Expand Up @@ -332,3 +353,7 @@ func trafficGenName(suffix string) string {
func trafficGenConfigMapName(suffix string) string {
return TrafficGenConfigMapNamePrefix + "-" + suffix
}

func vmiUnderTestConfigMapName(suffix string) string {
return vmiUnderTestConfigMapNamePrefix + "-" + suffix
}
Comment on lines +357 to +359
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function is a duplicate of trafficGenConfigMapName(), please consider adjusting the signature of trafficGenConfigMapName and using a single function for both uses.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's do it in a later PR

2 changes: 1 addition & 1 deletion pkg/internal/checkup/checkup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ func TestTeardownShouldFailWhen(t *testing.T) {
})
}

func TestTrafficGenCMTeardownFailure(t *testing.T) {
func TestVMConfigMapTeardownFailure(t *testing.T) {
testClient := newClientStub()
testConfig := newTestConfig()

Expand Down
21 changes: 19 additions & 2 deletions pkg/internal/checkup/vmi.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,23 @@ const (
terminationGracePeriodSeconds = 0
)

func newVMIUnderTest(name string, checkupConfig config.Config) *kvcorev1.VirtualMachineInstance {
func newVMIUnderTest(name string, checkupConfig config.Config, configMapName string) *kvcorev1.VirtualMachineInstance {
const (
configDiskSerial = "DEADBEEF"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please consider increasing the scope of the original configDiskSerial const, and share it between the VMIs.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see a reason to do that, It would imply that it is connected somehow..
Both VMIs have configmaps, both happen to have the same serial..

configVolumeName = "vmi-under-test-config"
)

optionsToApply := baseOptions(checkupConfig)

optionsToApply = append(optionsToApply,
vmi.WithAffinity(Affinity(checkupConfig.VMUnderTestTargetNodeName, checkupConfig.PodUID)),
vmi.WithSRIOVInterface(eastNetworkName, checkupConfig.VMUnderTestEastMacAddress.String(), config.VMIEastNICPCIAddress),
vmi.WithSRIOVInterface(westNetworkName, checkupConfig.VMUnderTestWestMacAddress.String(), config.VMIWestNICPCIAddress),
vmi.WithContainerDisk(rootDiskName, checkupConfig.VMUnderTestContainerDiskImage),
vmi.WithCloudInitNoCloudVolume(cloudInitDiskName, CloudInit(config.VMIUsername, config.VMIPassword, nil)),
vmi.WithCloudInitNoCloudVolume(cloudInitDiskName,
CloudInit(config.VMIUsername, config.VMIPassword, vmiUnderTestBootCommands(configDiskSerial))),
vmi.WithConfigMapVolume(configVolumeName, configMapName),
vmi.WithConfigMapDisk(configVolumeName, configDiskSerial),
Comment on lines +71 to +72
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This part could potentially be moved to baseOptions() so it could be shared by the two VMIs.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought about it, but ended up not liking the fact that part of the configmap is loaded on the base function, and part here. It makes it less understood. WDYT?

)

return vmi.New(name, optionsToApply...)
Expand Down Expand Up @@ -156,3 +164,12 @@ func trafficGenBootCommands(configDiskSerial string) []string {
fmt.Sprintf("cp %s/*.py %s", configMountDirectory, trex.StreamsPyPath),
}
}

func vmiUnderTestBootCommands(configDiskSerial string) []string {
const configMountDirectory = "/mnt/app-config"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please consider increasing the scope of the existing configMountDirectory const, and share it between the functions.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we don't need it anywhere else. Everything is copied from this dir to where it will actually be executed.


return []string{
fmt.Sprintf("mkdir %s", configMountDirectory),
fmt.Sprintf("mount /dev/$(lsblk --nodeps -no name,serial | grep %s | cut -f1 -d' ') %s", configDiskSerial, configMountDirectory),
}
}
Loading