Skip to content

Commit 968f584

Browse files
committed
Added audit log collector to the mix
1 parent fbc2390 commit 968f584

File tree

4 files changed

+90
-28
lines changed

4 files changed

+90
-28
lines changed

wiz-admission-controller/templates/_helpers.tpl

Lines changed: 42 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,14 @@ 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 "-" }}
43+
{{- define "wiz-hpa-enforcer.name" -}}
44+
{{- $name := "wiz-hpa-enforcer" }}
45+
{{- default $name .Values.hpa.enforcerNameOverride | trunc 63 | trimSuffix "-" }}
46+
{{- end }}
47+
48+
{{- define "wiz-hpa-audit-logs.name" -}}
49+
{{- $name := "wiz-hpa-audit-logs" }}
50+
{{- default $name .Values.hpa.auditLogsNameOverride | trunc 63 | trimSuffix "-" }}
4651
{{- end }}
4752

4853
{{/*
@@ -110,11 +115,17 @@ app.kubernetes.io/name: {{ include "wiz-kubernetes-audit-log-collector.name" . }
110115
Wiz Horizontal Pod Autoscaler labels
111116
*/}}
112117

113-
{{- define "wiz-hpa.labels" -}}
118+
{{- define "wiz-hpa-enforcer.labels" -}}
119+
{{ include "wiz-admission-controller.labels" . }}
120+
app.kubernetes.io/name: {{ include "wiz-hpa-enforcer.name" . }}
121+
{{- end }}
122+
123+
{{- define "wiz-hpa-audit-logs.labels" -}}
114124
{{ include "wiz-admission-controller.labels" . }}
115-
app.kubernetes.io/name: {{ include "wiz-hpa.name" . }}
125+
app.kubernetes.io/name: {{ include "wiz-hpa-audit-logs.name" . }}
116126
{{- end }}
117127

128+
118129
{{/*
119130
120131
{{/*
@@ -203,3 +214,29 @@ Use for debug purpose only.
203214
{{- define "helpers.var_dump" -}}
204215
{{- . | mustToPrettyJson | printf "\nThe JSON output of the dumped var is: \n%s" | fail }}
205216
{{- end -}}
217+
218+
{{- define "wiz-admission-controller.resources" -}}
219+
{{- if not .Values.hpa.enabled }}
220+
{{- if hasKey .Values "resources" }}
221+
{{- toYaml .Values.resources }}
222+
{{- else -}}
223+
{}
224+
{{- end -}}
225+
{{- else }}
226+
{{- if hasKey .Values "resources" }}
227+
{{- toYaml .Values.resources }}
228+
{{- else -}}
229+
requests:
230+
cpu: 500m
231+
memory: 300Mi
232+
{{- end -}}
233+
{{- end -}}
234+
{{- end -}}
235+
236+
{{- define "wiz-admission-controller.isEnforcerEnabled" -}}
237+
{{- if or .Values.opaWebhook.enabled .Values.imageIntegrityWebhook.enabled .Values.debugWebhook.enabled }}
238+
true
239+
{{- else }}
240+
false
241+
{{- end }}
242+
{{- end }}

wiz-admission-controller/templates/deploymentauditlogs.yaml

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ metadata:
77
labels:
88
{{- include "wiz-kubernetes-audit-log-collector.labels" . | nindent 4 }}
99
spec:
10+
{{- if not .Values.hpa.enabled }}
1011
replicas: {{ .Values.kubernetesAuditLogsWebhook.replicaCount }}
12+
{{- end }}
1113
selector:
1214
matchLabels:
1315
{{- include "wiz-admission-controller.selectorLabels" . | nindent 6 }}
@@ -184,11 +186,7 @@ spec:
184186
value: "true"
185187
{{- end }}
186188
resources:
187-
{{- if hasKey .Values "resources" }}
188-
{{- toYaml .Values.resources | nindent 12 }}
189-
{{- else }}
190-
{}
191-
{{- end }}
189+
{{- include "wiz-admission-controller.resources" . | nindent 12 }}
192190
volumeMounts:
193191
- mountPath: /var/server-certs
194192
name: server-certs

wiz-admission-controller/templates/deploymentenforcement.yaml

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
{{- if or .Values.opaWebhook.enabled .Values.imageIntegrityWebhook.enabled .Values.debugWebhook.enabled}}
1+
{{- $isEnabled := include "wiz-admission-controller.isEnforcerEnabled" . | trim | lower }}
2+
{{- if eq $isEnabled "true" }}
23
apiVersion: apps/v1
34
kind: Deployment
45
metadata:
@@ -213,21 +214,7 @@ spec:
213214
value: "true"
214215
{{- end }}
215216
resources:
216-
{{- if not .Values.hpa.enabled }}
217-
{{- if hasKey .Values "resources" }}
218-
{{- toYaml .Values.resources | nindent 12 }}
219-
{{- else }}
220-
{}
221-
{{- end }}
222-
{{- else }}
223-
{{- if hasKey .Values "resources" }}
224-
{{- toYaml .Values.resources | nindent 12 }}
225-
{{- else }}
226-
requests:
227-
cpu: 500m
228-
memory: 300Mi
229-
{{- end }}
230-
{{- end }}
217+
{{- include "wiz-admission-controller.resources" . | nindent 12 }}
231218
volumeMounts:
232219
- mountPath: /var/cache
233220
name: cache

wiz-admission-controller/templates/hpa.yaml

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
{{- if .Values.hpa.enabled }}
2+
{{- $isEnabled := include "wiz-admission-controller.isEnforcerEnabled" . | trim | lower }}
3+
{{- if eq $isEnabled "true" }}
24
apiVersion: autoscaling/v2
35
kind: HorizontalPodAutoscaler
46
metadata:
5-
name: {{ include "wiz-hpa.name" . }}
7+
name: {{ include "wiz-hpa-enforcer.name" . }}
68
namespace: {{ .Release.Namespace }}
79
labels:
8-
{{- include "wiz-hpa.labels" . | nindent 4 }}
10+
{{- include "wiz-hpa-enforcer.labels" . | nindent 4 }}
911
spec:
1012
scaleTargetRef:
1113
apiVersion: apps/v1
@@ -33,4 +35,42 @@ spec:
3335
{{- if hasKey .Values.hpa "customMetrics" }}
3436
{{- toYaml .Values.hpa.customMetrics | nindent 4 }}
3537
{{- end }}
38+
---
39+
{{- end }}
40+
{{ if .Values.kubernetesAuditLogsWebhook.enabled -}}
41+
apiVersion: autoscaling/v2
42+
kind: HorizontalPodAutoscaler
43+
metadata:
44+
name: {{ include "wiz-hpa-audit-logs.name" . }}
45+
namespace: {{ .Release.Namespace }}
46+
labels:
47+
{{- include "wiz-hpa-audit-logs.labels" . | nindent 4 }}
48+
spec:
49+
scaleTargetRef:
50+
apiVersion: apps/v1
51+
kind: Deployment
52+
name: {{ include "wiz-kubernetes-audit-log-collector.name" . }}
53+
minReplicas: {{ .Values.hpa.minReplicas }}
54+
maxReplicas: {{ .Values.hpa.maxReplicas }}
55+
metrics:
56+
{{- if .Values.hpa.enableCPU }}
57+
- type: Resource
58+
resource:
59+
name: cpu
60+
target:
61+
type: Utilization
62+
averageUtilization: {{ .Values.hpa.targetCPUUtilizationPercentage }}
63+
{{- end }}
64+
{{- if .Values.hpa.enableMemory }}
65+
- type: Resource
66+
resource:
67+
name: memory
68+
target:
69+
type: Utilization
70+
averageUtilization: {{ .Values.hpa.targetMemoryUtilizationPercentage }}
71+
{{- end }}
72+
{{- if hasKey .Values.hpa "customMetrics" }}
73+
{{- toYaml .Values.hpa.customMetrics | nindent 4 }}
74+
{{- end }}
75+
{{- end }}
3676
{{- end }}

0 commit comments

Comments
 (0)