Skip to content

Commit cad8ca9

Browse files
unguiculusk8s-ci-robot
authored andcommitted
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 "$@"

0 commit comments

Comments
 (0)