Skip to content

Commit

Permalink
NETOBSERV-365 Fix errors in operator logs (#105)
Browse files Browse the repository at this point in the history
  • Loading branch information
jotak authored May 18, 2022
1 parent 1f0a50f commit b2dc47f
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 14 deletions.
2 changes: 1 addition & 1 deletion controllers/consoleplugin/consoleplugin_reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func (r *CPReconciler) InitStaticResources(ctx context.Context) error {
// PrepareNamespaceChange cleans up old namespace and restore the relevant "static" resources
func (r *CPReconciler) PrepareNamespaceChange(ctx context.Context) error {
// Switching namespace => delete everything in the previous namespace
r.nobjMngr.CleanupNamespace(ctx)
r.nobjMngr.CleanupPreviousNamespace(ctx)
return r.CreateOwned(ctx, buildServiceAccount(r.nobjMngr.Namespace))
}

Expand Down
20 changes: 11 additions & 9 deletions controllers/flowlogspipeline/flp_reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"fmt"
"reflect"

"github.com/netobserv/network-observability-operator/pkg/helper"
appsv1 "k8s.io/api/apps/v1"
ascv2 "k8s.io/api/autoscaling/v2beta2"
corev1 "k8s.io/api/core/v1"
Expand All @@ -16,6 +15,7 @@ import (
flowsv1alpha1 "github.com/netobserv/network-observability-operator/api/v1alpha1"
"github.com/netobserv/network-observability-operator/controllers/constants"
"github.com/netobserv/network-observability-operator/controllers/reconcilers"
"github.com/netobserv/network-observability-operator/pkg/helper"
)

// Type alias
Expand Down Expand Up @@ -97,9 +97,9 @@ func (r *FLPReconciler) InitStaticResources(ctx context.Context) error {
func (r *FLPReconciler) PrepareNamespaceChange(ctx context.Context) error {
// Switching namespace => delete everything in the previous namespace
for _, singleFlp := range r.singleReconcilers {
singleFlp.nobjMngr.CleanupNamespace(ctx)
singleFlp.nobjMngr.CleanupPreviousNamespace(ctx)
}
r.nobjMngr.CleanupNamespace(ctx)
r.nobjMngr.CleanupPreviousNamespace(ctx)
return r.reconcilePermissions(ctx)
}

Expand Down Expand Up @@ -150,25 +150,27 @@ func (r *singleDeploymentReconciler) Reconcile(ctx context.Context, desired *flo
if err != nil {
return err
}

shouldDeploy, err := checkDeployNeeded(desired.Spec.Kafka, r.confKind)
if err != nil {
return err
}
if !shouldDeploy {
r.nobjMngr.CleanupNamespace(ctx)
r.nobjMngr.CleanupCurrentNamespace(ctx)
return nil
}

portProtocol := corev1.ProtocolUDP
if desired.Spec.Agent == flowsv1alpha1.AgentEBPF {
portProtocol = corev1.ProtocolTCP
}
builder := newBuilder(r.nobjMngr.Namespace, portProtocol, desiredFLP, desiredLoki, r.confKind)
// Retrieve current owned objects
err = r.nobjMngr.FetchAll(ctx)
if err != nil {
return err
}

portProtocol := corev1.ProtocolUDP
if desired.Spec.Agent == flowsv1alpha1.AgentEBPF {
portProtocol = corev1.ProtocolTCP
}
builder := newBuilder(r.nobjMngr.Namespace, portProtocol, desiredFLP, desiredLoki, r.confKind)
newCM, configDigest := builder.configMap()
if !r.nobjMngr.Exists(r.owned.configMap) {
if err := r.CreateOwned(ctx, newCM); err != nil {
Expand Down
18 changes: 14 additions & 4 deletions controllers/reconcilers/namespaced_objects_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@ func (m *NamespacedObjectManager) FetchAll(ctx context.Context) error {
log.Info("Fetching " + ref.kind)
err := m.client.Get(ctx, types.NamespacedName{Name: ref.name, Namespace: m.Namespace}, ref.placeholder)
if err != nil {
if !errors.IsNotFound(err) {
if errors.IsNotFound(err) {
log.Info(ref.name + " " + ref.kind + " not found")
} else {
log.Error(err, "Failed to get "+ref.name+" "+ref.kind)
return err
}
Expand All @@ -65,9 +67,17 @@ func (m *NamespacedObjectManager) FetchAll(ctx context.Context) error {
return nil
}

// CleanupNamespace removes all managed objects (registered using AddManagedObject) from the previous namespace.
func (m *NamespacedObjectManager) CleanupNamespace(ctx context.Context) {
namespace := m.PreviousNamespace
// CleanupPreviousNamespace removes all managed objects (registered using AddManagedObject) from the previous namespace.
func (m *NamespacedObjectManager) CleanupPreviousNamespace(ctx context.Context) {
m.cleanup(ctx, m.PreviousNamespace)
}

// CleanupCurrentNamespace removes all managed objects (registered using AddManagedObject) from the current namespace.
func (m *NamespacedObjectManager) CleanupCurrentNamespace(ctx context.Context) {
m.cleanup(ctx, m.Namespace)
}

func (m *NamespacedObjectManager) cleanup(ctx context.Context, namespace string) {
log := log.FromContext(ctx)
for _, obj := range m.managedObjects {
ref := obj.placeholder.DeepCopyObject().(client.Object)
Expand Down

0 comments on commit b2dc47f

Please sign in to comment.