Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NETOBSERV-939: Detect which dashboards to show based on ocp version #399

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
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
34 changes: 18 additions & 16 deletions controllers/consoleplugin/consoleplugin_objects.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,16 @@ const metricsPort = 9002
const metricsPortName = "metrics"

type builder struct {
namespace string
labels map[string]string
selector map[string]string
desired *flowslatest.FlowCollectorSpec
imageName string
volumes volumes.Builder
namespace string
labels map[string]string
selector map[string]string
desired *flowslatest.FlowCollectorSpec
imageName string
volumes volumes.Builder
availableDashboards []string
}

func newBuilder(ns, imageName string, desired *flowslatest.FlowCollectorSpec) builder {
func newBuilder(ns, imageName string, desired *flowslatest.FlowCollectorSpec, dashboards []string) builder {
version := helper.ExtractVersion(imageName)
return builder{
namespace: ns,
Expand All @@ -55,8 +56,9 @@ func newBuilder(ns, imageName string, desired *flowslatest.FlowCollectorSpec) bu
selector: map[string]string{
"app": constants.PluginName,
},
desired: desired,
imageName: imageName,
desired: desired,
imageName: imageName,
availableDashboards: dashboards,
}
}

Expand Down Expand Up @@ -353,19 +355,19 @@ func (b *builder) configMap() (*corev1.ConfigMap, string) {
if helper.IsPktDropEnabled(b.desired) {
features = append(features, "pktDrop")
}

if helper.IsDNSTrackingEnabled(b.desired) {
features = append(features, "dnsTracking")
}
}

config := map[string]interface{}{
"recordTypes": outputRecordTypes,
"portNaming": b.desired.ConsolePlugin.PortNaming,
"quickFilters": b.desired.ConsolePlugin.QuickFilters,
"alertNamespaces": []string{b.namespace},
"sampling": helper.GetSampling(b.desired),
"features": features,
"recordTypes": outputRecordTypes,
"portNaming": b.desired.ConsolePlugin.PortNaming,
"quickFilters": b.desired.ConsolePlugin.QuickFilters,
"alertNamespaces": []string{b.namespace},
"sampling": helper.GetSampling(b.desired),
"features": features,
"availableDashboards": b.availableDashboards,
}

configStr := "{}"
Expand Down
8 changes: 5 additions & 3 deletions controllers/consoleplugin/consoleplugin_reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func NewReconciler(common *reconcilers.Common, imageName string) CPReconciler {
cmnInstance.Managed.AddManagedObject(constants.PluginName, owned.hpa)
cmnInstance.Managed.AddManagedObject(constants.PluginName, owned.serviceAccount)
cmnInstance.Managed.AddManagedObject(configMapName, owned.configMap)
if common.AvailableAPIs.HasSvcMonitor() {
if common.ClusterInfo.HasSvcMonitor() {
cmnInstance.Managed.AddManagedObject(constants.PluginName, owned.serviceMonitor)
}

Expand All @@ -82,8 +82,10 @@ func (r *CPReconciler) Reconcile(ctx context.Context, desired *flowslatest.FlowC
}

if helper.UseConsolePlugin(&desired.Spec) {
dashboards := r.ClusterInfo.Dashboards.GetList()

// Create object builder
builder := newBuilder(ns, r.Instance.Image, &desired.Spec)
builder := newBuilder(ns, r.Instance.Image, &desired.Spec, dashboards)

if err := r.reconcilePermissions(ctx, &builder); err != nil {
return err
Expand Down Expand Up @@ -231,7 +233,7 @@ func (r *CPReconciler) reconcileServices(ctx context.Context, builder *builder)
if err := r.ReconcileService(ctx, r.owned.metricsService, builder.metricsService(), &report); err != nil {
return err
}
if r.AvailableAPIs.HasSvcMonitor() {
if r.ClusterInfo.HasSvcMonitor() {
serviceMonitor := builder.serviceMonitor()
if err := reconcilers.GenericReconcile(ctx, r.Managed, &r.Client, r.owned.serviceMonitor, serviceMonitor, &report, helper.ServiceMonitorChanged); err != nil {
return err
Expand Down
22 changes: 13 additions & 9 deletions controllers/consoleplugin/consoleplugin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,14 +103,18 @@ func getAutoScalerSpecs() (ascv2.HorizontalPodAutoscaler, flowslatest.FlowCollec
return autoScaler, getPluginConfig()
}

func nbuilder(spec *flowslatest.FlowCollectorSpec) builder {
return newBuilder(testNamespace, testImage, spec, []string{})
}

func TestContainerUpdateCheck(t *testing.T) {
assert := assert.New(t)

//equals specs
plugin := getPluginConfig()
loki := flowslatest.FlowCollectorLoki{URL: "http://loki:3100/", TenantID: "netobserv"}
spec := flowslatest.FlowCollectorSpec{ConsolePlugin: plugin, Loki: loki}
builder := newBuilder(testNamespace, testImage, &spec)
builder := nbuilder(&spec)
old := builder.deployment("digest")
nEw := builder.deployment("digest")
report := helper.NewChangeReport("")
Expand Down Expand Up @@ -162,7 +166,7 @@ func TestContainerUpdateCheck(t *testing.T) {
},
}}
spec = flowslatest.FlowCollectorSpec{ConsolePlugin: plugin, Loki: loki}
builder = newBuilder(testNamespace, testImage, &spec)
builder = nbuilder(&spec)
nEw = builder.deployment("digest")
report = helper.NewChangeReport("")
assert.True(helper.PodChanged(&old.Spec.Template, &nEw.Spec.Template, constants.PluginName, &report))
Expand All @@ -172,7 +176,7 @@ func TestContainerUpdateCheck(t *testing.T) {
//new loki cert name
loki.TLS.CACert.Name = "cm-name-2"
spec = flowslatest.FlowCollectorSpec{ConsolePlugin: plugin, Loki: loki}
builder = newBuilder(testNamespace, testImage, &spec)
builder = nbuilder(&spec)
nEw = builder.deployment("digest")
report = helper.NewChangeReport("")
assert.True(helper.PodChanged(&old.Spec.Template, &nEw.Spec.Template, constants.PluginName, &report))
Expand All @@ -182,7 +186,7 @@ func TestContainerUpdateCheck(t *testing.T) {
//test again no change
loki.TLS.CACert.Name = "cm-name-2"
spec = flowslatest.FlowCollectorSpec{ConsolePlugin: plugin, Loki: loki}
builder = newBuilder(testNamespace, testImage, &spec)
builder = nbuilder(&spec)
nEw = builder.deployment("digest")
report = helper.NewChangeReport("")
assert.False(helper.PodChanged(&old.Spec.Template, &nEw.Spec.Template, constants.PluginName, &report))
Expand All @@ -194,7 +198,7 @@ func TestContainerUpdateCheck(t *testing.T) {
loki.StatusTLS.Enable = true

spec = flowslatest.FlowCollectorSpec{ConsolePlugin: plugin, Loki: loki}
builder = newBuilder(testNamespace, testImage, &spec)
builder = nbuilder(&spec)
nEw = builder.deployment("digest")
report = helper.NewChangeReport("")
assert.True(helper.PodChanged(&old.Spec.Template, &nEw.Spec.Template, constants.PluginName, &report))
Expand All @@ -209,7 +213,7 @@ func TestContainerUpdateCheck(t *testing.T) {
}

spec = flowslatest.FlowCollectorSpec{ConsolePlugin: plugin, Loki: loki}
builder = newBuilder(testNamespace, testImage, &spec)
builder = nbuilder(&spec)
nEw = builder.deployment("digest")
report = helper.NewChangeReport("")
assert.True(helper.PodChanged(&old.Spec.Template, &nEw.Spec.Template, constants.PluginName, &report))
Expand All @@ -225,7 +229,7 @@ func TestContainerUpdateCheck(t *testing.T) {
}

spec = flowslatest.FlowCollectorSpec{ConsolePlugin: plugin, Loki: loki}
builder = newBuilder(testNamespace, testImage, &spec)
builder = nbuilder(&spec)
nEw = builder.deployment("digest")
report = helper.NewChangeReport("")
assert.True(helper.PodChanged(&old.Spec.Template, &nEw.Spec.Template, constants.PluginName, &report))
Expand Down Expand Up @@ -264,7 +268,7 @@ func TestBuiltService(t *testing.T) {
plugin := getPluginConfig()
loki := flowslatest.FlowCollectorLoki{URL: "http://foo:1234"}
spec := flowslatest.FlowCollectorSpec{ConsolePlugin: plugin, Loki: loki}
builder := newBuilder(testNamespace, testImage, &spec)
builder := nbuilder(&spec)
old := builder.mainService()
nEw := builder.mainService()
report := helper.NewChangeReport("")
Expand All @@ -278,7 +282,7 @@ func TestLabels(t *testing.T) {
plugin := getPluginConfig()
loki := flowslatest.FlowCollectorLoki{URL: "http://foo:1234"}
spec := flowslatest.FlowCollectorSpec{ConsolePlugin: plugin, Loki: loki}
builder := newBuilder(testNamespace, testImage, &spec)
builder := nbuilder(&spec)

// Deployment
depl := builder.deployment("digest")
Expand Down
8 changes: 8 additions & 0 deletions controllers/constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,14 @@ const (
NewConnectionType = "newConnection"
HeartbeatType = "heartbeat"
EndConnectionType = "endConnection"

// Dashboards
FlowDashboardCMName = "grafana-dashboard-netobserv-flow-metrics"
HealthDashboardCMName = "grafana-dashboard-netobserv-health"
IngressDashboardCMName = "grafana-dashboard-ingress"
NetStatsDashboardCMName = "grafana-dashboard-network-stats"
OVNDashboardCMName = "grafana-dashboard-ovn-health"
KubernetesNetworkDashboard = "grafana-dashboard-cluster-total"
)

var LokiIndexFields = []string{"SrcK8S_Namespace", "SrcK8S_OwnerName", "DstK8S_Namespace", "DstK8S_OwnerName", "FlowDirection"}
Expand Down
2 changes: 1 addition & 1 deletion controllers/ebpf/internal/permissions/permissions.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ func (c *Reconciler) reconcileServiceAccount(ctx context.Context) error {
func (c *Reconciler) reconcileVendorPermissions(
ctx context.Context, desired *flowslatest.FlowCollectorEBPF,
) error {
if c.UseOpenShiftSCC {
if c.ClusterInfo.HasOCPSecurity() {
return c.reconcileOpenshiftPermissions(ctx, desired)
}
return nil
Expand Down
Loading
Loading