implement --force-systemd into cri-o
parent
fb7de65ba5
commit
205b492a87
|
@ -54,10 +54,9 @@ type CRIO struct {
|
|||
|
||||
// generateCRIOConfig sets up /etc/crio/crio.conf
|
||||
func generateCRIOConfig(cr CommandRunner, imageRepository string, kv semver.Version) error {
|
||||
cPath := crioConfigFile
|
||||
pauseImage := images.Pause(kv, imageRepository)
|
||||
|
||||
c := exec.Command("/bin/bash", "-c", fmt.Sprintf("sudo sed -e 's|^pause_image = .*$|pause_image = \"%s\"|' -i %s", pauseImage, cPath))
|
||||
c := exec.Command("/bin/bash", "-c", fmt.Sprintf("sudo sed -e 's|^pause_image = .*$|pause_image = \"%s\"|' -i %s", pauseImage, crioConfigFile))
|
||||
if _, err := cr.RunCmd(c); err != nil {
|
||||
return errors.Wrap(err, "generateCRIOConfig.")
|
||||
}
|
||||
|
@ -72,6 +71,16 @@ func generateCRIOConfig(cr CommandRunner, imageRepository string, kv semver.Vers
|
|||
return nil
|
||||
}
|
||||
|
||||
func (r *CRIO) forceSystemd() error {
|
||||
// remove `cgroup_manager` since cri-o defaults to `systemd` if nothing set
|
||||
c := exec.Command("/bin/bash", "-c", fmt.Sprintf("sudo sed -e 's|^cgroup_manager = .*$||' -i %s", crioConfigFile))
|
||||
if _, err := r.Runner.RunCmd(c); err != nil {
|
||||
return errors.Wrap(err, "force systemd")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Name is a human readable name for CRIO
|
||||
func (r *CRIO) Name() string {
|
||||
return "CRI-O"
|
||||
|
@ -139,7 +148,7 @@ func enableIPForwarding(cr CommandRunner) error {
|
|||
}
|
||||
|
||||
// Enable idempotently enables CRIO on a host
|
||||
func (r *CRIO) Enable(disOthers, _, inUserNamespace bool) error {
|
||||
func (r *CRIO) Enable(disOthers, forceSystemd, inUserNamespace bool) error {
|
||||
if inUserNamespace {
|
||||
return errors.New("inUserNamespace must not be true for cri-o (yet)")
|
||||
}
|
||||
|
@ -157,6 +166,11 @@ func (r *CRIO) Enable(disOthers, _, inUserNamespace bool) error {
|
|||
if err := enableIPForwarding(r.Runner); err != nil {
|
||||
return err
|
||||
}
|
||||
if forceSystemd {
|
||||
if err := r.forceSystemd(); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return r.Init.Start("crio")
|
||||
}
|
||||
|
||||
|
|
|
@ -94,6 +94,8 @@ func TestForceSystemdFlag(t *testing.T) {
|
|||
validateDockerSystemd(ctx, t, profile)
|
||||
case "containerd":
|
||||
validateContainerdSystemd(ctx, t, profile)
|
||||
case "crio":
|
||||
validateCrioSystemd(ctx, t, profile)
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -113,13 +115,25 @@ func validateDockerSystemd(ctx context.Context, t *testing.T, profile string) {
|
|||
func validateContainerdSystemd(ctx context.Context, t *testing.T, profile string) {
|
||||
rr, err := Run(t, exec.CommandContext(ctx, Target(), "-p", profile, "ssh", "cat /etc/containerd/config.toml"))
|
||||
if err != nil {
|
||||
t.Errorf("failed to get docker cgroup driver. args %q: %v", rr.Command(), err)
|
||||
t.Errorf("failed to get containerd cgroup driver. args %q: %v", rr.Command(), err)
|
||||
}
|
||||
if !strings.Contains(rr.Output(), "SystemdCgroup = true") {
|
||||
t.Fatalf("expected systemd cgroup driver, got: %v", rr.Output())
|
||||
}
|
||||
}
|
||||
|
||||
// validateCrioSystemd makes sure the --force-systemd flag worked with the cri-o container runtime
|
||||
func validateCrioSystemd(ctx context.Cotnext, t *testing.T, profile string) {
|
||||
rr, err := Run(t, exec.CommandContext(ctx, Target(), "-p", profile, "ssh", "cat /etc/crio/crio.conf"))
|
||||
if err != nil {
|
||||
t.Errorf("failed to get cri-o cgroup driver. args %q: %v", rr.Command(), err)
|
||||
}
|
||||
// cri-o defaults to `systemd` if `cgroup_manager` not set, so we remove `cgroup_manager` on force
|
||||
if strings.Contains(rr.Output(), "cgroup_manager = ") {
|
||||
t.Fatalf("expected systemd cgroup driver, got: %v", rr.Output())
|
||||
}
|
||||
}
|
||||
|
||||
// TestForceSystemdEnv makes sure the MINIKUBE_FORCE_SYSTEMD environment variable works just as well as the --force-systemd flag
|
||||
func TestForceSystemdEnv(t *testing.T) {
|
||||
if NoneDriver() {
|
||||
|
|
Loading…
Reference in New Issue