Skip to content

Commit ea7652a

Browse files
committed
add ability to create jwt on tests
1 parent bf4a5e6 commit ea7652a

File tree

7 files changed

+58
-15
lines changed

7 files changed

+58
-15
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
apiVersion: v1
2+
kind: ConfigMap
3+
metadata:
4+
name: nginx-config-mgmt
5+
namespace: nginx-ingress
6+
data:

deployments/deployment/nginx-plus-ingress.yaml

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,12 @@ spec:
2727
- name: nginx-plus-license
2828
secret:
2929
secretName: license-token
30-
- name: nim-ca
31-
secret:
32-
secretName: nim-ca
33-
- name: nim-client-cert
34-
secret:
35-
secretName: nim-client-cert
30+
# - name: nim-ca
31+
# secret:
32+
# secretName: nim-ca
33+
# - name: nim-client-cert
34+
# secret:
35+
# secretName: nim-client-cert
3636
# - name: nginx-etc
3737
# emptyDir: {}
3838
# - name: nginx-cache
@@ -81,10 +81,10 @@ spec:
8181
volumeMounts:
8282
- mountPath: /etc/nginx/license
8383
name: nginx-plus-license
84-
- mountPath: /etc/nginx/secrets/mgmt
85-
name: nim-ca
86-
- mountPath: /etc/nginx/secrets/mgmt_client
87-
name: nim-client-cert
84+
# - mountPath: /etc/nginx/secrets/mgmt
85+
# name: nim-ca
86+
# - mountPath: /etc/nginx/secrets/mgmt_client
87+
# name: nim-client-cert
8888
# - mountPath: /var/cache/nginx
8989
# name: nginx-cache
9090
# - mountPath: /var/lib/nginx

internal/configs/configmaps.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import (
1414

1515
const (
1616
minimumInterval = 60
17-
defaultInterval = "1h"
1817
)
1918

2019
// ParseConfigMap parses ConfigMap into ConfigParams.
@@ -567,8 +566,8 @@ func ParseMGMTConfigMap(ctx context.Context, cfgm *v1.ConfigMap, nginxPlus bool)
567566
nl.Errorf(l, "Configmap %s/%s: Invalid value for the interval key: got %q: %v", cfgm.GetNamespace(), cfgm.GetName(), i, err)
568567
}
569568
if t.Seconds() < minimumInterval {
570-
nl.Errorf(l, "Configmap %s/%s: Value too low for the interval key, got: %v, need higher than %ds. Falling back to default %s", cfgm.GetNamespace(), cfgm.GetName(), i, minimumInterval, defaultInterval)
571-
mgmtCfgParams.Interval = defaultInterval
569+
nl.Errorf(l, "Configmap %s/%s: Value too low for the interval key, got: %v, need higher than %ds.", cfgm.GetNamespace(), cfgm.GetName(), i, minimumInterval)
570+
mgmtCfgParams.Interval = ""
572571
} else {
573572
mgmtCfgParams.Interval = i
574573
}

internal/configs/version1/nginx-plus.tmpl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -360,8 +360,9 @@ stream {
360360

361361
{{- if .NginxVersion.PlusGreaterThanOrEqualTo "nginx-plus-r33" }}
362362
mgmt {
363+
#{{ .MGMTInterval }}#
363364
usage_report
364-
{{- if ne .MGMTEndpoint "" }} endpoint={{ .MGMTEndpoint }} {{- end }} interval={{ .MGMTInterval }};
365+
{{- if ne .MGMTEndpoint "" }} endpoint={{ .MGMTEndpoint }} {{- end }} {{- if ne .MGMTInterval "" }} interval={{ .MGMTInterval }} {{- end }};
365366
license_token /etc/nginx/license/license.jwt;
366367
{{ if .MGMTEnforceInitialReport -}}
367368
enforce_initial_report on;

tests/conftest.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,11 @@ def pytest_addoption(parser) -> None:
5555
default=DEFAULT_IC_TYPE,
5656
help="The type of the Ingress Controller: nginx-ingress or nginx-plus-ingress.",
5757
)
58+
parser.addoption(
59+
"--plus-jwt",
60+
action="store",
61+
help="The plus jwt for the Ingress Controller image.",
62+
)
5863
parser.addoption(
5964
"--service",
6065
action="store",

tests/suite/fixtures/fixtures.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
create_configmap_from_yaml,
2626
create_namespace_with_name_from_yaml,
2727
create_ns_and_sa_from_yaml,
28+
create_opaque_license_secret,
2829
create_secret_from_yaml,
2930
create_service_from_yaml,
3031
delete_namespace,
@@ -240,11 +241,20 @@ def ingress_controller_prerequisites(cli_arguments, kube_apis, request) -> Ingre
240241
]
241242
)
242243
config_map_yaml = f"{DEPLOYMENTS}/common/nginx-config.yaml"
244+
mgmt_config_map_yaml = f"{DEPLOYMENTS}/common/plus-mgmt-configmap.yaml"
243245
create_configmap_from_yaml(kube_apis.v1, namespace, config_map_yaml)
244246
with open(config_map_yaml) as f:
245247
config_map = yaml.safe_load(f)
248+
246249
create_secret_from_yaml(kube_apis.v1, namespace, f"{TEST_DATA}/common/default-server-secret.yaml")
247250

251+
# setup Plus JWT configuration
252+
if cli_arguments["ic-type"] == "nginx-plus-ingress" and "plus-jwt" in cli_arguments:
253+
print("Create Plus JWT Secret:")
254+
secret_name = create_opaque_license_secret(kube_apis.v1, namespace, cli_arguments["plus-jwt"])
255+
print(f"Secret created: {secret_name}")
256+
create_configmap_from_yaml(kube_apis.v1, namespace, mgmt_config_map_yaml)
257+
248258
def fin():
249259
if request.config.getoption("--skip-fixture-teardown") == "no":
250260
print("Clean up prerequisites")
@@ -323,6 +333,11 @@ def cli_arguments(request) -> {}:
323333
result["ic-type"] = request.config.getoption("--ic-type")
324334
assert result["ic-type"] in ALLOWED_IC_TYPES, f"IC type {result['ic-type']} is not allowed"
325335
print(f"Tests will run against the IC of type: {result['ic-type']}")
336+
if result["ic-type"] == "nginx-plus-ingress":
337+
jwt = request.config.getoption("--plus-jwt", None)
338+
assert jwt is not None and jwt != "", f"ic-type nginx-plus-ingress needs a jwt"
339+
result["plus-jwt"] = jwt
340+
print(f"Tests will use the Plus JWT: {result['plus-jwt']}")
326341

327342
result["replicas"] = request.config.getoption("--replicas")
328343
print(f"Number of pods spun up will be : {result['replicas']}")

tests/suite/utils/resources_utils.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,15 @@
1010
import pytest
1111
import requests
1212
import yaml
13-
from kubernetes.client import AppsV1Api, CoreV1Api, NetworkingV1Api, RbacAuthorizationV1Api, V1Service
13+
from kubernetes.client import (
14+
AppsV1Api,
15+
CoreV1Api,
16+
NetworkingV1Api,
17+
RbacAuthorizationV1Api,
18+
V1ObjectMeta,
19+
V1Secret,
20+
V1Service,
21+
)
1422
from kubernetes.client.rest import ApiException
1523
from kubernetes.stream import stream
1624
from more_itertools import first
@@ -556,6 +564,15 @@ def create_secret(v1: CoreV1Api, namespace, body) -> str:
556564
return body["metadata"]["name"]
557565

558566

567+
def create_opaque_license_secret(v1: CoreV1Api, namespace, jwt, license_token_name="license-token") -> str:
568+
sec = V1Secret()
569+
sec.type = "Opaque"
570+
sec.metadata = V1ObjectMeta(name=license_token_name)
571+
sec.data = {"license.jwt": base64.b64encode(jwt.encode("ascii")).decode()}
572+
v1.create_namespaced_secret(namespace=namespace, body=sec)
573+
return license_token_name
574+
575+
559576
def replace_secret(v1: CoreV1Api, name, namespace, yaml_manifest) -> str:
560577
"""
561578
Replace a secret based on yaml file.

0 commit comments

Comments
 (0)