-
Notifications
You must be signed in to change notification settings - Fork 31
feat: add support for k0s #124
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,7 +2,10 @@ package main | |
|
|
||
| import ( | ||
| "context" | ||
| "fmt" | ||
| "os" | ||
| "path/filepath" | ||
| "strings" | ||
| "testing" | ||
|
|
||
| "github.com/containerd/containerd/v2/cmd/containerd/server/config" | ||
|
|
@@ -90,11 +93,12 @@ imports = [ | |
| "runtime_zeropod.toml", | ||
| ] | ||
| ` | ||
| containerdv1AlreadyConfigured = fullContainerdConfigV2 + runtimeConfig + ` | ||
| ) | ||
|
|
||
| var containerdv1AlreadyConfigured = fullContainerdConfigV2 + fmt.Sprintf(runtimeConfig, strings.TrimSuffix(defaultOptPath, "/"), true) + ` | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. any reason this can't be in the existing |
||
| [plugins."io.containerd.internal.v1.opt"] | ||
| path = "/opt/zeropod" | ||
| ` | ||
| ) | ||
|
|
||
| type testConfig struct { | ||
| containerdConfig string | ||
|
|
@@ -197,7 +201,7 @@ func TestConfigureContainerd(t *testing.T) { | |
| assert.NoError(config.LoadConfig(ctx, configName+tc.newConfigSuffix, conf)) | ||
|
|
||
| if !tc.containerdv1 { | ||
| zeropodConfig, err := os.ReadFile(zeropodRuntimeConfigPath(configName)) | ||
| zeropodConfig, err := os.ReadFile(zeropodRuntimeConfigPath(tc.runtime, configName)) | ||
| require.NoError(err) | ||
| assert.NotEmpty(zeropodConfig) | ||
| t.Log(string(zeropodConfig)) | ||
|
|
@@ -218,6 +222,34 @@ func TestConfigureContainerd(t *testing.T) { | |
| } | ||
| } | ||
|
|
||
| func TestConfigureContainerdK0s(t *testing.T) { | ||
| t.Run("writes drop-in", func(t *testing.T) { | ||
| temp := t.TempDir() | ||
| cfg := filepath.Join(temp, "containerd.toml") | ||
| managedConfig := []byte("# " + k0sManagedSentinel + "\nversion = 2\n") | ||
| require.NoError(t, os.WriteFile(cfg, managedConfig, 0644)) | ||
|
|
||
| restart, err := configureContainerdK0s(context.Background(), cfg) | ||
| require.NoError(t, err) | ||
| assert.False(t, restart) | ||
|
|
||
| dropIn := filepath.Join(filepath.Dir(cfg), k0sDropInDirName, zeropodTomlName) | ||
| data, err := os.ReadFile(dropIn) | ||
| require.NoError(t, err) | ||
| assert.Contains(t, string(data), "runtime_type = \"io.containerd.runc.v2\"") | ||
| }) | ||
|
|
||
| t.Run("requires managed config", func(t *testing.T) { | ||
| temp := t.TempDir() | ||
| cfg := filepath.Join(temp, "containerd.toml") | ||
| require.NoError(t, os.WriteFile(cfg, []byte("version = 2\n"), 0644)) | ||
|
|
||
| _, err := configureContainerdK0s(context.Background(), cfg) | ||
| require.Error(t, err) | ||
| assert.Contains(t, err.Error(), "not k0s managed") | ||
| }) | ||
| } | ||
|
|
||
| func setupTestConfig(t *testing.T, tc testConfig) string { | ||
| temp := t.TempDir() | ||
| configFile, err := os.CreateTemp(temp, "containerd-config-*.toml") | ||
|
|
@@ -226,7 +258,7 @@ func setupTestConfig(t *testing.T, tc testConfig) string { | |
|
|
||
| if tc.preCreateZeropodConfig { | ||
| if !tc.containerdv1 { | ||
| require.NoError(t, writeZeropodRuntimeConfig(configFile.Name(), tc.expectedOptPath, tc.expectedOptPath == "", 2)) | ||
| require.NoError(t, writeZeropodRuntimeConfig(tc.runtime, configFile.Name(), tc.expectedOptPath, tc.expectedOptPath == "", 2, useSystemdCgroup(tc.runtime))) | ||
| } | ||
| require.NoError(t, backupContainerdConfig(configFile.Name())) | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| apiVersion: apps/v1 | ||
| kind: DaemonSet | ||
| metadata: | ||
| name: zeropod-node | ||
| namespace: zeropod-system | ||
| spec: | ||
| template: | ||
| spec: | ||
| volumes: | ||
| - name: containerd-etc | ||
| hostPath: | ||
| path: /etc/k0s | ||
| - name: containerd-run | ||
| hostPath: | ||
| path: /run/k0s | ||
| initContainers: | ||
| - name: installer | ||
| volumeMounts: | ||
| - name: containerd-etc | ||
| mountPath: /etc/k0s | ||
| - name: containerd-run | ||
| mountPath: /run/k0s | ||
|
Comment on lines
+16
to
+22
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This would not be needed if the installer would just look for the socket in |
||
| containers: | ||
| - name: manager | ||
| volumeMounts: | ||
| - name: containerd-etc | ||
| mountPath: /etc/k0s | ||
| - name: containerd-run | ||
| mountPath: /run/k0s | ||
|
Comment on lines
+23
to
+29
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This can be removed, the manager does not need to access the containerd config/socket. |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| resources: | ||
| - ../production | ||
| patches: | ||
| - path: k0s.yaml | ||
| - patch: |- | ||
| - op: add | ||
| path: /spec/template/spec/initContainers/0/args/- | ||
| value: -runtime=k0s | ||
| target: | ||
| kind: DaemonSet |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of changing the socket path, wouldn't it be simpler to only change the
hostPathand mount the socket into/run/containerdinside the container? We also do this fork3swhere the containerd socket is not in the standard path on the host. Same for theetccontainerd dir.