feat: add support for the keda-http-add-on

Externally, it is treated the same as any other scaling trigger, but requires that the chart be installed in order for it to be supported.
This commit is contained in:
Jose Diaz-Gonzalez committed 2024-11-13 03:29:26 -05:00
1 parent 1751bf30ba
commit b98863b6a7
7 files changed
+227 -16

No files matched your search

@@ -1,5 +1,11 @@
{{- $processName := "PROCESS_NAME" }}
{{- $config := index .Values.processes "PROCESS_NAME" }}
{{- $routeToKeda := false }}
{{- if and (eq $processName "web") (and $config.autoscaling (and $config.autoscaling.enabled (eq $config.autoscaling.type "keda"))) }}
{{- if and (.Capabilities.APIVersions.Has "http.keda.sh/v1alpha1") $config.autoscaling.http_trigger.type }}
{{- $routeToKeda = true }}
{{- end }}
{{- end }}
{{- if and $config.web.domains (eq $.Values.global.network.ingress_class "nginx") }}
{{- range $pdx, $domain := $config.web.domains }}
---
@@ -36,11 +42,19 @@ spec:
paths:
{{- if $config.web.port_maps }}
- backend:
{{- if $routeToKeda}}
service:
name: kip-{{ $.Values.global.app_name}}-{{ $processName }}
port:
number: 8080
pathType: Prefix
{{- else }}
service:
name: {{ $.Values.global.app_name }}-{{ $processName }}
port:
name: {{ include "primary.port" $config.web.port_maps }}
pathType: ImplementationSpecific
{{- end }}
path: /
{{- end }}
{{- end }}
@@ -0,0 +1,55 @@
{{- $processName := "PROCESS_NAME" }}
{{- $config := index .Values.processes "PROCESS_NAME" }}
{{- if and (eq $processName "web") (and $config.autoscaling (and $config.autoscaling.enabled (eq $config.autoscaling.type "keda"))) }}
{{- if .Capabilities.APIVersions.Has "http.keda.sh/v1alpha1" -}}
{{- if $config.autoscaling.http_trigger.type }}
{{- $mappings := dict }}
{{- range $pdx, $port_map := $config.web.port_maps }}
{{- $mappings := set $mappings $port_map.name "true" }}
{{- end }}
---
kind: HTTPScaledObject
apiVersion: http.keda.sh/v1alpha1
metadata:
annotations:
app.kubernetes.io/version: {{ $.Values.global.deployment_id | quote }}
dokku.com/managed: "true"
httpscaledobject.keda.sh/skip-scaledobject-creation: "true"
{{ include "print.annotations" (dict "config" $.Values.global "key" "keda_http_scaled_object") | indent 4 }}
{{ include "print.annotations" (dict "config" $config "key" "keda_http_scaled_object") | indent 4 }}
labels:
app.kubernetes.io/instance: {{ $.Values.global.app_name }}-{{ $processName }}
app.kubernetes.io/name: {{ $processName }}
app.kubernetes.io/part-of: {{ $.Values.global.app_name }}
{{ include "print.labels" (dict "config" $.Values.global "key" "keda_http_scaled_object") | indent 4 }}
{{ include "print.labels" (dict "config" $config "key" "keda_http_scaled_object") | indent 4 }}
name: {{ $.Values.global.app_name}}-{{ $processName }}
namespace: {{ $.Values.global.namespace }}
spec:
hosts:
{{- range $pdx, $domain := $config.web.domains }}
- {{ $domain.name | quote }}
{{- end }}
scaleTargetRef:
name: {{ $.Values.global.app_name }}-{{ $processName }}
kind: Deployment
apiVersion: apps/v1
service: {{ $.Values.global.app_name }}-{{ $processName }}
port: {{ $.Values.global.network.primary_service_port }}
replicas:
min: {{ $config.autoscaling.min_replicas }}
max: {{ $config.autoscaling.max_replicas }}
scaledownPeriod: {{ get $config.autoscaling.http_trigger.metadata "scaledown_period_seconds" }}
scalingMetric:
{{- if eq (get $config.autoscaling.http_trigger.metadata "scale_by") "request_rate" }}
requestRate:
granularity: {{ get $config.autoscaling.http_trigger.metadata "request_rate_granularity_seconds" }}s
targetValue: {{ get $config.autoscaling.http_trigger.metadata "request_rate_target_value" }}
window: {{ get $config.autoscaling.http_trigger.metadata "request_rate_window_seconds" }}s
{{- else }}
concurrency:
targetValue: {{ get $config.autoscaling.http_trigger.metadata "concurrency_target_value" }}
{{- end }}
{{- end }}
{{- end }}
{{- end }}
@@ -0,0 +1,26 @@
{{- $processName := "PROCESS_NAME" }}
{{- $config := index .Values.processes "PROCESS_NAME" }}
{{- if and (eq $processName "web") (and $config.autoscaling (and $config.autoscaling.enabled (eq $config.autoscaling.type "keda"))) }}
{{- if .Capabilities.APIVersions.Has "http.keda.sh/v1alpha1" -}}
---
kind: Service
apiVersion: v1
metadata:
annotations:
app.kubernetes.io/version: {{ $.Values.global.deployment_id | quote }}
dokku.com/managed: "true"
{{ include "print.annotations" (dict "config" $.Values.global "key" "keda_interceptor_proxy_service") | indent 4 }}
{{ include "print.annotations" (dict "config" $config "key" "keda_interceptor_proxy_service") | indent 4 }}
labels:
app.kubernetes.io/instance: {{ $.Values.global.app_name }}-{{ $processName }}
app.kubernetes.io/name: {{ $processName }}
app.kubernetes.io/part-of: {{ $.Values.global.app_name }}
{{ include "print.labels" (dict "config" $.Values.global "key" "keda_interceptor_proxy_service") | indent 4 }}
{{ include "print.labels" (dict "config" $config "key" "keda_interceptor_proxy_service") | indent 4 }}
name: kip-{{ $.Values.global.app_name}}-{{ $processName }}
namespace: {{ $.Values.global.namespace }}
spec:
type: ExternalName
externalName: keda-add-ons-http-interceptor-proxy.keda.svc.cluster.local
{{- end }}
{{- end }}