Skip to content

Commit 02a9a45

Browse files
committed
Split image config from CRI plugin
Signed-off-by: Derek McGowan <[email protected]>
1 parent d23ac11 commit 02a9a45

24 files changed

+269
-201
lines changed

contrib/fuzz/cri_server_fuzzer.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ func FuzzCRIServer(data []byte) int {
4444

4545
config := criconfig.Config{}
4646

47-
imageService, err := images.NewService(config, map[string]string{}, client)
47+
imageService, err := images.NewService(config.ImageConfig, map[string]string{}, map[string]images.RuntimePlatform{}, client)
4848
if err != nil {
4949
panic(err)
5050
}

integration/image_pull_timeout_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -478,17 +478,17 @@ func initLocalCRIPlugin(client *containerd.Client, tmpDir string, registryCfg cr
478478

479479
cfg := criconfig.Config{
480480
PluginConfig: criconfig.PluginConfig{
481-
ContainerdConfig: criconfig.ContainerdConfig{
482-
Snapshotter: containerd.DefaultSnapshotter,
481+
ImageConfig: criconfig.ImageConfig{
482+
Snapshotter: containerd.DefaultSnapshotter,
483+
Registry: registryCfg,
484+
ImagePullProgressTimeout: defaultImagePullProgressTimeout.String(),
485+
StatsCollectPeriod: 10,
483486
},
484-
Registry: registryCfg,
485-
ImagePullProgressTimeout: defaultImagePullProgressTimeout.String(),
486-
StatsCollectPeriod: 10,
487487
},
488488
ContainerdRootDir: containerdRootDir,
489489
RootDir: filepath.Join(criWorkDir, "root"),
490490
StateDir: filepath.Join(criWorkDir, "state"),
491491
}
492492

493-
return images.NewService(cfg, map[string]string{}, client)
493+
return images.NewService(cfg.ImageConfig, map[string]string{}, map[string]images.RuntimePlatform{}, client)
494494
}

pkg/cri/config/config.go

Lines changed: 45 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -116,25 +116,13 @@ type Runtime struct {
116116

117117
// ContainerdConfig contains toml config related to containerd
118118
type ContainerdConfig struct {
119-
// Snapshotter is the snapshotter used by containerd.
120-
Snapshotter string `toml:"snapshotter" json:"snapshotter"`
121119
// DefaultRuntimeName is the default runtime name to use from the runtimes table.
122120
DefaultRuntimeName string `toml:"default_runtime_name" json:"defaultRuntimeName"`
123121

124122
// Runtimes is a map from CRI RuntimeHandler strings, which specify types of runtime
125123
// configurations, to the matching configurations.
126124
Runtimes map[string]Runtime `toml:"runtimes" json:"runtimes"`
127125

128-
// DisableSnapshotAnnotations disables to pass additional annotations (image
129-
// related information) to snapshotters. These annotations are required by
130-
// stargz snapshotter (https://github.com/containerd/stargz-snapshotter).
131-
DisableSnapshotAnnotations bool `toml:"disable_snapshot_annotations" json:"disableSnapshotAnnotations"`
132-
133-
// DiscardUnpackedLayers is a boolean flag to specify whether to allow GC to
134-
// remove layers from the content store after successfully unpacking these
135-
// layers to the snapshotter.
136-
DiscardUnpackedLayers bool `toml:"discard_unpacked_layers" json:"discardUnpackedLayers"`
137-
138126
// IgnoreBlockIONotEnabledErrors is a boolean flag to ignore
139127
// blockio related errors when blockio support has not been
140128
// enabled.
@@ -249,17 +237,57 @@ type ImageDecryption struct {
249237
KeyModel string `toml:"key_model" json:"keyModel"`
250238
}
251239

240+
type ImageConfig struct {
241+
// Snapshotter is the snapshotter used by containerd.
242+
Snapshotter string `toml:"snapshotter" json:"snapshotter"`
243+
244+
// DisableSnapshotAnnotations disables to pass additional annotations (image
245+
// related information) to snapshotters. These annotations are required by
246+
// stargz snapshotter (https://github.com/containerd/stargz-snapshotter).
247+
DisableSnapshotAnnotations bool `toml:"disable_snapshot_annotations" json:"disableSnapshotAnnotations"`
248+
249+
// DiscardUnpackedLayers is a boolean flag to specify whether to allow GC to
250+
// remove layers from the content store after successfully unpacking these
251+
// layers to the snapshotter.
252+
DiscardUnpackedLayers bool `toml:"discard_unpacked_layers" json:"discardUnpackedLayers"`
253+
254+
// Registry contains config related to the registry
255+
Registry Registry `toml:"registry" json:"registry"`
256+
257+
// ImageDecryption contains config related to handling decryption of encrypted container images
258+
ImageDecryption `toml:"image_decryption" json:"imageDecryption"`
259+
260+
// MaxConcurrentDownloads restricts the number of concurrent downloads for each image.
261+
// TODO: Migrate to transfer service
262+
MaxConcurrentDownloads int `toml:"max_concurrent_downloads" json:"maxConcurrentDownloads"`
263+
264+
// ImagePullProgressTimeout is the maximum duration that there is no
265+
// image data read from image registry in the open connection. It will
266+
// be reset whatever a new byte has been read. If timeout, the image
267+
// pulling will be cancelled. A zero value means there is no timeout.
268+
//
269+
// The string is in the golang duration format, see:
270+
// https://golang.org/pkg/time/#ParseDuration
271+
ImagePullProgressTimeout string `toml:"image_pull_progress_timeout" json:"imagePullProgressTimeout"`
272+
273+
// ImagePullWithSyncFs is an experimental setting. It's to force sync
274+
// filesystem during unpacking to ensure that data integrity.
275+
// TODO: Migrate to transfer service
276+
ImagePullWithSyncFs bool `toml:"image_pull_with_sync_fs" json:"imagePullWithSyncFs"`
277+
278+
// StatsCollectPeriod is the period (in seconds) of snapshots stats collection.
279+
StatsCollectPeriod int `toml:"stats_collect_period" json:"statsCollectPeriod"`
280+
}
281+
252282
// PluginConfig contains toml config related to CRI plugin,
253283
// it is a subset of Config.
254284
type PluginConfig struct {
285+
// ImageConfig is the image service configuration
286+
ImageConfig
255287
// ContainerdConfig contains config related to containerd
256288
ContainerdConfig `toml:"containerd" json:"containerd"`
257289
// CniConfig contains config related to cni
258290
CniConfig `toml:"cni" json:"cni"`
259-
// Registry contains config related to the registry
260-
Registry Registry `toml:"registry" json:"registry"`
261-
// ImageDecryption contains config related to handling decryption of encrypted container images
262-
ImageDecryption `toml:"image_decryption" json:"imageDecryption"`
263291
// DisableTCPService disables serving CRI on the TCP server.
264292
DisableTCPService bool `toml:"disable_tcp_service" json:"disableTCPService"`
265293
// StreamServerAddress is the ip address streaming server is listening on.
@@ -278,8 +306,6 @@ type PluginConfig struct {
278306
SelinuxCategoryRange int `toml:"selinux_category_range" json:"selinuxCategoryRange"`
279307
// SandboxImage is the image used by sandbox container.
280308
SandboxImage string `toml:"sandbox_image" json:"sandboxImage"`
281-
// StatsCollectPeriod is the period (in seconds) of snapshots stats collection.
282-
StatsCollectPeriod int `toml:"stats_collect_period" json:"statsCollectPeriod"`
283309
// EnableTLSStreaming indicates to enable the TLS streaming support.
284310
EnableTLSStreaming bool `toml:"enable_tls_streaming" json:"enableTLSStreaming"`
285311
// X509KeyPairStreaming is a x509 key pair used for TLS streaming
@@ -298,8 +324,6 @@ type PluginConfig struct {
298324
// current OOMScoreADj.
299325
// This is useful when the containerd does not have permission to decrease OOMScoreAdj.
300326
RestrictOOMScoreAdj bool `toml:"restrict_oom_score_adj" json:"restrictOOMScoreAdj"`
301-
// MaxConcurrentDownloads restricts the number of concurrent downloads for each image.
302-
MaxConcurrentDownloads int `toml:"max_concurrent_downloads" json:"maxConcurrentDownloads"`
303327
// DisableProcMount disables Kubernetes ProcMount support. This MUST be set to `true`
304328
// when using containerd with Kubernetes <=1.11.
305329
DisableProcMount bool `toml:"disable_proc_mount" json:"disableProcMount"`
@@ -345,14 +369,7 @@ type PluginConfig struct {
345369
// For more details about CDI configuration please refer to
346370
// https://github.com/container-orchestrated-devices/container-device-interface#containerd-configuration
347371
CDISpecDirs []string `toml:"cdi_spec_dirs" json:"cdiSpecDirs"`
348-
// ImagePullProgressTimeout is the maximum duration that there is no
349-
// image data read from image registry in the open connection. It will
350-
// be reset whatever a new byte has been read. If timeout, the image
351-
// pulling will be cancelled. A zero value means there is no timeout.
352-
//
353-
// The string is in the golang duration format, see:
354-
// https://golang.org/pkg/time/#ParseDuration
355-
ImagePullProgressTimeout string `toml:"image_pull_progress_timeout" json:"imagePullProgressTimeout"`
372+
356373
// DrainExecSyncIOTimeout is the maximum duration to wait for ExecSync
357374
// API' IO EOF event after exec init process exits. A zero value means
358375
// there is no timeout.
@@ -362,9 +379,6 @@ type PluginConfig struct {
362379
//
363380
// For example, the value can be '5h', '2h30m', '10s'.
364381
DrainExecSyncIOTimeout string `toml:"drain_exec_sync_io_timeout" json:"drainExecSyncIOTimeout"`
365-
// ImagePullWithSyncFs is an experimental setting. It's to force sync
366-
// filesystem during unpacking to ensure that data integrity.
367-
ImagePullWithSyncFs bool `toml:"image_pull_with_sync_fs" json:"imagePullWithSyncFs"`
368382
}
369383

370384
// X509KeyPairStreaming contains the x509 configuration for streaming

pkg/cri/config/config_test.go

Lines changed: 45 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,11 @@ func TestValidateConfig(t *testing.T) {
5454
RuntimeDefault: {},
5555
},
5656
},
57-
Registry: Registry{
58-
Auths: map[string]AuthConfig{
59-
"https://gcr.io": {Username: "test"},
57+
ImageConfig: ImageConfig{
58+
Registry: Registry{
59+
Auths: map[string]AuthConfig{
60+
"https://gcr.io": {Username: "test"},
61+
},
6062
},
6163
},
6264
},
@@ -69,16 +71,18 @@ func TestValidateConfig(t *testing.T) {
6971
},
7072
},
7173
},
72-
Registry: Registry{
73-
Configs: map[string]RegistryConfig{
74-
"gcr.io": {
75-
Auth: &AuthConfig{
76-
Username: "test",
74+
ImageConfig: ImageConfig{
75+
Registry: Registry{
76+
Configs: map[string]RegistryConfig{
77+
"gcr.io": {
78+
Auth: &AuthConfig{
79+
Username: "test",
80+
},
7781
},
7882
},
79-
},
80-
Auths: map[string]AuthConfig{
81-
"https://gcr.io": {Username: "test"},
83+
Auths: map[string]AuthConfig{
84+
"https://gcr.io": {Username: "test"},
85+
},
8286
},
8387
},
8488
},
@@ -108,10 +112,12 @@ func TestValidateConfig(t *testing.T) {
108112
},
109113
},
110114
},
111-
Registry: Registry{
112-
ConfigPath: "/etc/containerd/conf.d",
113-
Mirrors: map[string]Mirror{
114-
"something.io": {},
115+
ImageConfig: ImageConfig{
116+
Registry: Registry{
117+
ConfigPath: "/etc/containerd/conf.d",
118+
Mirrors: map[string]Mirror{
119+
"something.io": {},
120+
},
115121
},
116122
},
117123
},
@@ -125,9 +131,11 @@ func TestValidateConfig(t *testing.T) {
125131
RuntimeDefault: {},
126132
},
127133
},
128-
Registry: Registry{
129-
Mirrors: map[string]Mirror{
130-
"example.com": {},
134+
ImageConfig: ImageConfig{
135+
Registry: Registry{
136+
Mirrors: map[string]Mirror{
137+
"example.com": {},
138+
},
131139
},
132140
},
133141
},
@@ -140,9 +148,11 @@ func TestValidateConfig(t *testing.T) {
140148
},
141149
},
142150
},
143-
Registry: Registry{
144-
Mirrors: map[string]Mirror{
145-
"example.com": {},
151+
ImageConfig: ImageConfig{
152+
Registry: Registry{
153+
Mirrors: map[string]Mirror{
154+
"example.com": {},
155+
},
146156
},
147157
},
148158
},
@@ -156,11 +166,13 @@ func TestValidateConfig(t *testing.T) {
156166
RuntimeDefault: {},
157167
},
158168
},
159-
Registry: Registry{
160-
Configs: map[string]RegistryConfig{
161-
"gcr.io": {
162-
Auth: &AuthConfig{
163-
Username: "test",
169+
ImageConfig: ImageConfig{
170+
Registry: Registry{
171+
Configs: map[string]RegistryConfig{
172+
"gcr.io": {
173+
Auth: &AuthConfig{
174+
Username: "test",
175+
},
164176
},
165177
},
166178
},
@@ -175,11 +187,13 @@ func TestValidateConfig(t *testing.T) {
175187
},
176188
},
177189
},
178-
Registry: Registry{
179-
Configs: map[string]RegistryConfig{
180-
"gcr.io": {
181-
Auth: &AuthConfig{
182-
Username: "test",
190+
ImageConfig: ImageConfig{
191+
Registry: Registry{
192+
Configs: map[string]RegistryConfig{
193+
"gcr.io": {
194+
Auth: &AuthConfig{
195+
Username: "test",
196+
},
183197
},
184198
},
185199
},

pkg/cri/config/config_unix.go

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,18 @@ func DefaultConfig() PluginConfig {
6262
NetworkPluginSetupSerially: false,
6363
NetworkPluginConfTemplate: "",
6464
},
65+
ImageConfig: ImageConfig{
66+
Snapshotter: containerd.DefaultSnapshotter,
67+
DisableSnapshotAnnotations: true,
68+
MaxConcurrentDownloads: 3,
69+
ImageDecryption: ImageDecryption{
70+
KeyModel: KeyModelNode,
71+
},
72+
ImagePullProgressTimeout: defaultImagePullProgressTimeoutDuration.String(),
73+
ImagePullWithSyncFs: false,
74+
StatsCollectPeriod: 10,
75+
},
6576
ContainerdConfig: ContainerdConfig{
66-
Snapshotter: containerd.DefaultSnapshotter,
6777
DefaultRuntimeName: "runc",
6878
Runtimes: map[string]Runtime{
6979
"runc": {
@@ -72,7 +82,6 @@ func DefaultConfig() PluginConfig {
7282
Sandboxer: string(ModePodSandbox),
7383
},
7484
},
75-
DisableSnapshotAnnotations: true,
7685
},
7786
DisableTCPService: true,
7887
StreamServerAddress: "127.0.0.1",
@@ -86,22 +95,15 @@ func DefaultConfig() PluginConfig {
8695
TLSCertFile: "",
8796
},
8897
SandboxImage: "registry.k8s.io/pause:3.9",
89-
StatsCollectPeriod: 10,
9098
MaxContainerLogLineSize: 16 * 1024,
91-
MaxConcurrentDownloads: 3,
9299
DisableProcMount: false,
93100
TolerateMissingHugetlbController: true,
94101
DisableHugetlbController: true,
95102
IgnoreImageDefinedVolumes: false,
96-
ImageDecryption: ImageDecryption{
97-
KeyModel: KeyModelNode,
98-
},
99-
EnableCDI: false,
100-
CDISpecDirs: []string{"/etc/cdi", "/var/run/cdi"},
101-
ImagePullProgressTimeout: defaultImagePullProgressTimeoutDuration.String(),
102-
DrainExecSyncIOTimeout: "0s",
103-
ImagePullWithSyncFs: false,
104-
EnableUnprivilegedPorts: true,
105-
EnableUnprivilegedICMP: true,
103+
EnableCDI: false,
104+
CDISpecDirs: []string{"/etc/cdi", "/var/run/cdi"},
105+
DrainExecSyncIOTimeout: "0s",
106+
EnableUnprivilegedPorts: true,
107+
EnableUnprivilegedICMP: true,
106108
}
107109
}

pkg/cri/config/config_windows.go

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,16 @@ func DefaultConfig() PluginConfig {
3434
NetworkPluginSetupSerially: false,
3535
NetworkPluginConfTemplate: "",
3636
},
37+
ImageConfig: ImageConfig{
38+
Snapshotter: containerd.DefaultSnapshotter,
39+
StatsCollectPeriod: 10,
40+
MaxConcurrentDownloads: 3,
41+
ImageDecryption: ImageDecryption{
42+
KeyModel: KeyModelNode,
43+
},
44+
ImagePullProgressTimeout: defaultImagePullProgressTimeoutDuration.String(),
45+
},
3746
ContainerdConfig: ContainerdConfig{
38-
Snapshotter: containerd.DefaultSnapshotter,
3947
DefaultRuntimeName: "runhcs-wcow-process",
4048
Runtimes: map[string]Runtime{
4149
"runhcs-wcow-process": {
@@ -74,16 +82,10 @@ func DefaultConfig() PluginConfig {
7482
TLSCertFile: "",
7583
},
7684
SandboxImage: "registry.k8s.io/pause:3.9",
77-
StatsCollectPeriod: 10,
7885
MaxContainerLogLineSize: 16 * 1024,
79-
MaxConcurrentDownloads: 3,
8086
IgnoreImageDefinedVolumes: false,
8187
// TODO(windows): Add platform specific config, so that most common defaults can be shared.
8288

83-
ImageDecryption: ImageDecryption{
84-
KeyModel: KeyModelNode,
85-
},
86-
ImagePullProgressTimeout: defaultImagePullProgressTimeoutDuration.String(),
87-
DrainExecSyncIOTimeout: "0s",
89+
DrainExecSyncIOTimeout: "0s",
8890
}
8991
}

pkg/cri/cri.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,8 @@ func initCRIService(ic *plugin.InitContext) (interface{}, error) {
9494
}
9595

9696
// TODO: Update this logic to use runtime snapshotter
97-
if client.SnapshotService(c.ContainerdConfig.Snapshotter) == nil {
98-
return nil, fmt.Errorf("failed to find snapshotter %q", c.ContainerdConfig.Snapshotter)
97+
if client.SnapshotService(c.ImageConfig.Snapshotter) == nil {
98+
return nil, fmt.Errorf("failed to find snapshotter %q", c.ImageConfig.Snapshotter)
9999
}
100100

101101
// TODO(dmcgowan): Get the full list directly from configured plugins

0 commit comments

Comments
 (0)