Merge ~mthaddon/charm-k8s-ingress/+git/charm-k8s-ingress:ingress-class into charm-k8s-ingress:master

Proposed by Tom Haddon
Status: Merged
Approved by: Jon Seager
Approved revision: ee8f9c7d6c87048d6b2bbe39ac2ad20fc277877c
Merged at revision: 42cc842963c8d790b111d3ba331578bf6f7e8c55
Proposed branch: ~mthaddon/charm-k8s-ingress/+git/charm-k8s-ingress:ingress-class
Merge into: charm-k8s-ingress:master
Diff against target: 61 lines (+18/-1)
3 files modified
config.yaml (+10/-0)
src/charm.py (+4/-0)
tests/unit/test_charm.py (+4/-1)
Reviewer Review Type Date Requested Status
ingress-charmers Pending
Review via email: mp+400949@code.launchpad.net

Commit message

Add ingress-class to allow user to target the correct ingress controller if their cluster has multiple

To post a comment you must log in.
Revision history for this message
🤖 Canonical IS Merge Bot (canonical-is-mergebot) wrote :

This merge proposal is being monitored by mergebot. Change the status to Approved to merge.

Revision history for this message
🤖 Canonical IS Merge Bot (canonical-is-mergebot) wrote :

Change successfully merged at revision 42cc842963c8d790b111d3ba331578bf6f7e8c55

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/config.yaml b/config.yaml
2index 9a9b7cf..5f0c3a4 100644
3--- a/config.yaml
4+++ b/config.yaml
5@@ -1,6 +1,16 @@
6 # Copyright 2021 Canonical Ltd.
7 # See LICENSE file for licensing details.
8 options:
9+ ingress-class:
10+ default: ""
11+ description: >
12+ The ingress class annotation to target for this ingress resource. If your
13+ kubernetes cluster has multiple ingress controllers, this allows you to
14+ target the correct one. See https://kubernetes.github.io/ingress-nginx/user-guide/multiple-ingress/
15+ for more details. Leaving empty will mean the "kubernetes.io/ingress.class"
16+ annotation is unset. This value isn't available to be set via the relation
17+ as it's a deploy-time configuration item.
18+ type: string
19 kube-config:
20 default: ""
21 description: k8s config. If you're using microk8s, this should be the output of `microk8s config`.
22diff --git a/src/charm.py b/src/charm.py
23index e14f76a..9f84ece 100755
24--- a/src/charm.py
25+++ b/src/charm.py
26@@ -227,6 +227,10 @@ class IngressCharm(CharmBase):
27 else:
28 annotations["nginx.ingress.kubernetes.io/ssl-redirect"] = "false"
29
30+ # Run-time configuration options.
31+ if self.config["ingress-class"]:
32+ annotations["kubernetes.io/ingress.class"] = self.config["ingress-class"]
33+
34 return kubernetes.client.NetworkingV1beta1Ingress(
35 api_version="networking.k8s.io/v1beta1",
36 kind="Ingress",
37diff --git a/tests/unit/test_charm.py b/tests/unit/test_charm.py
38index ac2f0c5..9dda0c1 100644
39--- a/tests/unit/test_charm.py
40+++ b/tests/unit/test_charm.py
41@@ -336,9 +336,11 @@ class TestCharm(unittest.TestCase):
42 )
43 self.harness.update_config({"tls-secret-name": "gunicorn_tls"})
44 self.assertEqual(self.harness.charm._get_k8s_ingress(), expected)
45- # Test max_body_size, retry_http_errors and session-cookie-max-age config options.
46+ # Test ingress-class, max_body_size, retry_http_errors and
47+ # session-cookie-max-age config options.
48 self.harness.update_config(
49 {
50+ "ingress-class": "nginx",
51 "max-body-size": 20,
52 "retry-errors": "error,timeout,http_502,http_503",
53 "session-cookie-max-age": 3600,
54@@ -351,6 +353,7 @@ class TestCharm(unittest.TestCase):
55 metadata=kubernetes.client.V1ObjectMeta(
56 name="gunicorn-ingress",
57 annotations={
58+ "kubernetes.io/ingress.class": "nginx",
59 "nginx.ingress.kubernetes.io/affinity": "cookie",
60 "nginx.ingress.kubernetes.io/affinity-mode": "balanced",
61 "nginx.ingress.kubernetes.io/proxy-body-size": "20m",

Subscribers

People subscribed via source and target branches

to all changes: