Utku Ozdemir 5ffc3f14bd
feat: show siderolink status on dashboard
Add a new resource, `SiderolinkStatus`, which combines the following info:
- The Siderolink API endpoint without the query parameters or fragments (potentially sensitive info due to the join token)
- The status of the Siderolink connection

This resource is not set as sensitive, so it can be retrieved by the users with `os:operator` role (e.g., using `talosctl dashboard` through Omni).

Make use of this resource in the dashboard to display the status of the Siderolink connection.

Additionally, rework the status columns in the dashboard to:
- Display a Linux terminal compatible "tick" or a "cross" prefix for statuses in addition to the red/green color coding.
- Move and combine some statuses to save rows and make them more even.

Closes siderolabs/talos#8643.

Signed-off-by: Utku Ozdemir <utku.ozdemir@siderolabs.com>
2024-06-18 12:31:54 +02:00

136 lines
3.6 KiB
Go

// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
package runtime
import (
"context"
"time"
"github.com/cosi-project/runtime/pkg/controller"
"github.com/cosi-project/runtime/pkg/safe"
"go.uber.org/zap"
"github.com/siderolabs/talos/internal/app/machined/pkg/controllers/runtime/internal/diagnostics"
"github.com/siderolabs/talos/pkg/machinery/resources/config"
"github.com/siderolabs/talos/pkg/machinery/resources/k8s"
"github.com/siderolabs/talos/pkg/machinery/resources/network"
"github.com/siderolabs/talos/pkg/machinery/resources/runtime"
"github.com/siderolabs/talos/pkg/machinery/resources/v1alpha1"
)
// DiagnosticsController analyzes state of Talos Linux system and provides warnings on common problems.
type DiagnosticsController struct{}
// Name implements controller.Controller interface.
func (ctrl *DiagnosticsController) Name() string {
return "runtime.DiagnosticsController"
}
// Inputs implements controller.Controller interface.
func (ctrl *DiagnosticsController) Inputs() []controller.Input {
return []controller.Input{
{
Namespace: network.NamespaceName,
Type: network.NodeAddressType,
Kind: controller.InputWeak,
},
{
Namespace: config.NamespaceName,
Type: config.MachineConfigType,
Kind: controller.InputWeak,
},
{
Namespace: v1alpha1.NamespaceName,
Type: v1alpha1.ServiceType,
Kind: controller.InputWeak,
},
{
Namespace: k8s.NamespaceName,
Type: k8s.NodenameType,
Kind: controller.InputWeak,
},
}
}
// Outputs implements controller.Controller interface.
func (ctrl *DiagnosticsController) Outputs() []controller.Output {
return []controller.Output{
{
Type: runtime.DiagnosticType,
Kind: controller.OutputExclusive,
},
}
}
const (
diagnosticsCheckTimeout = time.Minute
diagnostricsCheckInterval = time.Minute
)
// Run implements controller.Controller interface.
//
//nolint:gocyclo
func (ctrl *DiagnosticsController) Run(ctx context.Context, r controller.Runtime, logger *zap.Logger) error {
// firstDiscovery is used to track when a warning was first discovered.
firstDiscovered := map[string]time.Time{}
ticker := time.NewTicker(diagnostricsCheckInterval)
defer ticker.Stop()
for {
select {
case <-ctx.Done():
return nil
case <-r.EventCh():
case <-ticker.C:
}
r.StartTrackingOutputs()
for _, checkDescription := range diagnostics.Checks() {
if err := func() error {
checkCtx, checkCtxCancel := context.WithTimeout(ctx, diagnosticsCheckTimeout)
defer checkCtxCancel()
warning, err := checkDescription.Check(checkCtx, r, logger)
if err != nil {
logger.Debug("diagnostic check failed", zap.String("check", checkDescription.ID), zap.Error(err))
return nil
}
if warning == nil {
delete(firstDiscovered, checkDescription.ID)
return nil
}
firstDiscoveredTime, ok := firstDiscovered[checkDescription.ID]
if !ok {
firstDiscoveredTime = time.Now()
firstDiscovered[checkDescription.ID] = firstDiscoveredTime
}
if time.Since(firstDiscoveredTime) < checkDescription.Hysteresis {
// don't publish it yet
return nil
}
return safe.WriterModify(ctx, r, runtime.NewDiagnostic(runtime.NamespaceName, checkDescription.ID), func(res *runtime.Diagnostic) error {
*res.TypedSpec() = *warning
return nil
})
}(); err != nil {
return err
}
}
if err := safe.CleanupOutputs[*runtime.Diagnostic](ctx, r); err != nil {
return err
}
}
}