Skip to content

Commit

Permalink
Remove k8s v1.18 logic from tests (#1858)
Browse files Browse the repository at this point in the history
  • Loading branch information
soneillf5 committed Aug 18, 2021
1 parent 9cd857d commit 9708e54
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 96 deletions.
6 changes: 3 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -210,14 +210,14 @@ UPGRADE:
* For NGINX Plus, please build your own image using the 1.9.0 source code.
* For Helm, use version 0.7.0 of the chart.

For Kubernetes >= 1.18, when upgrading using the [manifests](https://docs.nginx.com/nginx-ingress-controller/installation/installation-with-manifests/), make sure to update the [ClusterRole](deployments/rbac/rbac.yaml) and create the [IngressClass resource](deployments/common/ingress-class.yaml), which is required for Kubernetes >= 1.18. Otherwise, the Ingress Controller will fail to start. If you run multiple NGINX Ingress Controllers in the cluster, each Ingress Controller has to have its own IngressClass resource. As the `-use-ingress-class-only` argument is now ignored (see NOTES), make sure your Ingress resources have the `ingressClassName` field or the `kubernetes.io/ingress.class` annotation set to the name of the IngressClass resource. Otherwise, the Ingress Controller will ignore them.
For Kubernetes >= 1.18, when upgrading using the [manifests](https://docs.nginx.com/nginx-ingress-controller/installation/installation-with-manifests/), make sure to update the [ClusterRole](deployments/rbac/rbac.yaml) and create the [IngressClass resource](deployments/common/ingress-class.yaml), which is required for Kubernetes >= 1.18. Otherwise, the Ingress Controller will fail to start. If you run multiple NGINX Ingress Controllers in the cluster, each Ingress Controller has to have its own IngressClass resource. Make sure your Ingress resources have the `ingressClassName` field or the `kubernetes.io/ingress.class` annotation set to the name of the IngressClass resource. Otherwise, the Ingress Controller will ignore them.

HELM UPGRADE:
* If you're using custom resources like VirtualServer and TransportServer (`controller.enableCustomResources` is set to `true`), after you run the `helm upgrade` command, the CRDs will not be upgraded. After running the `helm upgrade` command, run `kubectl apply -f deployments/helm-chart/crds` to upgrade the CRDs.
* For Kubernetes >= 1.18, a dedicated IngressClass resource, which is configured by `controller.ingressClass`, is required per helm release. Ensure `controller.ingressClass` is not set to the name of the IngressClass of other releases or Ingress Controllers. As the `controller.useIngressClassOnly` parameter is now ignored (see NOTES), make sure your Ingress resources have the `ingressClassName` field or the `kubernetes.io/ingress.class` annotation set to the value of `controller.ingressClass`. Otherwise, the Ingress Controller will ignore them.
* For Kubernetes >= 1.18, a dedicated IngressClass resource, which is configured by `controller.ingressClass`, is required per helm release. Ensure `controller.ingressClass` is not set to the name of the IngressClass of other releases or Ingress Controllers. Make sure your Ingress resources have the `ingressClassName` field or the `kubernetes.io/ingress.class` annotation set to the value of `controller.ingressClass`. Otherwise, the Ingress Controller will ignore them.

NOTES:
* When using Kubernetes >= 1.18, the `-use-ingress-class-only` command-line argument is now ignored, and the Ingress Controller will only process resources that belong to its class. See [IngressClass doc](https://docs.nginx.com/nginx-ingress-controller/installation/running-multiple-ingress-controllers/#ingress-class) to learn more.
* When using Kubernetes >= 1.18 the Ingress Controller will only process resources that belong to its class. See [IngressClass doc](https://docs.nginx.com/nginx-ingress-controller/installation/running-multiple-ingress-controllers/#ingress-class) to learn more.
* For Kubernetes >= 1.18, a dedicated IngressClass resource, which is configured by `controller.ingressClass`, is required per helm release. When upgrading or installing releases, ensure `controller.ingressClass` is not set to the name of the IngressClass of other releases or Ingress Controllers.

### 1.8.1
Expand Down
8 changes: 1 addition & 7 deletions deployments/helm-chart/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -119,19 +119,13 @@ controller:

## A class of the Ingress controller.

## For Kubernetes >= 1.18, a corresponding IngressClass resource with the name equal to the class must be deployed. Otherwise,
## IngressClass resource with the name equal to the class must be deployed. Otherwise,
## the Ingress Controller will fail to start.
## The Ingress controller only processes resources that belong to its class - i.e. have the "ingressClassName" field resource equal to the class.

## For Kubernetes < 1.18, the Ingress Controller only processes resources that belong to its class -
## i.e have the annotation "kubernetes.io/ingress.class" (for Ingress resources)
## or field "ingressClassName" equal to the class.
## Additionally, the Ingress Controller processes resources that do not have the class set.

## The Ingress Controller processes all the resources that do not have the "ingressClassName" field for all versions of kubernetes.
ingressClass: nginx

## Only for Kubernetes >= 1.18
## New Ingresses without an ingressClassName field specified will be assigned the class specified in `controller.ingressClass`.
setAsDefaultIngress: false

Expand Down
2 changes: 1 addition & 1 deletion examples/complete-example/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ $ kubectl create -f cafe.yaml
$ kubectl create -f cafe-secret.yaml
```

2. Create an Ingress resource (for Kubernetes >= 1.18, uncomment the ```ingressClassName``` field in the YAML file):
2. Create an Ingress resource:
```
$ kubectl create -f cafe-ingress.yaml
```
Expand Down
2 changes: 1 addition & 1 deletion examples/complete-example/cafe-ingress.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ kind: Ingress
metadata:
name: cafe-ingress
spec:
# ingressClassName: nginx # use only with k8s version >= 1.18.0
ingressClassName: nginx
tls:
- hosts:
- cafe.example.com
Expand Down
53 changes: 22 additions & 31 deletions tests/suite/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,13 +138,11 @@ class IngressControllerPrerequisites:
Attributes:
namespace (str): namespace name
config_map (str): config_map name
minorVer (int): k8s minor version
"""

def __init__(self, config_map, namespace, minorVer):
def __init__(self, config_map, namespace):
self.namespace = namespace
self.config_map = config_map
self.minorVer = minorVer


@pytest.fixture(autouse=True)
Expand Down Expand Up @@ -285,22 +283,16 @@ def ingress_controller_prerequisites(
print("------------------------- Create IC Prerequisites -----------------------------------")
rbac = configure_rbac(kube_apis.rbac_v1)
namespace = create_ns_and_sa_from_yaml(kube_apis.v1, f"{DEPLOYMENTS}/common/ns-and-sa.yaml")
k8sVersionBin = subprocess.run(["kubectl", "version"], capture_output=True)
k8sVersion = (k8sVersionBin.stdout).decode("ascii")
serverVersion = k8sVersion[k8sVersion.find("Server Version:") :].lstrip()
minorSerVer = serverVersion[serverVersion.find("Minor") :].lstrip()[0:10]
k8sMinorVersion = int("".join(filter(str.isdigit, minorSerVer)))
if k8sMinorVersion >= 18:
print("Create IngressClass resources:")
subprocess.run(["kubectl", "apply", "-f", f"{DEPLOYMENTS}/common/ingress-class.yaml"])
subprocess.run(
[
"kubectl",
"apply",
"-f",
f"{TEST_DATA}/ingress-class/resource/custom-ingress-class-res.yaml",
]
)
print("Create IngressClass resources:")
subprocess.run(["kubectl", "apply", "-f", f"{DEPLOYMENTS}/common/ingress-class.yaml"])
subprocess.run(
[
"kubectl",
"apply",
"-f",
f"{TEST_DATA}/ingress-class/resource/custom-ingress-class-res.yaml",
]
)
config_map_yaml = f"{DEPLOYMENTS}/common/nginx-config.yaml"
create_configmap_from_yaml(kube_apis.v1, namespace, config_map_yaml)
with open(config_map_yaml) as f:
Expand All @@ -312,22 +304,21 @@ def ingress_controller_prerequisites(
def fin():
print("Clean up prerequisites")
delete_namespace(kube_apis.v1, namespace)
if k8sMinorVersion >= 18:
print("Delete IngressClass resources:")
subprocess.run(["kubectl", "delete", "-f", f"{DEPLOYMENTS}/common/ingress-class.yaml"])
subprocess.run(
[
"kubectl",
"delete",
"-f",
f"{TEST_DATA}/ingress-class/resource/custom-ingress-class-res.yaml",
]
)
print("Delete IngressClass resources:")
subprocess.run(["kubectl", "delete", "-f", f"{DEPLOYMENTS}/common/ingress-class.yaml"])
subprocess.run(
[
"kubectl",
"delete",
"-f",
f"{TEST_DATA}/ingress-class/resource/custom-ingress-class-res.yaml",
]
)
cleanup_rbac(kube_apis.rbac_v1, rbac)

request.addfinalizer(fin)

return IngressControllerPrerequisites(config_map, namespace, k8sMinorVersion)
return IngressControllerPrerequisites(config_map, namespace)


@pytest.fixture(scope="session")
Expand Down
64 changes: 11 additions & 53 deletions tests/suite/test_ingress_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,45 +76,6 @@ def fin():

@pytest.mark.ingresses
class TestIngressClassArgs:
@pytest.mark.parametrize(
"ingress_controller, expected_responses",
[
pytest.param(
{"extra_args": ["-ingress-class=custom"]},
{"custom-class": 200, "nginx-class": 404, "no-class": 200},
id="custom-ingress-class",
),
pytest.param(
{"extra_args": None},
{"custom-class": 404, "nginx-class": 200, "no-class": 200},
id="no-args-set",
),
],
indirect=["ingress_controller"],
)
def test_response_codes_117(
self,
ingress_controller,
backend_setup,
expected_responses,
ingress_controller_prerequisites,
):
"""
Checks for ingressClass behaviour in k8s < 1.18
"""
if ingress_controller_prerequisites.minorVer < 18:
for item in ingresses_under_test:
ensure_response_from_backend(
backend_setup.req_url, backend_setup.ingress_hosts[item]
)
resp = requests.get(
backend_setup.req_url, headers={"host": backend_setup.ingress_hosts[item]}
)
assert (
resp.status_code == expected_responses[item]
), f"Expected: {expected_responses[item]} response code for {backend_setup.ingress_hosts[item]}"
else:
print(f"Skipping test because k8s version is >= 1.18")

@pytest.mark.parametrize(
"ingress_controller, expected_responses",
Expand All @@ -140,18 +101,15 @@ def test_response_codes_117_plus(
ingress_controller_prerequisites,
):
"""
Checks for ingressClass behaviour in k8s >= 1.18
Checks for ingressClass behaviour
"""
if ingress_controller_prerequisites.minorVer >= 18:
for item in ingresses_under_test:
ensure_response_from_backend(
backend_setup.req_url, backend_setup.ingress_hosts[item]
)
resp = requests.get(
backend_setup.req_url, headers={"host": backend_setup.ingress_hosts[item]}
)
assert (
resp.status_code == expected_responses[item]
), f"Expected: {expected_responses[item]} response code for {backend_setup.ingress_hosts[item]}"
else:
print(f"Skipping test because k8s version is < 1.18")
for item in ingresses_under_test:
ensure_response_from_backend(
backend_setup.req_url, backend_setup.ingress_hosts[item]
)
resp = requests.get(
backend_setup.req_url, headers={"host": backend_setup.ingress_hosts[item]}
)
assert (
resp.status_code == expected_responses[item]
), f"Expected: {expected_responses[item]} response code for {backend_setup.ingress_hosts[item]}"

0 comments on commit 9708e54

Please sign in to comment.