From 205b492a87e1c6a4d7fbda835473c8d4aaa64dcd Mon Sep 17 00:00:00 2001 From: Steven Powell Date: Wed, 22 Sep 2021 15:07:36 -0700 Subject: [PATCH 1/2] implement --force-systemd into cri-o --- pkg/minikube/cruntime/crio.go | 20 +++++++++++++++++--- test/integration/docker_test.go | 16 +++++++++++++++- 2 files changed, 32 insertions(+), 4 deletions(-) diff --git a/pkg/minikube/cruntime/crio.go b/pkg/minikube/cruntime/crio.go index 4da2bf4bada3..258bdebb89cc 100644 --- a/pkg/minikube/cruntime/crio.go +++ b/pkg/minikube/cruntime/crio.go @@ -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") } diff --git a/test/integration/docker_test.go b/test/integration/docker_test.go index db1f43862138..58f5f1a47377 100644 --- a/test/integration/docker_test.go +++ b/test/integration/docker_test.go @@ -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() { From 33e7a6317374934bfdba47d9edffbaf797daa1a2 Mon Sep 17 00:00:00 2001 From: Steven Powell Date: Wed, 22 Sep 2021 15:21:32 -0700 Subject: [PATCH 2/2] fix typo --- test/integration/docker_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/integration/docker_test.go b/test/integration/docker_test.go index 58f5f1a47377..4b7667690267 100644 --- a/test/integration/docker_test.go +++ b/test/integration/docker_test.go @@ -123,7 +123,7 @@ func validateContainerdSystemd(ctx context.Context, t *testing.T, profile string } // validateCrioSystemd makes sure the --force-systemd flag worked with the cri-o container runtime -func validateCrioSystemd(ctx context.Cotnext, t *testing.T, profile string) { +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)