Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add bootstrap option to prepare-node-script #406

Merged
merged 1 commit into from
Jan 16, 2025
Merged
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
14 changes: 4 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,12 @@ jobs:
# Accept all packets filtered for forward
sudo nft chain ip filter FORWARD '{policy accept;}'

sudo snap remove --purge lxd
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
11 changes: 3 additions & 8 deletions .github/workflows/test-snap.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,16 +66,11 @@ 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 remove --purge lxd
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 +90,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
61 changes: 59 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,76 @@
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

if [ -n "$(sudo --user $USER lxc network list --format csv | grep lxdbr0)" ]; then
echo 'Sunbeam requires the LXD bridge to be called anything except lxdbr0'
exit 1
fi

# Try to determine if LXD is already bootstrapped
gboutry marked this conversation as resolved.
Show resolved Hide resolved
if [ -z "$(sudo --user $USER lxc storage list --format csv)" ];
then
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: sunbeambr0
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 [ $? -ne 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:
gboutry marked this conversation as resolved.
Show resolved Hide resolved
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
Loading