Skip to content

Commit b60f91f

Browse files
author
Alan Christie
committed
feat: Adds ingressClass, ingressDomain, ingressTlsSecret
1 parent 8c0e7e7 commit b60f91f

File tree

2 files changed

+21
-11
lines changed

2 files changed

+21
-11
lines changed

operator/handlers.py

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,19 @@
1919
_DEFAULT_USER_ID: int = 1000
2020
_DEFAULT_GROUP_ID: int = 100
2121
_DEFAULT_INGRESS_PROXY_BODY_SIZE: str = "500m"
22-
23-
# The ingress class
24-
_INGRESS_CLASS: str = "nginx"
25-
# The ingress domain must be provided.
26-
ingress_domain: str = os.environ["INGRESS_DOMAIN"]
27-
# The ingress TLS secret is optional.
22+
# The default ingress domain (must be provided).
23+
# The user can provide an alternative via the CR.
24+
_DEFAULT_INGRESS_DOMAIN: str = os.environ["INGRESS_DOMAIN"]
25+
# The ingress TLS secret.
2826
# If provided it is used as the Ingress secret
2927
# and cert-manager is avoided.
30-
ingress_tls_secret: Optional[str] = os.environ.get("INGRESS_TLS_SECRET")
28+
# The uer can provide their own via the CR.
29+
_DEFAULT_INGRESS_TLS_SECRET: Optional[str] = os.environ.get("INGRESS_TLS_SECRET")
30+
# The ingress class
31+
_DEFAULT_INGRESS_CLASS: str = "nginx"
32+
3133
# The cert-manager issuer,
32-
# expected if a TLS certificate is not defined.
34+
# expected if a INGRESS_TLS_SECRET is not defined.
3335
ingress_cert_issuer: Optional[str] = os.environ.get("INGRESS_CERT_ISSUER")
3436

3537
# Application node selection
@@ -322,8 +324,10 @@ def create(spec: Dict[str, Any], name: str, namespace: str, **_: Any) -> Dict[st
322324
"ingressProxyBodySize", _DEFAULT_INGRESS_PROXY_BODY_SIZE
323325
)
324326

327+
ingress_class = material.get("ingressClass", _DEFAULT_INGRESS_CLASS)
328+
ingress_domain = material.get("ingressDomain", _DEFAULT_INGRESS_DOMAIN)
329+
ingress_tls_secret = material.get("ingressTlsSecret", _DEFAULT_INGRESS_TLS_SECRET)
325330
ingress_path = f"/{name}"
326-
tls_secret = ingress_tls_secret if ingress_tls_secret else f"{name}-tls"
327331

328332
ingress_body: Dict[Any, Any] = {
329333
"kind": "Ingress",
@@ -332,12 +336,12 @@ def create(spec: Dict[str, Any], name: str, namespace: str, **_: Any) -> Dict[st
332336
"name": name,
333337
"labels": {"app": name},
334338
"annotations": {
335-
"kubernetes.io/ingress.class": _INGRESS_CLASS,
339+
"kubernetes.io/ingress.class": ingress_class,
336340
"nginx.ingress.kubernetes.io/proxy-body-size": f"{ingress_proxy_body_size}",
337341
},
338342
},
339343
"spec": {
340-
"tls": [{"hosts": [ingress_domain], "secretName": tls_secret}],
344+
"tls": [{"hosts": [ingress_domain], "secretName": ingress_tls_secret}],
341345
"rules": [
342346
{
343347
"host": ingress_domain,

roles/operator/templates/crd.yaml.j2

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,12 @@ spec:
4444
type: string
4545
image:
4646
type: string
47+
ingressClass:
48+
type: string
49+
ingressDomain:
50+
type: string
51+
ingressTlsSecret:
52+
type: string
4753
ingressProxyBodySize:
4854
type: string
4955
resources:

0 commit comments

Comments
 (0)