Skip to content

Commit

Permalink
Add support for containerd
Browse files Browse the repository at this point in the history
  • Loading branch information
vpnachev committed Jun 13, 2020
1 parent 7794d16 commit a0160bf
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 3 deletions.
4 changes: 1 addition & 3 deletions pkg/generator/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
package generator

import (
"text/template"

ostemplate "github.com/gardener/gardener/extensions/pkg/controller/operatingsystemconfig/oscommon/template"
"github.com/gobuffalo/packr/v2"
"k8s.io/apimachinery/pkg/util/runtime"
Expand All @@ -32,7 +30,7 @@ func init() {
cloudInitTemplateString, err := box.FindString("cloud-init.gardenlinux.template")
runtime.Must(err)

cloudInitTemplate, err := template.New("cloud-init").Parse(cloudInitTemplateString)
cloudInitTemplate, err := ostemplate.NewTemplate("cloud-init").Parse(cloudInitTemplateString)
runtime.Must(err)
cloudInitGenerator = ostemplate.NewCloudInitGenerator(cloudInitTemplate, ostemplate.DefaultUnitsPath, cmd)
}
Expand Down
19 changes: 19 additions & 0 deletions pkg/generator/generator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,34 @@ package generator_test
import (
gardenlinux_generator "github.com/gardener/gardener-extension-os-gardenlinux/pkg/generator"

commongen "github.com/gardener/gardener/extensions/pkg/controller/operatingsystemconfig/oscommon/generator"
"github.com/gardener/gardener/extensions/pkg/controller/operatingsystemconfig/oscommon/generator/test"
"github.com/gardener/gardener/pkg/apis/extensions/v1alpha1"
"github.com/gobuffalo/packr"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)

var _ = Describe("Garden Linux OS Generator Test", func() {

Describe("Conformance Tests", func() {
var box = packr.NewBox("./testfiles")
g := gardenlinux_generator.CloudInitGenerator()
test.DescribeTest(gardenlinux_generator.CloudInitGenerator(), box)()

It("should render correctly with Containerd enabled", func() {
expectedCloudInit, err := box.Find("cloud-init-containerd")
Expect(err).NotTo(HaveOccurred())

cloudInit, _, err := g.Generate(
&commongen.OperatingSystemConfig{
CRI: &v1alpha1.CRIConfig{
Name: v1alpha1.CRINameContainerD,
},
})

Expect(err).NotTo(HaveOccurred())
Expect(cloudInit).To(Equal(expectedCloudInit))
})
})
})
14 changes: 14 additions & 0 deletions pkg/generator/templates/cloud-init.gardenlinux.template
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,16 @@ cat << EOF | base64 -d > '{{ .Path }}'
EOF
{{- end -}}

{{ if isContainerDEnabled .CRI -}}
mkdir -p /etc/systemd/system/containerd.service.d
cat <<EOF > /etc/systemd/system/containerd.service.d/11-exec_config.conf
[Service]
ExecStart=
ExecStart=/usr/bin/containerd --config=/etc/containerd/config.toml
EOF
chmod 0644 /etc/systemd/system/containerd.service.d/11-exec_config.conf
{{ end -}}

{{- range $_, $file := .Files -}}
mkdir -p '{{ $file.Dirname }}'
{{ template "put-content" $file }}
Expand All @@ -30,8 +40,12 @@ grep -sq "^nfsd$" /etc/modules || echo "nfsd" >>/etc/modules
modprobe nfsd
systemctl daemon-reload
{{ if .Bootstrap }}
{{ if isContainerDEnabled .CRI -}}
systemctl enable containerd && systemctl restart containerd
{{- else -}}
systemctl enable docker && systemctl restart docker
{{ end -}}
{{ end -}}


{{ range $_, $unit := .Units -}}
Expand Down
13 changes: 13 additions & 0 deletions pkg/generator/testfiles/cloud-init-containerd
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/bash

mkdir -p /etc/systemd/system/containerd.service.d
cat <<EOF > /etc/systemd/system/containerd.service.d/11-exec_config.conf
[Service]
ExecStart=
ExecStart=/usr/bin/containerd --config=/etc/containerd/config.toml
EOF
chmod 0644 /etc/systemd/system/containerd.service.d/11-exec_config.conf


systemctl daemon-reload

0 comments on commit a0160bf

Please sign in to comment.