Skip to content

Commit

Permalink
Improve cert-manager examples.
Browse files Browse the repository at this point in the history
Make them runnable by fetching CRDs using kustomize.
  • Loading branch information
mgoltzsche committed Dec 13, 2020
1 parent 6374267 commit 3862cb3
Show file tree
Hide file tree
Showing 19 changed files with 63 additions and 25,392 deletions.
1 change: 1 addition & 0 deletions .github/workflows/release-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ on:
branches:
- master
- v2
- v1

# Publish `v1.2.3` tags as releases.
tags:
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/verify.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ on:
branches:
- master
- v2
- v1

jobs:
build:
Expand Down
7 changes: 3 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@

/example/**/charts
/example/**/tmpcharts
/example/kpt/output-*
!/example/kpt/output-helm-kustomize
/example/kpt/output-helm-kustomize/output-kustomization
/example/kpt/output-helm-kustomize/static/generated-manifest.yaml
/example/kpt/*/output-*
/example/kpt/*/generated-*
/example/kpt/cert-manager/static/generated-manifest.yaml

1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ e2e-test: image khelm-static kpt kustomize
./e2e/kustomize-plugin-test.sh; \
IMAGE=$(IMAGE) ./e2e/image-cli-test.sh; \
./e2e/kpt-function-test.sh; \
./e2e/kpt-cert-manager-test.sh; \
}

fmt:
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,12 @@ kpt fn run --network . # Renders the chart into output-manifest.yaml
_For all available fields see the [table](#configuration-options) below._

Please note that, in case you need to refer to a local chart directory or values file, the source must be mounted to the function using `kpt fn run --mount=<SRC_MOUNT> .`.
The [example kpt project](example/kpt) and the corresponding [e2e test](e2e/kpt-function-test.sh) show how to do that.
An [example kpt project](example/kpt/test-cases) and the corresponding [e2e test](e2e/kpt-function-test.sh) show how to do that.

Kpt can also be leveraged to pull charts from other git repositories into your own repository using the `kpt pkg sync .` [command](https://googlecontainertools.github.io/kpt/reference/pkg/) (with a corresponding dependency set up) before running the khelm function (for this reason the go-getter support has been removed from this project).

If necessary the chart output can be transformed using kustomize.
This can be done by declaring the khelm and a kustomize function orderly within a file and specifying the chart output kustomization as input for the kustomize function as shown in [this example](example/kpt/helm-kustomize-pipeline.yaml).
This can be done by declaring the khelm and a kustomize function orderly within a file and specifying the chart output kustomization as input for the kustomize function as shown in the [cert-manager example](example/kpt/cert-manager).


### kustomize exec plugin
Expand Down
24 changes: 24 additions & 0 deletions e2e/kpt-cert-manager-test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/bin/sh

cd "$(dirname "$0")/../example"

echo
echo " TEST $0: Run kpt functions of example/cert-manager"
echo

set -e

rm -rf ./kpt/cert-manager/generated-kustomization ./kpt/cert-manager/static/generated-manifest.yaml

(
set -ex
kpt fn run --network ./kpt/cert-manager

[ -f ./kpt/cert-manager/static/generated-manifest.yaml ]
! grep -m1 -B10 -A1 ' namespace: ""' ./kpt/cert-manager/static/generated-manifest.yaml || (echo 'FAIL: output contains empty namespace field' >&2; false)
grep -Eq ' name: cert-manager-webhook$' ./kpt/cert-manager/static/generated-manifest.yaml || (echo 'FAIL: does not contain expected resource' >&2; false)
grep -Eq ' namespace: kube-system$' ./kpt/cert-manager/static/generated-manifest.yaml || (echo 'FAIL: did not preserve chart resource namespace' >&2; false)
grep -Eq '^kind: CustomResourceDefinition$' ./kpt/cert-manager/static/generated-manifest.yaml || (echo 'FAIL: does not contain CustomResourceDefinition' >&2; false)
)

echo SUCCESS
26 changes: 11 additions & 15 deletions e2e/kpt-function-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,24 @@
cd "$(dirname "$0")/../example"

echo
echo " TEST $0: Run kpt functions"
echo " TEST $0: Run kpt functions of example/test-cases"
echo

set -e

rm -rf ./kpt/output-local ./kpt/output-kustomization ./kpt/output-remote \
./kpt/output-helm-kustomize/output-kustomization ./kpt/output-helm-kustomize/static/generated-manifest.yaml
rm -rf ./kpt/test-cases/output-local ./kpt/test-cases/output-kustomization ./kpt/test-cases/output-remote

(
set -ex
kpt fn run --network --mount "type=bind,source=`pwd`/namespace,target=/source" ./kpt

[ -f ./kpt/output-local.yaml ]
[ -f ./kpt/output-kustomization/configmap_myconfiga.yaml ]
[ -f ./kpt/output-kustomization/configmap_myconfigb.yaml ]
[ -f ./kpt/output-kustomization/kustomization.yaml ]
[ -f ./kpt/output-remote.yaml ]
[ -f ./kpt/output-helm-kustomize/static/generated-manifest.yaml ]
! grep -m1 -B10 -A1 ' namespace: ""' ./kpt/output-helm-kustomize/static/generated-manifest.yaml || (echo 'FAIL: output contains empty namespace field' >&2; false)
grep -q ' namespace: kube-system' ./kpt/output-helm-kustomize/static/generated-manifest.yaml || (echo 'FAIL: did not preserve chart resource namespace' >&2; false)

kustomize build ./kpt/output-kustomization | grep -q ' myconfiga'
kpt fn run --network --mount "type=bind,source=`pwd`/namespace,target=/source" ./kpt/test-cases

[ -f ./kpt/test-cases/output-local.yaml ]
[ -f ./kpt/test-cases/output-kustomization/configmap_myconfiga.yaml ]
[ -f ./kpt/test-cases/output-kustomization/configmap_myconfigb.yaml ]
[ -f ./kpt/test-cases/output-kustomization/kustomization.yaml ]
[ -f ./kpt/test-cases/output-remote.yaml ]

kustomize build ./kpt/test-cases/output-kustomization | grep -q ' myconfiga'
)

echo SUCCESS
7 changes: 3 additions & 4 deletions example/cert-manager/README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
This example kustomization renders the [cert-manager](https://github.com/jetstack/cert-manager) crds, namespace and
helm chart without the webhook (to run on [k3s](https://github.com/rancher/k3s)).
This example kustomization renders the [cert-manager](https://github.com/jetstack/cert-manager) with CRDs and `Namespace´.

It can be rendered and deployed as follows:
```
kustomize build --enable_alpha_plugins github.com/mgoltzsche/helm-kustomize-plugin/example/cert-manager | kubectl apply -f -
```
kustomize build --enable_alpha_plugins github.com/mgoltzsche/khelm/example/cert-manager | kubectl apply -f -
```
Loading

0 comments on commit 3862cb3

Please sign in to comment.