Skip to content

Commit

Permalink
Use factored out testing lib (helm#5231)
Browse files Browse the repository at this point in the history
* [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
  • Loading branch information
unguiculus authored and or1can committed Jul 10, 2018
1 parent 4996654 commit 206719b
Show file tree
Hide file tree
Showing 19 changed files with 193 additions and 769 deletions.
27 changes: 20 additions & 7 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,28 @@
version: 2
jobs:
build:
lint-scripts:
docker:
- image: circleci/python:3.6.4
- image: koalaman/shellcheck-alpine
steps:
- checkout
- run:
name: install tools
command: test/circle/install.sh
name: lint
command: |
shellcheck -x test/build.sh
shellcheck -x test/e2e.sh
shellcheck -x test/helm-test-e2e.sh
shellcheck -x test/repo-sync.sh
lint-charts:
docker:
- image: gcr.io/kubernetes-charts-ci/test-image:v2.0.2
steps:
- checkout
- run:
name: lint
command: test/circle/lint.sh
command: |
git remote add k8s https://github.com/kubernetes/charts
git fetch k8s master
chart_test.sh --config test/.testenv --no-install
sync:
docker:
- image: google/cloud-sdk
Expand All @@ -21,9 +33,10 @@ jobs:
command: test/repo-sync.sh
workflows:
version: 2
test:
lint:
jobs:
- build
- lint-scripts
- lint-charts
sync:
triggers:
- schedule:
Expand Down
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,6 @@ Session.vim
.netrwhist

# Chart dependencies
**/charts/*.tgz
**/charts/*.tgz

.history
2 changes: 2 additions & 0 deletions test/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*
! .testenv
23 changes: 23 additions & 0 deletions test/.testenv
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# The name of the Git remote
REMOTE=k8s

# The name of the Git target branch
TARGET_BRANCH=master

# Chart directories separated by a space
CHART_DIRS=(
stable
incubator
)

# Charts that should be skipped
EXCLUDED_CHARTS=(
common
)

# Additional chart repos to add (<name>=<url>), separated by a space
CHART_REPOS=(
incubator=https://kubernetes-charts-incubator.storage.googleapis.com/
)

TIMEOUT=600
54 changes: 14 additions & 40 deletions test/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2016 The Kubernetes Authors All rights reserved.
# Copyright 2018 The Kubernetes Authors. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -12,45 +12,19 @@
# See the License for the specific language governing permissions and
# limitations under the License.

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

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

RUN set -x \
&& cd /opt \
&& echo 'debconf debconf/frontend select Noninteractive' | debconf-set-selections \
&& apt-get update \
&& apt-get install --no-install-recommends -y jq wget python git localepurge ca-certificates \
&& wget -q https://dl.google.com/dl/cloudsdk/channels/rapid/downloads/google-cloud-sdk-${GOOGLE_CLOUD_SDK_VERSION}-linux-x86_64.tar.gz \
&& tar zxfv google-cloud-sdk-${GOOGLE_CLOUD_SDK_VERSION}-linux-x86_64.tar.gz \
&& ./google-cloud-sdk/install.sh \
&& gcloud components install kubectl \
&& gcloud config set project ${GOOGLE_PROJECT}
RUN apt-get -y purge localepurge \
&& apt-get clean \
&& cd / \
&& rm -rf \
/opt/google-cloud-sdk-${GOOGLE_CLOUD_SDK_VERSION}-linux-x86_64.tar.gz \
/opt/helm-${HELM_VERSION}-linux-amd64.tar.gz \
doc \
man \
info \
locale \
/var/lib/apt/lists/* \
/var/log/* \
/var/cache/debconf/* \
common-licenses \
~/.bashrc \
/etc/systemd \
/lib/lsb \
/lib/udev \
/usr/share/doc/ \
/usr/share/doc-base/ \
/usr/share/man/ \
/tmp/*
RUN gcloud config set core/disable_usage_reporting true && \
gcloud config set component_manager/disable_update_check true && \
gcloud config set metrics/environment github_docker_image

VOLUME "/src"
WORKDIR "/src"
WORKDIR /workdir
13 changes: 2 additions & 11 deletions test/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,10 @@ The configuration of the Pull Request trigger is [in the config.json](https://gi

This snippet tells Test Infra to run the [test/e2e.sh](https://github.com/kubernetes/charts/blob/master/test/e2e.sh)
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)
to run the [test/changed.sh](https://github.com/kubernetes/charts/blob/master/test/changed.sh) script. This script
to run the [chart_test.sh](https://github.com/kubernetes-helm/chart-testing/blob/master/chart_test.sh) script. This script
is the main logic for validation of a pull request. It intends to only test charts that have changed in this PR.

The logic is as follows:

1. [Get credentials for the Kubernetes cluster used for testing.](https://github.com/kubernetes/charts/blob/master/test/changed.sh#L128)
1. [Install and initialize Helm](https://github.com/kubernetes/charts/blob/master/test/changed.sh#L143)
1. [For any charts that have changed](https://github.com/kubernetes/charts/blob/master/test/changed.sh#L161):
- Download dependent charts, if any, with `helm dep build`
- Run `helm install` in a new namespace for this PR build
- 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
- Run `helm test` on the release
- Delete the release
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.

#### Providing Custom Test Values

Expand Down
74 changes: 74 additions & 0 deletions test/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
#!/usr/bin/env bash

# Copyright 2018 The Kubernetes Authors. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

set -o errexit
set -o nounset
set -o pipefail

readonly IMAGE_TAG=v2.0.2
readonly IMAGE_REPOSITORY="gcr.io/kubernetes-charts-ci/test-image"
readonly SCRIPT_DIR=$(dirname "$(readlink -f "$0")")

show_help() {
cat << EOF
Usage: ${0##*/} <args>
-h, --help Display help
-v, --verbose Display verbose output
-p, --push Push image to registry
EOF
}

main() {
local verbose=
local push=

while :; do
case "${1:-}" in
-h|--help)
show_help
exit
;;
-v|--verbose)
verbose=true
;;
-p|--push)
push=true
;;
-?*)
printf 'WARN: Unknown option (ignored): %s\n' "$1" >&2
;;
*)
break
;;
esac

shift
done

[[ -n "$verbose" ]] && set -o xtrace

pushd "$SCRIPT_DIR"

docker build --tag "$IMAGE_REPOSITORY:$IMAGE_TAG" .

if [[ -n "$push" ]]; then
docker push "$IMAGE_REPOSITORY:$IMAGE_TAG"
fi

popd
}

main "$@"
Loading

0 comments on commit 206719b

Please sign in to comment.