Skip to content

Commit

Permalink
daemon: allow an extension to install group of packages
Browse files Browse the repository at this point in the history
In the previous implementation, an extension was one to one
mapping with the package it would install on the host. This can
become confusing if enabling an extension would require
installing multiple sets of packages which are not install
time dependency.

Also added e2e test for kernel-devel extensions
  • Loading branch information
sinnykumari committed Oct 22, 2020
1 parent bbf9163 commit c30db97
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 11 deletions.
29 changes: 25 additions & 4 deletions pkg/daemon/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -865,22 +865,43 @@ func generateExtensionsArgs(oldConfig, newConfig *mcfgv1.MachineConfig) []string
}
}

// Supported extensions has package list info that is required
// to enable an extension
extensions := getSupportedExtensions()

extArgs := []string{"update"}
for _, ext := range added {
extArgs = append(extArgs, "--install", ext)
for _, pkg := range extensions[ext] {
extArgs = append(extArgs, "--install", pkg)
}
}
for _, ext := range removed {
extArgs = append(extArgs, "--uninstall", ext)
for _, pkg := range extensions[ext] {
extArgs = append(extArgs, "--uninstall", pkg)
}
}

return extArgs
}

// Returns list of extensions possible to install on a CoreOS based system.
func getSupportedExtensions() map[string][]string {
// In future when list of extensions grow, it will make
// more sense to populate it in a dynamic way.

// These are RHCOS supported extensions.
// Each extension keeps a list of packages required to get enabled on host.
return map[string][]string{
"usbguard": {"usbguard"},
"kernel-devel": {"kernel-devel", "kernel-headers"},
}
}

func validateExtensions(exts []string) error {
supportedExtensions := []string{"usbguard", "kernel-devel"}
supportedExtensions := getSupportedExtensions()
invalidExts := []string{}
for _, ext := range exts {
if !ctrlcommon.InSlice(ext, supportedExtensions) {
if _, ok := supportedExtensions[ext]; !ok {
invalidExts = append(invalidExts, ext)
}
}
Expand Down
23 changes: 16 additions & 7 deletions test/e2e/mcd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ func TestExtensions(t *testing.T) {
Config: runtime.RawExtension{
Raw: helpers.MarshalOrDie(ctrlcommon.NewIgnConfig()),
},
Extensions: []string{"usbguard"},
Extensions: []string{"usbguard", "kernel-devel"},
},
}

Expand All @@ -269,10 +269,14 @@ func TestExtensions(t *testing.T) {
assert.Equal(t, infraNode.Annotations[constants.CurrentMachineConfigAnnotationKey], renderedConfig)
assert.Equal(t, infraNode.Annotations[constants.MachineConfigDaemonStateAnnotationKey], constants.MachineConfigDaemonStateDone)

installedExtesnions := execCmdOnNode(t, cs, infraNode, "chroot", "/rootfs", "rpm", "-qa", "usbguard")
if !strings.Contains(installedExtesnions, "usbguard") {
t.Fatalf("Node %s doesn't have expected extensions", infraNode.Name)
installedPackages := execCmdOnNode(t, cs, infraNode, "chroot", "/rootfs", "rpm", "-q", "usbguard", "kernel-devel", "kernel-headers")
expectedPackages := []string{"usbguard", "kernel-devel", "kernel-headers"}
for _, v := range expectedPackages {
if !strings.Contains(installedPackages, v) {
t.Fatalf("Node %s doesn't have expected extensions", infraNode.Name)
}
}

t.Logf("Node %s has expected extensions installed", infraNode.Name)

// Delete the applied kerneltype MachineConfig to make sure rollback works fine
Expand All @@ -292,10 +296,15 @@ func TestExtensions(t *testing.T) {

assert.Equal(t, infraNode.Annotations[constants.CurrentMachineConfigAnnotationKey], oldInfraRenderedConfig)
assert.Equal(t, infraNode.Annotations[constants.MachineConfigDaemonStateAnnotationKey], constants.MachineConfigDaemonStateDone)
installedExtesnions = execCmdOnNode(t, cs, infraNode, "chroot", "/rootfs", "rpm", "-qa", "usbguard")
if strings.Contains(installedExtesnions, "usbguard") {
t.Fatalf("Node %s did not rollback successfully", infraNode.Name)

installedPackages = execCmdOnNode(t, cs, infraNode, "chroot", "/rootfs", "rpm", "-qa", "usbguard", "kernel-devel", "kernel-headers")
expectedPackages = []string{"usbguard", "kernel-devel", "kernel-headers"}
for _, v := range expectedPackages {
if strings.Contains(installedPackages, v) {
t.Fatalf("Node %s did not rollback successfully", infraNode.Name)
}
}

t.Logf("Node %s has successfully rolled back", infraNode.Name)

unlabelFunc()
Expand Down

0 comments on commit c30db97

Please sign in to comment.