Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: add helm test step to gh-actions #895

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/ci/ct.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
chart-dirs:
- charts
helm-extra-args: "--timeout=5m"
helm-extra-set-args: "--set=kind=Deployment --set=podSecurityPolicy.create=false"
check-version-increment: false
target-branch: master
26 changes: 25 additions & 1 deletion .github/workflows/helm.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ on:
- release-*
paths:
- 'charts/**'
- '.github/workflows/helm.yaml'
pull_request:
paths:
- 'charts/**'
- '.github/workflows/helm.yaml'

jobs:
lint-and-test:
Expand All @@ -23,14 +25,16 @@ jobs:
- name: Set up Helm
uses: azure/[email protected]
with:
version: v3.4.2
version: v3.9.2

- uses: actions/[email protected]
with:
python-version: 3.7

- name: Set up chart-testing
uses: helm/[email protected]
with:
version: v3.7.0

- name: Run chart-testing (list-changed)
id: list-changed
Expand All @@ -39,6 +43,26 @@ jobs:
if [[ -n "$changed" ]]; then
echo "::set-output name=changed::true"
fi

# Force linting/test in debug runs with a change (this action only runs on chart and helm.yaml workflow diffs anyways)
- name: Change Kind to deployment
run: "sed -i \"s|kind: [^ ]*|kind: Deployment|g\" charts/descheduler/values.yaml"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this seems odd to do, when we can have a specific values file that can do this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was only to force ct lint and ct install to show changes, it is unrelated to this value change itself. I want to remove this when the work is finished.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Initially I was planning on leaving this, but now I see it is too ugly/confusing 😅

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will wait for lgtms and approves, but /hold so I remember to remove this line when reviews are done


- name: Run chart-testing (lint)
run: ct lint --config=.github/ci/ct.yaml --validate-maintainers=false

# Need a multi node cluster so descheduler runs until evictions
- name: Create multi node Kind cluster
run: |
kind create cluster --name kind --config ./hack/kind_config.yaml --wait 2m

# helm-extra-set-args only available after ct 3.6.0
- name: Run chart-testing (install)
run: ct install --config=.github/ci/ct.yaml

- name: E2E after chart install
env:
KUBERNETES_VERSION: "v1.24.0"
KIND_E2E: true
SKIP_INSTALL: true
run: make test-e2e
7 changes: 5 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -148,5 +148,8 @@ lint-chart: ensure-helm-install
build-helm:
helm package ./charts/descheduler --dependency-update --destination ./bin/chart

test-helm: ensure-helm-install
./test/run-helm-tests.sh
kind-multi-node:
kind create cluster --name kind --config ./hack/kind_config.yaml --wait 2m

ct-helm:
./hack/verify-chart.sh
30 changes: 0 additions & 30 deletions charts/descheduler/templates/tests/test-descheduler-pod.yaml

This file was deleted.

26 changes: 12 additions & 14 deletions docs/contributor-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,27 +31,14 @@ View all CLI options.
## Run Tests
```
GOOS=linux make dev-image
kind create cluster --config hack/kind_config.yaml
make kind-multi-node
kind load docker-image <image name>
kind get kubeconfig > /tmp/admin.conf
export KUBECONFIG=/tmp/admin.conf
make test-unit
make test-e2e
```

## Run Helm Tests
Run the helm test for a particular descheduler release by setting below variables,
```
HELM_IMAGE_REPO="descheduler"
HELM_IMAGE_TAG="helm-test"
HELM_CHART_LOCATION="./charts/descheduler"
```
The helm tests runs as part of descheduler CI. But, to run it manually from the descheduler root,

```
make test-helm
knelasevero marked this conversation as resolved.
Show resolved Hide resolved
```

## Build Helm Package locally

If you made some changes in the chart, and just want to check if templating is ok, or if the chart is buildable, you can run this command to have a package built from the `./charts` directory.
Expand All @@ -68,5 +55,16 @@ To check linting of your changes in the helm chart locally you can run:
make lint-helm
```

## Test helm changes locally with kind and ct

You will need kind and docker (or equivalent) installed. We can use ct public image to avoid installing ct and all its dependencies.


```
make kind-multi-node
make ct-helm
```


### Miscellaneous
See the [hack directory](https://github.com/kubernetes-sigs/descheduler/tree/master/hack) for additional tools and scripts used for developing the descheduler.
3 changes: 3 additions & 0 deletions hack/verify-chart.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash

docker run -it --rm --network host --workdir=/data --volume ~/.kube/config:/root/.kube/config:ro --volume $(pwd):/data quay.io/helmpack/chart-testing:v3.7.0 /bin/bash -c "git config --global --add safe.directory /data; ct install --config=.github/ci/ct.yaml --helm-extra-set-args=\"--set=kind=Deployment --set=podSecurityPolicy.create=false\""
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For some reason when calling from make the helm-extra-set-args from .github/ci/ct.yaml are being ignored... had to set them manually here as arguments of ct.

20 changes: 13 additions & 7 deletions test/run-e2e-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,21 @@ set -x
set -o errexit
set -o nounset

# Set to empty if unbound/empty
SKIP_INSTALL=${SKIP_INSTALL:-}

# This just runs e2e tests.
if [ -n "$KIND_E2E" ]; then
K8S_VERSION=${KUBERNETES_VERSION:-v1.24.0}
curl -Lo kubectl https://storage.googleapis.com/kubernetes-release/release/${K8S_VERSION}/bin/linux/amd64/kubectl && chmod +x kubectl && mv kubectl /usr/local/bin/
wget https://github.com/kubernetes-sigs/kind/releases/download/v0.13.0/kind-linux-amd64
chmod +x kind-linux-amd64
mv kind-linux-amd64 kind
export PATH=$PATH:$PWD
kind create cluster --image kindest/node:${K8S_VERSION} --config=./hack/kind_config.yaml
# If we did not set SKIP_INSTALL
if [ -z "$SKIP_INSTALL" ]; then
K8S_VERSION=${KUBERNETES_VERSION:-v1.24.0}
curl -Lo kubectl https://storage.googleapis.com/kubernetes-release/release/${K8S_VERSION}/bin/linux/amd64/kubectl && chmod +x kubectl && mv kubectl /usr/local/bin/
wget https://github.com/kubernetes-sigs/kind/releases/download/v0.13.0/kind-linux-amd64
chmod +x kind-linux-amd64
mv kind-linux-amd64 kind
export PATH=$PATH:$PWD
kind create cluster --image kindest/node:${K8S_VERSION} --config=./hack/kind_config.yaml
fi
docker pull kubernetes/pause
kind load docker-image kubernetes/pause
kind get kubeconfig > /tmp/admin.conf
Expand Down
37 changes: 0 additions & 37 deletions test/run-helm-tests.sh

This file was deleted.