Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ metadata:
operatorframework.io/cluster-monitoring: "true"
operatorframework.io/suggested-namespace: openshift-gitops-operator
operators.openshift.io/infrastructure-features: '["disconnected"]'
operators.operatorframework.io/builder: operator-sdk-v1.35.0
operators.operatorframework.io/builder: operator-sdk-v1.42.2
operators.operatorframework.io/project_layout: go.kubebuilder.io/v4
repository: https://github.com/redhat-developer/gitops-operator
support: Red Hat
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@ metadata:
name: openshift-gitops-operator-metrics-monitor
spec:
endpoints:
- bearerTokenSecret:
key: token
name: openshift-gitops-operator-metrics-monitor-bearer-token
- authorization:
credentials:
key: token
name: openshift-gitops-operator-metrics-monitor-bearer-token
type: Bearer
interval: 30s
path: /metrics
port: metrics
Expand Down
8 changes: 8 additions & 0 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,14 @@ func main() {
setupLog.Error(err, "unable to create controller", "controller", "Argo CD metrics")
os.Exit(1)
}

if err = (&controllers.OperatorMetricsTokenReconciler{
Client: client,
Scheme: mgr.GetScheme(),
}).SetupWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "Operator metrics token")
os.Exit(1)
}
} else {
setupLog.Info("Monitoring API not found, skipping Argo CD metrics controller setup")
}
Expand Down
17 changes: 5 additions & 12 deletions config/prometheus/monitor.yaml
Original file line number Diff line number Diff line change
@@ -1,14 +1,5 @@
---
apiVersion: v1
kind: Secret
metadata:
name: metrics-monitor-bearer-token
namespace: openshift-gitops-operator
annotations:
kubernetes.io/service-account.name: openshift-gitops-operator-controller-manager
type: kubernetes.io/service-account-token
---
apiVersion: v1
kind: ConfigMap
metadata:
annotations:
Expand All @@ -31,9 +22,11 @@ spec:
matchLabels:
control-plane: gitops-operator
endpoints:
- bearerTokenSecret:
name: openshift-gitops-operator-metrics-monitor-bearer-token
key: token
- authorization:
type: Bearer
credentials:
name: openshift-gitops-operator-metrics-monitor-bearer-token
key: token
interval: 30s
path: /metrics
port: metrics
Expand Down
14 changes: 7 additions & 7 deletions controllers/argocd_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,16 @@ import (
)

const (
argocdNS = "openshift-gitops"
depracatedArgoCDNS = "openshift-pipelines-app-delivery"
consoleLinkName = "argocd"
argocdRouteName = "openshift-gitops-server"
iconFilePath = "/argo.png"
operatorPodNamespacePath = "/var/run/secrets/kubernetes.io/serviceaccount/namespace"
argocdNS = "openshift-gitops"
depracatedArgoCDNS = "openshift-pipelines-app-delivery"
consoleLinkName = "argocd"
argocdRouteName = "openshift-gitops-server"
iconFilePath = "/argo.png"
)

var (
encodedArgoImage string
operatorPodNamespacePath = "/var/run/secrets/kubernetes.io/serviceaccount/namespace"
encodedArgoImage string

//go:embed argocd/img/argo.png
argoImage []byte
Expand Down
55 changes: 5 additions & 50 deletions controllers/argocd_metrics_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"context"
"embed"
"fmt"
"os"
"path/filepath"
"strings"

Expand All @@ -44,13 +43,11 @@ import (
)

const (
readRoleNameFormat = "%s-read"
readRoleBindingNameFormat = "%s-prometheus-k8s-read-binding"
alertRuleName = "gitops-operator-argocd-alerts"
dashboardNamespace = "openshift-config-managed"
dashboardFolder = "dashboards"
operatorMetricsServiceName = "openshift-gitops-operator-metrics-service"
operatorMetricsMonitorName = "openshift-gitops-operator-metrics-monitor"
readRoleNameFormat = "%s-read"
readRoleBindingNameFormat = "%s-prometheus-k8s-read-binding"
alertRuleName = "gitops-operator-argocd-alerts"
dashboardNamespace = "openshift-config-managed"
dashboardFolder = "dashboards"
)

type ArgoCDMetricsReconciler struct {
Expand Down Expand Up @@ -182,11 +179,6 @@ func (r *ArgoCDMetricsReconciler) Reconcile(ctx context.Context, request reconci
if err != nil {
return reconcile.Result{}, err
}

err = r.reconcileOperatorMetricsServiceMonitor(reqLogger)
if err != nil {
return reconcile.Result{}, err
}
} else {
if exists {
namespace.Labels[monitoringLabel] = "false"
Expand Down Expand Up @@ -369,43 +361,6 @@ func (r *ArgoCDMetricsReconciler) deleteServiceMonitor(name string, namespace st

}

func (r *ArgoCDMetricsReconciler) reconcileOperatorMetricsServiceMonitor(reqLogger logr.Logger) error {

data, err := os.ReadFile(operatorPodNamespacePath)
if err != nil {
if os.IsNotExist(err) {
reqLogger.Info(fmt.Sprintf("Unable to retrieve the operator's running namespace via '%s': you should only see this message when running within unit tests, otherwise it is an error.", operatorPodNamespacePath))
return nil
}
reqLogger.Error(err, "Error retrieving operator's running namespace")
return err
}

operatorNS := string(data)
desiredMetricsServerName := operatorMetricsServiceName + "." + operatorNS + ".svc"

existingServiceMonitor := &monitoringv1.ServiceMonitor{}
err = r.Client.Get(context.TODO(), types.NamespacedName{Name: operatorMetricsMonitorName, Namespace: operatorNS}, existingServiceMonitor)

if err != nil {
if !errors.IsNotFound(err) {
reqLogger.Error(err, "Error querying for ServiceMonitor", "Namespace", operatorNS, "Name", operatorMetricsMonitorName)
return err
}

// no svc monitor found, nothing to do
return nil
}

currentServerName := existingServiceMonitor.Spec.Endpoints[0].TLSConfig.ServerName
if currentServerName == nil || *currentServerName != desiredMetricsServerName {
existingServiceMonitor.Spec.Endpoints[0].TLSConfig.ServerName = &desiredMetricsServerName
return r.Client.Update(context.TODO(), existingServiceMonitor)
}

return nil
}

func (r *ArgoCDMetricsReconciler) createPrometheusRuleIfAbsent(namespace string, argocd *argoapp.ArgoCD, reqLogger logr.Logger) error {
alertRule := newPrometheusRule(namespace)
existingAlertRule := &monitoringv1.PrometheusRule{}
Expand Down
Loading
Loading