charmlibs-nginx-k8s 0.0.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (25) hide show
  1. charmlibs_nginx_k8s-0.0.1/.gitignore +1 -0
  2. charmlibs_nginx_k8s-0.0.1/PKG-INFO +82 -0
  3. charmlibs_nginx_k8s-0.0.1/README.md +64 -0
  4. charmlibs_nginx_k8s-0.0.1/pyproject.toml +60 -0
  5. charmlibs_nginx_k8s-0.0.1/src/charmlibs/nginx_k8s/__init__.py +48 -0
  6. charmlibs_nginx_k8s-0.0.1/src/charmlibs/nginx_k8s/_config.py +645 -0
  7. charmlibs_nginx_k8s-0.0.1/src/charmlibs/nginx_k8s/_nginx.py +118 -0
  8. charmlibs_nginx_k8s-0.0.1/src/charmlibs/nginx_k8s/_nginx_prometheus_exporter.py +56 -0
  9. charmlibs_nginx_k8s-0.0.1/src/charmlibs/nginx_k8s/_tls_config.py +111 -0
  10. charmlibs_nginx_k8s-0.0.1/src/charmlibs/nginx_k8s/_tracer.py +7 -0
  11. charmlibs_nginx_k8s-0.0.1/src/charmlibs/nginx_k8s/py.typed +0 -0
  12. charmlibs_nginx_k8s-0.0.1/tests/integration/__init__.py +4 -0
  13. charmlibs_nginx_k8s-0.0.1/tests/integration/charms/k8s/charmcraft.yaml +35 -0
  14. charmlibs_nginx_k8s-0.0.1/tests/integration/charms/k8s/nginx_k8s/README.md +1 -0
  15. charmlibs_nginx_k8s-0.0.1/tests/integration/charms/k8s/nginx_k8s/__init__.py +0 -0
  16. charmlibs_nginx_k8s-0.0.1/tests/integration/charms/k8s/nginx_k8s/pyproject.toml +1 -0
  17. charmlibs_nginx_k8s-0.0.1/tests/integration/charms/k8s/pyproject.toml +12 -0
  18. charmlibs_nginx_k8s-0.0.1/tests/integration/charms/k8s/src/charm.py +91 -0
  19. charmlibs_nginx_k8s-0.0.1/tests/integration/conftest.py +39 -0
  20. charmlibs_nginx_k8s-0.0.1/tests/integration/pack.sh +31 -0
  21. charmlibs_nginx_k8s-0.0.1/tests/integration/test_nginx.py +59 -0
  22. charmlibs_nginx_k8s-0.0.1/tests/unit/conftest.py +48 -0
  23. charmlibs_nginx_k8s-0.0.1/tests/unit/test_container_managers.py +111 -0
  24. charmlibs_nginx_k8s-0.0.1/tests/unit/test_nginx_config_write.py +24 -0
  25. charmlibs_nginx_k8s-0.0.1/uv.lock +304 -0
@@ -0,0 +1 @@
1
+ .logs
@@ -0,0 +1,82 @@
1
+ Metadata-Version: 2.4
2
+ Name: charmlibs-nginx-k8s
3
+ Version: 0.0.1
4
+ Summary: Nginx sidecar container abstractions for k8s charms.
5
+ Project-URL: Documentation, https://documentation.ubuntu.com/charmlibs
6
+ Project-URL: Repository, https://github.com/canonical/charmlibs
7
+ Project-URL: Issues, https://github.com/canonical/charmlibs/issues
8
+ Author: The Observability team at Canonical Ltd.
9
+ Classifier: Development Status :: 3 - Alpha
10
+ Classifier: Intended Audience :: Developers
11
+ Classifier: License :: OSI Approved :: Apache Software License
12
+ Classifier: Operating System :: POSIX :: Linux
13
+ Classifier: Programming Language :: Python :: 3
14
+ Requires-Python: >=3.10
15
+ Requires-Dist: crossplane
16
+ Requires-Dist: ops<4,>=3
17
+ Description-Content-Type: text/markdown
18
+
19
+ # nginx-k8s
20
+
21
+ `nginx-k8s` provides abstractions for Juju Charms to run a sidecar Nginx container and a corresponding Prometheus exporter.
22
+ The supported Nginx configuration is not meant to fully cover all Nginx features, but a minimal subset sufficient to cover our immediate use cases.
23
+
24
+ To install, add `charmlibs-nginx-k8s` to your requirements. Then in your Python code, import as:
25
+
26
+ ```py
27
+ from charmlibs import nginx_k8s
28
+ ```
29
+
30
+ Check out the reference docs on the [charmlibs docsite](https://documentation.ubuntu.com/charmlibs/reference/charmlibs/nginx-k8s/).
31
+
32
+ # Getting started
33
+
34
+ To get started, you can add two sidecar containers to your charm's `charmcraft.yaml` and in `charm.py`,
35
+ instantiate the `Nginx` and `NginxPrometheusExporter` classes in your initializer and call their `.reconcile()` methods whenever you wish to synchronize the configuration files.
36
+
37
+ ```py
38
+ import ops
39
+
40
+ from charmlibs import nginx_k8s
41
+
42
+
43
+ class MyCharm(ops.CharmBase):
44
+ def __init__(self, framework: ops.Framework):
45
+ super().__init__(framework)
46
+ self._nginx = nginx_k8s.Nginx(
47
+ self.unit.get_container("nginx"), # container name as defined in charmcraft.yaml
48
+ nginx_config=nginx_k8s.NginxConfig(
49
+ server_name="foo",
50
+ upstream_configs=[
51
+ nginx_k8s.NginxUpstream(name="foo", port=4040, group="backend"),
52
+ nginx_k8s.NginxUpstream(name="bar", port=4041, group="frontend"),
53
+ ],
54
+ server_ports_to_locations={8080: [
55
+ nginx_k8s.NginxLocationConfig(
56
+ path="/",
57
+ backend="foo",
58
+ backend_url="/api/v1",
59
+ headers={"a": "b"},
60
+ modifier="=",
61
+ is_grpc=True,
62
+ upstream_tls=True
63
+ ),
64
+ ]}
65
+ )
66
+ )
67
+ self._nginx_pexp = nginx_k8s.NginxPrometheusExporter(
68
+ self.unit.get_container('nginx-pexp-container')
69
+ )
70
+
71
+ self.framework.observe(self.on.nginx_container_pebble_ready, self._on_reconcile)
72
+ self.framework.observe(self.on.nginx_pexp_container_pebble_ready, self._on_reconcile)
73
+
74
+ def _on_reconcile(self, _):
75
+ self._nginx.reconcile(
76
+ upstreams_to_addresses={
77
+ "foo": {"http://example.com"},
78
+ "bar": {"http://example.io"},
79
+ }
80
+ )
81
+ self._nginx_pexp.reconcile()
82
+ ```
@@ -0,0 +1,64 @@
1
+ # nginx-k8s
2
+
3
+ `nginx-k8s` provides abstractions for Juju Charms to run a sidecar Nginx container and a corresponding Prometheus exporter.
4
+ The supported Nginx configuration is not meant to fully cover all Nginx features, but a minimal subset sufficient to cover our immediate use cases.
5
+
6
+ To install, add `charmlibs-nginx-k8s` to your requirements. Then in your Python code, import as:
7
+
8
+ ```py
9
+ from charmlibs import nginx_k8s
10
+ ```
11
+
12
+ Check out the reference docs on the [charmlibs docsite](https://documentation.ubuntu.com/charmlibs/reference/charmlibs/nginx-k8s/).
13
+
14
+ # Getting started
15
+
16
+ To get started, you can add two sidecar containers to your charm's `charmcraft.yaml` and in `charm.py`,
17
+ instantiate the `Nginx` and `NginxPrometheusExporter` classes in your initializer and call their `.reconcile()` methods whenever you wish to synchronize the configuration files.
18
+
19
+ ```py
20
+ import ops
21
+
22
+ from charmlibs import nginx_k8s
23
+
24
+
25
+ class MyCharm(ops.CharmBase):
26
+ def __init__(self, framework: ops.Framework):
27
+ super().__init__(framework)
28
+ self._nginx = nginx_k8s.Nginx(
29
+ self.unit.get_container("nginx"), # container name as defined in charmcraft.yaml
30
+ nginx_config=nginx_k8s.NginxConfig(
31
+ server_name="foo",
32
+ upstream_configs=[
33
+ nginx_k8s.NginxUpstream(name="foo", port=4040, group="backend"),
34
+ nginx_k8s.NginxUpstream(name="bar", port=4041, group="frontend"),
35
+ ],
36
+ server_ports_to_locations={8080: [
37
+ nginx_k8s.NginxLocationConfig(
38
+ path="/",
39
+ backend="foo",
40
+ backend_url="/api/v1",
41
+ headers={"a": "b"},
42
+ modifier="=",
43
+ is_grpc=True,
44
+ upstream_tls=True
45
+ ),
46
+ ]}
47
+ )
48
+ )
49
+ self._nginx_pexp = nginx_k8s.NginxPrometheusExporter(
50
+ self.unit.get_container('nginx-pexp-container')
51
+ )
52
+
53
+ self.framework.observe(self.on.nginx_container_pebble_ready, self._on_reconcile)
54
+ self.framework.observe(self.on.nginx_pexp_container_pebble_ready, self._on_reconcile)
55
+
56
+ def _on_reconcile(self, _):
57
+ self._nginx.reconcile(
58
+ upstreams_to_addresses={
59
+ "foo": {"http://example.com"},
60
+ "bar": {"http://example.io"},
61
+ }
62
+ )
63
+ self._nginx_pexp.reconcile()
64
+ ```
@@ -0,0 +1,60 @@
1
+ [project]
2
+ name = "charmlibs-nginx-k8s"
3
+ description = "Nginx sidecar container abstractions for k8s charms."
4
+ readme = "README.md"
5
+ requires-python = ">=3.10"
6
+ authors = [
7
+ {name="The Observability team at Canonical Ltd."},
8
+ ]
9
+ classifiers = [
10
+ "Programming Language :: Python :: 3",
11
+ "License :: OSI Approved :: Apache Software License",
12
+ "Intended Audience :: Developers",
13
+ "Operating System :: POSIX :: Linux",
14
+ "Development Status :: 3 - Alpha",
15
+ ]
16
+ dynamic = ["version"]
17
+ dependencies = [
18
+ "ops>=3,<4",
19
+ "crossplane",
20
+ ]
21
+
22
+ [dependency-groups]
23
+ lint = [
24
+ "typing_extensions",
25
+ ]
26
+ unit = [
27
+ "ops[testing]>=3,<4",
28
+ ]
29
+ functional = []
30
+ integration = [
31
+ "jubilant",
32
+ "pytest-jubilant"
33
+ ]
34
+
35
+ [project.urls]
36
+ "Documentation" = "https://documentation.ubuntu.com/charmlibs"
37
+ "Repository" = "https://github.com/canonical/charmlibs"
38
+ "Issues" = "https://github.com/canonical/charmlibs/issues"
39
+
40
+ [build-system]
41
+ requires = ["hatchling"]
42
+ build-backend = "hatchling.build"
43
+
44
+ [tool.hatch.build.targets.wheel]
45
+ packages = ["src/charmlibs"]
46
+
47
+ [tool.hatch.version]
48
+ path = "src/charmlibs/nginx_k8s/__init__.py"
49
+
50
+ [tool.ruff]
51
+ extend = "../pyproject.toml"
52
+ src = ["src", "tests/unit", "tests/functional", "tests/integration"] # correctly sort local imports in tests
53
+
54
+ [tool.pyright]
55
+ extends = "../pyproject.toml"
56
+ include = ["./src"]
57
+ pythonVersion = "3.10"
58
+
59
+ [tool.charmlibs.integration]
60
+ tags = ["k8s"]
@@ -0,0 +1,48 @@
1
+ # Copyright 2025 Canonical Ltd.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ r"""Nginx sidecar container management abstractions.
16
+
17
+ The ``nginx_k8s`` charm library provides:
18
+
19
+ - :class:`Nginx`: A class to manage a nginx sidecar container.
20
+ Includes regular nginx config file generation, tls configuration, and reload logic.
21
+ - :class:`NginxPrometheusExporter`: A class to manage a nginx-prometheus-exporter
22
+ sidecar container.
23
+ - :class:`NginxConfig`: A nginx config file generation wrapper.
24
+
25
+ """
26
+
27
+ from __future__ import annotations
28
+
29
+ from ._config import (
30
+ NginxConfig,
31
+ NginxLocationConfig,
32
+ NginxUpstream,
33
+ )
34
+ from ._nginx import Nginx
35
+ from ._nginx_prometheus_exporter import NginxPrometheusExporter
36
+ from ._tls_config import TLSConfig, TLSConfigManager
37
+
38
+ __all__ = (
39
+ 'Nginx',
40
+ 'NginxConfig',
41
+ 'NginxLocationConfig',
42
+ 'NginxPrometheusExporter',
43
+ 'NginxUpstream',
44
+ 'TLSConfig',
45
+ 'TLSConfigManager',
46
+ )
47
+
48
+ __version__ = '0.0.1'