Skip to content

Commit cec290b

Browse files
committed
feat: allow extensions to log to console
Allow extensions to opt-in for their logs to be printed in the console, i.e., Talos kernel log buffer as well as their default logging target. Signed-off-by: Utku Ozdemir <[email protected]>
1 parent b7801df commit cec290b

File tree

5 files changed

+33
-13
lines changed

5 files changed

+33
-13
lines changed

internal/app/machined/pkg/system/runner/containerd/containerd.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ import (
2727

2828
// containerdRunner is a runner.Runner that runs container in containerd.
2929
type containerdRunner struct {
30-
args *runner.Args
31-
opts *runner.Options
32-
debug bool
30+
args *runner.Args
31+
opts *runner.Options
32+
logToConsole bool
3333

3434
stop chan struct{}
3535
stopped chan struct{}
@@ -41,13 +41,13 @@ type containerdRunner struct {
4141
}
4242

4343
// NewRunner creates runner.Runner that runs a container in containerd.
44-
func NewRunner(debug bool, args *runner.Args, setters ...runner.Option) runner.Runner {
44+
func NewRunner(logToConsole bool, args *runner.Args, setters ...runner.Option) runner.Runner {
4545
r := &containerdRunner{
46-
args: args,
47-
opts: runner.DefaultOptions(),
48-
debug: debug,
49-
stop: make(chan struct{}),
50-
stopped: make(chan struct{}),
46+
args: args,
47+
opts: runner.DefaultOptions(),
48+
logToConsole: logToConsole,
49+
stop: make(chan struct{}),
50+
stopped: make(chan struct{}),
5151
}
5252

5353
for _, setter := range setters {
@@ -170,7 +170,7 @@ func (c *containerdRunner) Run(eventSink events.Recorder) error {
170170

171171
var w io.Writer = logW
172172

173-
if c.debug {
173+
if c.logToConsole {
174174
w = io.MultiWriter(w, os.Stdout)
175175
}
176176

internal/app/machined/pkg/system/services/extension.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -201,14 +201,18 @@ func (svc *Extension) Runner(r runtime.Runtime) (runner.Runner, error) {
201201

202202
ociSpecOpts := svc.getOCIOptions(envVars, mounts)
203203

204-
debug := false
204+
logToConsole := false
205205

206206
if r.Config() != nil {
207-
debug = r.Config().Debug()
207+
logToConsole = r.Config().Debug()
208+
}
209+
210+
if svc.Spec.LogToConsole {
211+
logToConsole = true
208212
}
209213

210214
return restart.New(containerd.NewRunner(
211-
debug,
215+
logToConsole,
212216
&args,
213217
runner.WithLoggingManager(r.Logging()),
214218
runner.WithNamespace(constants.SystemContainerdNamespace),

pkg/machinery/extensions/services/services.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ type Spec struct {
3131
Depends []Dependency `yaml:"depends"`
3232
// Restart configuration.
3333
Restart RestartKind `yaml:"restart"`
34+
// LogToConsole enables sending service logs to the console.
35+
LogToConsole bool `yaml:"logToConsole"`
3436
}
3537

3638
// Container specifies service container to run.

website/content/v1.8/advanced/extension-services.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ depends:
4444
- etcfiles
4545
- time: true
4646
restart: never|always|untilSuccess
47+
logToConsole: true|false
4748
```
4849
4950
### `name`
@@ -139,6 +140,12 @@ Field `restart` defines the service restart policy, it allows to either configur
139140
* `never`: start service only once and never restart
140141
* `untilSuccess`: restart failing service, stop restarting on successful run
141142

143+
### `logToConsole`
144+
145+
Field `logToConsole` defines whether the service logs should also be written to the console, i.e., to kernel log buffer (or to the container logs in container mode).
146+
147+
This feature is particularly useful for debugging extensions that operate in maintenance mode or early in the boot process when service logs cannot be accessed yet.
148+
142149
## Example
143150

144151
Example layout of the Talos root filesystem contents for the extension service:

website/content/v1.9/advanced/extension-services.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ depends:
4444
- etcfiles
4545
- time: true
4646
restart: never|always|untilSuccess
47+
logToConsole: true|false
4748
```
4849
4950
### `name`
@@ -139,6 +140,12 @@ Field `restart` defines the service restart policy, it allows to either configur
139140
* `never`: start service only once and never restart
140141
* `untilSuccess`: restart failing service, stop restarting on successful run
141142

143+
### `logToConsole`
144+
145+
Field `logToConsole` defines whether the service logs should also be written to the console, i.e., to kernel log buffer (or to the container logs in container mode).
146+
147+
This feature is particularly useful for debugging extensions that operate in maintenance mode or early in the boot process when service logs cannot be accessed yet.
148+
142149
## Example
143150

144151
Example layout of the Talos root filesystem contents for the extension service:

0 commit comments

Comments
 (0)