Skip to content

Commit

Permalink
Switch to charmed-etcd snap and publish to Charmhub (#7)
Browse files Browse the repository at this point in the history
With this PR, we use revision 1 of the `charmed-etcd` snap instead of
legacy `etcd` snap. Furthermore the PR enables the release-workflow for
publishing to Charmhub `3.5/edge` on pushes to main.
  • Loading branch information
reneradoi authored Nov 29, 2024
1 parent 34849bc commit c2e05fa
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 21 deletions.
26 changes: 13 additions & 13 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,16 @@ jobs:
name: Build charm
uses: canonical/data-platform-workflows/.github/workflows/[email protected]

# release:
# name: Release charm
# needs:
# - ci-tests
# - build
# uses: canonical/data-platform-workflows/.github/workflows/[email protected]
# with:
# channel: 3.5/edge
# artifact-prefix: ${{ needs.build.outputs.artifact-prefix }}
# secrets:
# charmhub-token: ${{ secrets.CHARMHUB_TOKEN }}
# permissions:
# contents: write # Needed to create GitHub release
release:
name: Release charm
needs:
- ci-tests
- build
uses: canonical/data-platform-workflows/.github/workflows/[email protected]
with:
channel: 3.5/edge
artifact-prefix: ${{ needs.build.outputs.artifact-prefix }}
secrets:
charmhub-token: ${{ secrets.CHARMHUB_TOKEN }}
permissions:
contents: write # Needed to create GitHub release
4 changes: 3 additions & 1 deletion src/common/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import logging
import subprocess

from literals import SNAP_NAME

logger = logging.getLogger(__name__)


Expand Down Expand Up @@ -62,7 +64,7 @@ def _run_etcdctl(
try:
result = subprocess.run(
args=[
"etcdctl",
f"{SNAP_NAME}.etcdctl",
command,
subcommand,
f"--endpoints={endpoints}",
Expand Down
6 changes: 3 additions & 3 deletions src/literals.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@

from ops.model import ActiveStatus, BlockedStatus, MaintenanceStatus, StatusBase

SNAP_NAME = "etcd"
SNAP_REVISION = 233
SNAP_NAME = "charmed-etcd"
SNAP_REVISION = 1
SNAP_SERVICE = "etcd"
# this path will be updated when we switch to charmed-etcd snap
# it's the current config path for the legacy-etcd snap
CONFIG_FILE = "/var/snap/etcd/common/etcd.conf.yml"
CONFIG_FILE = "/var/snap/charmed-etcd/current/etcd.conf.yml"

PEER_RELATION = "etcd-peers"
CLIENT_PORT = 2379
Expand Down
1 change: 1 addition & 0 deletions src/managers/config/etcd.conf.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
data-dir: "/var/snap/charmed-etcd/common/var/lib/etcd"
initial-cluster-token: 'etcd-cluster'
snapshot-count: 10000
heartbeat-interval: 100
Expand Down
8 changes: 4 additions & 4 deletions tests/integration/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import yaml
from pytest_operator.plugin import OpsTest

from literals import CLIENT_PORT
from literals import CLIENT_PORT, SNAP_NAME

logger = logging.getLogger(__name__)

Expand All @@ -20,23 +20,23 @@

def put_key(model: str, unit: str, endpoints: str, key: str, value: str) -> str:
"""Write data to etcd using `etcdctl` via `juju ssh`."""
etcd_command = f"etcdctl put {key} {value} --endpoints={endpoints}"
etcd_command = f"{SNAP_NAME}.etcdctl put {key} {value} --endpoints={endpoints}"
juju_command = f"juju ssh --model={model} {unit} {etcd_command}"

return subprocess.getoutput(juju_command).split("\n")[0]


def get_key(model: str, unit: str, endpoints: str, key: str) -> str:
"""Read data from etcd using `etcdctl` via `juju ssh`."""
etcd_command = f"etcdctl get {key} --endpoints={endpoints}"
etcd_command = f"{SNAP_NAME}.etcdctl get {key} --endpoints={endpoints}"
juju_command = f"juju ssh --model={model} {unit} {etcd_command}"

return subprocess.getoutput(juju_command).split("\n")[1]


def get_cluster_members(model: str, unit: str, endpoints: str) -> list[dict]:
"""Query all cluster members from etcd using `etcdctl` via `juju ssh`."""
etcd_command = f"etcdctl member list --endpoints={endpoints} -w=json"
etcd_command = f"{SNAP_NAME}.etcdctl member list --endpoints={endpoints} -w=json"
juju_command = f"juju ssh --model={model} {unit} {etcd_command}"

result = subprocess.getoutput(juju_command).split("\n")[0]
Expand Down

0 comments on commit c2e05fa

Please sign in to comment.