diff --git a/helm/aws-load-balancer-controller/README.md b/helm/aws-load-balancer-controller/README.md index 775898e26..d850b7060 100644 --- a/helm/aws-load-balancer-controller/README.md +++ b/helm/aws-load-balancer-controller/README.md @@ -262,6 +262,7 @@ The default values set by the application itself can be confirmed [here](https:/ | `disableRestrictedSecurityGroupRules` | If disabled, controller will not specify port range restriction in the backend security group rules | `false` | | `objectSelector.matchExpressions` | Webhook configuration to select specific pods by specifying the expression to be matched | None | | `objectSelector.matchLabels` | Webhook configuration to select specific pods by specifying the key value label pair to be matched | None | +| `prometheusScrape.enabled` | If enabled, and `serviceMonitor.enabled` add the `prometheus.io` annotations to enable metrics scraping | `true` | | `serviceMonitor.enabled` | Specifies whether a service monitor should be created, requires the ServiceMonitor CRD to be installed | `false` | | `serviceMonitor.namespace` | Namespace in which to create the service monitor | None | | `serviceMonitor.additionalLabels` | Labels to add to the service monitor | `{}` | diff --git a/helm/aws-load-balancer-controller/templates/deployment.yaml b/helm/aws-load-balancer-controller/templates/deployment.yaml index 70fe8d5ca..c8b04099b 100644 --- a/helm/aws-load-balancer-controller/templates/deployment.yaml +++ b/helm/aws-load-balancer-controller/templates/deployment.yaml @@ -27,13 +27,12 @@ spec: {{- toYaml .Values.podLabels | nindent 8 }} {{- end }} annotations: - {{- if not .Values.serviceMonitor.enabled }} - prometheus.io/scrape: "true" - prometheus.io/port: "{{ (split ":" .Values.metricsBindAddr)._1 | default 8080 }}" - {{- end}} - {{- if .Values.podAnnotations }} - {{- toYaml .Values.podAnnotations | nindent 8 }} + {{- $promethusAnnotations := dict }} + {{- if and .Values.prometheusScrape.enabled (not .Values.serviceMonitor.enabled) }} + {{- $promethusAnnotations = dict "prometheus.io/scrape" "true" "prometheus.io/port" "8080"}} {{- end }} + {{- $podAnnotations := merge $promethusAnnotations .Values.podAnnotations }} + {{- toYaml $podAnnotations | default (dict) | nindent 8 }} spec: {{- with .Values.imagePullSecrets }} imagePullSecrets: diff --git a/helm/aws-load-balancer-controller/test.yaml b/helm/aws-load-balancer-controller/test.yaml index 584ca054b..a0057a52f 100644 --- a/helm/aws-load-balancer-controller/test.yaml +++ b/helm/aws-load-balancer-controller/test.yaml @@ -309,6 +309,12 @@ objectSelector: matchLabels: # key: value +prometheusScrape: + # Specifies whether the controller should be annotated for Prometheus scraping. + # Scraping annotations will not be added if serviceMonitor.enabled is set to true + # to prevent duplicate metrics. + enabled: true + serviceMonitor: # Specifies whether a service monitor should be created enabled: false diff --git a/helm/aws-load-balancer-controller/values.yaml b/helm/aws-load-balancer-controller/values.yaml index df9f360ae..1a1855e54 100644 --- a/helm/aws-load-balancer-controller/values.yaml +++ b/helm/aws-load-balancer-controller/values.yaml @@ -369,6 +369,12 @@ objectSelector: matchLabels: # key: value +prometheusScrape: + # Specifies whether the controller should be annotated for Prometheus scraping. + # Scraping annotations will not be added if serviceMonitor.enabled is set to true + # to prevent duplicate metrics. + enabled: true + serviceMonitor: # Specifies whether a service monitor should be created enabled: false