diff --git a/README.md b/README.md index 6528ea3..4b75115 100644 --- a/README.md +++ b/README.md @@ -305,6 +305,7 @@ Periodic probe of container liveness. Container will be restarted if the probe f | ------------------------ | -------------------------------------------------------------------------------------------- | --------------- | | serviceMonitor.enabled | Enable serviceMonitor | `false` | | serviceMonitor.additionalLabels | Labels for serviceMonitor | `{}` | +| serviceMonitor.name | ServiceMonitor name | `-svc-monitor` | | serviceMonitor.annotations | Annotations for serviceMonitor | `{}` | | serviceMonitor.jobLabel | Job Label used for application selector | `k8s-app` | | serviceMonitor.endpoints | Array of endpoints to be scraped by prometheus | - interval: 5s
  path: /actuator/prometheus
  port: http | @@ -411,12 +412,12 @@ Periodic probe of container liveness. Container will be restarted if the probe f | keda.name | ScaledObject name | `-scaler` | | keda.scaleTargetRef | `{apiVersion, kind, name}` of the scaled workload | `` | | keda.minReplicaCount / keda.maxReplicaCount | Replica bounds | `` | -| keda.pollingInterval / keda.cooldownPeriod / keda.advanced | Passed through | `` | +| keda.pollingInterval / keda.cooldownPeriod / keda.fallback / keda.advanced | Passed through | `` | | keda.triggerAuthentication.enabled | Render the TriggerAuthentication and reference it from every trigger | `true` | | keda.triggerAuthentication.name | TriggerAuthentication name | `-aws-credentials` | | keda.triggerAuthentication.podIdentityProvider | `spec.podIdentity.provider` | `aws` | | keda.triggerAuthentication.spec | Full spec, replaces `podIdentity` | `` | -| keda.triggers | Triggers rendered verbatim: `[{type, metadata, authenticationRef}]`; metadata values may use templates | `[]` | +| keda.triggers | Triggers rendered verbatim: `[{type, name, metricType, useCachedMetrics, metadata, authenticationRef}]`; metadata values may use templates; `authenticationRef: false` omits the reference for that trigger | `[]` | ### ExternalSecret Parameters diff --git a/charts/application/templates/keda.yaml b/charts/application/templates/keda.yaml index 48a11df..162418c 100644 --- a/charts/application/templates/keda.yaml +++ b/charts/application/templates/keda.yaml @@ -57,6 +57,10 @@ spec: {{- end }} {{- with .Values.keda.cooldownPeriod }} cooldownPeriod: {{ . }} + {{- end }} + {{- with .Values.keda.fallback }} + fallback: +{{ toYaml . | indent 4 }} {{- end }} {{- with .Values.keda.advanced }} advanced: @@ -65,9 +69,20 @@ spec: triggers: {{- range .Values.keda.triggers }} - type: {{ .type }} - {{- if or (not (hasKey $auth "enabled")) $auth.enabled }} + {{- with .name }} + name: {{ . }} + {{- end }} + {{- with .metricType }} + metricType: {{ . }} + {{- end }} + {{- if not (kindIs "invalid" .useCachedMetrics) }} + useCachedMetrics: {{ .useCachedMetrics }} + {{- end }} + {{- /* authenticationRef: false opts a trigger out (e.g. prometheus, which has no AWS identity to assume). */}} + {{- $ref := .authenticationRef }} + {{- if and (or (not (hasKey $auth "enabled")) $auth.enabled) (not (and (kindIs "bool" $ref) (not $ref))) }} authenticationRef: - name: {{ .authenticationRef | default $authName }} + name: {{ if kindIs "string" $ref }}{{ $ref }}{{ else }}{{ $authName }}{{ end }} {{- end }} metadata: {{- range $k, $v := .metadata }} diff --git a/charts/application/templates/servicemonitor.yaml b/charts/application/templates/servicemonitor.yaml index 533bd79..b989844 100644 --- a/charts/application/templates/servicemonitor.yaml +++ b/charts/application/templates/servicemonitor.yaml @@ -9,7 +9,7 @@ metadata: annotations: {{ toYaml .Values.serviceMonitor.annotations | indent 4 }} {{- end }} - name: {{ template "application.name" . }}-svc-monitor + name: {{ .Values.serviceMonitor.name | default (printf "%s-svc-monitor" (include "application.name" .)) }} namespace: {{ template "application.namespace" . }} spec: selector: diff --git a/charts/application/tests/keda_test.yaml b/charts/application/tests/keda_test.yaml index f7dcbd5..1662983 100644 --- a/charts/application/tests/keda_test.yaml +++ b/charts/application/tests/keda_test.yaml @@ -52,3 +52,74 @@ tests: count: 1 - notExists: path: spec.triggers[0].authenticationRef + + - it: trigger name, metricType and useCachedMetrics are emitted when set, and fallback is passed through + set: + keda.enabled: true + keda.fallback: + failureThreshold: 3 + replicas: 2 + keda.triggers: + - type: aws-sqs-queue + name: sqs_backlog + metricType: AverageValue + useCachedMetrics: true + metadata: + queueURL: https://sqs.us-east-1.amazonaws.com/123456789012/my-queue + asserts: + - equal: + path: spec.triggers[0].name + value: sqs_backlog + documentSelector: + path: kind + value: ScaledObject + - equal: + path: spec.triggers[0].metricType + value: AverageValue + documentSelector: + path: kind + value: ScaledObject + - equal: + path: spec.triggers[0].useCachedMetrics + value: true + documentSelector: + path: kind + value: ScaledObject + - equal: + path: spec.fallback.replicas + value: 2 + documentSelector: + path: kind + value: ScaledObject + + - it: a trigger with authenticationRef false has no authenticationRef while its siblings keep theirs + set: + keda.enabled: true + keda.triggers: + - type: aws-sqs-queue + metadata: + queueURL: https://sqs.us-east-1.amazonaws.com/123456789012/my-queue + - type: prometheus + authenticationRef: false + metadata: + serverAddress: http://prometheus.monitoring.svc:9090 + query: vector(1) + threshold: "1.5" + asserts: + - equal: + path: spec.triggers[0].authenticationRef.name + value: application-aws-credentials + documentSelector: + path: kind + value: ScaledObject + - notExists: + path: spec.triggers[1].authenticationRef + documentSelector: + path: kind + value: ScaledObject + - equal: + path: spec.triggers[1].metadata.threshold + value: "1.5" + documentSelector: + path: kind + value: ScaledObject diff --git a/charts/application/tests/servicemonitor_test.yaml b/charts/application/tests/servicemonitor_test.yaml new file mode 100644 index 0000000..85befec --- /dev/null +++ b/charts/application/tests/servicemonitor_test.yaml @@ -0,0 +1,34 @@ +suite: servicemonitor +templates: + - servicemonitor.yaml +tests: + - it: enabled false renders nothing + asserts: + - hasDocuments: + count: 0 + + - it: name defaults to applicationName-svc-monitor + set: + serviceMonitor.enabled: true + serviceMonitor.endpoints: + - port: http + path: /metrics + interval: 30s + asserts: + - equal: + path: metadata.name + value: application-svc-monitor + - equal: + path: spec.endpoints[0].port + value: http + + - it: serviceMonitor.name overrides the default + set: + serviceMonitor.enabled: true + serviceMonitor.name: executor + serviceMonitor.endpoints: + - port: http + asserts: + - equal: + path: metadata.name + value: executor diff --git a/charts/application/values.yaml b/charts/application/values.yaml index 2982094..1e1a1ab 100644 --- a/charts/application/values.yaml +++ b/charts/application/values.yaml @@ -640,6 +640,7 @@ pdb: ########################################################## serviceMonitor: enabled: false + # name: "" # defaults to -svc-monitor # Value of the `release` label; the Prometheus operator only selects matching ServiceMonitors. release: prometheus @@ -779,6 +780,7 @@ keda: maxReplicaCount: null pollingInterval: null cooldownPeriod: null + fallback: {} # e.g. {failureThreshold: 3, replicas: 2} advanced: {} triggerAuthentication: enabled: true @@ -786,9 +788,14 @@ keda: podIdentityProvider: aws # spec: {} # full TriggerAuthentication spec, replaces podIdentity # Rendered verbatim; metadata values may use templates. authenticationRef defaults - # to the TriggerAuthentication above. + # to the TriggerAuthentication above; `authenticationRef: false` omits it for a trigger. + # name / metricType / useCachedMetrics are emitted when set (scalingModifiers formulas + # reference triggers by name). triggers: [] # - type: aws-sqs-queue + # name: sqs_backlog + # metricType: AverageValue + # useCachedMetrics: true # metadata: # queueURL: https://sqs.us-east-1.amazonaws.com/123456789012/my-queue # queueLength: "100"