Skip to content

Commit cad8ca9

Browse files
unguiculusk8s-ci-robot
authored andcommittedJun 6, 2018
Use factored out testing lib (helm#5231)
* [WIP][CI] Use factored out testing lib * Incorporate upstream changes * Update Docker image for CircleCI * Update Docker image * Update Docker image * Align with upstream changes * Remove dummy chart and bump a few charts for testing * Fix Dockerfile * Align with upstream changes * Add summary * Update Chart.yaml * Update Docker images * Remove chart test bumps * Align with upstream changes * Bump some charts for testing * Create v2.0.0 * Remove chart version bumps * Revert repo-sync.sh in favor of helm#5847 * Bump image version * Use latest chart testing image
1 parent efa000e commit cad8ca9

19 files changed

+193
-769
lines changed
 

‎.circleci/config.yml

+20-7
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,28 @@
11
version: 2
22
jobs:
3-
build:
3+
lint-scripts:
44
docker:
5-
- image: circleci/python:3.6.4
5+
- image: koalaman/shellcheck-alpine
66
steps:
77
- checkout
88
- run:
9-
name: install tools
10-
command: test/circle/install.sh
9+
name: lint
10+
command: |
11+
shellcheck -x test/build.sh
12+
shellcheck -x test/e2e.sh
13+
shellcheck -x test/helm-test-e2e.sh
14+
shellcheck -x test/repo-sync.sh
15+
lint-charts:
16+
docker:
17+
- image: gcr.io/kubernetes-charts-ci/test-image:v2.0.2
18+
steps:
19+
- checkout
1120
- run:
1221
name: lint
13-
command: test/circle/lint.sh
22+
command: |
23+
git remote add k8s https://github.com/kubernetes/charts
24+
git fetch k8s master
25+
chart_test.sh --config test/.testenv --no-install
1426
sync:
1527
docker:
1628
- image: google/cloud-sdk
@@ -21,9 +33,10 @@ jobs:
2133
command: test/repo-sync.sh
2234
workflows:
2335
version: 2
24-
test:
36+
lint:
2537
jobs:
26-
- build
38+
- lint-scripts
39+
- lint-charts
2740
sync:
2841
triggers:
2942
- schedule:

‎.gitignore

+3-1
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,6 @@ Session.vim
3232
.netrwhist
3333

3434
# Chart dependencies
35-
**/charts/*.tgz
35+
**/charts/*.tgz
36+
37+
.history

‎test/.dockerignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
*
2+
! .testenv

‎test/.testenv

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# The name of the Git remote
2+
REMOTE=k8s
3+
4+
# The name of the Git target branch
5+
TARGET_BRANCH=master
6+
7+
# Chart directories separated by a space
8+
CHART_DIRS=(
9+
stable
10+
incubator
11+
)
12+
13+
# Charts that should be skipped
14+
EXCLUDED_CHARTS=(
15+
common
16+
)
17+
18+
# Additional chart repos to add (<name>=<url>), separated by a space
19+
CHART_REPOS=(
20+
incubator=https://kubernetes-charts-incubator.storage.googleapis.com/
21+
)
22+
23+
TIMEOUT=600

‎test/Dockerfile

+14-40
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2016 The Kubernetes Authors All rights reserved.
1+
# Copyright 2018 The Kubernetes Authors. All rights reserved.
22
#
33
# Licensed under the Apache License, Version 2.0 (the "License");
44
# you may not use this file except in compliance with the License.
@@ -12,45 +12,19 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
FROM debian:8.5
15+
FROM gcr.io/kubernetes-charts-ci/chart-testing:v1.0.2
1616

17-
ENV CLOUDSDK_CORE_DISABLE_PROMPTS=1 \
18-
PATH=/opt/google-cloud-sdk/bin:$PATH \
19-
GOOGLE_CLOUD_SDK_VERSION=154.0.0 \
20-
GOOGLE_PROJECT=kubernetes-charts-ci
17+
ENV PATH /google-cloud-sdk/bin:$PATH
18+
ARG CLOUD_SDK_VERSION=202.0.0
19+
RUN curl -LO "https://dl.google.com/dl/cloudsdk/channels/rapid/downloads/google-cloud-sdk-$CLOUD_SDK_VERSION-linux-x86_64.tar.gz" && \
20+
tar xzf "google-cloud-sdk-$CLOUD_SDK_VERSION-linux-x86_64.tar.gz" && \
21+
rm "google-cloud-sdk-$CLOUD_SDK_VERSION-linux-x86_64.tar.gz" && \
22+
ln -s /lib /lib64 && \
23+
rm -rf /google-cloud-sdk/.install/.backup && \
24+
gcloud version
2125

22-
RUN set -x \
23-
&& cd /opt \
24-
&& echo 'debconf debconf/frontend select Noninteractive' | debconf-set-selections \
25-
&& apt-get update \
26-
&& apt-get install --no-install-recommends -y jq wget python git localepurge ca-certificates \
27-
&& wget -q https://dl.google.com/dl/cloudsdk/channels/rapid/downloads/google-cloud-sdk-${GOOGLE_CLOUD_SDK_VERSION}-linux-x86_64.tar.gz \
28-
&& tar zxfv google-cloud-sdk-${GOOGLE_CLOUD_SDK_VERSION}-linux-x86_64.tar.gz \
29-
&& ./google-cloud-sdk/install.sh \
30-
&& gcloud components install kubectl \
31-
&& gcloud config set project ${GOOGLE_PROJECT}
32-
RUN apt-get -y purge localepurge \
33-
&& apt-get clean \
34-
&& cd / \
35-
&& rm -rf \
36-
/opt/google-cloud-sdk-${GOOGLE_CLOUD_SDK_VERSION}-linux-x86_64.tar.gz \
37-
/opt/helm-${HELM_VERSION}-linux-amd64.tar.gz \
38-
doc \
39-
man \
40-
info \
41-
locale \
42-
/var/lib/apt/lists/* \
43-
/var/log/* \
44-
/var/cache/debconf/* \
45-
common-licenses \
46-
~/.bashrc \
47-
/etc/systemd \
48-
/lib/lsb \
49-
/lib/udev \
50-
/usr/share/doc/ \
51-
/usr/share/doc-base/ \
52-
/usr/share/man/ \
53-
/tmp/*
26+
RUN gcloud config set core/disable_usage_reporting true && \
27+
gcloud config set component_manager/disable_update_check true && \
28+
gcloud config set metrics/environment github_docker_image
5429

55-
VOLUME "/src"
56-
WORKDIR "/src"
30+
WORKDIR /workdir

‎test/README.md

+2-11
Original file line numberDiff line numberDiff line change
@@ -27,19 +27,10 @@ The configuration of the Pull Request trigger is [in the config.json](https://gi
2727

2828
This snippet tells Test Infra to run the [test/e2e.sh](https://github.com/kubernetes/charts/blob/master/test/e2e.sh)
2929
when testing is triggered on a pull request. The e2e.sh script will use the [Charts test image](https://github.com/kubernetes/charts/blob/master/test/Dockerfile)
30-
to run the [test/changed.sh](https://github.com/kubernetes/charts/blob/master/test/changed.sh) script. This script
30+
to run the [chart_test.sh](https://github.com/kubernetes-helm/chart-testing/blob/master/chart_test.sh) script. This script
3131
is the main logic for validation of a pull request. It intends to only test charts that have changed in this PR.
3232

33-
The logic is as follows:
34-
35-
1. [Get credentials for the Kubernetes cluster used for testing.](https://github.com/kubernetes/charts/blob/master/test/changed.sh#L128)
36-
1. [Install and initialize Helm](https://github.com/kubernetes/charts/blob/master/test/changed.sh#L143)
37-
1. [For any charts that have changed](https://github.com/kubernetes/charts/blob/master/test/changed.sh#L161):
38-
- Download dependent charts, if any, with `helm dep build`
39-
- Run `helm install` in a new namespace for this PR build
40-
- Use the [test/verify-release.sh](https://github.com/kubernetes/charts/blob/master/test/verify-release.sh) to ensure that if any pods were launched that they get to the `Running` state
41-
- Run `helm test` on the release
42-
- Delete the release
33+
The testing logic has been extrated to the [chart-testing](https://github.com/kubernetes-helm/chart-testing) project. A bash library provides the required logic to lint, install, and test charts. It is provided as a Docker image and can be run by anyone on their own charts.
4334

4435
#### Providing Custom Test Values
4536

‎test/build.sh

+74
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
#!/usr/bin/env bash
2+
3+
# Copyright 2018 The Kubernetes Authors. All rights reserved.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
#     http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
set -o errexit
18+
set -o nounset
19+
set -o pipefail
20+
21+
readonly IMAGE_TAG=v2.0.2
22+
readonly IMAGE_REPOSITORY="gcr.io/kubernetes-charts-ci/test-image"
23+
readonly SCRIPT_DIR=$(dirname "$(readlink -f "$0")")
24+
25+
show_help() {
26+
cat << EOF
27+
Usage: ${0##*/} <args>
28+
-h, --help Display help
29+
-v, --verbose Display verbose output
30+
-p, --push Push image to registry
31+
EOF
32+
}
33+
34+
main() {
35+
local verbose=
36+
local push=
37+
38+
while :; do
39+
case "${1:-}" in
40+
-h|--help)
41+
show_help
42+
exit
43+
;;
44+
-v|--verbose)
45+
verbose=true
46+
;;
47+
-p|--push)
48+
push=true
49+
;;
50+
-?*)
51+
printf 'WARN: Unknown option (ignored): %s\n' "$1" >&2
52+
;;
53+
*)
54+
break
55+
;;
56+
esac
57+
58+
shift
59+
done
60+
61+
[[ -n "$verbose" ]] && set -o xtrace
62+
63+
pushd "$SCRIPT_DIR"
64+
65+
docker build --tag "$IMAGE_REPOSITORY:$IMAGE_TAG" .
66+
67+
if [[ -n "$push" ]]; then
68+
docker push "$IMAGE_REPOSITORY:$IMAGE_TAG"
69+
fi
70+
71+
popd
72+
}
73+
74+
main "$@"

‎test/changed.sh

-197
This file was deleted.

‎test/circle/README.md

-4
This file was deleted.

‎test/circle/install.sh

-47
This file was deleted.

‎test/circle/lint.sh

-116
This file was deleted.

‎test/circle/lintconf.yml

-42
This file was deleted.

‎test/circle/yaml-schemas/Chart.yaml

-20
This file was deleted.

‎test/e2e.sh

+31-31
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
#!/bin/bash
2-
# Copyright 2016 The Kubernetes Authors All rights reserved.
1+
#!/usr/bin/env bash
2+
3+
# Copyright 2018 The Kubernetes Authors. All rights reserved.
34
#
45
# Licensed under the Apache License, Version 2.0 (the "License");
56
# you may not use this file except in compliance with the License.
@@ -16,40 +17,39 @@
1617
set -o errexit
1718
set -o nounset
1819
set -o pipefail
19-
set -o xtrace
20-
21-
# TODO should we inject this. This is creating problems bumping the Docker version
22-
IMAGE_VERSION="test-image:v1.11"
23-
CHART_ROOT=${CHART_ROOT:-$(git rev-parse --show-toplevel)}
24-
IMAGE_NAME=${IMAGE_NAME:-"gcr.io/kubernetes-charts-ci/${IMAGE_VERSION}"}
25-
26-
VOLUMES="-v ${CHART_ROOT}:/src -v ${KUBECONFIG:=${HOME}/.kube/config}:/.kube/config"
27-
28-
GKE_CREDS=""
29-
if [ -f $HOME/.config/gcloud/application_default_credentials.json ];then
30-
GKE_CREDS="-v $HOME/.config/gcloud/application_default_credentials.json:/service-account.json:ro"
31-
GKE_CREDS="${GKE_CREDS} -e KUBECONFIG=/.kube/config"
32-
elif [ -n ${GOOGLE_APPLICATION_CREDENTIALS:=} ];then
33-
GKE_CREDS="-v ${GOOGLE_APPLICATION_CREDENTIALS}:/service-account.json:ro"
34-
else
35-
echo "Unable to find a suitable value for GOOGLE_APPLICATION_CREDENTIALS"
36-
exit 1
37-
fi
20+
21+
readonly IMAGE_TAG=v2.0.2
22+
readonly IMAGE_REPOSITORY="gcr.io/kubernetes-charts-ci/test-image"
23+
readonly REPO_ROOT="${REPO_ROOT:-$(git rev-parse --show-toplevel)}"
3824

3925
# Pull numbers are only available on presubmit jobs. When the tests are run as
4026
# part of a batch job (e.g., batch merge) the PULL_NUMBER is not available. Pull
4127
# numbers are useful for some debugging. When no PULL_NUMBER is supplied we build
4228
# from other info.
43-
PULL_INFO=${PULL_NUMBER:-}
29+
PULL_INFO="${PULL_NUMBER:-}"
4430
if [ -z "$PULL_INFO" ]; then
45-
PULL_INFO=${PULL_BASE_SHA}
31+
PULL_INFO="${PULL_BASE_SHA:-}"
4632
fi
33+
readonly PULL_INFO
34+
35+
main() {
36+
git remote add k8s https://github.com/kubernetes/charts
37+
git fetch k8s master
38+
39+
local config_container_id
40+
config_container_id=$(docker run -ti -d -v "$GOOGLE_APPLICATION_CREDENTIALS:/service-account.json" -v "$REPO_ROOT:/workdir" \
41+
-e "BUILD_ID=$JOB_TYPE-$PULL_INFO-$BUILD_ID" \
42+
"$IMAGE_REPOSITORY:$IMAGE_TAG" cat)
43+
44+
# shellcheck disable=SC2064
45+
trap "docker rm -f $config_container_id" EXIT
46+
47+
docker exec "$config_container_id" gcloud auth activate-service-account --key-file /service-account.json
48+
docker exec "$config_container_id" gcloud container clusters get-credentials jenkins --project kubernetes-charts-ci --zone us-west1-a
49+
docker exec "$config_container_id" kubectl cluster-info
50+
docker exec "$config_container_id" chart_test.sh --config /workdir/test/.testenv
51+
52+
echo "Done Testing!"
53+
}
4754

48-
docker run ${VOLUMES} ${GKE_CREDS} \
49-
-e GOOGLE_APPLICATION_CREDENTIALS=/service-account.json \
50-
-e "JOB_TYPE=$JOB_TYPE" \
51-
-e "PULL_INFO=$PULL_INFO" \
52-
-e "BUILD_ID=$BUILD_ID" \
53-
-e "VERIFICATION_PAUSE=${VERIFICATION_PAUSE:=0}" \
54-
${IMAGE_NAME} /src/test/changed.sh
55-
echo "Done Testing!"
55+
main

‎test/helm-test-e2e.sh

+24-11
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,41 @@
11
#!/usr/bin/env bash
22

3+
# Copyright 2018 The Kubernetes Authors. All rights reserved.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
#     http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
317
set -o errexit
418
set -o nounset
519
set -o pipefail
620
set -o xtrace
721

822
# Install and initialize helm/tiller
9-
HELM_URL=https://storage.googleapis.com/kubernetes-helm
10-
HELM_TARBALL=helm-v2.9.1-linux-amd64.tar.gz
23+
readonly HELM_URL=https://storage.googleapis.com/kubernetes-helm
24+
readonly HELM_TARBALL=helm-v2.9.1-linux-amd64.tar.gz
1125

12-
wget -q ${HELM_URL}/${HELM_TARBALL} -P ${WORKSPACE}
13-
tar xzfv ${WORKSPACE}/${HELM_TARBALL} -C ${WORKSPACE}
26+
wget -q "$HELM_URL/$HELM_TARBALL" -P "$WORKSPACE"
27+
tar xzfv "$WORKSPACE/$HELM_TARBALL" -C "$WORKSPACE"
1428

1529
# Housekeeping
30+
pushd "$WORKSPACE/linux-amd64"
31+
1632
kubectl -n kube-system create sa tiller
1733
kubectl create clusterrolebinding tiller --clusterrole cluster-admin --serviceaccount=kube-system:tiller
18-
${WORKSPACE}/linux-amd64/helm init --service-account tiller --upgrade
34+
./helm init --service-account tiller --upgrade
35+
./helm repo add incubator https://kubernetes-charts-incubator.storage.googleapis.com/
1936

20-
${WORKSPACE}/linux-amd64/helm repo add stable https://kubernetes-charts.storage.googleapis.com/
21-
${WORKSPACE}/linux-amd64/helm repo add incubator https://kubernetes-charts-incubator.storage.googleapis.com/
37+
popd
2238

2339
# Run test framework
24-
pushd .
25-
cd $GOPATH
2640
go get github.com/ghodss/yaml
27-
popd
28-
go run $GOPATH/src/k8s.io/charts/test/helm-test/main.go
41+
go run "$GOPATH/src/k8s.io/charts/test/helm-test/main.go"

‎test/pr-review.sh

-35
This file was deleted.

‎test/publish-docker.sh

-63
This file was deleted.

‎test/semvercompare.sh

-65
This file was deleted.

‎test/verify-release.sh

-79
This file was deleted.

0 commit comments

Comments
 (0)
Please sign in to comment.