Skip to content

Commit

Permalink
Add CI for kubectl-ng (#271)
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobtomlinson authored Jan 8, 2024
1 parent d3bce64 commit 74bcaa2
Show file tree
Hide file tree
Showing 7 changed files with 1,424 additions and 456 deletions.
63 changes: 63 additions & 0 deletions .github/workflows/kubectl-ng-test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
name: "Test kubectl-ng"
on:
pull_request:
paths:
- ".github/workflows/kubectl-ng-test.yaml"
- "examples/kubectl-ng/**"
push:
paths:
- ".github/workflows/kubectl-ng-test.yaml"
- "examples/kubectl-ng/**"

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

jobs:
test:
runs-on: ubuntu-latest
timeout-minutes: 45
strategy:
fail-fast: false
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
kubernetes-version: ["1.29.0"]
include:
- python-version: '3.10'
kubernetes-version: 1.28.0
- python-version: '3.10'
kubernetes-version: 1.27.3
- python-version: '3.10'
kubernetes-version: 1.26.6
env:
KUBECONFIG: .pytest-kind/pytest-kind/kubeconfig

steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install Poetry
uses: snok/install-poetry@v1
with:
virtualenvs-create: true
virtualenvs-in-project: true
installer-parallel: true
- name: Install kubectl-ng, dev version of kr8s and testing dependencies
run: |
pushd examples/kubectl-ng
poetry install --with test
popd
source examples/kubectl-ng/.venv/bin/activate
pip install .
- name: Run tests
env:
KUBERNETES_VERSION: ${{ matrix.kubernetes-version }}
run: |
source examples/kubectl-ng/.venv/bin/activate
pytest examples/kubectl-ng
- name: Debug k8s resources
if: always()
run: |
cat ${KUBECONFIG}
kubectl get all -A
8 changes: 8 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
name: "Test"
on:
pull_request:
paths:
- ".github/workflows/test.yaml"
- "kr8s/**"
- "./pyproject.toml"
push:
paths:
- ".github/workflows/.yaml"
- "kr8s/**"
- "./pyproject.toml"

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
Expand Down
9 changes: 5 additions & 4 deletions ci/update-kubernetes.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ def get_versions():
return data


def update_test_workflow(versions):
workflow = yaml.load(Path(".github/workflows/test.yaml"))
def update_workflow(versions, workflow):
workflow = yaml.load(Path(workflow))
workflow["jobs"]["test"]["strategy"]["matrix"]["kubernetes-version"][0] = versions[
0
]["latest_kind_container"]
Expand All @@ -69,7 +69,7 @@ def update_test_workflow(versions):
"kubernetes-version": version["latest_kind_container"],
}
)
yaml.dump(workflow, Path(".github/workflows/test.yaml"))
yaml.dump(workflow, Path(workflow))


def update_badges(filename, versions):
Expand All @@ -95,7 +95,8 @@ def main():
f"For {version['cycle']} using kindest/node {version['latest_kind_container']} until {version['eol']}"
)

update_test_workflow(versions)
update_workflow(versions, ".github/workflows/test.yaml")
update_workflow(versions, ".github/workflows/kubectl-ng-test.yaml")
update_badges("README.md", versions)
update_badges("docs/index.md", versions)

Expand Down
30 changes: 30 additions & 0 deletions conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import os
import time

import pytest
from pytest_kind.cluster import KindCluster


@pytest.fixture(scope="session", autouse=True)
def k8s_cluster(request) -> KindCluster:
image = None
if version := os.environ.get("KUBERNETES_VERSION"):
image = f"kindest/node:v{version}"

kind_cluster = KindCluster(
name="pytest-kind",
image=image,
)
kind_cluster.create()
os.environ["KUBECONFIG"] = str(kind_cluster.kubeconfig_path)
# CI fix, wait for default service account to be created before continuing
while True:
try:
kind_cluster.kubectl("get", "serviceaccount", "default")
break
except Exception:
time.sleep(1)
yield kind_cluster
del os.environ["KUBECONFIG"]
if not request.config.getoption("keep_cluster"): # pragma: no cover
kind_cluster.delete()
Loading

0 comments on commit 74bcaa2

Please sign in to comment.