Skip to content

Commit 3441d16

Browse files
Enable configuring containerd plugin runtime options
Signed-off-by: Kate Goldenring <[email protected]> Install and start D-Bus after configuring runtime options Signed-off-by: Kate Goldenring <[email protected]> Add D-Bus installation to restarter logic Signed-off-by: Kate Goldenring <[email protected]> Move latest shim CRD to helm chart Signed-off-by: Kate Goldenring <[email protected]>
1 parent a99127a commit 3441d16

File tree

13 files changed

+246
-59
lines changed

13 files changed

+246
-59
lines changed

api/v1alpha1/shim_types.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ type ShimSpec struct {
2626
FetchStrategy FetchStrategy `json:"fetchStrategy"`
2727
RuntimeClass RuntimeClassSpec `json:"runtimeClass"`
2828
RolloutStrategy RolloutStrategy `json:"rolloutStrategy"`
29+
// RuntimeOptions is a map of containerd runtime options for the shim plugin.
30+
// See an example of configuring cgroup driver via runtime options: https://github.com/containerd/containerd/blob/main/docs/cri/config.md#cgroup-driver
31+
RuntimeOptions map[string]string `json:"runtimeOptions"`
2932
}
3033

3134
type FetchStrategy struct {

api/v1alpha1/zz_generated.deepcopy.go

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cmd/node-installer/config.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ type Config struct {
2020
Runtime struct {
2121
Name string
2222
ConfigPath string
23+
// Options is a map of containerd runtime options for the shim plugin.
24+
// See an example of the cgroup drive option here:
25+
// https://github.com/containerd/containerd/blob/main/docs/cri/config.md#cgroup-driver
26+
Options map[string]string
2327
}
2428
RCM struct {
2529
Path string

cmd/node-installer/detect_test.go

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ func Test_DetectDistro(t *testing.T) {
4545
struct {
4646
Name string
4747
ConfigPath string
48-
}{"containerd", preset.MicroK8s.ConfigPath},
48+
Options map[string]string
49+
}{"containerd", preset.MicroK8s.ConfigPath, nil},
4950
struct {
5051
Path string
5152
AssetPath string
@@ -64,7 +65,8 @@ func Test_DetectDistro(t *testing.T) {
6465
struct {
6566
Name string
6667
ConfigPath string
67-
}{"containerd", "/etc/containerd/not_found.toml"},
68+
Options map[string]string
69+
}{"containerd", "/etc/containerd/not_found.toml", nil},
6870
struct {
6971
Path string
7072
AssetPath string
@@ -83,7 +85,8 @@ func Test_DetectDistro(t *testing.T) {
8385
struct {
8486
Name string
8587
ConfigPath string
86-
}{"containerd", ""},
88+
Options map[string]string
89+
}{"containerd", "", nil},
8790
struct {
8891
Path string
8992
AssetPath string
@@ -102,7 +105,8 @@ func Test_DetectDistro(t *testing.T) {
102105
struct {
103106
Name string
104107
ConfigPath string
105-
}{"containerd", ""},
108+
Options map[string]string
109+
}{"containerd", "", nil},
106110
struct {
107111
Path string
108112
AssetPath string
@@ -121,7 +125,8 @@ func Test_DetectDistro(t *testing.T) {
121125
struct {
122126
Name string
123127
ConfigPath string
124-
}{"containerd", ""},
128+
Options map[string]string
129+
}{"containerd", "", nil},
125130
struct {
126131
Path string
127132
AssetPath string
@@ -140,7 +145,8 @@ func Test_DetectDistro(t *testing.T) {
140145
struct {
141146
Name string
142147
ConfigPath string
143-
}{"containerd", ""},
148+
Options map[string]string
149+
}{"containerd", "", nil},
144150
struct {
145151
Path string
146152
AssetPath string
@@ -159,7 +165,8 @@ func Test_DetectDistro(t *testing.T) {
159165
struct {
160166
Name string
161167
ConfigPath string
162-
}{"containerd", ""},
168+
Options map[string]string
169+
}{"containerd", "", nil},
163170
struct {
164171
Path string
165172
AssetPath string
@@ -178,7 +185,8 @@ func Test_DetectDistro(t *testing.T) {
178185
struct {
179186
Name string
180187
ConfigPath string
181-
}{"containerd", ""},
188+
Options map[string]string
189+
}{"containerd", "", nil},
182190
struct {
183191
Path string
184192
AssetPath string

cmd/node-installer/install.go

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package main
1818

1919
import (
20+
"encoding/json"
2021
"fmt"
2122
"io/fs"
2223
"log/slog"
@@ -50,6 +51,12 @@ var installCmd = &cobra.Command{
5051
os.Exit(1)
5152
}
5253

54+
config.Runtime.Options, err = RuntimeOptions()
55+
if err != nil {
56+
slog.Error("failed to get runtime options", "error", err)
57+
os.Exit(1)
58+
}
59+
5360
if err := RunInstall(config, rootFs, hostFs, distro.Restarter); err != nil {
5461
slog.Error("failed to install", "error", err)
5562
os.Exit(1)
@@ -82,7 +89,7 @@ func RunInstall(config Config, rootFs, hostFs afero.Fs, restarter containerd.Res
8289
config.RCM.AssetPath = path.Dir(config.RCM.AssetPath)
8390
}
8491

85-
containerdConfig := containerd.NewConfig(hostFs, config.Runtime.ConfigPath, restarter)
92+
containerdConfig := containerd.NewConfig(hostFs, config.Runtime.ConfigPath, restarter, config.Runtime.Options)
8693
shimConfig := shim.NewConfig(rootFs, hostFs, config.RCM.AssetPath, config.RCM.Path)
8794

8895
anythingChanged := false
@@ -117,3 +124,16 @@ func RunInstall(config Config, rootFs, hostFs afero.Fs, restarter containerd.Res
117124

118125
return nil
119126
}
127+
128+
func RuntimeOptions() (map[string]string, error) {
129+
runtimeOptions := make(map[string]string)
130+
optionsJSON := os.Getenv("RUNTIME_OPTIONS")
131+
config.Runtime.Options = make(map[string]string)
132+
if optionsJSON != "" {
133+
err := json.Unmarshal([]byte(optionsJSON), &runtimeOptions)
134+
if err != nil {
135+
return nil, fmt.Errorf("failed to unmarshal runtime options JSON %s: %w", optionsJSON, err)
136+
}
137+
}
138+
return runtimeOptions, nil
139+
}

cmd/node-installer/install_test.go

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ func Test_RunInstall(t *testing.T) {
4949
struct {
5050
Name string
5151
ConfigPath string
52-
}{"containerd", "/etc/containerd/config.toml"},
52+
Options map[string]string
53+
}{"containerd", "/etc/containerd/config.toml", nil},
5354
struct {
5455
Path string
5556
AssetPath string
@@ -68,7 +69,8 @@ func Test_RunInstall(t *testing.T) {
6869
struct {
6970
Name string
7071
ConfigPath string
71-
}{"containerd", "/etc/containerd/config.toml"},
72+
Options map[string]string
73+
}{"containerd", "/etc/containerd/config.toml", nil},
7274
struct {
7375
Path string
7476
AssetPath string
@@ -80,6 +82,27 @@ func Test_RunInstall(t *testing.T) {
8082
},
8183
false,
8284
},
85+
{
86+
// TODO figure out how to test that the runtime options are set in the config
87+
"new shim with runtime options",
88+
args{
89+
main.Config{
90+
struct {
91+
Name string
92+
ConfigPath string
93+
Options map[string]string
94+
}{"containerd", "/etc/containerd/config.toml", map[string]string{"SystemdCgroup": "true"}},
95+
struct {
96+
Path string
97+
AssetPath string
98+
}{"/opt/rcm", "/assets"},
99+
struct{ RootPath string }{"/containerd/missing-containerd-shim-config"},
100+
},
101+
tests.FixtureFs("../../testdata/node-installer"),
102+
tests.FixtureFs("../../testdata/node-installer/containerd/missing-containerd-shim-config"),
103+
},
104+
false,
105+
},
83106
}
84107
for _, tt := range tests {
85108
t.Run(tt.name, func(t *testing.T) {

cmd/node-installer/uninstall.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,12 @@ var uninstallCmd = &cobra.Command{
4545

4646
config.Runtime.ConfigPath = distro.ConfigPath
4747

48+
config.Runtime.Options, err = RuntimeOptions()
49+
if err != nil {
50+
slog.Error("failed to get runtime options", "error", err)
51+
os.Exit(1)
52+
}
53+
4854
if err := RunUninstall(config, rootFs, hostFs, distro.Restarter); err != nil {
4955
slog.Error("failed to uninstall", "error", err)
5056
os.Exit(1)
@@ -61,7 +67,7 @@ func RunUninstall(config Config, rootFs, hostFs afero.Fs, restarter containerd.R
6167
shimName := config.Runtime.Name
6268
runtimeName := path.Join(config.RCM.Path, "bin", shimName)
6369

64-
containerdConfig := containerd.NewConfig(hostFs, config.Runtime.ConfigPath, restarter)
70+
containerdConfig := containerd.NewConfig(hostFs, config.Runtime.ConfigPath, restarter, config.Runtime.Options)
6571
shimConfig := shim.NewConfig(rootFs, hostFs, config.RCM.AssetPath, config.RCM.Path)
6672

6773
binPath, err := shimConfig.Uninstall(shimName)

config/crd/bases/runtime.spinkube.dev_shims.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,18 @@ spec:
9595
- handler
9696
- name
9797
type: object
98+
runtimeOptions:
99+
additionalProperties:
100+
type: string
101+
description: |-
102+
RuntimeOptions is a map of containerd runtime options for the shim plugin.
103+
See an example of configuring cgroup driver via runtime options: https://github.com/containerd/containerd/blob/main/docs/cri/config.md#cgroup-driver
104+
type: object
98105
required:
99106
- fetchStrategy
100107
- rolloutStrategy
101108
- runtimeClass
109+
- runtimeOptions
102110
type: object
103111
status:
104112
description: ShimStatus defines the observed state of Shim

config/samples/test_shim_spin.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ spec:
1717
anonHttp:
1818
location: "https://github.com/spinframework/containerd-shim-spin/releases/download/v0.19.0/containerd-shim-spin-v2-linux-aarch64.tar.gz"
1919

20+
runtimeOptions:
21+
SystemdCgroup: "true"
22+
2023
runtimeClass:
2124
# Note: this name is used by the Spin Operator project as its default:
2225
# https://github.com/spinframework/spin-operator/blob/main/config/samples/spin-shim-executor.yaml

deploy/helm/crds/runtime.spinkube.dev_shims.yaml

Lines changed: 37 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ apiVersion: apiextensions.k8s.io/v1
33
kind: CustomResourceDefinition
44
metadata:
55
annotations:
6-
controller-gen.kubebuilder.io/version: v0.13.0
6+
controller-gen.kubebuilder.io/version: v0.16.3
77
name: shims.runtime.spinkube.dev
88
spec:
99
group: runtime.spinkube.dev
@@ -30,14 +30,19 @@ spec:
3030
description: Shim is the Schema for the shims API
3131
properties:
3232
apiVersion:
33-
description: 'APIVersion defines the versioned schema of this representation
34-
of an object. Servers should convert recognized schemas to the latest
35-
internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources'
33+
description: |-
34+
APIVersion defines the versioned schema of this representation of an object.
35+
Servers should convert recognized schemas to the latest internal value, and
36+
may reject unrecognized values.
37+
More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources
3638
type: string
3739
kind:
38-
description: 'Kind is a string value representing the REST resource this
39-
object represents. Servers may infer this from the endpoint the client
40-
submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds'
40+
description: |-
41+
Kind is a string value representing the REST resource this object represents.
42+
Servers may infer this from the endpoint the client submits requests to.
43+
Cannot be updated.
44+
In CamelCase.
45+
More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds
4146
type: string
4247
metadata:
4348
type: object
@@ -90,53 +95,53 @@ spec:
9095
- handler
9196
- name
9297
type: object
98+
runtimeOptions:
99+
additionalProperties:
100+
type: string
101+
description: |-
102+
RuntimeOptions is a map of containerd runtime options for the shim plugin.
103+
See an example of configuring cgroup driver via runtime options: https://github.com/containerd/containerd/blob/main/docs/cri/config.md#cgroup-driver
104+
type: object
93105
required:
94106
- fetchStrategy
95107
- rolloutStrategy
96108
- runtimeClass
109+
- runtimeOptions
97110
type: object
98111
status:
99112
description: ShimStatus defines the observed state of Shim
100113
properties:
101114
conditions:
102115
items:
103-
description: "Condition contains details for one aspect of the current
104-
state of this API Resource. --- This struct is intended for direct
105-
use as an array at the field path .status.conditions. For example,
106-
\n type FooStatus struct{ // Represents the observations of a
107-
foo's current state. // Known .status.conditions.type are: \"Available\",
108-
\"Progressing\", and \"Degraded\" // +patchMergeKey=type // +patchStrategy=merge
109-
// +listType=map // +listMapKey=type Conditions []metav1.Condition
110-
`json:\"conditions,omitempty\" patchStrategy:\"merge\" patchMergeKey:\"type\"
111-
protobuf:\"bytes,1,rep,name=conditions\"` \n // other fields }"
116+
description: Condition contains details for one aspect of the current
117+
state of this API Resource.
112118
properties:
113119
lastTransitionTime:
114-
description: lastTransitionTime is the last time the condition
115-
transitioned from one status to another. This should be when
116-
the underlying condition changed. If that is not known, then
117-
using the time when the API field changed is acceptable.
120+
description: |-
121+
lastTransitionTime is the last time the condition transitioned from one status to another.
122+
This should be when the underlying condition changed. If that is not known, then using the time when the API field changed is acceptable.
118123
format: date-time
119124
type: string
120125
message:
121-
description: message is a human readable message indicating
122-
details about the transition. This may be an empty string.
126+
description: |-
127+
message is a human readable message indicating details about the transition.
128+
This may be an empty string.
123129
maxLength: 32768
124130
type: string
125131
observedGeneration:
126-
description: observedGeneration represents the .metadata.generation
127-
that the condition was set based upon. For instance, if .metadata.generation
128-
is currently 12, but the .status.conditions[x].observedGeneration
129-
is 9, the condition is out of date with respect to the current
130-
state of the instance.
132+
description: |-
133+
observedGeneration represents the .metadata.generation that the condition was set based upon.
134+
For instance, if .metadata.generation is currently 12, but the .status.conditions[x].observedGeneration is 9, the condition is out of date
135+
with respect to the current state of the instance.
131136
format: int64
132137
minimum: 0
133138
type: integer
134139
reason:
135-
description: reason contains a programmatic identifier indicating
136-
the reason for the condition's last transition. Producers
137-
of specific condition types may define expected values and
138-
meanings for this field, and whether the values are considered
139-
a guaranteed API. The value should be a CamelCase string.
140+
description: |-
141+
reason contains a programmatic identifier indicating the reason for the condition's last transition.
142+
Producers of specific condition types may define expected values and meanings for this field,
143+
and whether the values are considered a guaranteed API.
144+
The value should be a CamelCase string.
140145
This field may not be empty.
141146
maxLength: 1024
142147
minLength: 1
@@ -151,10 +156,6 @@ spec:
151156
type: string
152157
type:
153158
description: type of condition in CamelCase or in foo.example.com/CamelCase.
154-
--- Many .condition.type values are consistent across resources
155-
like Available, but because arbitrary conditions can be useful
156-
(see .node.status.conditions), the ability to deconflict is
157-
important. The regex it matches is (dns1123SubdomainFmt/)?(qualifiedNameFmt)
158159
maxLength: 316
159160
pattern: ^([a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*/)?(([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9])$
160161
type: string

0 commit comments

Comments
 (0)