Skip to content

Commit e3446ea

Browse files
committed
NETOBSERV-2375: make consistent status handling
Address some old "TODOs" in status management. All statuses now follow this pattern: - They are initialized unknown - When controller found unused, status set to unused - At any point, if an error occurs, it's set with that error - Deployment/DaemonSet check progress set status either as InProgress, or Ready - New Degraded condition can be optionally set; a degraded status does not prevent it from being "ready". Make the LokiStack status fit in this model (it was previously using an entirely different pattern) Also, previously, in 2 different places LokiStack was fetched to get its status (for propagating status into FlowCollector status and into console plugin config) Now consolidated into a single entry point to get the loki status. Status changes: - New status: EBPFAgents - New status: WebConsole - New status: DemoLoki - New status: LokiStack - Renamed status: FlowCollectorLegacy => FlowCollectorController - Removed: LokiIssue and LokiWarning
1 parent 3d1ec8f commit e3446ea

20 files changed

+627
-752
lines changed

internal/controller/consoleplugin/consoleplugin_objects.go

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99
"strconv"
1010
"time"
1111

12-
lokiv1 "github.com/grafana/loki/operator/apis/loki/v1"
1312
osv1 "github.com/openshift/api/console/v1"
1413
monitoringv1 "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1"
1514
"gopkg.in/yaml.v2"
@@ -28,6 +27,7 @@ import (
2827
"github.com/netobserv/netobserv-operator/internal/controller/reconcilers"
2928
"github.com/netobserv/netobserv-operator/internal/pkg/helper"
3029
"github.com/netobserv/netobserv-operator/internal/pkg/helper/loki"
30+
"github.com/netobserv/netobserv-operator/internal/pkg/manager/status"
3131
"github.com/netobserv/netobserv-operator/internal/pkg/metrics"
3232
"github.com/netobserv/netobserv-operator/internal/pkg/metrics/alerts"
3333
"github.com/netobserv/netobserv-operator/internal/pkg/volumes"
@@ -521,25 +521,9 @@ func (b *builder) getHealthRecordingAnnotations() map[string]map[string]string {
521521
return annotsPerRecording
522522
}
523523

524-
func getLokiStatus(lokiStack *lokiv1.LokiStack) string {
525-
if lokiStack == nil {
526-
// This case should not happen
527-
return ""
528-
}
529-
for _, conditions := range lokiStack.Status.Conditions {
530-
if conditions.Reason == "ReadyComponents" {
531-
if conditions.Status == "True" {
532-
return "ready"
533-
}
534-
break
535-
}
536-
}
537-
return "pending"
538-
}
539-
540524
// returns a configmap with a digest of its configuration contents, which will be used to
541525
// detect any configuration change
542-
func (b *builder) configMap(ctx context.Context, lokiStack *lokiv1.LokiStack) (*corev1.ConfigMap, string, error) {
526+
func (b *builder) configMap(ctx context.Context, lokiStatus status.ComponentStatus) (*corev1.ConfigMap, string, error) {
543527
config := cfg.PluginConfig{
544528
Server: cfg.ServerConfig{
545529
Port: int(*b.advanced.Port),
@@ -555,9 +539,13 @@ func (b *builder) configMap(ctx context.Context, lokiStack *lokiv1.LokiStack) (*
555539
// configure loki
556540
var err error
557541
config.Loki, err = b.getLokiConfig()
558-
if lokiStack != nil {
559-
config.Loki.Status = getLokiStatus(lokiStack)
542+
if lokiStatus.Status != status.StatusUnknown {
560543
config.Loki.StatusURL = ""
544+
if lokiStatus.Status == status.StatusReady {
545+
config.Loki.Status = "ready"
546+
} else {
547+
config.Loki.Status = "pending"
548+
}
561549
}
562550
if err != nil {
563551
return nil, "", err

internal/controller/consoleplugin/consoleplugin_reconciler.go

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ import (
1313
"k8s.io/apimachinery/pkg/types"
1414
"sigs.k8s.io/controller-runtime/pkg/log"
1515

16-
lokiv1 "github.com/grafana/loki/operator/apis/loki/v1"
1716
flowslatest "github.com/netobserv/netobserv-operator/api/flowcollector/v1beta2"
1817
"github.com/netobserv/netobserv-operator/internal/controller/constants"
1918
"github.com/netobserv/netobserv-operator/internal/controller/reconcilers"
2019
"github.com/netobserv/netobserv-operator/internal/pkg/helper"
20+
"github.com/netobserv/netobserv-operator/internal/pkg/manager/status"
2121
"github.com/netobserv/netobserv-operator/internal/pkg/resources"
2222
apierrors "k8s.io/apimachinery/pkg/api/errors"
2323
)
@@ -54,10 +54,26 @@ func NewReconciler(cmn *reconcilers.Instance) CPReconciler {
5454
}
5555

5656
// Reconcile is the reconciler entry point to reconcile the current plugin state with the desired configuration
57-
func (r *CPReconciler) Reconcile(ctx context.Context, desired *flowslatest.FlowCollector) error {
58-
l := log.FromContext(ctx).WithName("console-plugin")
57+
func (r *CPReconciler) Reconcile(ctx context.Context, desired *flowslatest.FlowCollector, lokiStatus status.ComponentStatus) error {
58+
l := log.FromContext(ctx).WithName("web-console")
5959
ctx = log.IntoContext(ctx, l)
6060

61+
defer r.Status.Commit(ctx, r.Client)
62+
63+
err := r.reconcile(ctx, desired, lokiStatus)
64+
if err != nil {
65+
l.Error(err, "Web Console reconcile failure")
66+
// Set status failure unless it was already set
67+
if !r.Status.HasFailure() {
68+
r.Status.SetFailure("WebConsoleError", err.Error())
69+
}
70+
return err
71+
}
72+
73+
return nil
74+
}
75+
76+
func (r *CPReconciler) reconcile(ctx context.Context, desired *flowslatest.FlowCollector, lokiStatus status.ComponentStatus) error {
6177
// Retrieve current owned objects
6278
err := r.Managed.FetchAll(ctx)
6379
if err != nil {
@@ -84,7 +100,7 @@ func (r *CPReconciler) Reconcile(ctx context.Context, desired *flowslatest.FlowC
84100
}
85101
}
86102

87-
cmDigest, err := r.reconcileConfigMap(ctx, &builder, &desired.Spec)
103+
cmDigest, err := r.reconcileConfigMap(ctx, &builder, lokiStatus)
88104
if err != nil {
89105
return err
90106
}
@@ -114,6 +130,11 @@ func (r *CPReconciler) Reconcile(ctx context.Context, desired *flowslatest.FlowC
114130
} else {
115131
// delete any existing owned object
116132
r.Managed.TryDeleteAll(ctx)
133+
if desired.Spec.OnHold() {
134+
r.Status.SetUnused("FlowCollector is on hold")
135+
} else {
136+
r.Status.SetUnused("Web console not enabled")
137+
}
117138
}
118139

119140
return nil
@@ -180,29 +201,8 @@ func (r *CPReconciler) reconcilePlugin(ctx context.Context, builder *builder, de
180201
return nil
181202
}
182203

183-
func (r *CPReconciler) reconcileConfigMap(ctx context.Context, builder *builder, desired *flowslatest.FlowCollectorSpec) (string, error) {
184-
var lokiStack *lokiv1.LokiStack
185-
if desired.Loki.Mode == flowslatest.LokiModeLokiStack {
186-
lokiStack = &lokiv1.LokiStack{}
187-
ns := desired.Loki.LokiStack.Namespace
188-
if ns == "" {
189-
ns = desired.Namespace
190-
}
191-
if err := r.Client.Get(ctx, types.NamespacedName{Name: desired.Loki.LokiStack.Name, Namespace: ns}, lokiStack); err != nil {
192-
lokiStack = nil
193-
if apierrors.IsNotFound(err) {
194-
log.FromContext(ctx).Info("LokiStack resource not found, status will not be available",
195-
"name", desired.Loki.LokiStack.Name,
196-
"namespace", ns)
197-
} else {
198-
log.FromContext(ctx).Error(err, "Failed to get LokiStack resource",
199-
"name", desired.Loki.LokiStack.Name,
200-
"namespace", ns)
201-
}
202-
}
203-
}
204-
205-
newCM, configDigest, err := builder.configMap(ctx, lokiStack)
204+
func (r *CPReconciler) reconcileConfigMap(ctx context.Context, builder *builder, lokiStatus status.ComponentStatus) (string, error) {
205+
newCM, configDigest, err := builder.configMap(ctx, lokiStatus)
206206
if err != nil {
207207
return "", err
208208
}

0 commit comments

Comments
 (0)