-
Notifications
You must be signed in to change notification settings - Fork 631
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support to run systemd in containers
Signed-off-by: Spencer von der Ohe <s.vonderohe40@gmail.com>
- Loading branch information
Showing
8 changed files
with
171 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
/* | ||
Copyright The containerd Authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package main | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/containerd/nerdctl/v2/pkg/testutil" | ||
) | ||
|
||
func TestRunWithSystemdAlways(t *testing.T) { | ||
testutil.DockerIncompatible(t) | ||
t.Parallel() | ||
base := testutil.NewBase(t) | ||
containerName := testutil.Identifier(t) | ||
defer base.Cmd("container", "rm", "-f", containerName).AssertOK() | ||
|
||
base.Cmd("run", "--name", containerName, "--systemd=always", "--entrypoint=/bin/bash", testutil.UbuntuImage, "-c", "mount | grep cgroup").AssertOutContains("(rw,") | ||
|
||
base.Cmd("inspect", "--format", "{{json .Config.Labels}}", containerName).AssertOutContains("SIGRTMIN+3") | ||
|
||
} | ||
|
||
func TestRunWithSystemdTrueEnabled(t *testing.T) { | ||
testutil.DockerIncompatible(t) | ||
t.Parallel() | ||
base := testutil.NewBase(t) | ||
containerName := testutil.Identifier(t) | ||
defer base.Cmd("container", "rm", "-f", containerName).AssertOK() | ||
|
||
base.Cmd("run", "-d", "--name", containerName, "--systemd=true", "--entrypoint=/sbin/init", testutil.SystemdImage).AssertOK() | ||
|
||
base.Cmd("inspect", "--format", "{{json .Config.Labels}}", containerName).AssertOutContains("SIGRTMIN+3") | ||
|
||
base.Cmd("exec", containerName, "systemctl", "list-jobs").AssertOutContains("jobs listed.") | ||
} | ||
|
||
func TestRunWithSystemdTrueDisabled(t *testing.T) { | ||
testutil.DockerIncompatible(t) | ||
t.Parallel() | ||
base := testutil.NewBase(t) | ||
containerName := testutil.Identifier(t) | ||
defer base.Cmd("rm", "-f", containerName).AssertOK() | ||
|
||
base.Cmd("run", "--name", containerName, "--systemd=true", "--entrypoint=/bin/bash", testutil.SystemdImage, "-c", "systemctl list-jobs || true").AssertCombinedOutContains("System has not been booted with systemd as init system") | ||
} | ||
|
||
func TestRunWithSystemdFalse(t *testing.T) { | ||
testutil.DockerIncompatible(t) | ||
t.Parallel() | ||
base := testutil.NewBase(t) | ||
containerName := testutil.Identifier(t) | ||
defer base.Cmd("rm", "-f", containerName).AssertOK() | ||
|
||
base.Cmd("run", "--name", containerName, "--systemd=false", "--entrypoint=/bin/bash", testutil.UbuntuImage, "-c", "mount | grep cgroup").AssertOutContains("(ro,") | ||
|
||
base.Cmd("inspect", "--format", "{{json .Config.Labels}}", containerName).AssertOutContains("SIGTERM") | ||
} | ||
|
||
func TestRunWithNoSystemd(t *testing.T) { | ||
testutil.DockerIncompatible(t) | ||
t.Parallel() | ||
base := testutil.NewBase(t) | ||
containerName := testutil.Identifier(t) | ||
defer base.Cmd("rm", "-f", containerName).AssertOK() | ||
|
||
base.Cmd("run", "--name", containerName, "--entrypoint=/bin/bash", testutil.UbuntuImage, "-c", "mount | grep cgroup").AssertOutContains("(ro,") | ||
|
||
base.Cmd("inspect", "--format", "{{json .Config.Labels}}", containerName).AssertOutContains("SIGTERM") | ||
} | ||
|
||
func TestRunWithSystemdPrivilegedError(t *testing.T) { | ||
testutil.DockerIncompatible(t) | ||
t.Parallel() | ||
base := testutil.NewBase(t) | ||
|
||
base.Cmd("run", "--privileged", "--rm", "--systemd=always", "--entrypoint=/sbin/init", testutil.SystemdImage).AssertCombinedOutContains("if --privileged is used with systemd `--security-opt privileged-without-host-devices` must also be used") | ||
} | ||
|
||
func TestRunWithSystemdPrivilegedSuccess(t *testing.T) { | ||
testutil.DockerIncompatible(t) | ||
t.Parallel() | ||
base := testutil.NewBase(t) | ||
containerName := testutil.Identifier(t) | ||
defer base.Cmd("container", "rm", "-f", containerName).AssertOK() | ||
|
||
base.Cmd("run", "-d", "--name", containerName, "--privileged", "--security-opt", "privileged-without-host-devices", "--systemd=true", "--entrypoint=/sbin/init", testutil.SystemdImage).AssertOK() | ||
|
||
base.Cmd("inspect", "--format", "{{json .Config.Labels}}", containerName).AssertOutContains("SIGRTMIN+3") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters