Skip to content

Commit

Permalink
CSS-10666: Add enable DB tls config (#42)
Browse files Browse the repository at this point in the history
* add enable db tls config
  • Loading branch information
kelkawi-a authored Sep 18, 2024
1 parent 40c7315 commit 478a1d3
Show file tree
Hide file tree
Showing 18 changed files with 129 additions and 141 deletions.
39 changes: 13 additions & 26 deletions .github/workflows/integration_test.yaml
Original file line number Diff line number Diff line change
@@ -1,32 +1,19 @@
name: Integration tests

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

on:
pull_request:
workflow_call:

jobs:
integration-test-microk8s:
name: Integration tests (microk8s)
strategy:
fail-fast: false
matrix:
tox-environments:
- integration-charm
- integration-scaling
- integration-upgrades
- integration-auth
- integration-server-upgrade
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Setup operator environment
uses: charmed-kubernetes/actions-operator@main
with:
juju-channel: 3.1/stable
provider: microk8s
microk8s-addons: "ingress storage dns rbac registry"
channel: 1.25-strict/stable
- name: Run integration tests
# set a predictable model name so it can be consumed by charm-logdump-action
run: tox -e ${{ matrix.tox-environments }}
integration-tests:
uses: canonical/operator-workflows/.github/workflows/integration_test.yaml@main
secrets: inherit
with:
channel: 1.28-strict/stable
modules: '["test_charm.py", "test_auth.py", "test_scaling.py", "test_server_upgrade.py", "test_upgrades.py"]'
juju-channel: 3.4/stable
self-hosted-runner: false
microk8s-addons: "dns ingress rbac storage metallb:10.15.119.2-10.15.119.4 registry"
2 changes: 1 addition & 1 deletion .github/workflows/promote_charm.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ on:

jobs:
promote-charm:
uses: canonical/operator-workflows/.github/workflows/promote_charm.yaml@8892eb826818585b397295e40276ddd0c5d3d459
uses: canonical/operator-workflows/.github/workflows/promote_charm.yaml@main
with:
origin-channel: ${{ github.event.inputs.origin-channel }}
destination-channel: ${{ github.event.inputs.destination-channel }}
Expand Down
13 changes: 13 additions & 0 deletions .github/workflows/publish_charm.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
name: Publish to edge

on:
push:
branches:
- main

jobs:
publish-charm:
uses: canonical/operator-workflows/.github/workflows/publish_charm.yaml@main
secrets: inherit
with:
channel: latest/edge
2 changes: 1 addition & 1 deletion .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ on:

jobs:
unit-tests:
uses: canonical/operator-workflows/.github/workflows/test.yaml@8892eb826818585b397295e40276ddd0c5d3d459
uses: canonical/operator-workflows/.github/workflows/test.yaml@main
secrets: inherit
29 changes: 0 additions & 29 deletions .github/workflows/test_and_publish_charm.yaml

This file was deleted.

9 changes: 4 additions & 5 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,10 @@ workflows are as follows:
library checks which run on every pull request.
- `integration_test.yaml`: This runs the suite of integration tests included
with the charm and runs on every pull request.
- `test_and_publish_charm.yaml`: This runs either by manual dispatch or on every
push to the main branch or a special track/\*\* branch. Once a PR is merged
with one of these branches, this workflow runs to ensure the tests have passed
before building the charm and publishing the new version to the edge channel
on Charmhub.
- `publish_charm.yaml`: This runs on every push to the main branch. Once a PR is
merged with one of these branches, this workflow runs to ensure the tests have
passed before building the charm and publishing the new version to the edge
channel on Charmhub.
- `promote_charm.yaml`: This is a manually triggered workflow which publishes
the charm currently on the edge channel to the stable channel on Charmhub.

Expand Down
5 changes: 5 additions & 0 deletions config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -119,3 +119,8 @@ options:
in this config will fall back to the value defined in `global-rps-limit`.
default: ""
type: string

db-tls-enabled:
description: Where TLS is enabled on the database.
default: False
type: boolean
1 change: 1 addition & 0 deletions src/charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,7 @@ def _update(self, event):
"SQL_VIS_MAX_CONNS": self.config["visibility-max-conns"],
"SQL_VIS_MAX_IDLE_CONNS": self.config["visibility-max-idle-conns"],
"SQL_VIS_MAX_CONN_TIME": self.config["visibility-max-conn-time"],
"SQL_TLS_ENABLED": db_conn.get("tls", False),
}
)

Expand Down
3 changes: 3 additions & 0 deletions src/relations/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,9 @@ def _provide_db_info(self):
"""Provide DB info to the admin charm."""
charm = self.charm

if not charm.unit.is_leader():
return

try:
database_connections = charm.database_connections()
except ValueError as err:
Expand Down
2 changes: 2 additions & 0 deletions src/relations/postgresql.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,12 @@ def _on_database_changed(self, event: DatabaseEvent) -> None:
"port": port,
"password": event.password,
"user": event.username,
"tls": self.charm.config["db-tls-enabled"],
}

self._update_db_connections(rel_name, db_conn)

self.charm.admin._provide_db_info()
self.charm._update(event)

@log_event_handler(logger)
Expand Down
4 changes: 4 additions & 0 deletions tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Copyright 2024 Canonical Ltd.
# See LICENSE file for licensing details.

"""Tests module."""
16 changes: 16 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Copyright 2024 Canonical Ltd.
# See LICENSE file for licensing details.

"""Fixtures for charm tests."""

import pytest


def pytest_addoption(parser: pytest.Parser):
"""Parse additional pytest options.
Args:
parser: pytest command line parser.
"""
# The prebuilt charm file.
parser.addoption("--charm-file", action="append", default=[])
31 changes: 27 additions & 4 deletions tests/integration/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import asyncio
import logging
from pathlib import Path

import pytest_asyncio
from helpers import (
Expand All @@ -15,15 +16,26 @@
create_default_namespace,
perform_temporal_integrations,
)
from pytest import FixtureRequest
from pytest_operator.plugin import OpsTest

logger = logging.getLogger(__name__)


@pytest_asyncio.fixture(scope="module", name="charm")
async def charm_fixture(request: FixtureRequest, ops_test: OpsTest) -> str | Path:
"""Fetch the path to charm."""
charms = request.config.getoption("--charm-file")
if not charms:
charm = await ops_test.build_charm(".")
assert charm, "Charm not built"
return charm
return charms[0]


@pytest_asyncio.fixture(name="deploy", scope="module")
async def deploy(ops_test: OpsTest):
async def deploy(ops_test: OpsTest, charm: str):
"""The app is up and running."""
charm = await ops_test.build_charm(".")
resources = {"temporal-server-image": METADATA["containers"]["temporal"]["upstream-source"]}

# Deploy temporal server, temporal admin and postgresql charms.
Expand All @@ -32,16 +44,27 @@ async def deploy(ops_test: OpsTest):
charm,
resources=resources,
application_name=APP_NAME,
config={"num-history-shards": 1, "global-rps-limit": 100, "namespace-rps-limit": "default:50|test:40"},
config={
"num-history-shards": 1,
"global-rps-limit": 100,
"db-tls-enabled": True,
"namespace-rps-limit": "default:50|test:40",
},
),
ops_test.model.deploy(APP_NAME_ADMIN, channel="edge"),
ops_test.model.deploy(APP_NAME_UI, channel="edge"),
ops_test.model.deploy("postgresql-k8s", channel="14/stable", trust=True),
ops_test.model.deploy("self-signed-certificates", channel="latest/stable"),
)

async with ops_test.fast_forward():
await ops_test.model.wait_for_idle(
apps=["postgresql-k8s"], status="active", raise_on_blocked=False, timeout=1200
apps=["postgresql-k8s", "self-signed-certificates"], status="active", raise_on_blocked=False, timeout=1200
)

await ops_test.model.integrate("self-signed-certificates", "postgresql-k8s")
await ops_test.model.wait_for_idle(
apps=["postgresql-k8s", "self-signed-certificates"], status="active", raise_on_blocked=False, timeout=1200
)
await ops_test.model.wait_for_idle(
apps=[APP_NAME, APP_NAME_ADMIN, APP_NAME_UI], status="blocked", raise_on_blocked=False, timeout=600
Expand Down
6 changes: 5 additions & 1 deletion tests/integration/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,11 @@ async def simulate_charm_crash(ops_test: OpsTest):

# Deploy temporal server, temporal admin and postgresql charms.
await ops_test.model.deploy(
charm, resources=resources, application_name=APP_NAME, num_units=1, config={"num-history-shards": 1}
charm,
resources=resources,
application_name=APP_NAME,
num_units=1,
config={"num-history-shards": 1, "db-tls-enabled": True},
)

async with ops_test.fast_forward():
Expand Down
5 changes: 4 additions & 1 deletion tests/integration/test_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,10 @@ async def test_openfga_relation(self, ops_test: OpsTest):
)
result = await action.wait()
logger.info(f"attempt {i} -> action result {result.status} {result.results}")
if result.status == "completed" and result.results == {"return-code": 0}:
if result.status == "completed" and result.results == {
"result": "successfully created authorization model",
"return-code": 0,
}:
break
time.sleep(2)

Expand Down
22 changes: 18 additions & 4 deletions tests/integration/test_server_upgrade.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
logger = logging.getLogger(__name__)


@pytest.mark.skip # TODO (kelkawi-a): investigate bug with test https://github.com/canonical/temporal-k8s-operator/actions/runs/10886756137/job/30209211247
@pytest.mark.skip_if_deployed
@pytest_asyncio.fixture(name="deploy", scope="module")
async def deploy(ops_test: OpsTest):
Expand Down Expand Up @@ -62,6 +63,7 @@ async def deploy(ops_test: OpsTest):
await run_sample_workflow(ops_test)


@pytest.mark.skip
@pytest.mark.abort_on_fail
@pytest.mark.usefixtures("deploy")
class TestServerUpgrade:
Expand All @@ -74,22 +76,34 @@ class TestServerUpgrade:
async def test_server_upgrade(self, ops_test: OpsTest):
"""Refresh the charm with a new resource which requires a schema update."""
# Update admin charm to v1.21.2 first
await ops_test.model.applications[APP_NAME_ADMIN].refresh(
resources={"temporal-admin-image": "temporalio/admin-tools:1.21.2"},
await ops_test.model.applications[APP_NAME_ADMIN].destroy()
await ops_test.model.block_until(lambda: APP_NAME_ADMIN not in ops_test.model.applications)
await ops_test.model.deploy(
APP_NAME_ADMIN, channel="edge", resources={"temporal-admin-image": "temporalio/admin-tools:1.21.2"}
)
await ops_test.model.wait_for_idle(
apps=[APP_NAME_ADMIN], raise_on_error=False, status="active", raise_on_blocked=False, timeout=600
)

admin_unit = ops_test.model.applications[APP_NAME_ADMIN].units[0]
action = await admin_unit.run_action("setup-schema")
await action.wait()

# Needed for a local charm refresh
charm = await ops_test.build_charm(".")

# Update server charm to v1.21.2
await ops_test.model.applications[APP_NAME].refresh(
await ops_test.model.applications[APP_NAME].destroy()
await ops_test.model.block_until(lambda: APP_NAME not in ops_test.model.applications)
await ops_test.model.deploy(
charm,
application_name=APP_NAME,
resources={"temporal-server-image": "temporalio/server:1.21.2"},
path=str(charm),
config={"num-history-shards": "1"},
)

await perform_temporal_integrations(ops_test)

# This is to accmmodate for a self-resolving error which sometimes appears when Temporal
# services attempt to connect to the cluster before the application is ready.
await ops_test.model.wait_for_idle(
Expand Down
Loading

0 comments on commit 478a1d3

Please sign in to comment.