Skip to content

Commit

Permalink
Merge pull request #12553 from spowelljr/addForceSystemdCrio
Browse files Browse the repository at this point in the history
Implement --force-systemd into cri-o
  • Loading branch information
medyagh authored Sep 23, 2021
2 parents f24c81b + 33e7a63 commit 8c0e46c
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 4 deletions.
20 changes: 17 additions & 3 deletions pkg/minikube/cruntime/crio.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.")
}
Expand All @@ -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"
Expand Down Expand Up @@ -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)")
}
Expand All @@ -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")
}

Expand Down
16 changes: 15 additions & 1 deletion test/integration/docker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

}
Expand All @@ -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.Context, 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() {
Expand Down

0 comments on commit 8c0e46c

Please sign in to comment.