From 817652a449634fa8b82be3d46f2719c576f429b2 Mon Sep 17 00:00:00 2001 From: FuyuanChu <86345114+FuyuanChu@users.noreply.github.com> Date: Thu, 9 Dec 2021 22:56:32 +0800 Subject: [PATCH] feat(argocd-applicationset): Add resources metrics-service and servicemonitor. (#1041) * [argocd-applicationset]: Add metrics-service and servicemonitor to applicationset. Signed-off-by: fuyuan.chu * [argocd-applicationset]: Add ci values for servicemonitor. Signed-off-by: fuyuan.chu * format indent Signed-off-by: fuyuan.chu * update helm docs Signed-off-by: fuyuan.chu * update ci values Signed-off-by: fuyuan.chu * update ci values Signed-off-by: fuyuan.chu * chore: Use consistent indents and file ending Signed-off-by: Marco Kilchhofer * Also disable mounts of ArgoCD during metrics test Signed-off-by: Marco Kilchhofer Co-authored-by: Marco Kilchhofer --- charts/argocd-applicationset/Chart.yaml | 5 +-- charts/argocd-applicationset/README.md | 11 ++++++ .../ci/servicemonitor-values.yaml | 7 ++++ .../templates/deployment.yaml | 3 ++ .../templates/metrics-service.yaml | 25 ++++++++++++ .../templates/servicemonitor.yaml | 38 +++++++++++++++++++ charts/argocd-applicationset/values.yaml | 29 ++++++++++++++ 7 files changed, 115 insertions(+), 3 deletions(-) create mode 100644 charts/argocd-applicationset/ci/servicemonitor-values.yaml create mode 100644 charts/argocd-applicationset/templates/metrics-service.yaml create mode 100644 charts/argocd-applicationset/templates/servicemonitor.yaml diff --git a/charts/argocd-applicationset/Chart.yaml b/charts/argocd-applicationset/Chart.yaml index 1c088119..5185d857 100644 --- a/charts/argocd-applicationset/Chart.yaml +++ b/charts/argocd-applicationset/Chart.yaml @@ -2,7 +2,7 @@ apiVersion: v2 name: argocd-applicationset description: A Helm chart for installing ArgoCD ApplicationSet type: application -version: 1.6.0 +version: 1.7.0 appVersion: "v0.2.0" home: https://github.com/argoproj/argo-helm icon: https://argocd-applicationset.readthedocs.io/en/stable/assets/logo.png @@ -14,5 +14,4 @@ maintainers: - name: maruina annotations: artifacthub.io/changes: | - - "[Added]: Install the chart into a kind cluster during the chart testing process" - - "[Changed]: Parameter 'args.namespace' now defaults to the namespace where you install the chart to" + - "[Added]: Add resources metrics-service and servicemonitor, not enabled by default." diff --git a/charts/argocd-applicationset/README.md b/charts/argocd-applicationset/README.md index a89d9f6f..53fd218f 100644 --- a/charts/argocd-applicationset/README.md +++ b/charts/argocd-applicationset/README.md @@ -73,6 +73,17 @@ kubectl apply -k https://github.com/argoproj-labs/applicationset.git/manifests/c | image.repository | string | `"quay.io/argoproj/argocd-applicationset"` | The image repository | | image.tag | string | `""` | Overrides the image tag whose default is the chart appVersion. | | imagePullSecrets | list | `[]` | If defined, uses a Secret to pull an image from a private Docker registry or repository. | +| metrics.enabled | bool | `false` | Deploy metrics service | +| metrics.service.annotations | object | `{}` | Metrics service annotations | +| metrics.service.labels | object | `{}` | Metrics service labels | +| metrics.service.servicePort | int | `8085` | Metrics service port | +| metrics.serviceMonitor.additionalLabels | object | `{}` | Prometheus ServiceMonitor labels | +| metrics.serviceMonitor.enabled | bool | `false` | Enable a prometheus ServiceMonitor | +| metrics.serviceMonitor.interval | string | `"30s"` | Prometheus ServiceMonitor interval | +| metrics.serviceMonitor.metricRelabelings | list | `[]` | Prometheus [MetricRelabelConfigs] to apply to samples before ingestion | +| metrics.serviceMonitor.namespace | string | `""` | Prometheus ServiceMonitor namespace | +| metrics.serviceMonitor.relabelings | list | `[]` | Prometheus [RelabelConfigs] to apply to samples before scraping | +| metrics.serviceMonitor.selector | object | `{}` | Prometheus ServiceMonitor selector | | mountGPGKeyringVolume | bool | `true` | Mount an emptyDir volume for `gpg-keyring` | | mountGPGKeysVolume | bool | `false` | Mount the `argocd-gpg-keys-cm` volume | | mountSSHKnownHostsVolume | bool | `true` | Mount the `argocd-ssh-known-hosts-cm` volume | diff --git a/charts/argocd-applicationset/ci/servicemonitor-values.yaml b/charts/argocd-applicationset/ci/servicemonitor-values.yaml new file mode 100644 index 00000000..61bc0901 --- /dev/null +++ b/charts/argocd-applicationset/ci/servicemonitor-values.yaml @@ -0,0 +1,7 @@ +metrics: + enabled: true + +# Disable mounts of ArgoCD related ConfigMaps as ArgoCD isn't installed during chart testing +mountSSHKnownHostsVolume: false +mountTLSCertsVolume: false +mountGPGKeysVolume: false diff --git a/charts/argocd-applicationset/templates/deployment.yaml b/charts/argocd-applicationset/templates/deployment.yaml index 281882b6..b40c94d2 100644 --- a/charts/argocd-applicationset/templates/deployment.yaml +++ b/charts/argocd-applicationset/templates/deployment.yaml @@ -53,6 +53,9 @@ spec: - name: http containerPort: {{ (split ":" .Values.args.probeBindAddr)._1 }} protocol: TCP + - name: metrics + containerPort: {{ (split ":" .Values.args.metricsAddr)._1 }} + protocol: TCP resources: {{- toYaml .Values.resources | nindent 12 }} volumeMounts: diff --git a/charts/argocd-applicationset/templates/metrics-service.yaml b/charts/argocd-applicationset/templates/metrics-service.yaml new file mode 100644 index 00000000..b929dfc1 --- /dev/null +++ b/charts/argocd-applicationset/templates/metrics-service.yaml @@ -0,0 +1,25 @@ +{{- if .Values.metrics.enabled }} +apiVersion: v1 +kind: Service +metadata: + {{- if .Values.metrics.service.annotations }} + annotations: + {{- range $key, $value := .Values.metrics.service.annotations }} + {{ $key }}: {{ $value | quote }} + {{- end }} + {{- end }} + labels: + {{- include "argo-applicationset.labels" . | nindent 4 }} + {{- with .Values.metrics.service.labels }} + {{- toYaml . | nindent 4 }} + {{- end }} + name: {{ template "argo-applicationset.fullname" . }}-metrics +spec: + ports: + - name: metrics + protocol: TCP + port: {{ .Values.metrics.service.servicePort }} + targetPort: metrics + selector: + {{- include "argo-applicationset.selectorLabels" . | nindent 4 }} +{{- end }} diff --git a/charts/argocd-applicationset/templates/servicemonitor.yaml b/charts/argocd-applicationset/templates/servicemonitor.yaml new file mode 100644 index 00000000..fe3a614c --- /dev/null +++ b/charts/argocd-applicationset/templates/servicemonitor.yaml @@ -0,0 +1,38 @@ +{{- if and .Values.metrics.enabled .Values.metrics.serviceMonitor.enabled }} +apiVersion: monitoring.coreos.com/v1 +kind: ServiceMonitor +metadata: + name: {{ template "argo-applicationset.fullname" . }} + {{- if .Values.metrics.serviceMonitor.namespace }} + namespace: {{ .Values.metrics.serviceMonitor.namespace }} + {{- end }} + labels: + {{- include "argo-applicationset.labels" . | nindent 4 }} + {{- with .Values.metrics.serviceMonitor.selector }} + {{- toYaml . | nindent 4 }} + {{- end }} + {{- with .Values.metrics.serviceMonitor.additionalLabels }} + {{- toYaml . | nindent 4 }} + {{- end }} +spec: + endpoints: + - port: metrics + {{- with .Values.metrics.serviceMonitor.interval }} + interval: {{ . }} + {{- end }} + path: /metrics + {{- with .Values.metrics.serviceMonitor.relabelings }} + relabelings: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.metrics.serviceMonitor.metricRelabelings }} + metricRelabelings: + {{- toYaml . | nindent 8 }} + {{- end }} + namespaceSelector: + matchNames: + - {{ .Release.Namespace }} + selector: + matchLabels: + {{- include "argo-applicationset.selectorLabels" . | nindent 6 }} +{{- end }} diff --git a/charts/argocd-applicationset/values.yaml b/charts/argocd-applicationset/values.yaml index b65716a9..c493e28a 100644 --- a/charts/argocd-applicationset/values.yaml +++ b/charts/argocd-applicationset/values.yaml @@ -31,6 +31,35 @@ args: # -- Enable dry run mode dryRun: false + ## Metrics service configuration +metrics: + # -- Deploy metrics service + enabled: false + service: + # -- Metrics service annotations + annotations: {} + # -- Metrics service labels + labels: {} + # -- Metrics service port + servicePort: 8085 + serviceMonitor: + # -- Enable a prometheus ServiceMonitor + enabled: false + # -- Prometheus ServiceMonitor interval + interval: 30s + # -- Prometheus [RelabelConfigs] to apply to samples before scraping + relabelings: [] + # -- Prometheus [MetricRelabelConfigs] to apply to samples before ingestion + metricRelabelings: [] + # -- Prometheus ServiceMonitor selector + selector: {} + # prometheus: kube-prometheus + + # -- Prometheus ServiceMonitor namespace + namespace: "" # monitoring + # -- Prometheus ServiceMonitor labels + additionalLabels: {} + # -- If defined, uses a Secret to pull an image from a private Docker registry or repository. imagePullSecrets: [] # -- Provide a name in place of `argocd-applicationset`