MCPcopy Create free account
hub / github.com/containerd/containerd / initCRIRuntime

Function initCRIRuntime

plugins/cri/runtime/plugin.go:59–114  ·  view source on GitHub ↗
(ic *plugin.InitContext)

Source from the content-addressed store, hash-verified

57}
58
59func initCRIRuntime(ic *plugin.InitContext) (any, error) {
60 ic.Meta.Platforms = []imagespec.Platform{platforms.DefaultSpec()}
61 ic.Meta.Exports = map[string]string{"CRIVersion": constants.CRIVersion}
62 ctx := ic.Context
63 pluginConfig := ic.Config.(*criconfig.RuntimeConfig)
64 if warnings, err := criconfig.ValidateRuntimeConfig(ctx, pluginConfig); err != nil {
65 return nil, fmt.Errorf("invalid plugin config: %w", err)
66 } else if len(warnings) > 0 {
67 ws, err := ic.GetSingle(plugins.WarningPlugin)
68 if err != nil {
69 return nil, err
70 }
71 warn := ws.(warning.Service)
72 for _, w := range warnings {
73 warn.Emit(ctx, w)
74 }
75 }
76
77 // For backward compatibility, we have to keep the rootDir and stateDir the same as before.
78 containerdRootDir := filepath.Dir(ic.Properties[plugins.PropertyRootDir])
79 rootDir := filepath.Join(containerdRootDir, "io.containerd.grpc.v1.cri")
80 containerdStateDir := filepath.Dir(ic.Properties[plugins.PropertyStateDir])
81 stateDir := filepath.Join(containerdStateDir, "io.containerd.grpc.v1.cri")
82 if err := os.MkdirAll(stateDir, 0o700); err != nil {
83 return nil, err
84 }
85 // chmod is needed for upgrading from an older release that created the dir with 0o755
86 if err := os.Chmod(stateDir, 0o700); err != nil {
87 return nil, err
88 }
89 c := criconfig.Config{
90 RuntimeConfig: *pluginConfig,
91 ContainerdRootDir: containerdRootDir,
92 ContainerdEndpoint: ic.Properties[plugins.PropertyGRPCAddress],
93 RootDir: rootDir,
94 StateDir: stateDir,
95 }
96
97 // Ignoring errors here; this should never fail.
98 cfg, _ := json.Marshal(c)
99 log.G(ctx).WithFields(log.Fields{"config": string(cfg)}).Info("starting cri plugin")
100
101 if err := setGLogLevel(); err != nil {
102 return nil, fmt.Errorf("failed to set glog level: %w", err)
103 }
104
105 ociSpec, err := loadBaseOCISpecs(&c)
106 if err != nil {
107 return nil, fmt.Errorf("failed to create load basic oci spec: %w", err)
108 }
109
110 return &runtime{
111 config: c,
112 baseOCISpecs: ociSpec,
113 }, nil
114}
115
116// runtime contains common dependencies for CRI's runtime, image, and podsandbox services.

Callers

nothing calls this directly

Calls 7

setGLogLevelFunction · 0.85
loadBaseOCISpecsFunction · 0.85
DirMethod · 0.80
EmitMethod · 0.65
MkdirAllMethod · 0.65
InfoMethod · 0.65
MarshalMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…