@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
14
14
limitations under the License.
15
15
*/
16
16
17
- package worker
17
+ package containerd
18
18
19
19
import (
20
20
"bufio"
@@ -41,7 +41,6 @@ import (
41
41
"github.com/k0sproject/k0s/pkg/assets"
42
42
"github.com/k0sproject/k0s/pkg/component/manager"
43
43
workerconfig "github.com/k0sproject/k0s/pkg/component/worker/config"
44
- "github.com/k0sproject/k0s/pkg/component/worker/containerd"
45
44
"github.com/k0sproject/k0s/pkg/config"
46
45
"github.com/k0sproject/k0s/pkg/constant"
47
46
"github.com/k0sproject/k0s/pkg/debounce"
@@ -68,8 +67,8 @@ const confPathWindows = "C:\\Program Files\\containerd\\config.toml"
68
67
const importsPathPosix = "/etc/k0s/containerd.d/"
69
68
const importsPathWindows = "C:\\ etc\\ k0s\\ containerd.d\\ "
70
69
71
- // Containerd implements the component interface to manage containerd as a k0s component.
72
- type Containerd struct {
70
+ // Component implements the component interface to manage containerd as a k0s component.
71
+ type Component struct {
73
72
supervisor supervisor.Supervisor
74
73
LogLevel string
75
74
K0sVars * config.CfgVars
@@ -80,8 +79,8 @@ type Containerd struct {
80
79
importsPath string
81
80
}
82
81
83
- func NewContainerd (logLevel string , vars * config.CfgVars , profile * workerconfig.Profile ) * Containerd {
84
- c := & Containerd {
82
+ func NewComponent (logLevel string , vars * config.CfgVars , profile * workerconfig.Profile ) * Component {
83
+ c := & Component {
85
84
LogLevel : logLevel ,
86
85
K0sVars : vars ,
87
86
Profile : profile ,
@@ -99,10 +98,10 @@ func NewContainerd(logLevel string, vars *config.CfgVars, profile *workerconfig.
99
98
return c
100
99
}
101
100
102
- var _ manager.Component = (* Containerd )(nil )
101
+ var _ manager.Component = (* Component )(nil )
103
102
104
103
// Init extracts the needed binaries
105
- func (c * Containerd ) Init (ctx context.Context ) error {
104
+ func (c * Component ) Init (ctx context.Context ) error {
106
105
g , _ := errgroup .WithContext (ctx )
107
106
for _ , bin := range c .binaries {
108
107
b := bin
@@ -116,7 +115,7 @@ func (c *Containerd) Init(ctx context.Context) error {
116
115
return g .Wait ()
117
116
}
118
117
119
- func (c * Containerd ) windowsInit () error {
118
+ func (c * Component ) windowsInit () error {
120
119
if runtime .GOOS != "windows" {
121
120
return nil
122
121
}
@@ -127,7 +126,7 @@ func (c *Containerd) windowsInit() error {
127
126
}
128
127
129
128
// Run runs containerd.
130
- func (c * Containerd ) Start (ctx context.Context ) error {
129
+ func (c * Component ) Start (ctx context.Context ) error {
131
130
logrus .Info ("Starting containerd" )
132
131
133
132
if err := c .setupConfig (); err != nil {
@@ -162,21 +161,21 @@ func (c *Containerd) Start(ctx context.Context) error {
162
161
return nil
163
162
}
164
163
165
- func (c * Containerd ) windowsStart (_ context.Context ) error {
164
+ func (c * Component ) windowsStart (_ context.Context ) error {
166
165
if err := winExecute ("Start-Service containerd" ); err != nil {
167
166
return fmt .Errorf ("failed to start Windows Service %q: %w" , "containerd" , err )
168
167
}
169
168
return nil
170
169
}
171
170
172
- func (c * Containerd ) windowsStop () error {
171
+ func (c * Component ) windowsStop () error {
173
172
if err := winExecute ("Stop-Service containerd" ); err != nil {
174
173
return fmt .Errorf ("failed to stop Windows Service %q: %w" , "containerd" , err )
175
174
}
176
175
return nil
177
176
}
178
177
179
- func (c * Containerd ) setupConfig () error {
178
+ func (c * Component ) setupConfig () error {
180
179
// Check if the config file is user managed
181
180
// If it is, we should not touch it
182
181
@@ -195,9 +194,18 @@ func (c *Containerd) setupConfig() error {
195
194
if err := dir .Init (filepath .Dir (c .importsPath ), 0755 ); err != nil {
196
195
return fmt .Errorf ("can't create containerd config imports dir: %w" , err )
197
196
}
198
- containerdConfigurer := containerd .NewConfigurer (c .Profile .PauseImage , filepath .Join (c .importsPath , "*.toml" ))
199
197
200
- imports , err := containerdConfigurer .HandleImports ()
198
+ configurer := & configurer {
199
+ loadPath : filepath .Join (c .importsPath , "*.toml" ),
200
+ pauseImage : c .Profile .PauseImage .URI (),
201
+ log : logrus .WithField ("component" , "containerd" ),
202
+ criRuntimePath : "/run/k0s/containerd-cri.toml" ,
203
+ }
204
+ if runtime .GOOS == "windows" {
205
+ configurer .criRuntimePath = `C:\var\lib\k0s\run\containerd-cri.toml`
206
+ }
207
+
208
+ imports , err := configurer .handleImports ()
201
209
if err != nil {
202
210
return fmt .Errorf ("can't handle imports: %w" , err )
203
211
}
@@ -217,7 +225,7 @@ func (c *Containerd) setupConfig() error {
217
225
return file .WriteContentAtomically (c .confPath , output .Bytes (), 0644 )
218
226
}
219
227
220
- func (c * Containerd ) watchDropinConfigs (ctx context.Context ) {
228
+ func (c * Component ) watchDropinConfigs (ctx context.Context ) {
221
229
log := logrus .WithField ("component" , "containerd" )
222
230
watcher , err := fsnotify .NewWatcher ()
223
231
if err != nil {
@@ -265,7 +273,7 @@ func (c *Containerd) watchDropinConfigs(ctx context.Context) {
265
273
}
266
274
}
267
275
268
- func (c * Containerd ) restart () {
276
+ func (c * Component ) restart () {
269
277
log := logrus .WithFields (logrus.Fields {"component" : "containerd" , "phase" : "restart" })
270
278
271
279
log .Info ("restart requested" )
@@ -293,7 +301,7 @@ func (c *Containerd) restart() {
293
301
}
294
302
295
303
// Stop stops containerd.
296
- func (c * Containerd ) Stop () error {
304
+ func (c * Component ) Stop () error {
297
305
if runtime .GOOS == "windows" {
298
306
return c .windowsStop ()
299
307
}
0 commit comments