From 955929d89df3c10c4b06de5675eb1ffda4ef92e6 Mon Sep 17 00:00:00 2001 From: Rimas Mocevicius Date: Wed, 15 May 2019 20:21:12 +0100 Subject: [PATCH] use circleci for chart testing (#1225) * use circleci for chart testing * update ct flags * trigger ci * restore circleci config --- .circleci/config.yml | 33 ++++++++-- .drone.yml | 11 ---- test/e2e-kind.sh | 99 ++++++++++++++++++++++++++++ test/local-path-provisioner.yaml | 108 +++++++++++++++++++++++++++++++ 4 files changed, 236 insertions(+), 15 deletions(-) create mode 100755 test/e2e-kind.sh create mode 100644 test/local-path-provisioner.yaml diff --git a/.circleci/config.yml b/.circleci/config.yml index 08fe33e7..991a1fce 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -1,8 +1,33 @@ -version: 2 +version: 2.1 jobs: - build: + lint-scripts: docker: - - image: circleci/ruby:2.4.1 + - image: koalaman/shellcheck-alpine steps: - checkout - - run: echo "A first hello" + - run: + command: | + shellcheck -x test/e2e-kind.sh + + lint-install-charts: + machine: true + environment: + CHART_TESTING_IMAGE: quay.io/helmpack/chart-testing + CHART_TESTING_TAG: v2.3.3 + CHARTS_REPO: https://github.com/rimusz/charts + K8S_VERSION: v1.13.4 + KIND_VERSION: 0.2.1 + steps: + - checkout + - run: + command: test/e2e-kind.sh + no_output_timeout: 3600 + +workflows: + version: 2 + lint_and_install: + jobs: + - lint-scripts + - lint-install-charts: + requires: + - lint-scripts diff --git a/.drone.yml b/.drone.yml index a7b99629..bd1c071d 100644 --- a/.drone.yml +++ b/.drone.yml @@ -4,17 +4,6 @@ name: default steps: -- name: chart-lint - image: quay.io/helmpack/chart-testing:v2.3.3 - commands: - - ct lint --config test/ct.yaml - when: - branch: - - master - event: - - push - - pull_request - - name: build image: golang:1.12 commands: diff --git a/test/e2e-kind.sh b/test/e2e-kind.sh new file mode 100755 index 00000000..96675387 --- /dev/null +++ b/test/e2e-kind.sh @@ -0,0 +1,99 @@ +#!/usr/bin/env bash + +set -o errexit +set -o nounset +set -o pipefail + +readonly CLUSTER_NAME=chart-testing + +run_ct_container() { + echo 'Running ct container...' + docker run --rm --interactive --detach --network host --name ct \ + --volume "$(pwd):/workdir" \ + --workdir /workdir \ + "$CHART_TESTING_IMAGE:$CHART_TESTING_TAG" \ + cat + echo +} + +cleanup() { + echo 'Removing ct container...' + docker kill ct > /dev/null 2>&1 + + echo 'Done!' +} + +docker_exec() { + docker exec --interactive -e HELM_HOST=127.0.0.1:44134 -e HELM_TILLER_SILENT=true ct "$@" +} + +create_kind_cluster() { + echo 'Installing kind...' + + curl -sSLo kind "https://github.com/kubernetes-sigs/kind/releases/download/$KIND_VERSION/kind-linux-amd64" + chmod +x kind + sudo mv kind /usr/local/bin/kind + + kind create cluster --name "$CLUSTER_NAME" --image "kindest/node:$K8S_VERSION" + + docker_exec mkdir -p /root/.kube + + echo 'Copying kubeconfig to container...' + local kubeconfig + kubeconfig="$(kind get kubeconfig-path --name "$CLUSTER_NAME")" + docker cp "$kubeconfig" ct:/root/.kube/config + + docker_exec kubectl cluster-info + echo + + echo -n 'Waiting for cluster to be ready...' + until ! grep --quiet 'NotReady' <(docker_exec kubectl get nodes --no-headers); do + printf '.' + sleep 1 + done + + echo '✔︎' + echo + + docker_exec kubectl get nodes + echo + + echo 'Cluster ready!' + echo +} + +install_local-path-provisioner() { + # Remove default storage class. It will be recreated by local-path-provisioner + docker_exec kubectl delete storageclass standard + + echo 'Installing local-path-provisioner...' + docker_exec kubectl apply -f test/local-path-provisioner.yaml + echo +} + +install_tiller() { + docker_exec apk add bash + echo "Install Tillerless Helm plugin..." + docker_exec helm init --client-only + docker_exec helm plugin install https://github.com/rimusz/helm-tiller + docker_exec bash -c 'echo "Starting Tiller..."; helm tiller start-ci >/dev/null 2>&1 &' + docker_exec bash -c 'echo "Waiting Tiller to launch on 44134..."; while ! nc -z localhost 44134; do sleep 1; done; echo "Tiller launched..."' + echo +} + +install_charts() { + docker_exec ct lint-and-install --config /workdir/test/ct.yaml + echo +} + +main() { + run_ct_container + trap cleanup EXIT + + create_kind_cluster + install_local-path-provisioner + install_tiller + install_charts +} + +main diff --git a/test/local-path-provisioner.yaml b/test/local-path-provisioner.yaml new file mode 100644 index 00000000..5dc0ed59 --- /dev/null +++ b/test/local-path-provisioner.yaml @@ -0,0 +1,108 @@ +apiVersion: v1 +kind: Namespace +metadata: + name: local-path-storage +--- +apiVersion: v1 +kind: ServiceAccount +metadata: + name: local-path-provisioner-service-account + namespace: local-path-storage +--- +apiVersion: rbac.authorization.k8s.io/v1beta1 +kind: ClusterRole +metadata: + name: local-path-provisioner-role + namespace: local-path-storage +rules: +- apiGroups: [""] + resources: ["nodes", "persistentvolumeclaims"] + verbs: ["get", "list", "watch"] +- apiGroups: [""] + resources: ["endpoints", "persistentvolumes", "pods"] + verbs: ["*"] +- apiGroups: [""] + resources: ["events"] + verbs: ["create", "patch"] +- apiGroups: ["storage.k8s.io"] + resources: ["storageclasses"] + verbs: ["get", "list", "watch"] +--- +apiVersion: rbac.authorization.k8s.io/v1beta1 +kind: ClusterRoleBinding +metadata: + name: local-path-provisioner-bind + namespace: local-path-storage +roleRef: + apiGroup: rbac.authorization.k8s.io + kind: ClusterRole + name: local-path-provisioner-role +subjects: +- kind: ServiceAccount + name: local-path-provisioner-service-account + namespace: local-path-storage +--- +apiVersion: apps/v1beta2 +kind: Deployment +metadata: + name: local-path-provisioner + namespace: local-path-storage +spec: + replicas: 1 + selector: + matchLabels: + app: local-path-provisioner + template: + metadata: + labels: + app: local-path-provisioner + spec: + serviceAccountName: local-path-provisioner-service-account + containers: + - name: local-path-provisioner + image: rancher/local-path-provisioner:v0.0.8 + imagePullPolicy: Always + command: + - local-path-provisioner + - --debug + - start + - --config + - /etc/config/config.json + volumeMounts: + - name: config-volume + mountPath: /etc/config/ + env: + - name: POD_NAMESPACE + valueFrom: + fieldRef: + fieldPath: metadata.namespace + volumes: + - name: config-volume + configMap: + name: local-path-config +--- +apiVersion: storage.k8s.io/v1 +kind: StorageClass +metadata: + name: local-path + annotations: + storageclass.kubernetes.io/is-default-class: "true" +provisioner: rancher.io/local-path +volumeBindingMode: WaitForFirstConsumer +reclaimPolicy: Delete +--- +kind: ConfigMap +apiVersion: v1 +metadata: + name: local-path-config + namespace: local-path-storage +data: + config.json: |- + { + "nodePathMap":[ + { + "node":"DEFAULT_PATH_FOR_NON_LISTED_NODES", + "paths":["/opt/local-path-provisioner"] + } + ] + }