Skip to content

Commit 6aed532

Browse files
committed
fixes
1 parent 8f4daef commit 6aed532

File tree

5 files changed

+64
-29
lines changed

5 files changed

+64
-29
lines changed

internal/app/machined/pkg/controllers/runtime/fs_scrub.go

Lines changed: 43 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -110,36 +110,62 @@ func (ctrl *FSScrubController) Run(ctx context.Context, r controller.Runtime, lo
110110
logger.Error("error running filesystem scrub", zap.Error(err))
111111
}
112112
case <-r.EventCh():
113-
err := ctrl.updateSchedule(ctx, r, logger)
113+
err := ctrl.updateSchedule(ctx, r)
114114
if err != nil {
115115
return err
116116
}
117117
}
118118

119-
r.StartTrackingOutputs()
119+
if err := ctrl.reportStatus(ctx, r); err != nil {
120+
return err
121+
}
122+
}
123+
}
120124

121-
for _, entry := range ctrl.status {
122-
if err := safe.WriterModify(ctx, r, runtimeres.NewFSScrubStatus(entry.id), func(status *runtimeres.FSScrubStatus) error {
123-
status.TypedSpec().Mountpoint = entry.mountpoint
124-
status.TypedSpec().Period = entry.period
125-
status.TypedSpec().Time = entry.time
126-
status.TypedSpec().Duration = entry.duration
127-
status.TypedSpec().Status = entry.result.Error()
125+
func (ctrl *FSScrubController) reportStatus(ctx context.Context, r controller.Runtime) error {
126+
r.StartTrackingOutputs()
128127

129-
return nil
130-
}); err != nil {
131-
return fmt.Errorf("error updating filesystem scrub status: %w", err)
128+
presentStatuses, err := safe.ReaderListAll[*runtimeres.FSScrubStatus](ctx, r)
129+
if err != nil && !state.IsNotFoundError(err) {
130+
return fmt.Errorf("error getting existing FS scrub statuses: %w", err)
131+
}
132+
133+
for entry := range presentStatuses.All() {
134+
if _, ok := ctrl.status[entry.TypedSpec().Mountpoint]; !ok {
135+
if err := r.Destroy(ctx, runtimeres.NewFSScrubStatus(entry.Metadata().ID()).Metadata()); err != nil {
136+
return fmt.Errorf("error destroying old FS scrub status: %w", err)
132137
}
133138
}
139+
}
134140

135-
if err := safe.CleanupOutputs[*runtimeres.FSScrubStatus](ctx, r); err != nil {
136-
return err
141+
for _, entry := range ctrl.status {
142+
if err := safe.WriterModify(ctx, r, runtimeres.NewFSScrubStatus(entry.id), func(status *runtimeres.FSScrubStatus) error {
143+
status.TypedSpec().Mountpoint = entry.mountpoint
144+
status.TypedSpec().Period = entry.period
145+
status.TypedSpec().Time = entry.time
146+
status.TypedSpec().Duration = entry.duration
147+
148+
if entry.result != nil {
149+
status.TypedSpec().Status = entry.result.Error()
150+
} else {
151+
status.TypedSpec().Status = "success"
152+
}
153+
154+
return nil
155+
}); err != nil {
156+
return fmt.Errorf("error updating filesystem scrub status: %w", err)
137157
}
138158
}
159+
160+
if err := safe.CleanupOutputs[*runtimeres.FSScrubStatus](ctx, r); err != nil {
161+
return err
162+
}
163+
164+
return nil
139165
}
140166

141167
//nolint:gocyclo,cyclop
142-
func (ctrl *FSScrubController) updateSchedule(ctx context.Context, r controller.Runtime, logger *zap.Logger) error {
168+
func (ctrl *FSScrubController) updateSchedule(ctx context.Context, r controller.Runtime) error {
143169
volumesStatus, err := safe.ReaderListAll[*block.VolumeStatus](ctx, r)
144170
if err != nil && !state.IsNotFoundError(err) {
145171
return fmt.Errorf("error getting volume status: %w", err)
@@ -207,8 +233,6 @@ func (ctrl *FSScrubController) updateSchedule(ctx context.Context, r controller.
207233
_, ok := ctrl.schedule[mountpoint]
208234

209235
if period == nil {
210-
logger.Warn("!!! scrub !!! not in config, descheduling", zap.String("mountpoint", mountpoint))
211-
212236
if ok {
213237
ctrl.cancelScrub(mountpoint)
214238
}
@@ -218,12 +242,10 @@ func (ctrl *FSScrubController) updateSchedule(ctx context.Context, r controller.
218242

219243
if !ok {
220244
firstTimeout := time.Duration(rand.Int64N(int64(period.Seconds()))) * time.Second
221-
logger.Warn("!!! scrub !!! firstTimeout", zap.Duration("firstTimeout", firstTimeout))
222245

223246
// When scheduling the first scrub, we use a random time to avoid all scrubs running in a row.
224247
// After the first scrub, we use the period defined in the config.
225248
cb := func() {
226-
logger.Warn("!!! scrub !!! ding", zap.String("path", mountpoint))
227249
ctrl.c <- mountpoint
228250
ctrl.schedule[mountpoint].timer.Reset(ctrl.schedule[mountpoint].period)
229251
}
@@ -242,12 +264,8 @@ func (ctrl *FSScrubController) updateSchedule(ctx context.Context, r controller.
242264
duration: 0,
243265
result: fmt.Errorf("scheduled"),
244266
}
245-
246-
logger.Warn("!!! scrub !!! scheduled", zap.String("path", mountpoint), zap.Duration("period", *period))
247267
} else if ctrl.schedule[mountpoint].period != *period {
248268
// reschedule if period has changed
249-
logger.Warn("!!! scrub !!! reschedule", zap.String("path", mountpoint), zap.Duration("period", *period))
250-
251269
ctrl.schedule[mountpoint].timer.Stop()
252270
ctrl.schedule[mountpoint].timer.Reset(*period)
253271
ctrl.schedule[mountpoint] = scrubSchedule{
@@ -259,7 +277,7 @@ func (ctrl *FSScrubController) updateSchedule(ctx context.Context, r controller.
259277
id: item.Metadata().ID(),
260278
mountpoint: mountpoint,
261279
period: *period,
262-
time: time.Now().Add(*period),
280+
time: ctrl.status[mountpoint].time,
263281
duration: ctrl.status[mountpoint].duration,
264282
result: ctrl.status[mountpoint].result,
265283
}
@@ -304,7 +322,7 @@ func (ctrl *FSScrubController) runScrub(mountpoint string, opts []string) error
304322
mountpoint: mountpoint,
305323
period: ctrl.schedule[mountpoint].period,
306324
time: start,
307-
duration: time.Now().Sub(start),
325+
duration: time.Since(start),
308326
result: err,
309327
}
310328

pkg/machinery/config/types/runtime/fs_scrub.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import (
2121
const FilesystemScrubKind = "FilesystemScrubConfig"
2222

2323
func init() {
24-
fmt.Println("TEST! FilesystemScrubKind: ", FilesystemScrubKind)
2524
registry.Register(FilesystemScrubKind, func(version string) config.Document {
2625
switch version {
2726
case "v1alpha1":

pkg/machinery/config/types/runtime/kmsg_log.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ package runtime
88

99
import (
1010
"errors"
11-
"fmt"
1211
"net/url"
1312

1413
"github.com/siderolabs/gen/ensure"
@@ -23,7 +22,6 @@ import (
2322
const KmsgLogKind = "KmsgLogConfig"
2423

2524
func init() {
26-
fmt.Println("AAAAA! KmsgLogKind: ", KmsgLogKind)
2725
registry.Register(KmsgLogKind, func(version string) config.Document {
2826
switch version {
2927
case "v1alpha1":

pkg/machinery/constants/constants.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1278,7 +1278,7 @@ var DefaultDroppedCapabilities = map[string]struct{}{
12781278
}
12791279

12801280
// XFSScrubDroppedCapabilities is the set of capabilities to drop for xfs_scrub.
1281-
// All but cap_sys_admin cap_fowner cap_dac_override cap_dac_read_search cap_sys_rawio
1281+
// All but cap_sys_admin cap_fowner cap_dac_override cap_dac_read_search cap_sys_rawio.
12821282
var XFSScrubDroppedCapabilities = map[string]struct{}{
12831283
"cap_audit_control": {},
12841284
"cap_audit_write": {},

website/content/v1.9/reference/api.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,7 @@ description: Talos gRPC API reference.
255255
- [ExtensionServiceConfigSpec](#talos.resource.definitions.runtime.ExtensionServiceConfigSpec)
256256
- [ExtensionServiceConfigStatusSpec](#talos.resource.definitions.runtime.ExtensionServiceConfigStatusSpec)
257257
- [FSScrubConfigSpec](#talos.resource.definitions.runtime.FSScrubConfigSpec)
258+
- [FSScrubStatusSpec](#talos.resource.definitions.runtime.FSScrubStatusSpec)
258259
- [KernelModuleSpecSpec](#talos.resource.definitions.runtime.KernelModuleSpecSpec)
259260
- [KernelParamSpecSpec](#talos.resource.definitions.runtime.KernelParamSpecSpec)
260261
- [KernelParamStatusSpec](#talos.resource.definitions.runtime.KernelParamStatusSpec)
@@ -4680,6 +4681,25 @@ FSScrubConfigSpec describes configuration of watchdog timer.
46804681

46814682

46824683

4684+
<a name="talos.resource.definitions.runtime.FSScrubStatusSpec"></a>
4685+
4686+
### FSScrubStatusSpec
4687+
FSScrubStatusSpec describes configuration of watchdog timer.
4688+
4689+
4690+
| Field | Type | Label | Description |
4691+
| ----- | ---- | ----- | ----------- |
4692+
| mountpoint | [string](#string) | | |
4693+
| period | [google.protobuf.Duration](#google.protobuf.Duration) | | |
4694+
| time | [google.protobuf.Timestamp](#google.protobuf.Timestamp) | | |
4695+
| duration | [google.protobuf.Duration](#google.protobuf.Duration) | | |
4696+
| status | [string](#string) | | |
4697+
4698+
4699+
4700+
4701+
4702+
46834703
<a name="talos.resource.definitions.runtime.KernelModuleSpecSpec"></a>
46844704

46854705
### KernelModuleSpecSpec

0 commit comments

Comments
 (0)