Skip to content

Commit 4ba5bd1

Browse files
committed
Addressing reviews comments
1 parent 685bae5 commit 4ba5bd1

3 files changed

Lines changed: 6 additions & 96 deletions

File tree

manifests/08-flowcollector.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ spec:
66
agent:
77
ebpf:
88
features:
9-
- PacketDrop
9+
- DNSTracking
1010
sampling: 400
1111
type: eBPF
12-
deploymentModel: Direct
12+
deploymentModel: Service
1313
loki:
1414
enable: false
1515
namespace: netobserv

pkg/controller/observability/observability_controller.go

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ type ReconcileObservability struct {
8888
func (r *ReconcileObservability) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
8989
klog.Info("Reconcile Network Observability")
9090

91-
if req.Name != "cluster" {
91+
if req.Name != FlowCollectorName {
9292
return ctrl.Result{}, nil // only reconcile the singleton Network object
9393
}
9494

@@ -102,7 +102,7 @@ func (r *ReconcileObservability) Reconcile(ctx context.Context, req ctrl.Request
102102

103103
// Get Network CR information
104104
var network configv1.Network
105-
if err := r.client.Get(ctx, types.NamespacedName{Name: "cluster"}, &network); err != nil {
105+
if err := r.client.Get(ctx, types.NamespacedName{Name: FlowCollectorName}, &network); err != nil {
106106
return ctrl.Result{}, crclient.IgnoreNotFound(err)
107107
}
108108

@@ -132,20 +132,6 @@ func (r *ReconcileObservability) Reconcile(ctx context.Context, req ctrl.Request
132132
return ctrl.Result{}, err
133133
}
134134
if !installed {
135-
// Create namespace if it doesn't exist
136-
ns := &corev1.Namespace{ObjectMeta: metav1.ObjectMeta{Name: OperatorNamespace}}
137-
if err := r.client.Get(ctx, types.NamespacedName{Name: OperatorNamespace}, ns); err != nil {
138-
if errors.IsNotFound(err) {
139-
if err := r.client.Create(ctx, ns); err != nil {
140-
r.status.SetDegraded(statusmanager.ObservabilityConfig, "CreateNamespaceError", fmt.Sprintf("Failed to create namespace %s: %v", OperatorNamespace, err))
141-
return ctrl.Result{}, err
142-
}
143-
} else {
144-
r.status.SetDegraded(statusmanager.ObservabilityConfig, "GetNamespaceError", fmt.Sprintf("Failed to get namespace %s: %v", OperatorNamespace, err))
145-
return ctrl.Result{}, err
146-
}
147-
}
148-
149135
// Install Network Observability Operator
150136
if err := r.installNetObservOperator(ctx); err != nil {
151137
r.status.SetDegraded(statusmanager.ObservabilityConfig, "InstallOperatorError", fmt.Sprintf("Failed to install Network Observability Operator: %v", err))

pkg/controller/observability/observability_controller_test.go

Lines changed: 2 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -407,8 +407,9 @@ func TestReconcile_InstallsWhenNil(t *testing.T) {
407407
},
408408
}
409409
infra := createTestInfrastructure(configv1.HighlyAvailableTopologyMode)
410+
operatorNs := createTestNamespace(OperatorNamespace)
410411

411-
client := fake.NewClientBuilder().WithScheme(scheme).WithObjects(network, infra).Build()
412+
client := fake.NewClientBuilder().WithScheme(scheme).WithObjects(network, infra, operatorNs).Build()
412413

413414
r := &ReconcileObservability{
414415
client: client,
@@ -422,12 +423,6 @@ func TestReconcile_InstallsWhenNil(t *testing.T) {
422423
// This will fail because the manifest doesn't exist, which proves it tried to install
423424
g.Expect(err).To(HaveOccurred())
424425
g.Expect(err.Error()).To(ContainSubstring("failed to read"))
425-
426-
// Verify that the operator namespace was created despite the error
427-
ns := &corev1.Namespace{}
428-
nsErr := client.Get(context.TODO(), types.NamespacedName{Name: OperatorNamespace}, ns)
429-
g.Expect(nsErr).NotTo(HaveOccurred())
430-
g.Expect(ns.Name).To(Equal(OperatorNamespace))
431426
}
432427

433428
func TestReconcile_SkipsInstallWhenNilOnSNO(t *testing.T) {
@@ -1115,12 +1110,6 @@ func TestReconcile_PartialFailure_OperatorInstallFails(t *testing.T) {
11151110

11161111
// Should fail at operator installation
11171112
g.Expect(err).To(HaveOccurred())
1118-
1119-
// Verify that namespace was created despite operator install failure
1120-
ns := &corev1.Namespace{}
1121-
nsErr := client.Get(context.TODO(), types.NamespacedName{Name: OperatorNamespace}, ns)
1122-
g.Expect(nsErr).NotTo(HaveOccurred())
1123-
g.Expect(ns.Name).To(Equal(OperatorNamespace))
11241113
}
11251114

11261115
// TestReconcile_RecoveryAfterOperatorBecomesReady tests that reconciliation
@@ -1173,71 +1162,6 @@ func TestReconcile_RecoveryAfterOperatorBecomesReady(t *testing.T) {
11731162
g.Expect(err2.Error()).To(ContainSubstring("failed to read"))
11741163
}
11751164

1176-
// TestReconcile_NamespaceCreation tests namespace creation logic
1177-
func TestReconcile_NamespaceCreation(t *testing.T) {
1178-
g := NewGomegaWithT(t)
1179-
1180-
scheme := runtime.NewScheme()
1181-
_ = configv1.AddToScheme(scheme)
1182-
_ = corev1.AddToScheme(scheme)
1183-
1184-
network := createTestNetwork("cluster", "InstallAndEnable")
1185-
1186-
client := fake.NewClientBuilder().WithScheme(scheme).
1187-
WithObjects(network).
1188-
Build()
1189-
1190-
r := &ReconcileObservability{
1191-
client: client,
1192-
status: newMockStatusManager(),
1193-
}
1194-
1195-
req := ctrl.Request{NamespacedName: types.NamespacedName{Name: "cluster"}}
1196-
1197-
// Reconciliation will fail, but should create the operator namespace first
1198-
_, _ = r.Reconcile(context.TODO(), req)
1199-
1200-
// Verify operator namespace was created
1201-
ns := &corev1.Namespace{}
1202-
err := client.Get(context.TODO(), types.NamespacedName{Name: OperatorNamespace}, ns)
1203-
g.Expect(err).NotTo(HaveOccurred())
1204-
g.Expect(ns.Name).To(Equal(OperatorNamespace))
1205-
}
1206-
1207-
// TestReconcile_NamespaceAlreadyExists tests that reconciliation
1208-
// handles pre-existing namespaces gracefully
1209-
func TestReconcile_NamespaceAlreadyExists(t *testing.T) {
1210-
g := NewGomegaWithT(t)
1211-
1212-
scheme := runtime.NewScheme()
1213-
_ = configv1.AddToScheme(scheme)
1214-
_ = corev1.AddToScheme(scheme)
1215-
1216-
network := createTestNetwork("cluster", "InstallAndEnable")
1217-
// Namespace already exists
1218-
operatorNs := createTestNamespace(OperatorNamespace)
1219-
1220-
client := fake.NewClientBuilder().WithScheme(scheme).
1221-
WithObjects(network, operatorNs).
1222-
Build()
1223-
1224-
r := &ReconcileObservability{
1225-
client: client,
1226-
status: newMockStatusManager(),
1227-
}
1228-
1229-
req := ctrl.Request{NamespacedName: types.NamespacedName{Name: "cluster"}}
1230-
1231-
// Reconciliation should handle existing namespace gracefully
1232-
_, _ = r.Reconcile(context.TODO(), req)
1233-
1234-
// Verify namespace still exists
1235-
ns := &corev1.Namespace{}
1236-
err := client.Get(context.TODO(), types.NamespacedName{Name: OperatorNamespace}, ns)
1237-
g.Expect(err).NotTo(HaveOccurred())
1238-
g.Expect(ns.Name).To(Equal(OperatorNamespace))
1239-
}
1240-
12411165
// Performance/Stress Tests
12421166

12431167
// TestReconcile_ConcurrentReconciliations tests that multiple concurrent

0 commit comments

Comments
 (0)