Skip to content

Commit

Permalink
Test using concierge
Browse files Browse the repository at this point in the history
  • Loading branch information
addyess committed Oct 13, 2024
1 parent 834965c commit d886c54
Show file tree
Hide file tree
Showing 6 changed files with 167 additions and 6 deletions.
3 changes: 3 additions & 0 deletions .github/actions/with-post-steps/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ inputs:
post:
description: "Post command/script."
required: true
json:
description: "Inputs to pass through to the main command."
required: true
key:
description: "Name of the state variable used to detect the post step."
required: false
Expand Down
2 changes: 1 addition & 1 deletion .github/actions/with-post-steps/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const { appendFileSync } = require("fs");
const { EOL } = require("os");

function run(cmd) {
const subprocess = spawn(cmd, { stdio: "inherit", shell: true });
const subprocess = spawn(cmd, { stdio: "inherit", shell: true, env: process.env });
subprocess.on("exit", (exitCode) => {
process.exitCode = exitCode;
});
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/e2e.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
name: Test Operator Setup
on:
push:
branches: [main]
branches: [main, concierge]
pull_request:
branches: [main]
branches: [main, concierge]

jobs:
Inclusive-naming-check:
Expand Down
1 change: 1 addition & 0 deletions action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ runs:
- name: Cache
uses: ./.github/actions/with-post-steps
with:
json: ${{ toJson(inputs) }}
main: "src/bootstrap/main.sh"
post: "src/cleanup/main.sh"
branding:
Expand Down
110 changes: 107 additions & 3 deletions src/bootstrap/main.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,110 @@
#!/bin/bash
set -eu

# The following will eventually just be snap install concierge
sudo snap install go --classic
go install github.com/jnsgruk/concierge@latest
function _get_input() {
local __resultvar=$1
local key=$2
local default_value=${3:-''}
local value=$(echo "$INPUT_JSON" | grep -oP '"'"$key"'"\s*:\s*"\K[^"]+')
value=${value:-$default_value}
eval $__resultvar="'$value'"
}


function install_concierge() {
# The following will eventually just be snap install concierge
export PATH=$PATH:$HOME/go/bin
sudo snap install go --classic
go install github.com/jnsgruk/concierge@latest
}


function install_tox_if_needed() {
local version=""
_get_input version "tox-version"
echo "Ensuring tox installed..."

if command -v tox &> /dev/null; then
echo "tox is already installed"
tox --version
elif command -v pip &> /dev/null; then
echo "Installing tox with pip..."
TOX_VERSION_ARG=$([ -n "$version" ] && echo "==$version" || echo "")
pip install tox$TOX_VERSION_ARG
else
echo "Installing tox with apt..."
sudo apt-get update
sudo apt-get install python3-tox
fi
}

function plan_concierge() {
local provider=""
local channel=""
local lxd_channel=""
local charm_channel=""
local charmcraft_channel=""
local juju_channel=""
local jq_channel=""
local juju_bundle_channel=""
local juju_crashdump_channel=""
local microk8s_addons=""

_get_input provider "provider"
_get_input channel "channel"
_get_input lxd_channel "lxd-channel"
_get_input charm_channel "charm-channel"
_get_input charmcraft_channel "charmcraft-channel"
_get_input juju_channel "juju-channel"
_get_input jq_channel "jq-channel" "latest/stable"
_get_input juju_bundle_channel "juju-bundle-channel" "latest/stable"
_get_input juju_crashdump_channel "juju-crashdump-channel" "latest/stable"
_get_input microk8s_addons "microk8s-addons"

export CONCIERGE_JUJU_CHANNEL=${juju_channel}
export CONCIERGE_LXD_CHANNEL=${lxd_channel}
export CONCIERGE_CHARMCRAFT_CHANNEL=${charmcraft_channel}

cat <<EOF > concierge.yaml
juju:
model-defaults:
providers:
EOF
if [ ${provider} == "microk8s" ]; then
# Convert space-separated list to JSON array
microk8s_addons_json=$(echo "$microk8s_addons" | awk '{printf "["; for(i=1;i<=NF;i++) printf "\"%s\"%s", $i, (i<NF?",":""); printf "]"}')
cat <<EOF >> concierge.yaml
microk8s:
enable: true
channel: ${channel}
addons: ${microk8s_addons_json}
EOF
elif [ ${provider} == "lxd" ]; then
local lxd_used_channel=${channel:-$lxd_channel}
cat <<EOF >> concierge.yaml
lxd:
enable: true
channel: ${lxd_used_channel}
EOF
fi
cat <<EOF >> concierge.yaml
host:
snaps:
- charm/${charm_channel}
- jq/${jq_channel}
- juju-bundle/${juju_bundle_channel}
- juju-crashdump/${juju_crashdump_channel}
EOF
echo "Concierge plan:"
cat concierge.yaml
echo "Running concierge..."
SHELL=/bin/bash concierge prepare --trace -v
}

function run() {
install_concierge
install_tox_if_needed
plan_concierge
}

run
53 changes: 53 additions & 0 deletions src/cleanup/main.sh
Original file line number Diff line number Diff line change
@@ -1 +1,54 @@
#!/bin/bash
set -e
echo "Cleaning up..."

function destroy_controller() {
local controller=$1
local juju_channel=${INPUT_juju-channel};

echo "Removing controller ${controller}..."
if [[ "${juju_channel}" == 2.9* ]]; then
juju destroy-controller -y ${controller} --destroy-all-models --destroy-storage
else
juju destroy-controller ${controller} --no-prompt --destroy-all-models --destroy-storage
fi
}

function find_and_upload_juju_crashdump() {
local crashdump_files=$(find . -name "juju-crashdump-*.tar.xz")

if [ -z "${crashdump_files}" ]; then
echo "No juju-crashdump files found."
else
for file in ${crashdump_files}; do
echo "Found crashdump file: ${file}"
upload_artifact $file
done
fi
}

function upload_artifact() {
local file=$1
local artifact_name=$(basename $file)

echo "Uploading artifact not yet implemented: ${artifact_name}"
echo "::set-output name=artifact::${artifact_name}"
echo "::set-output name=artifact_path::${file}"
}

function run() {
local controller=${CONTROLLER_NAME}
local provider=${INPUT_PROVIDER}

if [ -n "${controller}"]; then
if [ "${provider}" != "microk8s" ] && [ "${provider}" != "lxd" ]; then
destroy_controller ${controller}
fi

echo "::group uploading juju-crashdump"
find_and_upload_juju_crashdump
echo "::endgroup"
fi
}

run

0 comments on commit d886c54

Please sign in to comment.