-
Notifications
You must be signed in to change notification settings - Fork 8
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 microk8s controller #1216
Add microk8s controller #1216
Changes from all commits
6e553fd
d1f4528
8179f26
32786af
3fe239b
5220a29
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#!/bin/bash | ||
|
||
|
||
# Explanation: | ||
# JIMM needs to contact the controller and cannot do so from the docker compose to microk8s easily. | ||
# As such, we turn the controllers default service into a node port service. | ||
# This allows the service to be access on the hosts network at 30040. | ||
|
||
# Next, we have TLS issues as the controller only has limited SANs, one of them being "juju-apiserver" | ||
# As such, we update jimm's container to map juju-apiserver to "172.17.0.1". This IP address is dockers | ||
# host network interface address, enabling access to the localhost of the host. | ||
|
||
# Finally, we update jimmctls info output attempt to contact the controller on "juju-apiserver" | ||
# and due to the SAN matching, having a nodeport available and using dockers host network interface, | ||
# we can contact. | ||
|
||
# For routing explanation: | ||
# JIMM -> jujuapi-server -> 172.17.0.1 -> localhost (of the host) -> localhost:30040 -> NodePort -> Cluster -> Controller | ||
|
||
go build ./cmd/jimmctl | ||
|
||
# Patch the controller such that it is reachable on the host at 30040 | ||
microk8s.kubectl patch -n controller-qa-microk8s svc/controller-service --type='json' -p '[{"op":"replace","path":"/spec/type","value":"NodePort"},{"op":"replace","path":"/spec/ports/0/nodePort","value":30040}]' | ||
|
||
# 172.17.0.1 is dockers host interface, enabling access the host machines host network | ||
# despite being in a strictly confined docker compose network. | ||
docker compose exec jimm bash -c "echo '172.17.0.1 juju-apiserver' >> /etc/hosts" | ||
|
||
./jimmctl controller-info --local qa-microk8s ./qa-microk8s-controller.yaml | ||
|
||
# Update api & public addresses to match /etc/hosts of jimm container | ||
yq e -i '.api-addresses = ["juju-apiserver:30040"]' ./qa-microk8s-controller.yaml | ||
yq e -i '.public-address = "juju-apiserver:30040"' ./qa-microk8s-controller.yaml | ||
|
||
# Finally add the controller to jimm and add the microk8s credential | ||
juju switch jimm-dev | ||
./jimmctl add-controller ./qa-microk8s-controller.yaml | ||
|
||
juju update-credentials microk8s --controller jimm-dev | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
#!/bin/bash | ||
|
||
# QA-lxd | ||
# This script spins up JIMM (from compose) and sets up a LXD controller and a test model | ||
# to QA against. | ||
# | ||
# It handles the removal of all older resources to ensure a fresh QA env. | ||
# | ||
# Please make sure you've run make "make dev-env-setup" for this script to work. | ||
|
||
|
||
cleanup() { | ||
echo "Destroying qa-lxd controller if exists..." | ||
destroy_qa_output=$(juju destroy-controller qa-lxd --force --no-prompt --destroy-all-models 2>&1) || true | ||
if [ $? -ne 0 ]; then | ||
echo "$destroy_qa_output" | ||
fi | ||
|
||
echo "Unregistering jimm-dev controller if exists..." | ||
unregister_jimm_output=$(juju unregister jimm-dev --no-prompt 2>&1) || true | ||
if [ $? -ne 0 ]; then | ||
echo "$unregister_jimm_output" | ||
fi | ||
|
||
echo "Tearing down compose..." | ||
compose_teardown_output=$(docker compose --project-directory ../../ --file ../../docker-compose.yaml --profile dev down -v 2>&1) || true | ||
if [ $? -ne 0 ]; then | ||
echo "$compose_teardown_output" | ||
fi | ||
} | ||
|
||
cleanup | ||
|
||
echo "*** Starting QA environment setup ***" | ||
|
||
docker compose --project-directory ../../ --file ../../docker-compose.yaml --profile dev up -d | ||
|
||
juju login jimm.localhost -c jimm-dev | ||
|
||
./local/jimm/setup-controller.sh | ||
./local/jimm/add-controller.sh | ||
|
||
juju add-model test-lxd | ||
|
||
# Add a test charm (this is a basic hello-juju, that requires postgres to become healthy) | ||
# Essentially, a perfect test bed for performing relations etc against. | ||
juju deploy hello-juju |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#!/bin/bash | ||
|
||
# QA-microk8s | ||
# This script spins up JIMM (from compose) and sets up a K8S controller and a test model | ||
# to QA against. | ||
# | ||
# It handles the removal of all older resources to ensure a fresh QA env. | ||
# | ||
# Please make sure you've run make "make dev-env-setup" for this script to work. | ||
|
||
cleanup() { | ||
echo "Destroying qa-microk8s controller if exists..." | ||
destroy_qa_output=$(juju destroy-controller qa-microk8s --force --no-prompt --destroy-all-models 2>&1) || true | ||
if [ $? -ne 0 ]; then | ||
echo "$destroy_qa_output" | ||
fi | ||
|
||
echo "Unregistering jimm-dev controller if exists..." | ||
unregister_jimm_output=$(juju unregister jimm-dev --no-prompt 2>&1) || true | ||
if [ $? -ne 0 ]; then | ||
echo "$unregister_jimm_output" | ||
fi | ||
|
||
echo "Tearing down compose..." | ||
compose_teardown_output=$(docker compose --project-directory ../../ --file ../../docker-compose.yaml --profile dev down -v 2>&1) || true | ||
if [ $? -ne 0 ]; then | ||
echo "$compose_teardown_output" | ||
fi | ||
} | ||
|
||
cleanup | ||
|
||
docker compose --project-directory ../../ --file ../../docker-compose.yaml --profile dev up -d | ||
|
||
juju login jimm.localhost -c jimm-dev | ||
|
||
./setup-microk8s-controller.sh | ||
./add-microk8s-controller.sh | ||
|
||
# Add a test model | ||
juju add-model test microk8s | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,15 +4,13 @@ | |
# It will bootstrap a Juju controller and configure the necessary config to enable the controller | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggestion.. should this be renamed to setup-lxd-controller.sh to keep the naming convention in line with setup-microk8s-controller.sh There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah can do, but you won't see this when running top level scripts |
||
# to communicate with the docker compose | ||
|
||
set -ux | ||
kian99 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
CLOUDINIT_FILE="cloudinit.temp.yaml" | ||
function finish { | ||
rm "$CLOUDINIT_FILE" | ||
} | ||
trap finish EXIT | ||
|
||
CONTROLLER_NAME="${CONTROLLER_NAME:-qa-controller}" | ||
CONTROLLER_NAME="${CONTROLLER_NAME:-qa-lxd}" | ||
CLOUDINIT_TEMPLATE=$'cloudinit-userdata: | | ||
preruncmd: | ||
- echo "%s jimm.localhost" >> /etc/hosts | ||
|
@@ -23,4 +21,4 @@ CLOUDINIT_TEMPLATE=$'cloudinit-userdata: | | |
printf "$CLOUDINIT_TEMPLATE" "$(lxc network get lxdbr0 ipv4.address | cut -f1 -d/)" "$(cat local/traefik/certs/ca.crt | sed -e 's/^/ /')" > "${CLOUDINIT_FILE}" | ||
|
||
echo "Bootstrapping controller" | ||
juju bootstrap lxd "${CONTROLLER_NAME}" --config "${CLOUDINIT_FILE}" --config login-token-refresh-url=https://jimm.localhost/.well-known/jwks.json --debug | ||
kian99 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
juju bootstrap lxd "${CONTROLLER_NAME}" --config "${CLOUDINIT_FILE}" --config login-token-refresh-url=https://jimm.localhost/.well-known/jwks.json |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#!/bin/bash | ||
|
||
# Host-access has some issues, TLDR to fix it: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. could this be automated? like.. adding microk8s snap install to makefile target dev-env-setup along with enable storage and host-access.. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm a bit hesitant on this idk, we could put it in make target?? |
||
# 1. enable host-access | ||
# 2. ifconfig 172.16.12.223 (get private address) | ||
# 3. append line: | ||
# --node-ip=172.16.12.223 | ||
# to /var/snap/microk8s/current/args/kubelet | ||
kian99 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
# 4. sudo snap restart microk8s | ||
juju bootstrap microk8s "qa-microk8s" --config login-token-refresh-url=http://10.0.1.1:17070/.well-known/jwks.json | ||
kian99 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
ale8k marked this conversation as resolved.
Show resolved
Hide resolved
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe cleanup() could be extracted to a separate file and sourced to keep it DRY since the only difference between the fn in qa-lxd and qa-microk8s is the name passed to juju destroy-controller? If some changes in the future affect this it's always nicer to have to bring only one script up-to-date.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i agree, but just want to land this as its been waiting ages, can come back and fix in later?