Skip to content

Commit

Permalink
add nginx workload and some config
Browse files Browse the repository at this point in the history
  • Loading branch information
lucabello committed Dec 1, 2023
1 parent 393b524 commit 2e13fb4
Show file tree
Hide file tree
Showing 5 changed files with 358 additions and 9 deletions.
16 changes: 8 additions & 8 deletions metadata.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,19 @@ summary: Mimir coordinator
description: |
Mimir coordinator.
#containers:
# nginx:
# resource: nginx-image
containers:
nginx:
resource: nginx-image

storage:
data:
type: filesystem

#resources:
# nginx-image:
# type: oci-image
# description: OCI image for nginx
# upstream-source: ubuntu/nginx:1.18-22.04_beta
resources:
nginx-image:
type: oci-image
description: OCI image for nginx
upstream-source: ubuntu/nginx:1.18-22.04_beta
# agent-image:
# type: oci-image
# upstream-source: ghcr.io/canonical/grafana-agent:latest
Expand Down
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
ops
pydantic
# crossplane is a package from nginxinc to interact with the Nginx config
crossplane
17 changes: 17 additions & 0 deletions src/charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
PrometheusRemoteWriteConsumer,
)
from mimir_coordinator import MimirCoordinator
from nginx import Nginx
from ops.charm import CharmBase, CollectStatusEvent
from ops.main import main
from ops.model import ActiveStatus, BlockedStatus, Relation
Expand All @@ -32,6 +33,10 @@ class MimirCoordinatorK8SOperatorCharm(CharmBase):

def __init__(self, *args):
super().__init__(*args)

self._nginx_container = self.unit.get_container("nginx")
self._nginx_config_path = "/etc/nginx/nginx.conf"

self.framework.observe(self.on.config_changed, self._on_config_changed)
self.framework.observe(self.on.collect_unit_status, self._on_collect_status)

Expand All @@ -42,6 +47,12 @@ def __init__(self, *args):
self.cluster_provider = MimirClusterProvider(self)
self.coordinator = MimirCoordinator(cluster_provider=self.cluster_provider)

self.nginx = Nginx()
self.framework.observe(
self.on.nginx_pebble_ready, # pyright: ignore
self._on_nginx_pebble_ready,
)

self.framework.observe(
self.on.mimir_cluster_relation_changed, # pyright: ignore
self._on_mimir_cluster_changed,
Expand Down Expand Up @@ -123,6 +134,12 @@ def _on_loki_relation_changed(self, _):
# TODO Update rules relation with the new list of Loki push-api endpoints
pass

def _on_nginx_pebble_ready(self, _event) -> None:
self._nginx_container.push(self.nginx.config_path, self.nginx.config, make_dirs=True)

self._nginx_container.add_layer("nginx", self.nginx.layer, combine=True)
self._nginx_container.autostart()


if __name__ == "__main__": # pragma: nocover
main(MimirCoordinatorK8SOperatorCharm)
Loading

0 comments on commit 2e13fb4

Please sign in to comment.