Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 8 additions & 20 deletions internal/controller/consoleplugin/consoleplugin_objects.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"strconv"
"time"

lokiv1 "github.com/grafana/loki/operator/apis/loki/v1"
osv1 "github.com/openshift/api/console/v1"
monitoringv1 "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1"
"gopkg.in/yaml.v2"
Expand All @@ -28,6 +27,7 @@ import (
"github.com/netobserv/netobserv-operator/internal/controller/reconcilers"
"github.com/netobserv/netobserv-operator/internal/pkg/helper"
"github.com/netobserv/netobserv-operator/internal/pkg/helper/loki"
"github.com/netobserv/netobserv-operator/internal/pkg/manager/status"
"github.com/netobserv/netobserv-operator/internal/pkg/metrics"
"github.com/netobserv/netobserv-operator/internal/pkg/metrics/alerts"
"github.com/netobserv/netobserv-operator/internal/pkg/volumes"
Expand Down Expand Up @@ -521,25 +521,9 @@ func (b *builder) getHealthRecordingAnnotations() map[string]map[string]string {
return annotsPerRecording
}

func getLokiStatus(lokiStack *lokiv1.LokiStack) string {
if lokiStack == nil {
// This case should not happen
return ""
}
for _, conditions := range lokiStack.Status.Conditions {
if conditions.Reason == "ReadyComponents" {
if conditions.Status == "True" {
return "ready"
}
break
}
}
return "pending"
}

// returns a configmap with a digest of its configuration contents, which will be used to
// detect any configuration change
func (b *builder) configMap(ctx context.Context, lokiStack *lokiv1.LokiStack) (*corev1.ConfigMap, string, error) {
func (b *builder) configMap(ctx context.Context, lokiStatus status.ComponentStatus) (*corev1.ConfigMap, string, error) {
config := cfg.PluginConfig{
Server: cfg.ServerConfig{
Port: int(*b.advanced.Port),
Expand All @@ -555,9 +539,13 @@ func (b *builder) configMap(ctx context.Context, lokiStack *lokiv1.LokiStack) (*
// configure loki
var err error
config.Loki, err = b.getLokiConfig()
if lokiStack != nil {
config.Loki.Status = getLokiStatus(lokiStack)
if lokiStatus.Status != status.StatusUnknown {
config.Loki.StatusURL = ""
if lokiStatus.Status == status.StatusReady {
config.Loki.Status = "ready"
} else {
config.Loki.Status = "pending"
}
}
if err != nil {
return nil, "", err
Expand Down
54 changes: 27 additions & 27 deletions internal/controller/consoleplugin/consoleplugin_reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ import (
"k8s.io/apimachinery/pkg/types"
"sigs.k8s.io/controller-runtime/pkg/log"

lokiv1 "github.com/grafana/loki/operator/apis/loki/v1"
flowslatest "github.com/netobserv/netobserv-operator/api/flowcollector/v1beta2"
"github.com/netobserv/netobserv-operator/internal/controller/constants"
"github.com/netobserv/netobserv-operator/internal/controller/reconcilers"
"github.com/netobserv/netobserv-operator/internal/pkg/helper"
"github.com/netobserv/netobserv-operator/internal/pkg/manager/status"
"github.com/netobserv/netobserv-operator/internal/pkg/resources"
apierrors "k8s.io/apimachinery/pkg/api/errors"
)
Expand Down Expand Up @@ -54,10 +54,26 @@ func NewReconciler(cmn *reconcilers.Instance) CPReconciler {
}

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

defer r.Status.Commit(ctx, r.Client)

err := r.reconcile(ctx, desired, lokiStatus)
if err != nil {
l.Error(err, "Web Console reconcile failure")
// Set status failure unless it was already set
if !r.Status.HasFailure() {
r.Status.SetFailure("WebConsoleError", err.Error())
}
return err
}

return nil
}

func (r *CPReconciler) reconcile(ctx context.Context, desired *flowslatest.FlowCollector, lokiStatus status.ComponentStatus) error {
// Retrieve current owned objects
err := r.Managed.FetchAll(ctx)
if err != nil {
Expand All @@ -84,7 +100,7 @@ func (r *CPReconciler) Reconcile(ctx context.Context, desired *flowslatest.FlowC
}
}

cmDigest, err := r.reconcileConfigMap(ctx, &builder, &desired.Spec)
cmDigest, err := r.reconcileConfigMap(ctx, &builder, lokiStatus)
if err != nil {
return err
}
Expand Down Expand Up @@ -114,6 +130,11 @@ func (r *CPReconciler) Reconcile(ctx context.Context, desired *flowslatest.FlowC
} else {
// delete any existing owned object
r.Managed.TryDeleteAll(ctx)
if desired.Spec.OnHold() {
r.Status.SetUnused("FlowCollector is on hold")
} else {
r.Status.SetUnused("Web console not enabled")
}
}

return nil
Expand Down Expand Up @@ -180,29 +201,8 @@ func (r *CPReconciler) reconcilePlugin(ctx context.Context, builder *builder, de
return nil
}

func (r *CPReconciler) reconcileConfigMap(ctx context.Context, builder *builder, desired *flowslatest.FlowCollectorSpec) (string, error) {
var lokiStack *lokiv1.LokiStack
if desired.Loki.Mode == flowslatest.LokiModeLokiStack {
lokiStack = &lokiv1.LokiStack{}
ns := desired.Loki.LokiStack.Namespace
if ns == "" {
ns = desired.Namespace
}
if err := r.Client.Get(ctx, types.NamespacedName{Name: desired.Loki.LokiStack.Name, Namespace: ns}, lokiStack); err != nil {
lokiStack = nil
if apierrors.IsNotFound(err) {
log.FromContext(ctx).Info("LokiStack resource not found, status will not be available",
"name", desired.Loki.LokiStack.Name,
"namespace", ns)
} else {
log.FromContext(ctx).Error(err, "Failed to get LokiStack resource",
"name", desired.Loki.LokiStack.Name,
"namespace", ns)
}
}
}

newCM, configDigest, err := builder.configMap(ctx, lokiStack)
func (r *CPReconciler) reconcileConfigMap(ctx context.Context, builder *builder, lokiStatus status.ComponentStatus) (string, error) {
newCM, configDigest, err := builder.configMap(ctx, lokiStatus)
if err != nil {
return "", err
}
Expand Down
Loading