mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-07-13 15:14:08 +00:00
cli: only set systemd related kernel parameters when needed
When we install agent as init process in initrd based boot, there is no systemd to be configured. Signed-off-by: Peng Tao <bergwolf@gmail.com>
This commit is contained in:
parent
463e6dee0b
commit
38af66ca39
@ -152,35 +152,48 @@ func create(containerID, bundlePath, console, pidFilePath string, detach bool,
|
|||||||
return createPIDFile(pidFilePath, process.Pid)
|
return createPIDFile(pidFilePath, process.Pid)
|
||||||
}
|
}
|
||||||
|
|
||||||
func getKernelParams(containerID string) []vc.Param {
|
var systemdKernelParam = []vc.Param{
|
||||||
return []vc.Param{
|
{
|
||||||
{
|
Key: "init",
|
||||||
Key: "init",
|
Value: "/usr/lib/systemd/systemd",
|
||||||
Value: "/usr/lib/systemd/systemd",
|
},
|
||||||
},
|
{
|
||||||
{
|
Key: "systemd.unit",
|
||||||
Key: "systemd.unit",
|
Value: systemdUnitName,
|
||||||
Value: systemdUnitName,
|
},
|
||||||
},
|
{
|
||||||
{
|
Key: "systemd.mask",
|
||||||
Key: "systemd.mask",
|
Value: "systemd-networkd.service",
|
||||||
Value: "systemd-networkd.service",
|
},
|
||||||
},
|
{
|
||||||
{
|
Key: "systemd.mask",
|
||||||
Key: "systemd.mask",
|
Value: "systemd-networkd.socket",
|
||||||
Value: "systemd-networkd.socket",
|
},
|
||||||
},
|
}
|
||||||
|
|
||||||
|
func getKernelParams(containerID string, needSystemd bool) []vc.Param {
|
||||||
|
p := []vc.Param{
|
||||||
{
|
{
|
||||||
Key: "ip",
|
Key: "ip",
|
||||||
Value: fmt.Sprintf("::::::%s::off::", containerID),
|
Value: fmt.Sprintf("::::::%s::off::", containerID),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if needSystemd {
|
||||||
|
p = append(p, systemdKernelParam...)
|
||||||
|
}
|
||||||
|
|
||||||
|
return p
|
||||||
|
}
|
||||||
|
|
||||||
|
func needSystemd(config vc.HypervisorConfig) bool {
|
||||||
|
return config.ImagePath != ""
|
||||||
}
|
}
|
||||||
|
|
||||||
// setKernelParams adds the user-specified kernel parameters (from the
|
// setKernelParams adds the user-specified kernel parameters (from the
|
||||||
// configuration file) to the defaults so that the former take priority.
|
// configuration file) to the defaults so that the former take priority.
|
||||||
func setKernelParams(containerID string, runtimeConfig *oci.RuntimeConfig) error {
|
func setKernelParams(containerID string, runtimeConfig *oci.RuntimeConfig) error {
|
||||||
defaultKernelParams := getKernelParamsFunc(containerID)
|
defaultKernelParams := getKernelParamsFunc(containerID, needSystemd(runtimeConfig.HypervisorConfig))
|
||||||
|
|
||||||
if runtimeConfig.HypervisorConfig.Debug {
|
if runtimeConfig.HypervisorConfig.Debug {
|
||||||
strParams := vc.SerializeParams(defaultKernelParams, "=")
|
strParams := vc.SerializeParams(defaultKernelParams, "=")
|
||||||
|
@ -861,7 +861,7 @@ func TestCreateInvalidKernelParams(t *testing.T) {
|
|||||||
getKernelParamsFunc = savedFunc
|
getKernelParamsFunc = savedFunc
|
||||||
}()
|
}()
|
||||||
|
|
||||||
getKernelParamsFunc = func(containerID string) []vc.Param {
|
getKernelParamsFunc = func(containerID string, needSystemd bool) []vc.Param {
|
||||||
return []vc.Param{
|
return []vc.Param{
|
||||||
{
|
{
|
||||||
Key: "",
|
Key: "",
|
||||||
|
Loading…
Reference in New Issue
Block a user