Skip to content

Commit be29e59

Browse files
[CLOUDP-343558] Run helm chart-testing tool ct as part of CI (lint_repo) (mongodb#450)
# Summary Whenever we raised PR in to helm chart repo CI failed there because we had linting issues in our helm chart. A previous PR that [I raised](mongodb#445) fixed the linting problem. But we should have a linting mechanism in our CI that would consistently check if we have made any mistake in our charts. This PR does that. The `chart_schema.yaml` and `lintconf.yaml` are the default yaml files using which `ct` should be run. And `ct` is the tool that is used for linting in our helm charts repo. ## Proof of Work Passing `lint_repo` task here https://spruce.mongodb.com/version/68c43aae1d5d5d000770c624/tasks?sorts=STATUS%3AASC%3BBASE_STATUS%3ADESC and in this PR as well. ## Checklist - [x] Have you linked a jira ticket and/or is the ticket in the title? - [x] Have you checked whether your jira ticket required DOCSP changes? - [x] Have you added changelog file? - use `skip-changelog` label if not needed - refer to [Changelog files and Release Notes](https://github.com/mongodb/mongodb-kubernetes/blob/master/CONTRIBUTING.md#changelog-files-and-release-notes) section in CONTRIBUTING.md for more details
1 parent 4e4ad0b commit be29e59

File tree

9 files changed

+145
-1
lines changed

9 files changed

+145
-1
lines changed

.evergreen-functions.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,13 @@ functions:
250250
add_to_path:
251251
- ${workdir}/bin
252252
command: scripts/evergreen/setup_yq.sh
253+
- command: subprocess.exec
254+
type: setup
255+
params:
256+
working_dir: src/github.com/mongodb/mongodb-kubernetes
257+
add_to_path:
258+
- ${workdir}/bin
259+
command: scripts/dev/setup_chart_testing_cli.sh
253260
- command: subprocess.exec
254261
type: test
255262
params:

.githooks/pre-commit

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,10 @@ lint_code() {
163163
scripts/evergreen/lint_code.sh
164164
}
165165

166+
lint_helm_chart() {
167+
scripts/dev/lint_helm_chart.sh
168+
}
169+
166170
function validate_snippets() {
167171
scripts/code_snippets/validate_snippets.py
168172
}
@@ -222,6 +226,7 @@ pre_commit() {
222226
run_job_in_background "python_formatting"
223227
run_job_in_background "check_erroneous_kubebuilder_annotations"
224228
run_job_in_background "validate_snippets"
229+
run_job_in_background "lint_helm_chart"
225230

226231
if wait_for_all_background_jobs; then
227232
echo -e "${GREEN}pre-commit: All checks passed!${NO_COLOR}"

Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -420,3 +420,7 @@ prepare-local-olm-e2e:
420420

421421
prepare-operator-configmap: # prepares the local environment to run a local operator
422422
source scripts/dev/set_env_context.sh && source scripts/funcs/printing && source scripts/funcs/operator_deployment && prepare_operator_config_map "$(kubectl config current-context)"
423+
424+
# Lint the helm chart using helm chart-testing tool (`ct`) using the default configuration available at `helm_chart/tests/schemas/`
425+
lint-chart:
426+
scripts/dev/lint_helm_chart.sh
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: str()
2+
home: str(required=False)
3+
version: str()
4+
apiVersion: str()
5+
appVersion: any(str(), num(), required=False)
6+
description: str(required=False)
7+
keywords: list(str(), required=False)
8+
sources: list(str(), required=False)
9+
maintainers: list(include('maintainer'), required=False)
10+
dependencies: list(include('dependency'), required=False)
11+
icon: str(required=False)
12+
engine: str(required=False)
13+
condition: str(required=False)
14+
tags: str(required=False)
15+
deprecated: bool(required=False)
16+
kubeVersion: str(required=False)
17+
annotations: map(str(), str(), required=False)
18+
type: str(required=False)
19+
---
20+
maintainer:
21+
name: str()
22+
email: str(required=False)
23+
url: str(required=False)
24+
---
25+
dependency:
26+
name: str()
27+
version: str()
28+
repository: str(required=False)
29+
condition: str(required=False)
30+
tags: list(str(), required=False)
31+
enabled: bool(required=False)
32+
import-values: list(any(str(), include('import-value')), required=False)
33+
alias: str(required=False)
34+
---
35+
import-value:
36+
child: str()
37+
parent: str()
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
---
2+
rules:
3+
braces:
4+
min-spaces-inside: 0
5+
max-spaces-inside: 0
6+
min-spaces-inside-empty: -1
7+
max-spaces-inside-empty: -1
8+
brackets:
9+
min-spaces-inside: 0
10+
max-spaces-inside: 0
11+
min-spaces-inside-empty: -1
12+
max-spaces-inside-empty: -1
13+
colons:
14+
max-spaces-before: 0
15+
max-spaces-after: 1
16+
commas:
17+
max-spaces-before: 0
18+
min-spaces-after: 1
19+
max-spaces-after: 1
20+
comments:
21+
require-starting-space: true
22+
min-spaces-from-content: 2
23+
document-end: disable
24+
document-start: disable # No --- to start a file
25+
empty-lines:
26+
max: 2
27+
max-start: 0
28+
max-end: 0
29+
hyphens:
30+
max-spaces-after: 1
31+
indentation:
32+
spaces: consistent
33+
indent-sequences: whatever # - list indentation will handle both indentation and without
34+
check-multi-line-strings: false
35+
key-duplicates: enable
36+
line-length: disable # Lines can be any length
37+
new-line-at-end-of-file: enable
38+
new-lines:
39+
type: unix
40+
trailing-spaces: enable
41+
truthy:
42+
level: warning

requirements.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ botocore==1.40.7
3535
boto3==1.40.7
3636
python-frontmatter==1.1.0
3737
python-on-whales==0.78.0
38+
yamale==6.0.0
39+
yamllint==1.37.1
3840

3941
# from kubeobject
4042
freezegun==1.5.5

scripts/dev/install.sh

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ set -Eeou pipefail
44
source scripts/funcs/printing
55
source scripts/dev/set_env_context.sh
66

7-
tools="kubectl helm coreutils kind jq shellcheck python@${PYTHON_VERSION}"
7+
tools="kubectl helm coreutils kind jq shellcheck python@${PYTHON_VERSION} chart-testing"
88
echo "The following tools will be installed using homebrew: ${tools}"
99
echo "Note, that you must download 'go' and Docker by yourself"
1010

@@ -28,6 +28,9 @@ elif [ "$(uname)" = "Linux" ] ; then # Ubuntu only
2828

2929
sudo snap install --channel=edge shellcheck
3030

31+
# install helm chart testing tool chart-testing (ct)
32+
./setup_chart_testing_cli.sh
33+
3134
else
3235
echo "This only works on OSX & Ubuntu - please install the tools yourself. Sorry!"
3336
exit 1

scripts/dev/lint_helm_chart.sh

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/usr/bin/env bash
2+
set -Eeou pipefail
3+
4+
source scripts/dev/set_env_context.sh
5+
6+
if ! command -v ct &> /dev/null; then
7+
echo "Error: 'ct' command not found in PATH. Please download it from here https://github.com/helm/chart-testing" >&2
8+
exit 1
9+
fi
10+
11+
if [ -z "${PROJECT_DIR}" ]; then
12+
echo "Error: PROJECT_DIR environment variable is not set. Please set a context or set it (PROJECT_DIR var) to your local MCK repo manually." >&2
13+
exit 1
14+
fi
15+
16+
# the binaries yamale and yamllint required by ct are available at `${PROJECT_DIR}/venv/bin`
17+
export PATH=${PROJECT_DIR}/venv/bin:${PATH}
18+
19+
ct lint --charts="${PROJECT_DIR}/helm_chart/" \
20+
--chart-yaml-schema "${PROJECT_DIR}/helm_chart/tests/schemas/chart_schema.yaml" \
21+
--lint-conf "${PROJECT_DIR}/helm_chart/tests/schemas/lintconf.yaml"
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/usr/bin/env bash
2+
3+
# A script Evergreen will use to setup helm chart testing CLI (https://github.com/helm/chart-testing)
4+
#
5+
# This should be executed from root of the evergreen build dir
6+
7+
set -Eeou pipefail
8+
9+
source scripts/dev/set_env_context.sh
10+
11+
if [[ -n "${PROJECT_DIR:-}" ]]; then
12+
bindir="${PROJECT_DIR}/bin"
13+
tmpdir="${PROJECT_DIR}/tmp"
14+
else
15+
bindir="${GOPATH}/bin"
16+
tmpdir="${GOPATH}/tmp"
17+
fi
18+
19+
mkdir -p "${bindir}" "${tmpdir}"
20+
21+
curl -s --retry 3 -L -o "${tmpdir}/chart-testing_3.13.0_linux_amd64.tar.gz" "https://github.com/helm/chart-testing/releases/download/v3.13.0/chart-testing_3.13.0_linux_amd64.tar.gz"
22+
tar xvf "${tmpdir}/chart-testing_3.13.0_linux_amd64.tar.gz" -C "${tmpdir}/"
23+
mv "${tmpdir}/ct" "${bindir}"

0 commit comments

Comments
 (0)