Skip to content

Commit 689feed

Browse files
feat: vcluster - add templates for auto scaledown with Keda (#123)
1 parent 2bac9b4 commit 689feed

File tree

7 files changed

+103
-10
lines changed

7 files changed

+103
-10
lines changed

charts/cf-vcluster/Chart.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ apiVersion: v2
22
name: cf-vcluster
33
description: Umbrella chart over vCluster adjusted for Codefresh use cases - mainly in Crossplane compositions
44
type: application
5-
version: 0.28.0-3
5+
version: 0.28.0-4
66
appVersion: "0.28.0"
77
dependencies:
88
- name: vcluster

charts/cf-vcluster/README.md

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# cf-vcluster
22

3-
![Version: 0.28.0-3](https://img.shields.io/badge/Version-0.28.0--3-informational?style=flat-square) ![Type: application](https://img.shields.io/badge/Type-application-informational?style=flat-square) ![AppVersion: 0.28.0](https://img.shields.io/badge/AppVersion-0.28.0-informational?style=flat-square)
3+
![Version: 0.28.0-4](https://img.shields.io/badge/Version-0.28.0--4-informational?style=flat-square) ![Type: application](https://img.shields.io/badge/Type-application-informational?style=flat-square) ![AppVersion: 0.28.0](https://img.shields.io/badge/AppVersion-0.28.0-informational?style=flat-square)
44

55
Umbrella chart over vCluster adjusted for Codefresh use cases - mainly in Crossplane compositions
66

@@ -20,21 +20,26 @@ Umbrella chart over vCluster adjusted for Codefresh use cases - mainly in Crossp
2020

2121
| Key | Type | Default | Description |
2222
|-----|------|---------|-------------|
23+
| automaticScaleDown.enabled | bool | `false` | |
24+
| automaticScaleDown.httpScaler | object | `{"host":"keda-add-ons-http-external-scaler.keda","port":9090}` | Scaler address on vCluster host |
25+
| automaticScaleDown.initialCooldownPeriod | int | `120` | |
26+
| automaticScaleDown.interceptor | object | `{"host":"keda-add-ons-http-interceptor-proxy.keda","port":8443}` | Interceptor address on vCluster host |
27+
| automaticScaleDown.periodSeconds | int | `43200` | How many seconds of no requests to vcluster until it is scaled down to zero. Defaults to 12 hours (43200s) |
2328
| global.ingress.internal.annotations."nginx.ingress.kubernetes.io/backend-protocol" | string | `"HTTPS"` | |
2429
| global.ingress.internal.annotations."nginx.ingress.kubernetes.io/ssl-passthrough" | string | `"true"` | |
2530
| global.ingress.internal.annotations."nginx.ingress.kubernetes.io/ssl-redirect" | string | `"true"` | |
2631
| global.ingress.internal.backendServiceOverride | object | `{}` | Possibility to override backend service name for ingress. If not set default vcluster backend service will be used |
2732
| global.ingress.internal.enabled | bool | `false` | |
2833
| global.ingress.internal.host.domain | string | `"corp.local"` | |
29-
| global.ingress.internal.host.name | string | `"{{ .Release.Name }}"` | |
34+
| global.ingress.internal.host.name | string | `"{{ .Release.Namespace }}-vcluster"` | |
3035
| global.ingress.internal.ingressClassName | string | `"nginx-internal"` | |
3136
| global.ingress.public.annotations."nginx.ingress.kubernetes.io/backend-protocol" | string | `"HTTPS"` | |
3237
| global.ingress.public.annotations."nginx.ingress.kubernetes.io/ssl-passthrough" | string | `"true"` | |
3338
| global.ingress.public.annotations."nginx.ingress.kubernetes.io/ssl-redirect" | string | `"true"` | |
3439
| global.ingress.public.backendServiceOverride | object | `{}` | Possibility to override backend service name for ingress. If not set default vcluster backend service will be used |
3540
| global.ingress.public.enabled | bool | `false` | |
3641
| global.ingress.public.host.domain | string | `"example.com"` | |
37-
| global.ingress.public.host.name | string | `"{{ .Release.Name }}"` | |
42+
| global.ingress.public.host.name | string | `"{{ .Release.Namespace }}-vcluster"` | |
3843
| global.ingress.public.ingressClassName | string | `"nginx-public"` | |
3944
| vcluster.controlPlane.distro.k8s.apiServer.extraArgs[0] | string | `"--oidc-issuer-url=https://dexidp.shared-services.cf-infra.com"` | |
4045
| vcluster.controlPlane.distro.k8s.apiServer.extraArgs[1] | string | `"--oidc-client-id=vcluster-login"` | |

charts/cf-vcluster/templates/ingresses.tpl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ spec:
1818
- path: /
1919
pathType: {{ $.Values.vcluster.controlPlane.ingress.pathType }}
2020
backend:
21-
{{- if $ingress.backendServiceOverride}}
21+
{{- if $.Values.automaticScaleDown.enabled}}
2222
service:
23-
name: {{ $ingress.backendServiceOverride.name }}
23+
name: {{ $.Release.Name }}-keda-http-interceptor
2424
port:
25-
number: {{ $ingress.backendServiceOverride.port }}
25+
number: {{ $.Values.automaticScaleDown.interceptor.port }}
2626
{{- else }}
2727
service:
2828
name: {{ $.Release.Name }}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
{{- if .Values.automaticScaleDown.enabled }}
2+
{{ $vclusterContext := (index .Subcharts "vcluster")}}
3+
apiVersion: http.keda.sh/v1alpha1
4+
kind: HTTPScaledObject
5+
metadata:
6+
name: {{ .Release.Name }}
7+
annotations:
8+
# Workaround for idleReplicaCount - https://github.com/kedacore/http-add-on/pull/594
9+
httpscaledobject.keda.sh/skip-scaledobject-creation: "true"
10+
spec:
11+
hosts:
12+
{{- if .Values.global.ingress.internal.enabled }}
13+
- {{ tpl (printf "%s.%s" .Values.global.ingress.internal.host.name .Values.global.ingress.internal.host.domain) . }}
14+
{{- else if .Values.global.ingress.public.enabled }}
15+
- {{ tpl (printf "%s.%s" .Values.global.ingress.public.host.name .Values.global.ingress.public.host.domain) . }}
16+
{{- else }}
17+
- {{ fail "Cannot enable autoScaledown if no ingress is enabled" }}
18+
{{- end }}
19+
scaleTargetRef:
20+
name: {{ .Release.Name }}
21+
kind: {{ include "vcluster.kind" $vclusterContext }}
22+
apiVersion: apps/v1
23+
service: {{ .Release.Name }}
24+
port: 443
25+
replicas:
26+
min: {{ $vclusterContext.Values.controlPlane.statefulSet.highAvailability.replicas }}
27+
max: {{ $vclusterContext.Values.controlPlane.statefulSet.highAvailability.replicas }}
28+
scaledownPeriod: {{ .Values.automaticScaleDown.periodSeconds }}
29+
scalingMetric:
30+
requestRate:
31+
granularity: 1s
32+
targetValue: 1
33+
window: 1m
34+
---
35+
# Workaround for idleReplicaCount - https://github.com/kedacore/http-add-on/pull/594
36+
apiVersion: keda.sh/v1alpha1
37+
kind: ScaledObject
38+
metadata:
39+
name: {{ .Release.Name }}
40+
spec:
41+
advanced:
42+
restoreToOriginalReplicaCount: true
43+
scalingModifiers: {}
44+
initialCooldownPeriod: {{ .Values.automaticScaleDown.initialCooldownPeriod }}
45+
cooldownPeriod: {{ .Values.automaticScaleDown.periodSeconds }}
46+
maxReplicaCount: {{ $vclusterContext.Values.controlPlane.statefulSet.highAvailability.replicas }}
47+
minReplicaCount: {{ $vclusterContext.Values.controlPlane.statefulSet.highAvailability.replicas }}
48+
idleReplicaCount: 0
49+
pollingInterval: 15
50+
scaleTargetRef:
51+
apiVersion: apps/v1
52+
kind: {{ include "vcluster.kind" $vclusterContext }}
53+
name: {{ .Release.Name }}
54+
triggers:
55+
- metadata:
56+
httpScaledObject: {{ .Release.Name }}
57+
scalerAddress: {{ printf "%s:%d" .Values.automaticScaleDown.httpScaler.host (int64 .Values.automaticScaleDown.httpScaler.port) }}
58+
type: external-push
59+
{{- end }}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{{- if .Values.automaticScaleDown.enabled }}
2+
apiVersion: v1
3+
kind: Service
4+
metadata:
5+
name: {{ .Release.Name }}-keda-http-interceptor
6+
spec:
7+
type: ExternalName
8+
externalName: {{ .Values.automaticScaleDown.interceptor.host}}
9+
{{- end }}

charts/cf-vcluster/values.test.rnd-sandbox.yaml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,8 @@ global:
55
enabled: true
66
className: nginx-internal
77
host:
8-
domain: rnd-sandbox.cf-infra.com
8+
domain: vclusters.rnd-sandbox.cf-infra.com
9+
10+
automaticScaleDown:
11+
enabled: true
12+
periodSeconds: 60

charts/cf-vcluster/values.yaml

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ global:
1313
# name: "interceptor-service"
1414
# port: 80
1515
host:
16-
name: "{{ .Release.Name }}"
16+
name: "{{ .Release.Namespace }}-vcluster"
1717
domain: corp.local
1818
public:
1919
enabled: false
@@ -28,7 +28,7 @@ global:
2828
nginx.ingress.kubernetes.io/ssl-passthrough: "true"
2929
nginx.ingress.kubernetes.io/ssl-redirect: "true"
3030
host:
31-
name: "{{ .Release.Name }}"
31+
name: "{{ .Release.Namespace }}-vcluster"
3232
domain: example.com
3333

3434
vcluster:
@@ -138,3 +138,19 @@ vcluster:
138138
rbac:
139139
clusterRole:
140140
enabled: true
141+
142+
# Automatic scaledown with Keda
143+
automaticScaleDown:
144+
enabled: false
145+
# How many seconds to wait until scaler is active from creation (prevent release failure)
146+
initialCooldownPeriod: 120
147+
# -- How many seconds of no requests to vcluster until it is scaled down to zero. Defaults to 12 hours (43200s)
148+
periodSeconds: 43200
149+
# -- Interceptor address on vCluster host
150+
interceptor:
151+
host: "keda-add-ons-http-interceptor-proxy.keda"
152+
port: 8443
153+
# -- Scaler address on vCluster host
154+
httpScaler:
155+
host: keda-add-ons-http-external-scaler.keda
156+
port: 9090

0 commit comments

Comments
 (0)