Skip to content

Commit c565d1d

Browse files
committed
Add Horizontal Pod Autoscaling (HPA) support to Wiz AC
By default this is disabled. Prerequisites: metrics-server installed on the cluster: https://github.com/kubernetes-sigs/metrics-server To enable HPA, set: wiz-admission-controller: hpa: enabled: true
1 parent a199827 commit c565d1d

File tree

6 files changed

+93
-3
lines changed

6 files changed

+93
-3
lines changed

wiz-admission-controller/Chart.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ type: application
77
# This is the chart version. This version number should be incremented each time you make changes
88
# to the chart and its templates, including the app version.
99
# Versions are expected to follow Semantic Versioning (https://semver.org/)
10-
version: 3.6.0
10+
version: 3.7.0
1111

1212
# This is the version number of the application being deployed. This version number should be
1313
# incremented each time you make changes to the application. Versions are not expected to

wiz-admission-controller/templates/_helpers.tpl

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@ If release name contains chart name it will be used as a full name.
4040
{{- end }}
4141
{{- end }}
4242

43+
{{- define "wiz-hpa.name" -}}
44+
{{- $name := "wiz-hpa" }}
45+
{{- default $name .Values.hpa.nameOverride | trunc 63 | trimSuffix "-" }}
46+
{{- end }}
47+
4348
{{/*
4449
Create chart name and version as used by the chart label.
4550
*/}}
@@ -101,6 +106,19 @@ app.kubernetes.io/name: {{ include "wiz-kubernetes-audit-log-collector.name" . }
101106
{{ include "wiz-kubernetes-audit-log-collector.selectorLabels" . }}
102107
{{- end }}
103108

109+
{{/*
110+
Wiz Horizontal Pod Autoscaler selector labels
111+
*/}}
112+
113+
{{- define "wiz-hpa.selectorLabels" -}}
114+
app.kubernetes.io/name: {{ include "wiz-hpa.name" . }}
115+
{{- end }}
116+
117+
{{- define "wiz-hpa.labels" -}}
118+
{{ include "wiz-admission-controller.labels" . }}
119+
{{ include "wiz-hpa.selectorLabels" . }}
120+
{{- end }}
121+
104122
{{/*
105123
106124
{{/*

wiz-admission-controller/templates/deploymentauditlogs.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ metadata:
55
name: {{ include "wiz-kubernetes-audit-log-collector.name" . }}
66
namespace: {{ .Release.Namespace | quote }}
77
labels:
8-
{{- include "wiz-kubernetes-audit-log-collector.labels" . | nindent 4 }}
8+
{{- include "wiz-hpa.labels" . | nindent 4 }}
99
spec:
1010
replicas: {{ .Values.kubernetesAuditLogsWebhook.replicaCount }}
1111
selector:

wiz-admission-controller/templates/deploymentenforcement.yaml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ metadata:
77
labels:
88
{{- include "wiz-admission-controller-enforcement.labels" . | nindent 4 }}
99
spec:
10+
{{- if not .Values.hpa.enabled }}
1011
replicas: {{ .Values.replicaCount }}
12+
{{- end }}
1113
selector:
1214
matchLabels:
1315
{{- include "wiz-admission-controller.selectorLabels" . | nindent 6 }}
@@ -209,9 +211,17 @@ spec:
209211
{{- if .Values.debugWebhook.enabled }}
210212
- name: WIZ_DEBUG_WEBHOOK_ENABLED
211213
value: "true"
212-
{{- end }}
214+
{{- end }}
213215
resources:
216+
{{- if .Values.hpa.enabled }}
217+
{{- if hasKey .Values.hpa "customResources" }}
218+
{{- toYaml .Values.hpa.customResources | nindent 12 }}
219+
{{- else }}
220+
{{- toYaml .Values.hpa.defaultResources | nindent 12 }}
221+
{{- end }}
222+
{{- else }}
214223
{{- toYaml .Values.resources | nindent 12 }}
224+
{{- end }}
215225
volumeMounts:
216226
- mountPath: /var/cache
217227
name: cache
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
{{- if .Values.hpa.enabled }}
2+
apiVersion: autoscaling/v2
3+
kind: HorizontalPodAutoscaler
4+
metadata:
5+
name: {{ include "wiz-hpa.name" . }}
6+
namespace: {{ .Release.Namespace }}
7+
labels:
8+
{{- include "wiz-hpa.labels" . | nindent 4 }}
9+
spec:
10+
scaleTargetRef:
11+
apiVersion: apps/v1
12+
kind: Deployment
13+
name: {{ include "wiz-admission-controller.fullname" . }}
14+
minReplicas: {{ .Values.hpa.minReplicas }}
15+
maxReplicas: {{ .Values.hpa.maxReplicas }}
16+
metrics:
17+
{{- if .Values.hpa.enableCPU }}
18+
- type: Resource
19+
resource:
20+
name: cpu
21+
target:
22+
type: Utilization
23+
averageUtilization: {{ .Values.hpa.targetCPUUtilizationPercentage }}
24+
{{- end }}
25+
{{- if .Values.hpa.enableMemory }}
26+
- type: Resource
27+
resource:
28+
name: memory
29+
target:
30+
type: Utilization
31+
averageUtilization: {{ .Values.hpa.targetMemoryUtilizationPercentage }}
32+
{{- end }}
33+
{{- if hasKey .Values.hpa "customMetrics" }}
34+
{{- toYaml .Values.hpa.customMetrics | nindent 4 }}
35+
{{- end }}
36+
{{- end }}

wiz-admission-controller/values.yaml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,32 @@ probes: # Probes config for the container
426426
timeoutSeconds: 30
427427
failureThreshold: 3
428428

429+
# Horizontal Pod Autoscaling support.
430+
hpa:
431+
enabled: false
432+
minReplicas: 2
433+
maxReplicas: 5
434+
enableCPU: true
435+
targetCPUUtilizationPercentage: 50
436+
enableMemory: false
437+
targetMemoryUtilizationPercentage: 50
438+
customMetrics: []
439+
440+
# When using HPA, Wiz Helm Charts process the requests and limits
441+
# for the Wiz Admission Controller deployment in the following order:
442+
# customResources -> defaultResources
443+
#
444+
# Populating the following `customResources` in your user-supplied values.yaml
445+
# allows you to customize and override the `defaultResources`.
446+
#
447+
# customResources: {}
448+
449+
defaultResources:
450+
requests:
451+
cpu: 500m
452+
memory: 300Mi
453+
454+
429455
# Global values to override chart values.
430456
global:
431457
nameOverride: "" # Override the release’s name.

0 commit comments

Comments
 (0)