Merge ~mthaddon/charm-k8s-ingress/+git/charm-k8s-ingress:proxy-body-size-session-affinity into charm-k8s-ingress:master

Proposed by Tom Haddon
Status: Merged
Approved by: Jon Seager
Approved revision: 2b42bdb305509ca56758ba9774ea6d62824d7553
Merged at revision: 6ee4da1fce2b3fab9dda117d6f2385ae754910e0
Proposed branch: ~mthaddon/charm-k8s-ingress/+git/charm-k8s-ingress:proxy-body-size-session-affinity
Merge into: charm-k8s-ingress:master
Diff against target: 123 lines (+65/-4)
3 files modified
config.yaml (+10/-2)
src/charm.py (+13/-1)
tests/unit/test_charm.py (+42/-1)
Reviewer Review Type Date Requested Status
🤖 prod-jenkaas-is (community) continuous-integration Approve
ingress-charmers Pending
Review via email: mp+400180@code.launchpad.net

Commit message

Add session affinity and max upload size as config options, standardise on dashes for config options rather than underscores

To post a comment you must log in.
Revision history for this message
🤖 prod-jenkaas-is (prod-jenkaas-is) wrote :

A CI job is currently in progress. A follow up comment will be added when it completes.

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
🤖 prod-jenkaas-is (prod-jenkaas-is) wrote :

PASSED: Continuous integration, rev:2b42bdb305509ca56758ba9774ea6d62824d7553
https://jenkins.canonical.com/is/job/lp-charm-k8s-ingress-ci/6/
Executed test runs:
    SUCCESS: https://jenkins.canonical.com/is/job/lp-charm-test/36/
    None: https://jenkins.canonical.com/is/job/lp-update-mp/49328/

Click here to trigger a rebuild:
https://jenkins.canonical.com/is/job/lp-charm-k8s-ingress-ci/6//rebuild

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

Change successfully merged at revision 6ee4da1fce2b3fab9dda117d6f2385ae754910e0

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 e9d5df8..d432fc6 100644
3--- a/config.yaml
4+++ b/config.yaml
5@@ -5,6 +5,10 @@ options:
6 default: ""
7 description: k8s config. If you're using microk8s, this should be the output of `microk8s config`.
8 type: string
9+ max-body-size:
10+ default: 20
11+ description: Max allowed body-size (for file uploads) in megabytes, set to 0 to disable limits.
12+ type: int
13 service-hostname:
14 default: ""
15 description: The hostname of the service to create an ingress for.
16@@ -21,7 +25,11 @@ options:
17 default: 0
18 description: The port of the service to create an ingress for.
19 type: int
20- tls_secret_name:
21+ session-cookie-max-age:
22+ default: 0
23+ description: The max age to configure a session cookie for. Leaving unset or setting to 0 will disable session cookies and cookie-based affinity.
24+ type: int
25+ tls-secret-name:
26 default: ""
27- description: The name of the TLS secret to use. Leaving this empty will configure an Ingress with TLS disabled.
28+ description: The name of the TLS secret to use. Leaving this empty will configure an ingress with TLS disabled.
29 type: string
30diff --git a/src/charm.py b/src/charm.py
31index 7639bdb..b014c67 100755
32--- a/src/charm.py
33+++ b/src/charm.py
34@@ -122,8 +122,20 @@ class CharmK8SIngressCharm(CharmBase):
35 )
36 annotations = {
37 "nginx.ingress.kubernetes.io/rewrite-target": "/",
38+ "nginx.ingress.kubernetes.io/proxy-body-size": "{}m".format(self.config["max-body-size"]),
39 }
40- tls_secret_name = self.config.get("tls_secret_name")
41+ if self.config["session-cookie-max-age"]:
42+ annotations["nginx.ingress.kubernetes.io/affinity"] = "cookie"
43+ annotations["nginx.ingress.kubernetes.io/affinity-mode"] = "balanced"
44+ annotations["nginx.ingress.kubernetes.io/session-cookie-change-on-failure"] = "true"
45+ annotations["nginx.ingress.kubernetes.io/session-cookie-max-age"] = "{}".format(
46+ self.config["session-cookie-max-age"]
47+ )
48+ annotations["nginx.ingress.kubernetes.io/session-cookie-name"] = "{}_AFFINITY".format(
49+ self.config["service-name"].upper()
50+ )
51+ annotations["nginx.ingress.kubernetes.io/session-cookie-samesite"] = "Lax"
52+ tls_secret_name = self.config["tls-secret-name"]
53 if tls_secret_name:
54 spec.tls = kubernetes.client.NetworkingV1beta1IngressTLS(
55 hosts=[self.config["service-hostname"]],
56diff --git a/tests/unit/test_charm.py b/tests/unit/test_charm.py
57index 2d335c7..a7062ae 100644
58--- a/tests/unit/test_charm.py
59+++ b/tests/unit/test_charm.py
60@@ -64,6 +64,7 @@ class TestCharm(unittest.TestCase):
61 metadata=kubernetes.client.V1ObjectMeta(
62 name="gunicorn-ingress",
63 annotations={
64+ "nginx.ingress.kubernetes.io/proxy-body-size": "20m",
65 "nginx.ingress.kubernetes.io/rewrite-target": "/",
66 "nginx.ingress.kubernetes.io/ssl-redirect": "false",
67 },
68@@ -95,6 +96,7 @@ class TestCharm(unittest.TestCase):
69 metadata=kubernetes.client.V1ObjectMeta(
70 name="gunicorn-ingress",
71 annotations={
72+ "nginx.ingress.kubernetes.io/proxy-body-size": "20m",
73 "nginx.ingress.kubernetes.io/rewrite-target": "/",
74 },
75 ),
76@@ -121,7 +123,46 @@ class TestCharm(unittest.TestCase):
77 ),
78 ),
79 )
80- self.harness.update_config({"tls_secret_name": "gunicorn_tls"})
81+ self.harness.update_config({"tls-secret-name": "gunicorn_tls"})
82+ self.assertEqual(self.harness.charm._get_k8s_ingress(), expected)
83+ # Test max_body_size and session-cookie-max-age config options.
84+ self.harness.update_config({"tls-secret-name": "", "max-body-size": 0, "session-cookie-max-age": 3600})
85+ expected = kubernetes.client.NetworkingV1beta1Ingress(
86+ api_version="networking.k8s.io/v1beta1",
87+ kind="Ingress",
88+ metadata=kubernetes.client.V1ObjectMeta(
89+ name="gunicorn-ingress",
90+ annotations={
91+ "nginx.ingress.kubernetes.io/affinity": "cookie",
92+ "nginx.ingress.kubernetes.io/affinity-mode": "balanced",
93+ "nginx.ingress.kubernetes.io/proxy-body-size": "0m",
94+ "nginx.ingress.kubernetes.io/rewrite-target": "/",
95+ "nginx.ingress.kubernetes.io/session-cookie-change-on-failure": "true",
96+ "nginx.ingress.kubernetes.io/session-cookie-max-age": "3600",
97+ "nginx.ingress.kubernetes.io/session-cookie-name": "GUNICORN_AFFINITY",
98+ "nginx.ingress.kubernetes.io/session-cookie-samesite": "Lax",
99+ "nginx.ingress.kubernetes.io/ssl-redirect": "false",
100+ },
101+ ),
102+ spec=kubernetes.client.NetworkingV1beta1IngressSpec(
103+ rules=[
104+ kubernetes.client.NetworkingV1beta1IngressRule(
105+ host="foo.internal",
106+ http=kubernetes.client.NetworkingV1beta1HTTPIngressRuleValue(
107+ paths=[
108+ kubernetes.client.NetworkingV1beta1HTTPIngressPath(
109+ path="/",
110+ backend=kubernetes.client.NetworkingV1beta1IngressBackend(
111+ service_port=80,
112+ service_name="gunicorn-service",
113+ ),
114+ )
115+ ]
116+ ),
117+ )
118+ ]
119+ ),
120+ )
121 self.assertEqual(self.harness.charm._get_k8s_ingress(), expected)
122
123 def test_get_k8s_service(self):

Subscribers

People subscribed via source and target branches

to all changes: