Skip to content

Commit

Permalink
Add bootstrap option to prepare-node-script
Browse files Browse the repository at this point in the history
Add bootstrap option on prepare-node-script to setup juju controller on
LXD on primary node.

Signed-off-by: Guillaume Boutry <[email protected]>
  • Loading branch information
gboutry committed Jan 15, 2025
1 parent 11c767e commit 557eb7b
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 21 deletions.
13 changes: 3 additions & 10 deletions .github/workflows/build-snap.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,6 @@ jobs:
sudo apt remove --purge docker.io containerd runc -y
sudo rm -rf /run/containerd
sudo lxd init --auto
sudo lxc network create br0
sudo lxc profile device remove default eth0
sudo lxc profile device add default eth0 nic network=br0 name=eth0
sudo lxc network delete lxdbr0
sudo snap install juju --channel 3.6/stable
juju bootstrap localhost lxdcloud
# Allow lxd controller to reach to k8s controller on loadbalancer ip
# sudo nft insert rule ip filter FORWARD tcp dport 17070 accept
# sudo nft insert rule ip filter FORWARD tcp sport 17070 accept
Expand All @@ -65,9 +56,11 @@ jobs:
# Accept all packets filtered for forward
sudo nft chain ip filter FORWARD '{policy accept;}'
sudo snap install --channel 3.6 juju
sudo snap install ${{ needs.build.outputs.snap }} --dangerous
openstack.sunbeam prepare-node-script | bash -x
sudo snap connect openstack:juju-bin juju:juju-bin
openstack.sunbeam prepare-node-script --bootstrap | bash -x
sudo snap connect openstack:dot-local-share-juju
sudo snap connect openstack:dot-config-openstack
sudo snap connect openstack:dot-local-share-openstack
Expand Down
10 changes: 2 additions & 8 deletions .github/workflows/test-snap.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,16 +66,10 @@ jobs:
# 2023.x, 2024.1/beta does not support k8s provider
if [[ ! ${{ inputs.snap-channel }} =~ "2024.1/edge" && ${{ inputs.k8s-provider }} == "k8s" ]]; then echo "k8s provider not supported"; exit 1; fi
sudo lxd init --auto
sudo lxc network create br0
sudo lxc profile device remove default eth0
sudo lxc profile device add default eth0 nic network=br0 name=eth0
sudo lxc network delete lxdbr0
sudo snap install juju --channel 3.6/stable
juju bootstrap localhost lxdcloud
sudo snap install openstack --channel ${{ inputs.snap-channel }}
sudo snap connect openstack:juju-bin juju:juju-bin
sudo snap set openstack k8s.provider=${{ inputs.k8s-provider }}
# New manifest is applicable from 2024.1/edge
Expand All @@ -95,7 +89,7 @@ jobs:
sed -i 's|MYSQL_ROUTER_CHARM|${{ inputs.mysql-router-charm-channel }}|' manifest.yml
echo "Manifest used:"
cat manifest.yml
sunbeam prepare-node-script | bash -x
sunbeam prepare-node-script --bootstrap | bash -x
sg snap_daemon "sunbeam cluster bootstrap --manifest ./manifest.yml --accept-defaults --topology single --database ${{ inputs.multi-mysql }}"
sg snap_daemon "sunbeam cluster list"
# Note: Moving configure before enabling caas just to ensure caas images are not downloaded
Expand Down
2 changes: 1 addition & 1 deletion docs/deploy-locally-built-snap.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ sudo snap alias openstack.sunbeam sunbeam
Prepare the node:

```
sunbeam prepare-node-script | bash -x && newgrp snap_daemon
sunbeam prepare-node-script --bootstrap | bash -x && newgrp snap_daemon
```

Because it's installed in dangerous mode, snap connections aren't added automatically. This must be done after installing the Juju snap (Juju is installed by running the prepare node script above), and before we begin bootstrapping. So add the connections now:
Expand Down
62 changes: 60 additions & 2 deletions sunbeam-python/sunbeam/commands/prepare_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import click
from rich.console import Console

from sunbeam.versions import JUJU_CHANNEL, SUPPORTED_RELEASE
from sunbeam.versions import JUJU_CHANNEL, LXD_CHANNEL, SUPPORTED_RELEASE

console = Console()

Expand Down Expand Up @@ -111,19 +111,77 @@
fi
"""

BOOTSTRAP_TEMPLATE = f"""
# Install the lxd snap
sudo snap install lxd --channel {LXD_CHANNEL}
USER=$(whoami)
# Ensure current user is part of the LXD group
sudo usermod --append --groups lxd $USER
# Try to determine if LXD is already bootstrapped
if [ -z "$(sudo --user $USER lxc storage list --format csv)" ];
then
lxdbr=$(sudo --user $USER lxc network list --format csv | grep lxdbr0)
if [ -z "$lxdbr" ]; then
echo 'Sunbeam requires the LXD bridge to be called anything except lxdbr0'
exit 1
fi
echo 'Bootstrapping LXD'
cat <<EOF | sudo --user $USER lxd init --preseed
networks:
- config:
ipv4.address: auto
ipv6.address: none
name: sunbeambr0
project: default
storage_pools:
- name: default
driver: dir
profiles:
- devices:
eth0:
name: eth0
network: br0
type: nic
root:
path: /
pool: default
type: disk
name: default
EOF
fi
# Bootstrap juju onto LXD
echo 'Bootstrapping Juju onto LXD'
sudo --user $USER juju show-controller
if [ $? -eq 0 ]; then
sudo --user $USER juju bootstrap localhost
fi
"""


@click.command()
@click.option(
"--bootstrap",
is_flag=True,
help="Prepare the node for use as primary node.",
default=False,
)
@click.option(
"--client",
"-c",
is_flag=True,
help="Prepare the node for use as a client.",
default=False,
)
def prepare_node_script(client: bool = False) -> None:
def prepare_node_script(bootstrap: bool = False, client: bool = False) -> None:
"""Generate script to prepare a node for Sunbeam use."""
if bootstrap and client:
raise click.UsageError("Cannot prepare node as both client and bootstrap")
script = "#!/bin/bash\n"
if not client:
script += PREPARE_NODE_TEMPLATE
script += COMMON_TEMPLATE
if bootstrap:
script += BOOTSTRAP_TEMPLATE
console.print(script, soft_wrap=True)
1 change: 1 addition & 0 deletions sunbeam-python/sunbeam/versions.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
CONSUL_CHANNEL = "1.19/edge"
TEMPEST_CHANNEL = "2024.1/stable"
K8S_CHANNEL = "1.32/beta"
LXD_CHANNEL = "5.21/stable"

# List of charms with default channels
OPENSTACK_CHARMS_K8S = {
Expand Down

0 comments on commit 557eb7b

Please sign in to comment.