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-1295: Fix cacert monitoring copy #414

Merged
merged 1 commit into from
Sep 14, 2023
Merged
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
3 changes: 3 additions & 0 deletions controllers/constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ const (
NewConnectionType = "newConnection"
HeartbeatType = "heartbeat"
EndConnectionType = "endConnection"

MonitoringNamespace = "openshift-monitoring"
MonitoringServiceAccount = "prometheus-k8s"
Comment on lines +36 to +37
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what are these hard coded values for?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Constants for monitoring namespace and monitoring role, they were already there, I just moved them to the constant file since they are now used at different places.

)

var LokiIndexFields = []string{"SrcK8S_Namespace", "SrcK8S_OwnerName", "DstK8S_Namespace", "DstK8S_OwnerName", "FlowDirection"}
Expand Down
16 changes: 7 additions & 9 deletions controllers/flowcollector_objects.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,11 @@ import (
var healthDashboardEmbed string

const (
downstreamLabelKey = "openshift.io/cluster-monitoring"
downstreamLabelValue = "true"
roleSuffix = "-metrics-reader"
monitoringServiceAccount = "prometheus-k8s"
monitoringNamespace = "openshift-monitoring"
dashboardCMNamespace = "openshift-config-managed"
dashboardCMAnnotation = "console.openshift.io/dashboard"
downstreamLabelKey = "openshift.io/cluster-monitoring"
downstreamLabelValue = "true"
roleSuffix = "-metrics-reader"
dashboardCMNamespace = "openshift-config-managed"
dashboardCMAnnotation = "console.openshift.io/dashboard"

flowDashboardCMName = "grafana-dashboard-netobserv-flow-metrics"
flowDashboardCMFile = "netobserv-flow-metrics.json"
Expand Down Expand Up @@ -74,8 +72,8 @@ func buildRoleBindingMonitoringReader(ns string) *rbacv1.ClusterRoleBinding {
},
Subjects: []rbacv1.Subject{{
Kind: "ServiceAccount",
Name: monitoringServiceAccount,
Namespace: monitoringNamespace,
Name: constants.MonitoringServiceAccount,
Namespace: constants.MonitoringNamespace,
}},
}
}
Expand Down
5 changes: 5 additions & 0 deletions controllers/flowlogspipeline/flp_ingest_reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,11 @@ func (r *flpIngesterReconciler) reconcile(ctx context.Context, desired *flowslat
return err
}

// Watch for monitoring caCert
if err = reconcileMonitoringCerts(ctx, r.Common, &desired.Spec.Processor.Metrics.Server.TLS, r.Namespace); err != nil {
return err
}

return r.reconcileDaemonSet(ctx, builder.daemonSet(annotations))
}

Expand Down
5 changes: 5 additions & 0 deletions controllers/flowlogspipeline/flp_monolith_reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,11 @@ func (r *flpMonolithReconciler) reconcile(ctx context.Context, desired *flowslat
return err
}

// Watch for monitoring caCert
if err = reconcileMonitoringCerts(ctx, r.Common, &desired.Spec.Processor.Metrics.Server.TLS, r.Namespace); err != nil {
return err
}

return r.reconcileDaemonSet(ctx, builder.daemonSet(annotations))
}

Expand Down
17 changes: 17 additions & 0 deletions controllers/flowlogspipeline/flp_reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,3 +101,20 @@ func annotateKafkaCerts(ctx context.Context, info *reconcilers.Common, spec *flo
}
return nil
}

func reconcileMonitoringCerts(ctx context.Context, info *reconcilers.Common, tlsConfig *flowslatest.ServerTLS, ns string) error {
if tlsConfig.Type == flowslatest.ServerTLSProvided && tlsConfig.Provided != nil {
_, err := info.Watcher.ProcessCertRef(ctx, info.Client, tlsConfig.Provided, ns)
if err != nil {
return err
}
}
if !tlsConfig.InsecureSkipVerify && tlsConfig.ProvidedCaFile != nil && tlsConfig.ProvidedCaFile.File != "" {
_, err := info.Watcher.ProcessFileReference(ctx, info.Client, *tlsConfig.ProvidedCaFile, ns)
if err != nil {
return err
}
}

return nil
}
4 changes: 4 additions & 0 deletions controllers/flowlogspipeline/flp_transfo_reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,10 @@ func (r *flpTransformerReconciler) reconcile(ctx context.Context, desired *flows
if err = annotateKafkaExporterCerts(ctx, r.Common, desired.Spec.Exporters, annotations); err != nil {
return err
}
// Watch for monitoring caCert
if err = reconcileMonitoringCerts(ctx, r.Common, &desired.Spec.Processor.Metrics.Server.TLS, r.Namespace); err != nil {
return err
}

return r.reconcileDeployment(ctx, &desired.Spec.Processor, &builder, annotations)
}
Expand Down
20 changes: 20 additions & 0 deletions pkg/watchers/watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,26 @@ func (w *Watcher) ProcessCACert(ctx context.Context, cl helper.Client, tls *flow
return caDigest, nil
}

func (w *Watcher) ProcessCertRef(ctx context.Context, cl helper.Client, cert *flowslatest.CertificateReference, targetNamespace string) (certDigest string, err error) {
if cert != nil {
certRef := w.refFromCert(cert)
certDigest, err = w.reconcile(ctx, cl, certRef, targetNamespace)
if err != nil {
return "", err
}
}

return certDigest, nil
}

func (w *Watcher) ProcessFileReference(ctx context.Context, cl helper.Client, file flowslatest.FileReference, targetNamespace string) (fileDigest string, err error) {
fileDigest, err = w.reconcile(ctx, cl, w.refFromFile(&file), targetNamespace)
if err != nil {
return "", err
}
return fileDigest, nil
}

func (w *Watcher) ProcessSASL(ctx context.Context, cl helper.Client, sasl *flowslatest.SASLConfig, targetNamespace string) (idDigest string, secretDigest string, err error) {
idDigest, err = w.reconcile(ctx, cl, w.refFromFile(&sasl.ClientIDReference), targetNamespace)
if err != nil {
Expand Down