Skip to content

Commit 556a259

Browse files
authored
Merge branch 'main' into fix-missing-interface
2 parents c977e64 + 4e96b1c commit 556a259

File tree

15 files changed

+583
-109
lines changed

15 files changed

+583
-109
lines changed

.github/workflows/helm-lint.yaml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# NOTE: This workflow can be run locally using https://github.com/nektos/act with:
2+
# act -W .github/workflows/helm-lint.yaml workflow_call -s GITHUB_TOKEN=$(gh auth token)
3+
name: Helm Lint
4+
on:
5+
workflow_call:
6+
inputs:
7+
ref:
8+
type: string
9+
description: The Git ref under test.
10+
required: true
11+
12+
jobs:
13+
lint:
14+
runs-on: ubuntu-latest
15+
steps:
16+
- name: Checkout
17+
uses: actions/checkout@v4
18+
with:
19+
ref: ${{ inputs.ref }}
20+
fetch-depth: 0
21+
22+
- name: Set up Helm
23+
uses: azure/setup-helm@v4
24+
with:
25+
version: v3.15.3
26+
27+
- name: Set up chart-testing
28+
uses: helm/chart-testing-action@v2
29+
30+
- name: Run chart-testing (lint)
31+
run: |-
32+
ct lint \
33+
--target-branch ${{ github.event.repository.default_branch }} \
34+
--charts chart/ \
35+
--validate-maintainers=false
36+
37+
- name: Run template validation
38+
run: |-
39+
helm template foo chart \
40+
| docker run -i --rm ghcr.io/yannh/kubeconform:latest \
41+
--strict --summary
42+
43+
- name: Run manifest snapshot test
44+
run: docker run -i --rm -v $(pwd):/apps helmunittest/helm-unittest chart

.github/workflows/test-pr.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@ jobs:
3131
with:
3232
ref: ${{ github.event.pull_request.head.sha }}
3333

34+
# Run the chart linting on every PR, even from external repos
35+
lint:
36+
uses: ./.github/workflows/helm-lint.yaml
37+
with:
38+
ref: ${{ github.event.pull_request.head.sha }}
39+
3440
# This job exists so that PRs from outside the main repo are rejected
3541
fail_on_remote:
3642
runs-on: ubuntu-latest

.github/workflows/tox.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ on:
1111
jobs:
1212
build:
1313
name: Tox unit tests and linting
14-
runs-on: ubuntu-latest
14+
runs-on: ubuntu-24.04
1515
strategy:
1616
matrix:
17-
python-version: ['3.10']
17+
python-version: ['3.12','3.13']
1818

1919
steps:
2020
- name: Check out the repository
@@ -41,5 +41,5 @@ jobs:
4141
- name: Archive code coverage results
4242
uses: actions/upload-artifact@v4
4343
with:
44-
name: code-coverage-report
44+
name: "code-coverage-report-${{ matrix.python-version }}"
4545
path: cover/

Dockerfile

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
FROM ubuntu:jammy AS python-builder
1+
FROM ubuntu:24.04 AS python-builder
22

33
RUN apt-get update && \
4-
apt-get install -y python3 python3-venv && \
5-
rm -rf /var/lib/apt/lists/*
4+
apt-get install -y python3 python3-venv
65

76
RUN python3 -m venv /venv && \
87
/venv/bin/pip install -U pip setuptools
@@ -14,16 +13,16 @@ COPY . /app
1413
RUN /venv/bin/pip install /app
1514

1615

17-
FROM ubuntu:jammy
16+
FROM ubuntu:24.04
1817

1918
# Don't buffer stdout and stderr as it breaks realtime logging
20-
ENV PYTHONUNBUFFERED 1
19+
ENV PYTHONUNBUFFERED=1
2120

2221
# Create the user that will be used to run the app
23-
ENV APP_UID 1001
24-
ENV APP_GID 1001
25-
ENV APP_USER app
26-
ENV APP_GROUP app
22+
ENV APP_UID=1001
23+
ENV APP_GID=1001
24+
ENV APP_USER=app
25+
ENV APP_GROUP=app
2726
RUN groupadd --gid $APP_GID $APP_GROUP && \
2827
useradd \
2928
--no-create-home \
@@ -40,5 +39,4 @@ RUN apt-get update && \
4039
COPY --from=python-builder /venv /venv
4140

4241
USER $APP_UID
43-
ENTRYPOINT ["tini", "-g", "--"]
44-
CMD ["/venv/bin/kopf", "run", "--module", "capi_janitor.openstack.operator", "--all-namespaces"]
42+
CMD ["/venv/bin/kopf", "run", "--module", "capi_janitor.openstack.operator", "--all-namespaces", "--verbose"]

README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,26 @@ helm upgrade \
2424
--install
2525
```
2626

27+
## Tox for unittests and linting
28+
29+
We use tox to run unit tests and linters across the code.
30+
To run all the checks, including efforts to automatically
31+
fix linting issues, please run:
32+
33+
```sh
34+
tox
35+
```
36+
37+
You can run individual unit tests by running:
38+
39+
```sh
40+
tox -e py3 -- <name-of-unit-test>
41+
```
42+
43+
Note, failures on your initial tox run may be automatically
44+
fixed, where possible. So your second tox run may pass.
45+
This way we can run the default tox target in CI.
46+
2747
## Configuration
2848

2949
`cluster-api-janitor-openstack` will always clean up

capi_janitor/openstack/openstack.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import urllib.parse
55

66
import httpx
7-
87
from easykube import rest
98

109

capi_janitor/openstack/operator.py

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,10 @@
55
import random
66
import string
77

8-
import kopf
9-
import yaml
10-
118
import easykube
129
import httpx
10+
import kopf
11+
import yaml
1312

1413
from . import openstack
1514

@@ -47,9 +46,7 @@ async def on_startup(**kwargs):
4746

4847
@kopf.on.cleanup()
4948
async def on_cleanup(**kwargs):
50-
"""
51-
Runs on operator shutdown.
52-
"""
49+
"""Runs on operator shutdown."""
5350
# Make sure that the easykube client is shut down properly
5451
await ekclient.aclose()
5552

@@ -105,7 +102,6 @@ async def secgroups_for_cluster(resource, cluster):
105102

106103
async def filtered_volumes_for_cluster(resource, cluster):
107104
"""Async iterator for volumes belonging to the specified cluster."""
108-
109105
async for vol in resource.list():
110106
# CSI Cinder sets metadata on the volumes that we can look for
111107
owner = vol.metadata.get("cinder.csi.openstack.org/cluster")
@@ -162,7 +158,6 @@ async def purge_openstack_resources(
162158
logger, clouds, cloud_name, cacert, name, include_volumes, include_appcred
163159
):
164160
"""Cleans up the OpenStack resources created by the OCCM and CSI for a cluster."""
165-
166161
# Use the credential to delete external resources as required
167162
async with openstack.Cloud.from_clouds(clouds, cloud_name, cacert) as cloud:
168163
if not cloud.is_authenticated:
@@ -360,7 +355,6 @@ async def _on_openstackcluster_event_impl(
360355
name, namespace, meta, labels, spec, logger, **kwargs
361356
):
362357
"""Executes whenever an event occurs for an OpenStack cluster."""
363-
364358
# Get the resource for manipulating OpenStackClusters at the preferred version
365359
openstackclusters = await _get_os_cluster_client()
366360

@@ -375,7 +369,10 @@ async def _on_openstackcluster_event_impl(
375369
if not meta.get("deletionTimestamp"):
376370
if FINALIZER not in finalizers:
377371
await patch_finalizers(
378-
openstackclusters, name, namespace, finalizers + [FINALIZER]
372+
openstackclusters,
373+
name,
374+
namespace,
375+
[*finalizers, FINALIZER],
379376
)
380377
logger.info("added janitor finalizer to cluster")
381378
return

0 commit comments

Comments
 (0)