Skip to content
This repository has been archived by the owner on May 12, 2021. It is now read-only.

cli: add guest hook path option #720

Closed
wants to merge 1 commit into from
Closed
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
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ DEFENABLEDEBUG := false
DEFDISABLENESTINGCHECKS := false
DEFMSIZE9P := 8192
DEFHOTPLUGVFIOONROOTBUS := false
DEFGUESTHOOKPATH :=

SED = sed

Expand Down Expand Up @@ -204,6 +205,7 @@ USER_VARS += DEFENABLEDEBUG
USER_VARS += DEFDISABLENESTINGCHECKS
USER_VARS += DEFMSIZE9P
USER_VARS += DEFHOTPLUGVFIOONROOTBUS
USER_VARS += DEFGUESTHOOKPATH

V = @
Q = $(V:1=)
Expand Down Expand Up @@ -299,6 +301,7 @@ const defaultEnableDebug bool = $(DEFENABLEDEBUG)
const defaultDisableNestingChecks bool = $(DEFDISABLENESTINGCHECKS)
const defaultMsize9p uint32 = $(DEFMSIZE9P)
const defaultHotplugVFIOOnRootBus bool = $(DEFHOTPLUGVFIOONROOTBUS)
const defaultGuestHookPath string = "$(DEFGUESTHOOKPATH)"

// Default config file used by stateless systems.
var defaultRuntimeConfiguration = "$(CONFIG_PATH)"
Expand Down Expand Up @@ -386,6 +389,7 @@ $(GENERATED_FILES): %: %.in Makefile VERSION
-e "s|@DEFDISABLENESTINGCHECKS@|$(DEFDISABLENESTINGCHECKS)|g" \
-e "s|@DEFMSIZE9P@|$(DEFMSIZE9P)|g" \
-e "s|@DEFHOTPLUGONROOTBUS@|$(DEFHOTPLUGVFIOONROOTBUS)|g" \
-e "s|@DEFGUESTHOOKPATH@|$(DEFGUESTHOOKPATH)|g" \
$< > $@

generate-config: $(CONFIG)
Expand Down
10 changes: 10 additions & 0 deletions cli/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ type hypervisor struct {
EnableIOThreads bool `toml:"enable_iothreads"`
UseVSock bool `toml:"use_vsock"`
HotplugVFIOOnRootBus bool `toml:"hotplug_vfio_on_root_bus"`
GuestHookPath string `toml:"guest_hook_path"`
}

type proxy struct {
Expand Down Expand Up @@ -275,6 +276,13 @@ func (h hypervisor) useVSock() bool {
return h.UseVSock
}

func (h hypervisor) guestHookPath() string {
eguzman3 marked this conversation as resolved.
Show resolved Hide resolved
if h.GuestHookPath == "" {
return defaultGuestHookPath
}
return h.GuestHookPath
}

func (p proxy) path() string {
if p.Path == "" {
return defaultProxyPath
Expand Down Expand Up @@ -375,6 +383,7 @@ func newQemuHypervisorConfig(h hypervisor) (vc.HypervisorConfig, error) {
Msize9p: h.msize9p(),
UseVSock: useVSock,
HotplugVFIOOnRootBus: h.HotplugVFIOOnRootBus,
GuestHookPath: h.guestHookPath(),
}, nil
}

Expand Down Expand Up @@ -490,6 +499,7 @@ func loadConfiguration(configPath string, ignoreLogging bool) (resolvedConfigPat
EnableIOThreads: defaultEnableIOThreads,
Msize9p: defaultMsize9p,
HotplugVFIOOnRootBus: defaultHotplugVFIOOnRootBus,
GuestHookPath: defaultGuestHookPath,
}

err = config.InterNetworkModel.SetModel(defaultInterNetworkingModel)
Expand Down
5 changes: 5 additions & 0 deletions cli/config/configuration.toml.in
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,11 @@ enable_iothreads = @DEFENABLEIOTHREADS@
# Default false
#hotplug_vfio_on_root_bus = true

# If set to an absolute path within the guest rootfs, the agent
# will search this directory for OCI hooks and add them to the guest
# container's lifecycle.
#guest_hook_path = "@DEFGUESTHOOKPATH@"

[factory]
# VM templating support. Once enabled, new VMs are created from template
# using vm cloning. They will share the same initial kernel, initramfs and
Expand Down
18 changes: 18 additions & 0 deletions cli/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ func makeRuntimeConfigFileData(hypervisor, hypervisorPath, kernelPath, imagePath
enable_iothreads = ` + strconv.FormatBool(enableIOThreads) + `
hotplug_vfio_on_root_bus = ` + strconv.FormatBool(hotplugVFIOOnRootBus) + `
msize_9p = ` + strconv.FormatUint(uint64(defaultMsize9p), 10) + `
guest_hook_path = "` + defaultGuestHookPath + `"

[proxy.kata]
path = "` + proxyPath + `"
Expand Down Expand Up @@ -143,6 +144,7 @@ func createAllRuntimeConfigFiles(dir, hypervisor string) (config testRuntimeConf
EnableIOThreads: enableIOThreads,
HotplugVFIOOnRootBus: hotplugVFIOOnRootBus,
Msize9p: defaultMsize9p,
GuestHookPath: defaultGuestHookPath,
}

agentConfig := vc.KataAgentConfig{}
Expand Down Expand Up @@ -562,6 +564,7 @@ func TestMinimalRuntimeConfig(t *testing.T) {
Mlock: !defaultEnableSwap,
BlockDeviceDriver: defaultBlockDeviceDriver,
Msize9p: defaultMsize9p,
GuestHookPath: defaultGuestHookPath,
}

expectedAgentConfig := vc.KataAgentConfig{}
Expand Down Expand Up @@ -1035,6 +1038,21 @@ func TestHypervisorDefaultsImage(t *testing.T) {
assert.Equal(p, "")
}

func TestHypervisorDefaultsGuestHookPath(t *testing.T) {
assert := assert.New(t)

h := hypervisor{}
guestHookPath := h.guestHookPath()
assert.Equal(guestHookPath, defaultGuestHookPath, "default guest hook path wrong")

testGuestHookPath := "/test/guest/hook/path"
h = hypervisor{
GuestHookPath: testGuestHookPath,
}
guestHookPath = h.guestHookPath()
assert.Equal(guestHookPath, testGuestHookPath, "custom guest hook path wrong")
}

func TestProxyDefaults(t *testing.T) {
p := proxy{}

Expand Down
Loading