mirror of
https://github.com/cmur2/kube-stale-resources.git
synced 2024-12-22 12:54:25 +01:00
ci: add e2e tests using kind + k8s
This commit is contained in:
parent
9ada4edb06
commit
297c5e6a28
36
.github/workflows/ci.yml
vendored
36
.github/workflows/ci.yml
vendored
@ -9,9 +9,9 @@ jobs:
|
|||||||
build:
|
build:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v1
|
- uses: actions/checkout@v2
|
||||||
- name: Set up Python 3.8
|
- name: Set up Python 3.8
|
||||||
uses: actions/setup-python@v1
|
uses: actions/setup-python@v2
|
||||||
with:
|
with:
|
||||||
python-version: 3.8
|
python-version: 3.8
|
||||||
- name: Install dependencies
|
- name: Install dependencies
|
||||||
@ -21,3 +21,35 @@ jobs:
|
|||||||
- name: Linting
|
- name: Linting
|
||||||
run: |
|
run: |
|
||||||
make lint
|
make lint
|
||||||
|
|
||||||
|
e2e-with-kind:
|
||||||
|
name: e2e with kind
|
||||||
|
needs: build
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
k8s-version:
|
||||||
|
- v1.16.9
|
||||||
|
- v1.18.8
|
||||||
|
env:
|
||||||
|
kind-version: v0.8.1
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
- name: Set up Python 3.8
|
||||||
|
uses: actions/setup-python@v2
|
||||||
|
with:
|
||||||
|
python-version: 3.8
|
||||||
|
- name: Install dependencies
|
||||||
|
run: |
|
||||||
|
pip install poetry
|
||||||
|
poetry install
|
||||||
|
- name: Set up kind with K8s version ${{ matrix.k8s-version }}
|
||||||
|
uses: engineerd/setup-kind@v0.4.0
|
||||||
|
with:
|
||||||
|
image: kindest/node:${{ matrix.k8s-version }}
|
||||||
|
version: ${{ env.kind-version }}
|
||||||
|
- name: E2E test
|
||||||
|
run: |
|
||||||
|
kubectl cluster-info
|
||||||
|
kubectl proxy &
|
||||||
|
make e2e-with-kind
|
||||||
|
20
Makefile
20
Makefile
@ -18,6 +18,26 @@ lint: ## Lint all source code
|
|||||||
poetry run pylint *.py
|
poetry run pylint *.py
|
||||||
poetry run mypy *.py
|
poetry run mypy *.py
|
||||||
|
|
||||||
|
.PHONY: e2e-with-kind
|
||||||
|
e2e-with-kind: ## Run E2E tests against running kind (K8s in Docker) instance
|
||||||
|
function cleanup {
|
||||||
|
(kubectl delete namespace e2e || true)
|
||||||
|
}
|
||||||
|
trap cleanup EXIT
|
||||||
|
|
||||||
|
# no resources and empty cluster should have no stale resources
|
||||||
|
poetry run python kube-stale-resources.py --blacklist e2e/blacklist-kind-empty.txt -f e2e/resources-kind-empty.yml
|
||||||
|
|
||||||
|
# some resources in VCS and empty cluster should have no stale resources
|
||||||
|
kubectl apply -f e2e/resources-kind-one.yml
|
||||||
|
poetry run python kube-stale-resources.py --blacklist e2e/blacklist-kind-empty.txt -f e2e/resources-kind-one.yml
|
||||||
|
cleanup
|
||||||
|
|
||||||
|
# some resources NOT in VCS and empty cluster should have stale resources
|
||||||
|
kubectl apply -f e2e/resources-kind-one.yml
|
||||||
|
(poetry run python kube-stale-resources.py --blacklist e2e/blacklist-kind-empty.txt -f e2e/resources-kind-empty.yml && exit 1 || exit 0)
|
||||||
|
cleanup
|
||||||
|
|
||||||
.PHONY: help
|
.PHONY: help
|
||||||
help: ## Print this help text
|
help: ## Print this help text
|
||||||
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-15s\033[0m %s\n", $$1, $$2}'
|
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-15s\033[0m %s\n", $$1, $$2}'
|
||||||
|
2
e2e/blacklist-kind-empty.txt
Normal file
2
e2e/blacklist-kind-empty.txt
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
^default:events.k8s.io/v1beta1:Event:kind-.*$
|
||||||
|
^local-path-storage:.*$
|
0
e2e/resources-kind-empty.yml
Normal file
0
e2e/resources-kind-empty.yml
Normal file
19
e2e/resources-kind-one.yml
Normal file
19
e2e/resources-kind-one.yml
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
---
|
||||||
|
apiVersion: v1
|
||||||
|
kind: Namespace
|
||||||
|
metadata:
|
||||||
|
name: e2e
|
||||||
|
---
|
||||||
|
apiVersion: v1
|
||||||
|
kind: Service
|
||||||
|
metadata:
|
||||||
|
name: foo
|
||||||
|
namespace: e2e
|
||||||
|
spec:
|
||||||
|
type: ClusterIP
|
||||||
|
ports:
|
||||||
|
- port: 80
|
||||||
|
name: http
|
||||||
|
targetPort: 80
|
||||||
|
selector:
|
||||||
|
app: foo
|
@ -20,6 +20,7 @@ BLACKLIST_REGEXS = [
|
|||||||
r'^.*:batch/v1:Job:.*-\d{10,}$', # jobs created by cron jobs with unix timestamp suffix
|
r'^.*:batch/v1:Job:.*-\d{10,}$', # jobs created by cron jobs with unix timestamp suffix
|
||||||
r'^.*:metrics.k8s.io/v1beta1:PodMetrics:.*$',
|
r'^.*:metrics.k8s.io/v1beta1:PodMetrics:.*$',
|
||||||
r'^.*:v1:Endpoints:.*$',
|
r'^.*:v1:Endpoints:.*$',
|
||||||
|
r'^.*:.*:EndpointSlice:.*$',
|
||||||
r'^.*:v1:Event:.*$',
|
r'^.*:v1:Event:.*$',
|
||||||
r'^.*:v1:Pod:.*$',
|
r'^.*:v1:Pod:.*$',
|
||||||
r'^.*:v1:Secret:.*-token-\S{5}$', # secrets with token for service accounts
|
r'^.*:v1:Secret:.*-token-\S{5}$', # secrets with token for service accounts
|
||||||
@ -166,6 +167,8 @@ def main():
|
|||||||
print(' ' + x)
|
print(' ' + x)
|
||||||
print("..", counter, "entries")
|
print("..", counter, "entries")
|
||||||
|
|
||||||
|
sys.exit(len(list(slive - starget)))
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
|
Loading…
Reference in New Issue
Block a user