Skip to content

Commit

Permalink
Ingress v2 support (#58)
Browse files Browse the repository at this point in the history
  • Loading branch information
arturo-seijas committed Nov 14, 2023
1 parent ac6a9e5 commit cfbbb4d
Show file tree
Hide file tree
Showing 8 changed files with 707 additions and 1 deletion.
579 changes: 579 additions & 0 deletions lib/charms/traefik_k8s/v1/ingress.py

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions metadata.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ requires:
interface: jenkins_agent_v0
optional: true
limit: 2
ingress:
interface: ingress
optional: true
limit: 1
logging:
interface: loki_push_api
provides:
Expand Down
2 changes: 1 addition & 1 deletion src-docs/charm.py.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Charm Jenkins.
## <kbd>class</kbd> `JenkinsK8sOperatorCharm`
Charm Jenkins.

<a href="../src/charm.py#L30"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>
<a href="../src/charm.py#L31"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>

### <kbd>function</kbd> `__init__`

Expand Down
40 changes: 40 additions & 0 deletions src-docs/ingress.py.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<!-- markdownlint-disable -->

<a href="../src/ingress.py#L0"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>

# <kbd>module</kbd> `ingress.py`
Observer module for Jenkins to ingress integration.



---

## <kbd>class</kbd> `Observer`
The Jenkins Ingress integration observer.

<a href="../src/ingress.py#L15"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>

### <kbd>function</kbd> `__init__`

```python
__init__(charm: CharmBase)
```

Initialize the observer and register event handlers.



**Args:**

- <b>`charm`</b>: The parent charm to attach the observer to.


---

#### <kbd>property</kbd> model

Shortcut for more simple access the model.




2 changes: 2 additions & 0 deletions src/charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

import agent
import cos
import ingress
import jenkins
import status
import timerange
Expand Down Expand Up @@ -47,6 +48,7 @@ def __init__(self, *args: typing.Any):

self.agent_observer = agent.Observer(self, self.state)
self.cos_observer = cos.Observer(self)
self.ingress_observer = ingress.Observer(self)
self.framework.observe(self.on.jenkins_pebble_ready, self._on_jenkins_pebble_ready)
self.framework.observe(self.on.get_admin_password_action, self._on_get_admin_password)
self.framework.observe(self.on.update_status, self._on_update_status)
Expand Down
24 changes: 24 additions & 0 deletions src/ingress.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Copyright 2023 Canonical Ltd.
# See LICENSE file for licensing details.

"""Observer module for Jenkins to ingress integration."""

import ops
from charms.traefik_k8s.v1.ingress import IngressPerAppRequirer

import jenkins


class Observer(ops.Object):
"""The Jenkins Ingress integration observer."""

def __init__(self, charm: ops.CharmBase):
"""Initialize the observer and register event handlers.
Args:
charm: The parent charm to attach the observer to.
"""
super().__init__(charm, "ingress-observer")
self.charm = charm

self.ingress = IngressPerAppRequirer(self.charm, port=jenkins.WEB_PORT)
29 changes: 29 additions & 0 deletions tests/integration/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -666,3 +666,32 @@ async def grafana_related_fixture(application: Application):
raise_on_error=False,
)
return grafana


@pytest_asyncio.fixture(scope="module", name="external_hostname")
def external_hostname_fixture() -> str:
"""Return the external hostname for ingress-related tests."""
return "juju.test"


@pytest_asyncio.fixture(scope="module", name="ingress_related")
async def ingress_application_related_fixture(application: Application, external_hostname: str):
"""The application related to Jenkins via ingress v2 relation."""
traefik = await application.model.deploy(
"traefik-k8s",
channel="1.0/stable",
trust=True,
config={"external_hostname": external_hostname},
)
await application.model.wait_for_idle(
status="active", apps=[traefik.name], raise_on_error=False, timeout=30 * 60
)
await application.model.add_relation(f"{application.name}:ingress", traefik.name)
await application.model.wait_for_idle(
status="active",
apps=[traefik.name, application.name],
timeout=20 * 60,
idle_period=30,
raise_on_error=False,
)
return traefik
28 changes: 28 additions & 0 deletions tests/integration/test_ingress.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Copyright 2023 Canonical Ltd.
# See LICENSE file for licensing details.

"""Integration tests for jenkins-k8s-operator with ingress."""

import pytest
import requests
from juju.application import Application
from juju.model import Model


@pytest.mark.abort_on_fail
async def test_ingress_integration(
model: Model, ingress_related: Application, external_hostname: str
):
"""
arrange: deploy the Jenkins charm and establish relations via ingress.
act: send a request to the ingress in /.
assert: the response succeeds.
"""
status = await model.get_status(filters=[ingress_related.name])
unit = next(iter(status.applications[ingress_related.name].units))
response = requests.get(
f"http://{unit.address}",
headers={"Host": f"{model.name}-{ingress_related.name}.{external_hostname}"},
timeout=5,
).json()
assert response.status_code == 200

0 comments on commit cfbbb4d

Please sign in to comment.