Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions .github/scripts/install-dqlite.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/usr/bin/env bash
set -euo pipefail

sudo apt-get update
sudo apt-get install -y --no-install-recommends \
autoconf automake build-essential liblz4-dev libsqlite3-dev libtool libuv1-dev pkg-config

build_dir=$(mktemp -d)
trap 'rm -rf "$build_dir"' EXIT

git clone --depth 1 --branch lts-1.17.x https://github.com/canonical/dqlite "$build_dir"
cd "$build_dir"
autoreconf -i
./configure --enable-build-raft --prefix=/usr/local
make -j"$(nproc)"
sudo make install
sudo ldconfig
16 changes: 9 additions & 7 deletions .github/workflows/build-golang.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,20 @@ on:
jobs:
build:
name: Build binary
runs-on: ubuntu-latest
strategy:
matrix:
runner: [ubuntu-24.04, ubuntu-26.04]
runs-on: ${{ matrix.runner }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
uses: actions/checkout@v6
- name: Setup GO
uses: actions/setup-go@v4
uses: actions/setup-go@v6
with:
go-version: '1.27'
- name: Install dependencies
run: |
sudo add-apt-repository -y ppa:dqlite/dev
sudo apt install build-essential libdqlite1.17-dev -y
cache-dependency-path: sunbeam-microcluster/go.sum
- name: Build dqlite 1.17
run: bash .github/scripts/install-dqlite.sh
- name: Build binary
working-directory: ./sunbeam-microcluster
run: make build
2 changes: 2 additions & 0 deletions .github/workflows/pr-golang.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ on:
pull_request:
paths:
- 'sunbeam-microcluster/**'
- '.github/scripts/install-dqlite.sh'
- '.github/workflows/*-golang.yml'

jobs:
test:
Expand Down
32 changes: 18 additions & 14 deletions .github/workflows/test-golang.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,36 +6,40 @@ on:
jobs:
lint:
name: Lint
runs-on: ubuntu-latest
strategy:
matrix:
runner: [ubuntu-24.04, ubuntu-26.04]
runs-on: ${{ matrix.runner }}
steps:
- name: Checkout
uses: actions/checkout@v4
uses: actions/checkout@v6
- name: Setup GO
uses: actions/setup-go@v4
uses: actions/setup-go@v6
with:
go-version: '1.27'
- name: Install dependencies
run: |
sudo add-apt-repository -y ppa:dqlite/dev
sudo apt install build-essential libdqlite1.17-dev -y
cache-dependency-path: sunbeam-microcluster/go.sum
- name: Build dqlite 1.17
run: bash .github/scripts/install-dqlite.sh
- name: Run linters
working-directory: ./sunbeam-microcluster
run: make check-static

unit-test:
name: Unit tests
runs-on: ubuntu-latest
strategy:
matrix:
runner: [ubuntu-24.04, ubuntu-26.04]
runs-on: ${{ matrix.runner }}
steps:
- name: Checkout
uses: actions/checkout@v4
uses: actions/checkout@v6
- name: Setup GO
uses: actions/setup-go@v4
uses: actions/setup-go@v6
with:
go-version: '1.27'
- name: Install dependencies
run: |
sudo add-apt-repository -y ppa:dqlite/dev
sudo apt install build-essential libdqlite1.17-dev -y
cache-dependency-path: sunbeam-microcluster/go.sum
- name: Build dqlite 1.17
run: bash .github/scripts/install-dqlite.sh
- name: Run tests
working-directory: ./sunbeam-microcluster
run: make check-unit
Expand Down
11 changes: 7 additions & 4 deletions snap/snapcraft.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: openstack
base: core24
base: core26
summary: Dead simple OpenStack installation
license: Apache-2.0
description: |
Expand Down Expand Up @@ -88,7 +88,7 @@ parts:
- --prefix=
- --enable-build-raft
stage-packages:
- libuv1
- libuv1t64
- liblz4-1
- libsqlite3-0
build-packages:
Expand Down Expand Up @@ -249,18 +249,21 @@ parts:
- cargo
stage-packages:
- openssh-client
- python3-venv
override-build: |
uv export --directory sunbeam-python --extra=openstackclients --frozen --no-hashes --format=requirements-txt -o requirements.txt
craftctl default
override-prime: |
craftctl default
# Write out snap hooks
snap-helpers write-hooks
./bin/python3 ./bin/snap-helpers write-hooks
# Keep hooks on the snap's virtual environment when run by snapd.
sed -i '1c\#!/snap/openstack/current/bin/python3' snap/hooks/*
# This is the last step, let's now compile all our pyc files.
./bin/python3 -m compileall .
# Generate completer script snippets
mkdir -p usr/share/bash-completion/completions
./bin/openstack complete > usr/share/bash-completion/completions/openstack
./bin/python3 ./bin/openstack complete > usr/share/bash-completion/completions/openstack
echo "complete -F _openstack openstack.openstack" >> usr/share/bash-completion/completions/openstack
# Pre-generate sunbeam completion cache
cp completions/sunbeam-completion usr/share/bash-completion/completions/sunbeam-completion
Expand Down
86 changes: 79 additions & 7 deletions sunbeam-microcluster/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,86 @@ The cluster daemon for Sunbeam based on MicroCluster library
The MicroCluster library makes use of dqlite which provides a raft based
sqlite compatible database for shared state across the Sunbeam cluster.

This requires a few dependencies to be installed:
Build with Go 1.27 and dqlite 1.17. On Ubuntu 24.04 or 26.04, run
from the repository root:

sudo add-apt-repository -y ppa:dqlite/dev
sudo apt install gcc make libdqlite1.17-dev -y
sudo snap install --channel 1.21 --classic go
bash .github/scripts/install-dqlite.sh
make -C sunbeam-microcluster build

after which is possible to build sunbeam-microcluster:
The script builds dqlite from the `lts-1.17.x` branch used by the snap.

make build
## Upgrading clusterd from MicroCluster v2.2.5 to v3.1.3

Have fun!
Fresh deployments initialize the current schema during bootstrap. For
existing deployments, refresh the OpenStack snap in place. Snapd
restarts `openstack.clusterd`, and `sunbeamd` opens the existing database,
certificates, and truststore under `$SNAP_COMMON/state`. Keep that state
directory and the existing cluster membership.

MicroCluster v2.2.5 already uses `core_token_records`. Both versions have
the same internal schema version, so the library upgrade requires no
additional schema migration. OpenStack release upgrades can include
separate Sunbeam schema updates.
[MicroCluster v2.2.5 schema](https://github.com/canonical/microcluster/blob/v2.2.5/internal/db/update/update.go) ·
[MicroCluster v3.1.3 schema](https://github.com/canonical/microcluster/blob/v3.1.3/internal/db/update/update.go)

### Readiness and recovery

Start with healthy membership and quorum. When the schema version
stays the same, refresh one clusterd member at a time and wait for it to
come back online before refreshing the next member.
Comment thread
hemanthnakkina marked this conversation as resolved.
Resolved

Complete schema-changing upgrades in one maintenance window. Refreshed
members return HTTP 503 for database-backed requests until all members
start with the new schema version. Older members that are still running
can serve requests while dqlite has quorum. Manual clients on refreshed
nodes use the local daemon, and MAAS clients can also see 503 if their
configured endpoint is a refreshed member.

Continue to the next member once the current refresh completes and the
daemon reports that it is waiting for the schema update. Check that all
members are online and cluster state is readable after the final member
starts. Once the new schema commits, a daemon that supports only the
earlier schema cannot reopen the database. Plan recovery at the cluster
level.
[MicroCluster schema upgrade behavior](https://github.com/canonical/microcluster/blob/v3.1.3/doc/upgrades.md)

### Verifying a three-member MAAS refresh

Before refreshing, record the cluster membership and an existing Sunbeam
configuration value. Use each unit's local control socket for the checks
so that traffic cannot be routed to a different member. For example, read
an existing key with `GET /1.0/config/<key>` over
`/var/snap/openstack/common/state/control.socket`.

1. For a same-schema upgrade, run the `sunbeam-clusterd` charm's
`refresh-snap` action on one unit. Check that the refreshed unit can
read the recorded value and has rejoined the cluster before running
the action on the next unit. Run the same checks during a rolling
`snap revert openstack` on the same schema.
2. For a schema-changing upgrade, check that the refreshed unit either
reads the recorded value or explicitly reports `Database is waiting
for an upgrade` with HTTP 503 before advancing. A stopped daemon,
generic 503, or failed connection needs investigation. Check that the
remaining old units can still read while the cluster has quorum.
Once all units are refreshed, check the recorded value and membership
from each unit.
3. Create an unused join token before refresh and revoke it after
refresh. Create a second token after refresh and revoke it after a
same-schema revert. Check that each revoked token disappears from
the token list.

### Join-token revocation API

Use the route for the version running on the node you contact. Sunbeam's
CLI ships with the matching client for its local daemon.

| MicroCluster version | Request over the local control socket |
| --- | --- |
| v2.2.5 | `DELETE /core/1.0/tokens/<name>` |
| v3.1.3 | `DELETE /core/control/tokens/<name>` |

Token creation and listing still use `/core/control/tokens` in both
versions. A mismatched DELETE route returns HTTP 404, including when the
token still exists. Check the daemon version before interpreting a 404
from a direct API call.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main
package access

import (
"context"
Expand Down Expand Up @@ -131,7 +131,7 @@ func TestAuthenticateClient(t *testing.T) {

for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
allowed, err := authenticateClient(context.Background(), nil, tc.request, tc.trustedCerts)
allowed, err := AuthenticateClient(context.Background(), nil, tc.request, tc.trustedCerts)

if err != nil {
t.Errorf("Expected no error, got %v", err)
Expand Down
Loading
Loading