Skip to content
This repository has been archived by the owner on Jun 14, 2023. It is now read-only.

Commit

Permalink
add containerd support
Browse files Browse the repository at this point in the history
  • Loading branch information
moshloop committed Jun 25, 2019
1 parent 16e7a0b commit ec4cba5
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
2 changes: 2 additions & 0 deletions fixtures/containerd.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
container_runtime:
type: containerd
28 changes: 27 additions & 1 deletion pkg/apps/cri.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ func (c cri) ApplyPhase(sys *Config, ctx *SystemContext) ([]Command, Filesystem,

if sys.ContainerRuntime.Type == "docker" {
return c.Docker(sys, ctx)
} else if sys.ContainerRuntime.Type == "containerd" {
return c.Containerd(sys, ctx)
} else {
return []Command{}, Filesystem{}, fmt.Errorf("unknown container runtime %s", sys.ContainerRuntime.Type)
}
Expand All @@ -42,14 +44,23 @@ func (c cri) Verify(sys *Config, results *VerifyResults, flags ...Flag) bool {
results.Fail("docker ps failed with: %s", out)
}

} else if sys.ContainerRuntime.Type == "containerd" {
verify = verify && phases.VerifyService("containerd", results)
out, ok := utils.SafeExec("crictl ps")
if ok {
results.Pass("crictl ps returned %d containers", len(strings.Split(out, "\n"))-2)
} else {
verify = false
results.Fail("crictl ps failed with: %s", out)
}
} else {
results.Fail("Unknown runtime %s", sys.ContainerRuntime.Type)
return false
}
return verify
}

func (c cri) Docker(sys *Config, ctx *SystemContext) ([]Command, Filesystem, error) {
func addDockerRepos(sys *Config) {
sys.AppendPackageRepo(PackageRepo{
Name: "docker-ce",
URL: "https://download.docker.com/linux/ubuntu/",
Expand All @@ -76,6 +87,21 @@ func (c cri) Docker(sys *Config, ctx *SystemContext) ([]Command, Filesystem, err
GPGKey: "https://download.docker.com/linux/fedora/gpg",
}, FEDORA)

}

func (c cri) Containerd(sys *Config, ctx *SystemContext) ([]Command, Filesystem, error) {
addDockerRepos(sys)
sys.AddPackage("containerd.io device-mapper-persistent-data lvm2", &REDHAT_LIKE)
sys.AddPackage("containerd.io device-mapper-persistent-data lvm2", &FEDORA)
sys.AddPackage("containerd.io", &DEBIAN_LIKE)
sys.AddCommand("mkdir -p /etc/containerd && containerd config default > /etc/containerd/config.toml")
sys.AddCommand("systemctl enable containerd && systemctl start containerd")
sys.Environment["CONTAINER_RUNTIME_ENDPOINT"] = "unix:///var/run/containerd/containerd.sock"
return []Command{}, Filesystem{}, nil
}

func (c cri) Docker(sys *Config, ctx *SystemContext) ([]Command, Filesystem, error) {
addDockerRepos(sys)
sys.AddPackage("docker-ce docker-ce-cli containerd.io device-mapper-persistent-data lvm2", &REDHAT_LIKE)
sys.AddPackage("docker-ce docker-ce-cli containerd.io device-mapper-persistent-data lvm2", &FEDORA)
sys.AddPackage("docker-ce docker-ce-cli containerd.io", &DEBIAN_LIKE)
Expand Down
1 change: 1 addition & 0 deletions test/setup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ var fixtures = []struct {
{"containers.yml"},
{"docker.yml"},
{"ansible.yml"},
{"containerd.yml"},
{"files.yml"},
{"kubernetes.yml"},
{"packages.yml"},
Expand Down

0 comments on commit ec4cba5

Please sign in to comment.