Skip to content

Commit

Permalink
Fix certs monitoring copy (#414) (#416)
Browse files Browse the repository at this point in the history
  • Loading branch information
OlivierCazade authored Sep 14, 2023
1 parent 623a3b2 commit 5dbfa16
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 9 deletions.
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"
)

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

0 comments on commit 5dbfa16

Please sign in to comment.