-
Notifications
You must be signed in to change notification settings - Fork 218
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
4 changed files
with
155 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
version: 2 | ||
jobs: | ||
lint-scripts: | ||
docker: | ||
- image: koalaman/shellcheck-alpine | ||
steps: | ||
- checkout | ||
- run: | ||
name: lint | ||
command: | | ||
shellcheck -x test/e2e-kind.sh | ||
lint-charts: | ||
docker: | ||
- image: quay.io/helmpack/chart-testing:v2.0.1 | ||
steps: | ||
- checkout | ||
- run: | ||
name: lint | ||
command: | | ||
git remote add k8s https://github.com/your_git_repo/charts | ||
git fetch k8s master | ||
ct lint --config test/ct.yaml | ||
install-charts: | ||
machine: true | ||
environment: | ||
CHART_TESTING_IMAGE: quay.io/helmpack/chart-testing | ||
CHART_TESTING_TAG: v2.0.1 | ||
CHARTS_REPO: https://github.com/your_git_repo/charts | ||
K8S_VERSION: "v1.11.3" | ||
steps: | ||
- checkout | ||
- run: | ||
name: install | ||
command: | | ||
test/e2e-kind.sh | ||
no_output_timeout: 3600 | ||
workflows: | ||
version: 2 | ||
lint_and_install: | ||
jobs: | ||
- lint-scripts | ||
- lint-charts: | ||
requires: | ||
- lint-scripts | ||
- install-charts: | ||
requires: | ||
- lint-charts |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# Chart testing example with CircleCi and kind - `k`ubernetes `in` `d`ocker | ||
|
||
This example shows how to lint and test charts using CircleCi and [kind](https://github.com/kubernetes-sigs/kind). | ||
|
||
`kind` is a tool for running local/CI pipelines Kubernetes clusters using Docker container "nodes". |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
remote: k8s | ||
target-branch: master | ||
chart-dirs: | ||
- stable | ||
excluded-charts: | ||
- common | ||
helm-extra-args: --timeout 800 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -o errexit | ||
set -o nounset | ||
set -o pipefail | ||
|
||
readonly REPO_ROOT="${REPO_ROOT:-$(git rev-parse --show-toplevel)}" | ||
|
||
run_kind() { | ||
|
||
echo "Get kind binary..." | ||
docker run --rm -it -v "$(pwd)":/go/bin golang go get sigs.k8s.io/kind && chmod +x kind && sudo mv kind /usr/local/bin/ | ||
|
||
echo "Download kubectl..." | ||
curl -Lo kubectl https://storage.googleapis.com/kubernetes-release/release/"${K8S_VERSION}"/bin/linux/amd64/kubectl && chmod +x kubectl && sudo mv kubectl /usr/local/bin/ | ||
echo | ||
|
||
echo "Create Kubernetes cluster with kind..." | ||
kind create cluster --image=kindest/node:"$K8S_VERSION" | ||
|
||
echo "Export kubeconfig..." | ||
# shellcheck disable=SC2155 | ||
export KUBECONFIG="$(kind get kubeconfig-path)" | ||
echo | ||
|
||
echo "Ensure the apiserver is responding..." | ||
kubectl cluster-info | ||
echo | ||
|
||
echo "Wait for Kubernetes to be up and ready..." | ||
JSONPATH='{range .items[*]}{@.metadata.name}:{range @.status.conditions[*]}{@.type}={@.status};{end}{end}'; until kubectl get nodes -o jsonpath="$JSONPATH" 2>&1 | grep -q "Ready=True"; do sleep 1; done | ||
echo | ||
} | ||
|
||
install_tiller() { | ||
# Install Tiller with RBAC | ||
kubectl -n kube-system create sa tiller | ||
kubectl create clusterrolebinding tiller-cluster-rule --clusterrole=cluster-admin --serviceaccount=kube-system:tiller | ||
docker exec "$config_container_id" helm init --service-account tiller | ||
echo "Wait for Tiller to be up and ready..." | ||
until kubectl -n kube-system get pods 2>&1 | grep -w "tiller-deploy" | grep -w "1/1"; do sleep 1; done | ||
echo | ||
} | ||
|
||
install_hostpath-provisioner() { | ||
# kind doesn't support Dynamic PVC provisioning yet, this one of ways to get it working | ||
# https://github.com/rimusz/charts/tree/master/stable/hostpath-provisioner | ||
|
||
# delete the default storage class | ||
kubectl delete storageclass standard | ||
|
||
echo "Install Hostpath Provisioner..." | ||
docker exec "$config_container_id" helm repo add rimusz https://charts.rimusz.net | ||
docker exec "$config_container_id" helm repo update | ||
docker exec "$config_container_id" helm upgrade --install hostpath-provisioner --namespace kube-system rimusz/hostpath-provisioner | ||
echo | ||
} | ||
|
||
main() { | ||
|
||
echo "Starting kind ..." | ||
echo | ||
run_kind | ||
|
||
local config_container_id | ||
config_container_id=$(docker run -it -d -v "$REPO_ROOT:/workdir" --workdir /workdir "$CHART_TESTING_IMAGE:$CHART_TESTING_TAG" cat) | ||
|
||
# shellcheck disable=SC2064 | ||
trap "docker rm -f $config_container_id > /dev/null" EXIT | ||
|
||
# Get kind container IP | ||
kind_container_ip=$(docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' kind-1-control-plane) | ||
# Copy kubeconfig file | ||
docker exec "$config_container_id" mkdir /root/.kube | ||
docker cp "$KUBECONFIG" "$config_container_id:/root/.kube/config" | ||
# Update in kubeconfig localhost to kind container IP | ||
docker exec "$config_container_id" sed -i "s/localhost/$kind_container_ip/g" /root/.kube/config | ||
|
||
echo "Add git remote k8s ${CHARTS_REPO}" | ||
git remote add k8s "${CHARTS_REPO}" &> /dev/null || true | ||
git fetch k8s master | ||
echo | ||
|
||
# Install Tiller with RBAC | ||
install_tiller | ||
|
||
# Install hostpath-provisioner for Dynammic PVC provisioning | ||
install_hostpath-provisioner | ||
|
||
# shellcheck disable=SC2086 | ||
docker exec "$config_container_id" ct install --config /workdir/test/ct.yaml | ||
|
||
echo "Done Testing!" | ||
} | ||
|
||
main |