Skip to content

Commit

Permalink
feat(admission-controller): internal test (#1297)
Browse files Browse the repository at this point in the history
  • Loading branch information
hayk99 authored Aug 21, 2023
1 parent 731fd34 commit ffa2c43
Show file tree
Hide file tree
Showing 8 changed files with 93 additions and 4 deletions.
2 changes: 1 addition & 1 deletion charts/admission-controller/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ apiVersion: v2
name: admission-controller
description: Sysdig Admission Controller using Sysdig Secure inline image scanner
type: application
version: 0.12.3
version: 0.12.4
appVersion: 3.9.26
home: https://sysdiglabs.github.io/admission-controller/
icon: https://avatars.githubusercontent.com/u/5068817?s=200&v=4
Expand Down
4 changes: 2 additions & 2 deletions charts/admission-controller/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ For example:

```bash
helm upgrade --install admission-controller sysdig/admission-controller \
--create-namespace -n sysdig-admission-controller --version=0.12.3 \
--create-namespace -n sysdig-admission-controller --version=0.12.4 \
--set sysdig.secureAPIToken=YOUR-KEY-HERE,clusterName=YOUR-CLUSTER-NAME
```

Expand All @@ -80,7 +80,7 @@ For example:

```bash
helm upgrade --install admission-controller sysdig/admission-controller \
--create-namespace -n sysdig-admission-controller --version=0.12.3 \
--create-namespace -n sysdig-admission-controller --version=0.12.4 \
--values values.yaml
```
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Warning! This file is for internal tests only.
{{- if .Values.webhook.acConfig }}
apiVersion: v1
kind: ConfigMap
metadata:
name: admissioncontrollerconfigmap
namespace: {{ include "admissionController.namespace" . }}
labels:
{{ include "admissionController.webhook.labels" . | nindent 4 }}
data:
acConfig: |
{{ .Values.webhook.acConfig | nindent 4 }}
{{- end }}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ metadata:
labels:
app.kubernetes.io/managed-by: Helm
webhooks:
{{- if .Values.scanner.enabled }}
{{- if or .Values.scanner.enabled .Values.webhook.acConfig }}
- name: scanning.secure.sysdig.com
matchPolicy: Equivalent
rules:
Expand Down
13 changes: 13 additions & 0 deletions charts/admission-controller/templates/webhook/clusterrole.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,21 @@ rules:
- ""
resources:
- pods
{{- if .Values.webhook.acConfig }}
- configmaps
{{- end }}
verbs:
- get
{{- if .Values.webhook.acConfig }}
- apiGroups:
- "batch"
resources:
- jobs
verbs:
- create
- get
- delete
{{- end }}
- apiGroups:
- "apps"
resources:
Expand Down
6 changes: 6 additions & 0 deletions charts/admission-controller/templates/webhook/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,17 @@ spec:
value: {{ include "webhook.httpsProxy" . }}
- name: NO_PROXY
value: {{ include "webhook.noProxy" . }},{{ include "admissionController.scanner.fullname" . }}
- name: AC_NAMESPACE
value: {{ include "admissionController.namespace" . }}
{{- end }}
{{- if or .Values.webhook.ssl.ca.cert (eq (include "sysdig.custom_ca.enabled" (dict "global" .Values.global.ssl "component" .Values.webhook.ssl)) "true") }}
- name: SSL_CERT_DIR
value: /ca-certs
{{- end }}
{{- if .Values.webhook.acConfig }}
- name: VM_ENGINE_V2_ENABLED
value: "true"
{{- end }}
ports:
- name: http
containerPort: {{ .Values.webhook.http.port }}
Expand Down
56 changes: 56 additions & 0 deletions charts/admission-controller/tests/configmap_test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
suite: Test admissioncontrollerconfigmap
templates:
- templates/webhook/admissioncontrollerconfigmap.yaml
- templates/webhook/clusterrole.yaml
tests:
- it: Creates the configmap if webhook.acConfig is present
set:
webhook:
acConfig: |
foo: bar
fizz: buzz
asserts:
- containsDocument:
kind: ConfigMap
apiVersion: v1
template: templates/webhook/admissioncontrollerconfigmap.yaml
- it: Creates the clusterrole if webhook.acConfig is present
set:
webhook:
acConfig: |
foo: bar
fizz: buzz
asserts:
- isSubset:
path: rules[2]
content:
apiGroups: ["batch"]
resources: ["jobs"]
verbs: ["create", "get", "delete"]
template: templates/webhook/clusterrole.yaml
- isSubset:
path: rules[1]
content:
apiGroups: [""]
resources: ["pods", "configmaps"]
verbs: ["get"]
template: templates/webhook/clusterrole.yaml
- it: Does not create the configmap if webhook.acConfig is not present
set: {}
asserts:
- notContains:
path: rules
content:
apiGroups: [ "batch" ]
template: templates/webhook/clusterrole.yaml
- isSubset:
path: rules[1]
content:
apiGroups: [""]
resources: ["pods"]
verbs: ["get"]
template: templates/webhook/clusterrole.yaml
# asserts:
# - isNullOrEmpty:
# path: data
# template: templates/webhook/admissioncontrollerconfigmap.yaml
1 change: 1 addition & 0 deletions charts/admission-controller/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ webhook:

# The image pull secrets for webhook.
imagePullSecrets: []

# Resource request and limits for webhook.
resources: # +doc-gen:break
limits:
Expand Down

0 comments on commit ffa2c43

Please sign in to comment.