Skip to content
This repository has been archived by the owner on Sep 14, 2020. It is now read-only.

Commit

Permalink
Use proper v1 or v1beta1 APIs for KopfExample/KopfPeering in e2e tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nolar committed May 11, 2020
1 parent e0f6bf0 commit 61bde04
Show file tree
Hide file tree
Showing 6 changed files with 89 additions and 13 deletions.
9 changes: 5 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@ env:
- KUBERNETES_VERSION=latest CLIENT=yes # only one "yes" is enough
- KUBERNETES_VERSION=latest CLIENT=no
- KUBERNETES_VERSION=v1.16.0 CLIENT=no
- KUBERNETES_VERSION=v1.15.0 CLIENT=no
- KUBERNETES_VERSION=v1.14.0 CLIENT=no
- KUBERNETES_VERSION=v1.13.0 CLIENT=no
- KUBERNETES_VERSION=v1.12.0 CLIENT=no
- KUBERNETES_VERSION=v1.16.0 CLIENT=no CRDAPI=v1beta1
- KUBERNETES_VERSION=v1.15.0 CLIENT=no CRDAPI=v1beta1
- KUBERNETES_VERSION=v1.14.0 CLIENT=no CRDAPI=v1beta1
- KUBERNETES_VERSION=v1.13.0 CLIENT=no CRDAPI=v1beta1
- KUBERNETES_VERSION=v1.12.0 CLIENT=no CRDAPI=v1beta1
# - KUBERNETES_VERSION=v1.11.10 # Minikube fails on CRI preflight checks
# - KUBERNETES_VERSION=v1.10.13 # CRDs require spec.version, which fails on 1.14

Expand Down
10 changes: 8 additions & 2 deletions examples/09-testing/test_example_09.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,19 @@

import kopf.testing

crd_yaml = os.path.relpath(os.path.join(os.path.dirname(__file__), '..', 'crd.yaml'))
obj_yaml = os.path.relpath(os.path.join(os.path.dirname(__file__), '..', 'obj.yaml'))
example_py = os.path.relpath(os.path.join(os.path.dirname(__file__), 'example.py'))


@pytest.fixture(scope='session')
def crd_yaml():
crd_api = os.environ.get('CRDAPI', 'v1')
crd_file = 'crd.yaml' if crd_api == 'v1' else f'crd-{crd_api}.yaml'
return os.path.relpath(os.path.join(os.path.dirname(__file__), '..', crd_file))


@pytest.fixture(autouse=True)
def crd_exists():
def crd_exists(crd_yaml):
subprocess.run(f"kubectl apply -f {crd_yaml}",
check=True, timeout=10, capture_output=True, shell=True)

Expand Down
10 changes: 8 additions & 2 deletions examples/11-filtering-handlers/test_example_11.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,19 @@

import kopf.testing

crd_yaml = os.path.relpath(os.path.join(os.path.dirname(__file__), '..', 'crd.yaml'))
obj_yaml = os.path.relpath(os.path.join(os.path.dirname(__file__), '..', 'obj.yaml'))
example_py = os.path.relpath(os.path.join(os.path.dirname(__file__), 'example.py'))


@pytest.fixture(scope='session')
def crd_yaml():
crd_api = os.environ.get('CRDAPI', 'v1')
crd_file = 'crd.yaml' if crd_api == 'v1' else f'crd-{crd_api}.yaml'
return os.path.relpath(os.path.join(os.path.dirname(__file__), '..', crd_file))


@pytest.fixture(autouse=True)
def crd_exists():
def crd_exists(crd_yaml):
subprocess.run(f"kubectl apply -f {crd_yaml}",
check=True, timeout=10, capture_output=True, shell=True)

Expand Down
46 changes: 46 additions & 0 deletions peering-v1beta1.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# This file is for Kubernetes <= 1.15.
# For Kubernetes >= 1.16, use peering.yaml.
---
apiVersion: apiextensions.k8s.io/v1beta1
kind: CustomResourceDefinition
metadata:
name: clusterkopfpeerings.zalando.org
spec:
scope: Cluster
group: zalando.org
names:
kind: ClusterKopfPeering
plural: clusterkopfpeerings
singular: clusterkopfpeering
versions:
- name: v1
served: true
storage: true
---
apiVersion: apiextensions.k8s.io/v1beta1
kind: CustomResourceDefinition
metadata:
name: kopfpeerings.zalando.org
spec:
scope: Namespaced
group: zalando.org
names:
kind: KopfPeering
plural: kopfpeerings
singular: kopfpeering
versions:
- name: v1
served: true
storage: true
---
apiVersion: zalando.org/v1
kind: ClusterKopfPeering
metadata:
name: default
---
apiVersion: zalando.org/v1
kind: KopfPeering
metadata:
namespace: default
name: default
---
2 changes: 1 addition & 1 deletion peering.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# This file is for Kubernetes >= 1.16.
# For Kubernetes <= 1.15, change "v1" to "v1beta1", and remove schemas.
# For Kubernetes <= 1.15, use peering-v1beta1.yaml.
---
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
Expand Down
25 changes: 21 additions & 4 deletions tests/e2e/conftest.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import glob
import os.path
import re

import pathlib
import subprocess

Expand All @@ -16,15 +18,30 @@ def exampledir(request):
return pathlib.Path(request.param)


@pytest.fixture(scope='session')
def peering_yaml():
crd_api = os.environ.get('CRDAPI', 'v1')
crd_file = 'peering.yaml' if crd_api == 'v1' else f'peering-{crd_api}.yaml'
return f'{crd_file}'


@pytest.fixture(scope='session')
def crd_yaml():
crd_api = os.environ.get('CRDAPI', 'v1')
crd_file = 'crd.yaml' if crd_api == 'v1' else f'crd-{crd_api}.yaml'
return f'examples/{crd_file}'


@pytest.fixture()
def with_crd():
subprocess.run("kubectl apply -f examples/crd.yaml",
def with_crd(crd_yaml):
# Our best guess on which Kubernetes version we are running on.
subprocess.run(f"kubectl apply -f {crd_yaml}",
shell=True, check=True, timeout=10, capture_output=True)


@pytest.fixture()
def with_peering():
subprocess.run("kubectl apply -f peering.yaml",
def with_peering(peering_yaml):
subprocess.run(f"kubectl apply -f {peering_yaml}",
shell=True, check=True, timeout=10, capture_output=True)


Expand Down

0 comments on commit 61bde04

Please sign in to comment.