1
0
mirror of https://github.com/helm/chart-testing.git synced 2026-02-05 09:45:14 +01:00

Add an option to force install of all/single charts (#24)

* Add an option to force install of all/single chart

Signed-off-by: rimas <rmocius@gmail.com>

* replace flag `--force` with `--chart-all`
add an option to list charts for `--chart` flag

Signed-off-by: rimas <rmocius@gmail.com>

* address mattfarina and unguiculus comments

Signed-off-by: rimas <rmocius@gmail.com>

* fixing merge conflicts

Signed-off-by: rimas <rmocius@gmail.com>

* fixing merge conflicts 2

Signed-off-by: rimas <rmocius@gmail.com>

* fixing merge conflicts 3

Signed-off-by: rimas <rmocius@gmail.com>

* exporting CHECK_VERSION_INCREMENT before chart_lib.sh is sourced

Signed-off-by: rimas <rmocius@gmail.com>

* fix --chart -> --charts

Signed-off-by: rimas <rmocius@gmail.com>

* print skip version check before env vars

Signed-off-by: rimas <rmocius@gmail.com>

* Fix readme

Signed-off-by: Reinhard Nägele <unguiculus@gmail.com>
This commit is contained in:
Rimas Mocevicius
2018-09-21 16:58:02 +03:00
committed by Matt Farina
parent 9dfea37f89
commit 48e81aaa43
3 changed files with 105 additions and 7 deletions

View File

@@ -39,7 +39,12 @@ Usage: chart_test.sh <options>
--verbose Display verbose output
--no-lint Skip chart linting
--no-install Skip chart installation
--all Lint/install all charts
--charts Lint/install:
a standalone chart (e. g. stable/nginx)
a list of charts (e. g. stable/nginx,stable/cert-manager)
--config Path to the config file (optional)
-- End of all options
```
## Configuration
@@ -58,8 +63,8 @@ Note that this must be done before the script is sourced.
| `LINT_CONF` | Config file for YAML linter | `/testing/etc/lintconf.yaml` (path of default config file in Docker image) |
| `CHART_YAML_SCHEMA` | YAML schema for `Chart.yaml` | `/testing/etc/chart_schema.yaml` (path of default schema file in Docker image) |
| `VALIDATE_MAINTAINERS`| If `true`, maintainer names in `Chart.yaml` are validated to be existing Github accounts | `true` |
| `CHECK_VERSION_INCREMENT`| If `true`, the chart version is checked to be incremented from the version on the remote target branch | `true` |
| `GITHUB_INSTANCE`| Url of Github instance for maintainer validation | `https://github.com` |
| `CHECK_VERSION_INCREMENT`| If `true`, the chart version is checked to be incremented from the version on the remote target branch | `true` |
Note that `CHART_DIRS`, `EXCLUDED_CHARTS`, and `CHART_REPOS` must be configured as Bash arrays.
@@ -141,6 +146,26 @@ Linting chart 'stable/dummy'...
Done.
```
#### Linting Unchanged Charts
You can lint all charts with `--all` flag (chart version bump check will be ignored):
```shell
docker run --rm -v "$(pwd):/workdir" --workdir /workdir quay.io/helmpack/chart-testing:v1.0.5 chart_test.sh --no-install --config .mytestenv --all
```
You can lint a list of charts (separated by comma) with `--charts` flag (chart version bump check will be ignored):
```shell
docker run --rm -v "$(pwd):/workdir" --workdir /workdir quay.io/helmpack/chart-testing:v1.0.5 chart_test.sh --no-install --config .mytestenv --charts stable/nginx,stable/cert-manager
```
You can lint a single chart with `--charts` flag (chart version bump check will be ignored):
```shell
docker run --rm -v "$(pwd):/workdir" --workdir /workdir quay.io/helmpack/chart-testing:v1.0.5 chart_test.sh --no-install --config .mytestenv --charts stable/nginx
```
### Installing and Testing Charts
Installing a chart requires access to a Kubernetes cluster.
@@ -156,12 +181,31 @@ Make sure you set it based on the pull request number.
docker run --rm -v "$(pwd):/workdir" --workdir /workdir quay.io/helmpack/chart-testing:v1.0.5 chart_test.sh --no-lint --config .mytestenv
```
#### Installing Unchanged Charts
You can force to install all charts with `--all` flag:
```shell
docker run --rm -v "$(pwd):/workdir" --workdir /workdir quay.io/helmpack/chart-testing:v1.0.5 chart_test.sh --no-lint --config .mytestenv --all
```
You can force to install a list of charts (separated by comma) with `--charts` flag:
```shell
docker run --rm -v "$(pwd):/workdir" --workdir /workdir quay.io/helmpack/chart-testing:v1.0.5 chart_test.sh --no-lint --config .mytestenv --charts stable/nginx,stable/cert-manager
```
You can force to install one chart with `--charts` flag:
```shell
docker run --rm -v "$(pwd):/workdir" --workdir /workdir quay.io/helmpack/chart-testing:v1.0.5 chart_test.sh --no-lint --config .mytestenv --charts stable/nginx
```
#### GKE Example
An example for GKE is available in the [examples/gke](examples/gke) directory.
A custom `Dockerfile` additionally installs the `google-cloud-sdk` and a custom shell script puts everything together.
#### Docker for Mac Example
An example for Docker for Mac is available in the [examples/docker-for-mac](examples/docker-for-mac) directory.

View File

@@ -29,16 +29,22 @@ Usage: $(basename "$0") <options>
--verbose Display verbose output
--no-lint Skip chart linting
--no-install Skip chart installation
--all Lint/install all charts
--charts Lint/install:
a standalone chart (e. g. stable/nginx)
a list of charts (e. g. stable/nginx,stable/cert-manager)
--config Path to the config file (optional)
-- End of all options
EOF
}
main() {
local no_lint=
local no_install=
local config=
local verbose=
local no_install=
local no_lint=
local config=
local all=
local charts=
while :; do
case "${1:-}" in
@@ -55,6 +61,18 @@ main() {
--no-lint)
no_lint=true
;;
--all)
all=true
;;
--charts)
if [ -n "$2" ]; then
charts="$2"
shift
else
echo "ERROR: '--charts' cannot be empty." >&2
exit 1
fi
;;
--config)
if [ -n "$2" ]; then
config="$2"
@@ -85,6 +103,10 @@ main() {
fi
fi
if [[ "$all" == "true" || -n "$charts" ]]; then
export CHECK_VERSION_INCREMENT=false
fi
# shellcheck source=lib/chartlib.sh
source "$SCRIPT_DIR/lib/chartlib.sh"
@@ -101,7 +123,14 @@ main() {
local exit_code=0
read -ra changed_dirs <<< "$(chartlib::detect_changed_directories)"
if [[ "$all" == "true" ]]; then
read -ra changed_dirs <<< "$(chartlib::read_directories)"
elif [[ -n "$charts" ]]; then
charts="${charts//,/ }"
read -ra changed_dirs <<< "${charts}"
else
read -ra changed_dirs <<< "$(chartlib::detect_changed_directories)"
fi
if [[ -n "${changed_dirs[*]}" ]]; then
echo "Charts to be installed and tested: ${changed_dirs[*]}"

View File

@@ -26,8 +26,8 @@ readonly TIMEOUT="${TIMEOUT:-300}"
readonly LINT_CONF="${LINT_CONF:-/testing/etc/lintconf.yaml}"
readonly CHART_YAML_SCHEMA="${CHART_YAML_SCHEMA:-/testing/etc/chart_schema.yaml}"
readonly VALIDATE_MAINTAINERS="${VALIDATE_MAINTAINERS:-true}"
readonly CHECK_VERSION_INCREMENT="${CHECK_VERSION_INCREMENT:-true}"
readonly GITHUB_INSTANCE="${GITHUB_INSTANCE:-https://github.com}"
readonly CHECK_VERSION_INCREMENT="${CHECK_VERSION_INCREMENT:-true}"
# Special handling for arrays
[[ -z "${CHART_DIRS[*]}" ]] && CHART_DIRS=(charts); readonly CHART_DIRS
@@ -35,6 +35,10 @@ readonly GITHUB_INSTANCE="${GITHUB_INSTANCE:-https://github.com}"
[[ -z "${CHART_REPOS[*]}" ]] && CHART_REPOS=(); readonly CHART_REPOS
echo
if [[ "$CHECK_VERSION_INCREMENT" == false ]]; then
echo '--------------------------------------------------------------------------------'
echo " SKIPPING VERSION INCREMENT CHECK!"
fi
echo '--------------------------------------------------------------------------------'
echo ' Environment:'
echo " REMOTE=$REMOTE"
@@ -51,6 +55,25 @@ echo " CHECK_VERSION_INCREMENT=$CHECK_VERSION_INCREMENT"
echo '--------------------------------------------------------------------------------'
echo
# Read chart directories to be used with --force
chartlib::read_directories() {
local dir
while read -r dir; do
local excluded=
for excluded_dir in "${EXCLUDED_CHARTS[@]}"; do
if [[ "$dir" == "$excluded_dir" ]]; then
excluded=true
break
fi
done
if [[ -z "$excluded" && -d "$dir" ]]; then
changed_dirs=("${changed_dirs[@]}" "$dir")
fi
done < <(find "${CHART_DIRS[@]}" -mindepth 1 -maxdepth 1 -type d | awk -F/ '{ print $1"/"$2 }' | uniq)
echo "${changed_dirs[@]}"
}
# Detects chart directories that have changes against the
# target branch ("$REMOTE/$TARGET_BRANCH").
@@ -221,6 +244,8 @@ chartlib::validate_chart() {
if [[ "$CHECK_VERSION_INCREMENT" == true ]]; then
chartlib::check_for_version_bump "$chart_dir" || error=true
else
echo "Skipping version increment check!"
fi
chartlib::lint_yaml_file "$chart_dir/Chart.yaml" || error=true