From 6aed532c090132e96b3d45f4d0d4d235ce2f6ac6 Mon Sep 17 00:00:00 2001 From: Dmitry Sharshakov Date: Thu, 5 Dec 2024 18:24:38 +0100 Subject: [PATCH] fixes --- .../pkg/controllers/runtime/fs_scrub.go | 68 ++++++++++++------- .../config/types/runtime/fs_scrub.go | 1 - .../config/types/runtime/kmsg_log.go | 2 - pkg/machinery/constants/constants.go | 2 +- website/content/v1.9/reference/api.md | 20 ++++++ 5 files changed, 64 insertions(+), 29 deletions(-) diff --git a/internal/app/machined/pkg/controllers/runtime/fs_scrub.go b/internal/app/machined/pkg/controllers/runtime/fs_scrub.go index afa2dbb4c42..f3de78301f6 100644 --- a/internal/app/machined/pkg/controllers/runtime/fs_scrub.go +++ b/internal/app/machined/pkg/controllers/runtime/fs_scrub.go @@ -110,36 +110,62 @@ func (ctrl *FSScrubController) Run(ctx context.Context, r controller.Runtime, lo logger.Error("error running filesystem scrub", zap.Error(err)) } case <-r.EventCh(): - err := ctrl.updateSchedule(ctx, r, logger) + err := ctrl.updateSchedule(ctx, r) if err != nil { return err } } - r.StartTrackingOutputs() + if err := ctrl.reportStatus(ctx, r); err != nil { + return err + } + } +} - for _, entry := range ctrl.status { - if err := safe.WriterModify(ctx, r, runtimeres.NewFSScrubStatus(entry.id), func(status *runtimeres.FSScrubStatus) error { - status.TypedSpec().Mountpoint = entry.mountpoint - status.TypedSpec().Period = entry.period - status.TypedSpec().Time = entry.time - status.TypedSpec().Duration = entry.duration - status.TypedSpec().Status = entry.result.Error() +func (ctrl *FSScrubController) reportStatus(ctx context.Context, r controller.Runtime) error { + r.StartTrackingOutputs() - return nil - }); err != nil { - return fmt.Errorf("error updating filesystem scrub status: %w", err) + presentStatuses, err := safe.ReaderListAll[*runtimeres.FSScrubStatus](ctx, r) + if err != nil && !state.IsNotFoundError(err) { + return fmt.Errorf("error getting existing FS scrub statuses: %w", err) + } + + for entry := range presentStatuses.All() { + if _, ok := ctrl.status[entry.TypedSpec().Mountpoint]; !ok { + if err := r.Destroy(ctx, runtimeres.NewFSScrubStatus(entry.Metadata().ID()).Metadata()); err != nil { + return fmt.Errorf("error destroying old FS scrub status: %w", err) } } + } - if err := safe.CleanupOutputs[*runtimeres.FSScrubStatus](ctx, r); err != nil { - return err + for _, entry := range ctrl.status { + if err := safe.WriterModify(ctx, r, runtimeres.NewFSScrubStatus(entry.id), func(status *runtimeres.FSScrubStatus) error { + status.TypedSpec().Mountpoint = entry.mountpoint + status.TypedSpec().Period = entry.period + status.TypedSpec().Time = entry.time + status.TypedSpec().Duration = entry.duration + + if entry.result != nil { + status.TypedSpec().Status = entry.result.Error() + } else { + status.TypedSpec().Status = "success" + } + + return nil + }); err != nil { + return fmt.Errorf("error updating filesystem scrub status: %w", err) } } + + if err := safe.CleanupOutputs[*runtimeres.FSScrubStatus](ctx, r); err != nil { + return err + } + + return nil } //nolint:gocyclo,cyclop -func (ctrl *FSScrubController) updateSchedule(ctx context.Context, r controller.Runtime, logger *zap.Logger) error { +func (ctrl *FSScrubController) updateSchedule(ctx context.Context, r controller.Runtime) error { volumesStatus, err := safe.ReaderListAll[*block.VolumeStatus](ctx, r) if err != nil && !state.IsNotFoundError(err) { return fmt.Errorf("error getting volume status: %w", err) @@ -207,8 +233,6 @@ func (ctrl *FSScrubController) updateSchedule(ctx context.Context, r controller. _, ok := ctrl.schedule[mountpoint] if period == nil { - logger.Warn("!!! scrub !!! not in config, descheduling", zap.String("mountpoint", mountpoint)) - if ok { ctrl.cancelScrub(mountpoint) } @@ -218,12 +242,10 @@ func (ctrl *FSScrubController) updateSchedule(ctx context.Context, r controller. if !ok { firstTimeout := time.Duration(rand.Int64N(int64(period.Seconds()))) * time.Second - logger.Warn("!!! scrub !!! firstTimeout", zap.Duration("firstTimeout", firstTimeout)) // When scheduling the first scrub, we use a random time to avoid all scrubs running in a row. // After the first scrub, we use the period defined in the config. cb := func() { - logger.Warn("!!! scrub !!! ding", zap.String("path", mountpoint)) ctrl.c <- mountpoint ctrl.schedule[mountpoint].timer.Reset(ctrl.schedule[mountpoint].period) } @@ -242,12 +264,8 @@ func (ctrl *FSScrubController) updateSchedule(ctx context.Context, r controller. duration: 0, result: fmt.Errorf("scheduled"), } - - logger.Warn("!!! scrub !!! scheduled", zap.String("path", mountpoint), zap.Duration("period", *period)) } else if ctrl.schedule[mountpoint].period != *period { // reschedule if period has changed - logger.Warn("!!! scrub !!! reschedule", zap.String("path", mountpoint), zap.Duration("period", *period)) - ctrl.schedule[mountpoint].timer.Stop() ctrl.schedule[mountpoint].timer.Reset(*period) ctrl.schedule[mountpoint] = scrubSchedule{ @@ -259,7 +277,7 @@ func (ctrl *FSScrubController) updateSchedule(ctx context.Context, r controller. id: item.Metadata().ID(), mountpoint: mountpoint, period: *period, - time: time.Now().Add(*period), + time: ctrl.status[mountpoint].time, duration: ctrl.status[mountpoint].duration, result: ctrl.status[mountpoint].result, } @@ -304,7 +322,7 @@ func (ctrl *FSScrubController) runScrub(mountpoint string, opts []string) error mountpoint: mountpoint, period: ctrl.schedule[mountpoint].period, time: start, - duration: time.Now().Sub(start), + duration: time.Since(start), result: err, } diff --git a/pkg/machinery/config/types/runtime/fs_scrub.go b/pkg/machinery/config/types/runtime/fs_scrub.go index ced8aa34d13..4119cea3d03 100644 --- a/pkg/machinery/config/types/runtime/fs_scrub.go +++ b/pkg/machinery/config/types/runtime/fs_scrub.go @@ -21,7 +21,6 @@ import ( const FilesystemScrubKind = "FilesystemScrubConfig" func init() { - fmt.Println("TEST! FilesystemScrubKind: ", FilesystemScrubKind) registry.Register(FilesystemScrubKind, func(version string) config.Document { switch version { case "v1alpha1": diff --git a/pkg/machinery/config/types/runtime/kmsg_log.go b/pkg/machinery/config/types/runtime/kmsg_log.go index fb556569f00..a4c82dff5f5 100644 --- a/pkg/machinery/config/types/runtime/kmsg_log.go +++ b/pkg/machinery/config/types/runtime/kmsg_log.go @@ -8,7 +8,6 @@ package runtime import ( "errors" - "fmt" "net/url" "github.com/siderolabs/gen/ensure" @@ -23,7 +22,6 @@ import ( const KmsgLogKind = "KmsgLogConfig" func init() { - fmt.Println("AAAAA! KmsgLogKind: ", KmsgLogKind) registry.Register(KmsgLogKind, func(version string) config.Document { switch version { case "v1alpha1": diff --git a/pkg/machinery/constants/constants.go b/pkg/machinery/constants/constants.go index f2b4b0b84cb..375442e1df8 100644 --- a/pkg/machinery/constants/constants.go +++ b/pkg/machinery/constants/constants.go @@ -1278,7 +1278,7 @@ var DefaultDroppedCapabilities = map[string]struct{}{ } // XFSScrubDroppedCapabilities is the set of capabilities to drop for xfs_scrub. -// All but cap_sys_admin cap_fowner cap_dac_override cap_dac_read_search cap_sys_rawio +// All but cap_sys_admin cap_fowner cap_dac_override cap_dac_read_search cap_sys_rawio. var XFSScrubDroppedCapabilities = map[string]struct{}{ "cap_audit_control": {}, "cap_audit_write": {}, diff --git a/website/content/v1.9/reference/api.md b/website/content/v1.9/reference/api.md index 5958cecca97..d96cfaae97e 100644 --- a/website/content/v1.9/reference/api.md +++ b/website/content/v1.9/reference/api.md @@ -255,6 +255,7 @@ description: Talos gRPC API reference. - [ExtensionServiceConfigSpec](#talos.resource.definitions.runtime.ExtensionServiceConfigSpec) - [ExtensionServiceConfigStatusSpec](#talos.resource.definitions.runtime.ExtensionServiceConfigStatusSpec) - [FSScrubConfigSpec](#talos.resource.definitions.runtime.FSScrubConfigSpec) + - [FSScrubStatusSpec](#talos.resource.definitions.runtime.FSScrubStatusSpec) - [KernelModuleSpecSpec](#talos.resource.definitions.runtime.KernelModuleSpecSpec) - [KernelParamSpecSpec](#talos.resource.definitions.runtime.KernelParamSpecSpec) - [KernelParamStatusSpec](#talos.resource.definitions.runtime.KernelParamStatusSpec) @@ -4680,6 +4681,25 @@ FSScrubConfigSpec describes configuration of watchdog timer. + + +### FSScrubStatusSpec +FSScrubStatusSpec describes configuration of watchdog timer. + + +| Field | Type | Label | Description | +| ----- | ---- | ----- | ----------- | +| mountpoint | [string](#string) | | | +| period | [google.protobuf.Duration](#google.protobuf.Duration) | | | +| time | [google.protobuf.Timestamp](#google.protobuf.Timestamp) | | | +| duration | [google.protobuf.Duration](#google.protobuf.Duration) | | | +| status | [string](#string) | | | + + + + + + ### KernelModuleSpecSpec