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 k8s bootstrap script #273

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
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
1 change: 1 addition & 0 deletions kubernetes/pipeline/00setup
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export -a MOD_PASSTHROUGH_OPTS=()
export -A MOD_MSGS=()
# Use order 0 to ensure this is first displayed
MOD_MSGS[0_common.0]="run ./configure to initialise your deployment"
MOD_MSGS[0_common.1]="run ./tools/bootstrap-k8s-cloud.sh to deploy k8s bundles"

# Array list of overlays to use with this deployment.
export -a MOD_OVERLAYS=()
Expand Down
1 change: 1 addition & 0 deletions microk8s/pipeline/00setup
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export -a MOD_PASSTHROUGH_OPTS=()
export -A MOD_MSGS=()
# Use order 0 to ensure this is first displayed
MOD_MSGS[0_common.0]="run ./configure to initialise your deployment"
MOD_MSGS[0_common.1]="run ./tools/bootstrap-k8s-cloud.sh to deploy k8s bundles"

# Array list of overlays to use with this deployment.
export -a MOD_OVERLAYS=()
Expand Down
45 changes: 45 additions & 0 deletions tools/bootstrap-k8s-cloud.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#!/bin/bash -x
# Usage: ./tools/bootstrap-k8s-cloud.sh <cloud-name> <model-name> <controller-name>
CLOUD="${1:-k8scloud}"
MODEL="${2:-secloud}"
CONTROLLER="${3:-k8slord}"

check_kubeconfig() {
if [[ -z "$KUBECONFIG" && ! -f "${HOME}/.kube/config" ]]; then
echo 'ERROR: Cannot find KUBECONFIG! Set as environment variable.'
exit 1
fi
}

get_storageclass() {
default_storageclass="$(kubectl get sc | grep default | awk '{print $1}')"
if [[ -z "$default_storageclass" ]]; then
enable_storage
fi
}

enable_storage() {
if leader="$(juju status --format json| jq -r '.applications["microk8s"].units|to_entries[]|select(.value["leader"])|.key' 2> /dev/null)"; then
echo 'Enabling hostpath-storage and MetalLB on Microk8s.'
juju ssh "$leader" sudo microk8s enable hostpath-storage
iprange="$(for i in `kubectl get nodes -o json | jq -r '.items[].status.addresses[] | select(.type=="InternalIP") | .address'`; do iprange+="$i-${i},"; done; echo $iprange | sed -e 's/,$//')"
juju ssh "$leader" sudo microk8s enable metallb:"$iprange"
elif leader="$(juju status --format json| jq -r '.applications["k8s"].units|to_entries[]|select(.value["leader"])|.key' 2> /dev/null)"; then
echo 'Enabling local-storage and load-balancer on Canonical K8s.'
juju ssh "$leader" sudo k8s enable local-storage
juju ssh "$leader" sudo k8s enable load-balancer
else
echo 'ERROR: No default storage class in Kubernetes. Try deploying a k8s bundle with --ceph.'
exit 1
fi
}

bootstrap_k8s() {
juju add-k8s "$CLOUD" --client
juju bootstrap "$CLOUD" "$CONTROLLER"
juju add-model "$MODEL"
}

check_kubeconfig
get_storageclass
bootstrap_k8s