forked from XenitAB/gatekeeper-library
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
74 lines (61 loc) · 2.17 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
SHELL=/bin/bash
all: opa-fmt opa-test generate helm-lint helm-test
opa-fmt:
opa fmt -w library
opa-test:
opa test library --ignore *.yaml
update-external:
git submodule update --init --remote
get-external:
git submodule update --init
.ONESHELL: generate
.SILENT: generate
generate: get-external
set -e
TEMPLATES_GENERATED=./charts/gatekeeper-library-templates/generated
CONTRAINTS_GENERATED=./charts/gatekeeper-library-constraints/generated
rm -r $$TEMPLATES_GENERATED
mkdir -p $$TEMPLATES_GENERATED $$CONTRAINTS_GENERATED
CONSTRAINT_DEFAULTS=$$CONTRAINTS_GENERATED/constraint-defaults.yaml
> $$CONSTRAINT_DEFAULTS
ASSIGN_LIBRARY=$$(ls -d ./library/assigns/*)
for D in $$ASSIGN_LIBRARY
do
FILENAME=$$(basename $$D)
cp $$D $$CONTRAINTS_GENERATED/$$FILENAME
done
CONSTRAINT_LIBRARY=$$(ls -d ./library/constraints/*/)
for D in $$CONSTRAINT_LIBRARY
do
NAME=$$(yq '.kind' $$D/constraint.yaml | tr "[:upper:]" "[:lower:]")
SRC=$$(cat $$D/src.rego)
SRC=$$SRC yq -i '.spec.targets[0].rego = strenv(SRC)' $$D/template.yaml
kustomize build $$D > $$TEMPLATES_GENERATED/$$NAME.yaml
echo "$$NAME:" >> $$CONSTRAINT_DEFAULTS
yq '.spec' $$D/constraint.yaml | sed 's/^/ /' >> $$CONSTRAINT_DEFAULTS
done
EXTERNAL_LIBRARY=$$(ls -d ./external/library/*/*/)
for D in $$EXTERNAL_LIBRARY
do
if [[ -f $$D/template.yaml ]]; then
NAME=$$(yq '.metadata.name' $$D/template.yaml | tr "[:upper:]" "[:lower:]")
cat $$D/template.yaml > $$TEMPLATES_GENERATED/$$NAME.yaml
SAMPLE=$$(ls $$D/samples/ | head -n 1)
yq '.spec.match.kinds // {}' "$${D}samples/$$SAMPLE/constraint.yaml" | yq "{\"$$NAME\": {\"match\": {\"kinds\": . }}}" >> $$CONSTRAINT_DEFAULTS
touch $$TEMPLATES_GENERATED/config-values.yaml
if test -f $$D/sync.yaml; then
yq '.spec' "$$D/sync.yaml" | yq "{\"$$NAME\": . }" >> $$TEMPLATES_GENERATED/config-values.yaml
fi
fi
done
helm-lint:
helm lint charts/gatekeeper-library-constraints
helm lint charts/gatekeeper-library-templates
helm-test:
helm plugin install https://github.com/quintush/helm-unittest
helm unittest --helm3 charts/gatekeeper-library-constraints
helm unittest --helm3 charts/gatekeeper-library-templates
.PHONY: e2e
e2e:
cd e2e
./test.sh