commit 88d112b47b349901e674e81e14bfae962c11edce Author: kjuulh Date: Sat Dec 10 22:08:07 2022 +0100 Add bootstrapper base diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4c49bd7 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.env diff --git a/README.md b/README.md new file mode 100644 index 0000000..141bf84 --- /dev/null +++ b/README.md @@ -0,0 +1,4 @@ +# Clank bootstrapper + +- Links: + [preparations](https://github.com/syself/cluster-api-provider-hetzner/blob/main/docs/topics/preparation.md) diff --git a/clusterapi/.gitignore b/clusterapi/.gitignore new file mode 100755 index 0000000..050afac --- /dev/null +++ b/clusterapi/.gitignore @@ -0,0 +1,4 @@ +variables.sh +keys/ +manifest.json +output/ diff --git a/clusterapi/add-ccm.sh b/clusterapi/add-ccm.sh new file mode 100755 index 0000000..ac5e2ea --- /dev/null +++ b/clusterapi/add-ccm.sh @@ -0,0 +1,16 @@ +#!/bin/bash + +set -e + +. variables.sh + +helm repo add syself https://charts.syself.com +helm repo update syself + +CILIUM_VERSION=1.12.2 + +KUBECONFIG=$CAPH_WORKER_CLUSTER_KUBECONFIG helm upgrade --install ccm syself/ccm-hcloud --version 1.0.11 \ + --namespace kube-system \ + --set secret.name=hetzner \ + --set secret.tokenKeyName=hcloud \ + --set privateNetwork.enabled=false diff --git a/clusterapi/add-cni.sh b/clusterapi/add-cni.sh new file mode 100755 index 0000000..ba5026a --- /dev/null +++ b/clusterapi/add-cni.sh @@ -0,0 +1,13 @@ +#!/bin/bash + +set -e + +. variables.sh + +helm repo add cilium https://helm.cilium.io/ + +CILIUM_VERSION=1.12.2 + +KUBECONFIG=$CAPH_WORKER_CLUSTER_KUBECONFIG helm upgrade --install cilium cilium/cilium --version "$CILIUM_VERSION" \ +--namespace kube-system \ +-f https://raw.githubusercontent.com/syself/cluster-api-provider-hetzner/main/templates/cilium/cilium.yaml diff --git a/clusterapi/add-csi.sh b/clusterapi/add-csi.sh new file mode 100755 index 0000000..8d2556e --- /dev/null +++ b/clusterapi/add-csi.sh @@ -0,0 +1,15 @@ +#!/bin/bash + +set -e + +. variables.sh + +cat << EOF > output/csi-values.yaml +storageClasses: +- name: hcloud-volumes + defaultStorageClass: true + reclaimPolicy: Retain +EOF + +KUBECONFIG=$CAPH_WORKER_CLUSTER_KUBECONFIG helm upgrade --install csi syself/csi-hcloud --version 0.2.0 \ +--namespace kube-system -f output/csi-values.yaml diff --git a/clusterapi/get-config.sh b/clusterapi/get-config.sh new file mode 100755 index 0000000..5a3f068 --- /dev/null +++ b/clusterapi/get-config.sh @@ -0,0 +1,9 @@ +#!/bin/bash + +set -e + +. variables.sh + +mkdir -p output/ + +clusterctl get kubeconfig "$CLUSTER_NAME" > $CAPH_WORKER_CLUSTER_KUBECONFIG diff --git a/clusterapi/initialize-hetzner.sh b/clusterapi/initialize-hetzner.sh new file mode 100755 index 0000000..6a11ae6 --- /dev/null +++ b/clusterapi/initialize-hetzner.sh @@ -0,0 +1,31 @@ +#!/bin/bash + +set -e + +. variables.sh + +sleep 20 + +OUTPUT_TEMPLATE=/tmp/clusterapi/clank-management.yaml + +rm -rf "/tmp/clusterapi/" || true + +echo "templating management cluster" +mkdir -p /tmp/clusterapi/ +clusterctl generate cluster "$CLUSTER_NAME" > "$OUTPUT_TEMPLATE" + +nvim /tmp/clusterapi/clank-management.yaml + +read -p "Continue? (N/y) " -n 1 -r +echo +if [[ ! $REPLY =~ ^[Yy]$ ]] +then + echo "aborting" + [[ "$0" = "$BASH_SOURCE" ]] && exit 1 || return 1 +fi + +kubectl apply -f "$OUTPUT_TEMPLATE" + +kubectl wait --for=jsonpath='{.status.phase}'=Provisioned "cluster/$CLUSTER_NAME" + +echo "cluster has been provisioned" diff --git a/clusterapi/initialize.sh b/clusterapi/initialize.sh new file mode 100755 index 0000000..467be27 --- /dev/null +++ b/clusterapi/initialize.sh @@ -0,0 +1,7 @@ +#!/bin/bash + +set -e + +rm -rf output + +clusterctl init --core cluster-api --bootstrap kubeadm --control-plane kubeadm --infrastructure hetzner diff --git a/clusterapi/latest-releases.sh b/clusterapi/latest-releases.sh new file mode 100755 index 0000000..d32780d --- /dev/null +++ b/clusterapi/latest-releases.sh @@ -0,0 +1,15 @@ +#!/bin/bash + +set -e + +PROVIDER_OWNER=syself +PROVIDER_REPO=cluster-api-provider-hetzner +PROVIDER="$PROVIDER_OWNER/$PROVIDER_REPO" + +echo "listing newest releases (includes pre-releases)" +gh release list -R "$PROVIDER" + +echo +echo "view the most recent release" +newest=$(gh release list -R syself/cluster-api-provider-hetzner -L 1 | tail -n +1 | awk '{print $1}') +gh release view "$newest" -R "$PROVIDER" diff --git a/clusterapi/load-secret.sh b/clusterapi/load-secret.sh new file mode 100755 index 0000000..c2b2422 --- /dev/null +++ b/clusterapi/load-secret.sh @@ -0,0 +1,11 @@ +#!/bin/bash + +set -e + +. variables.sh + +echo "loading HCLOUD_TOKEN" + +kubectl create secret generic hetzner --from-literal=hcloud=$HCLOUD_TOKEN + +kubectl patch secret hetzner -p '{"metadata":{"labels":{"clusterctl.cluster.x-k8s.io/move":""}}}' diff --git a/clusterapi/move-cluster.sh b/clusterapi/move-cluster.sh new file mode 100755 index 0000000..43b9f94 --- /dev/null +++ b/clusterapi/move-cluster.sh @@ -0,0 +1,17 @@ +#!/bin/bash + +set -e + +. variables.sh + +echo "initializing cluster api in management cluster" +export KUBECONFIG=output/workload-kubeconfig + +clusterctl init --core cluster-api --bootstrap kubeadm --control-plane kubeadm --infrastructure hetzner + +echo "switching back to helm" +export KUBECONFIG=~/.kube/config + +clusterctl move --to-kubeconfig $CAPH_WORKER_CLUSTER_KUBECONFIG + +echo "move done" diff --git a/clusterapi/pack-image.sh b/clusterapi/pack-image.sh new file mode 100755 index 0000000..796c1e7 --- /dev/null +++ b/clusterapi/pack-image.sh @@ -0,0 +1,27 @@ +#!/bin/bash + +set -e + +. variables.sh + +RELEASE_VERSION="1.0.0-beta.10" +TEMPLATE_VERSION=$KUBERNETES_VERSION-ubuntu-22-04-containerd +PROVIDER_OWNER=syself +PROVIDER_REPO=cluster-api-provider-hetzner +OUTPUT_DIR=/tmp/clusterapi + +PROVIDER="$PROVIDER_OWNER/$PROVIDER_REPO" +OUTPUT_FILE=output.tar.gz +OUTPUT="$OUTPUT_DIR/$OUTPUT_FILE" + +rm -rf "$OUTPUT_DIR" || true + +gh release download "v$RELEASE_VERSION" \ + -R "$PROVIDER" \ + --archive tar.gz \ + -O "$OUTPUT" + +(cd $OUTPUT_DIR ; tar -xzf "$OUTPUT_FILE") + + +packer build "$OUTPUT_DIR/$PROVIDER_REPO-$RELEASE_VERSION/templates/node-image/$TEMPLATE_VERSION/image.json" diff --git a/flux/.gitignore b/flux/.gitignore new file mode 100755 index 0000000..c5497dd --- /dev/null +++ b/flux/.gitignore @@ -0,0 +1,2 @@ +keys/ +variables.sh diff --git a/flux/bootstrap.sh b/flux/bootstrap.sh new file mode 100755 index 0000000..9cf6922 --- /dev/null +++ b/flux/bootstrap.sh @@ -0,0 +1,18 @@ +#!/bin/bash + +set -e + +. variables.sh + +#eval "$(ssh-agent -s)" +#ssh-add keys/id_clank_management + +flux bootstrap git \ + --url="https://$MANAGEMENT_GITOPS_REPO" \ + --branch="main" \ + --path="clusters/clank-management" \ + --kubeconfig="$CAPH_WORKER_CLUSTER_KUBECONFIG" \ + --username="kjuulh" \ + --password="$GITEA_TOKEN" \ + --token-auth=true + diff --git a/flux/generate-keypair.sh b/flux/generate-keypair.sh new file mode 100755 index 0000000..95aa4b8 --- /dev/null +++ b/flux/generate-keypair.sh @@ -0,0 +1,7 @@ +#!/bin/bash + +set -e + +mkdir -p keys/ + +ssh-keygen -t ed25519 -C "clank_management@kjuulh.io" -f "keys/id_clank_management" diff --git a/kind/create-kind.sh b/kind/create-kind.sh new file mode 100755 index 0000000..3b463bd --- /dev/null +++ b/kind/create-kind.sh @@ -0,0 +1,16 @@ +#!/bin/bash +# +. kind.sh + +kind create cluster --name "$CLUSTER_NAME" + +until kubectl cluster-info --context "kind-$CLUSTER_NAME" +do + echo "waiting for cluster to come online..." + sleep 1 +done + +echo "checking nodes" +kubectl get nodes + +kubectl wait --for=condition=ready nodes/clank-boostrap-control-plane diff --git a/kind/delete-kind.sh b/kind/delete-kind.sh new file mode 100755 index 0000000..dfa1be6 --- /dev/null +++ b/kind/delete-kind.sh @@ -0,0 +1,5 @@ +#!/bin/bash + +. kind.sh + +kind delete cluster --name "$CLUSTER_NAME" diff --git a/kind/kind.sh b/kind/kind.sh new file mode 100755 index 0000000..243f190 --- /dev/null +++ b/kind/kind.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +CLUSTER_NAME=clank-boostrap diff --git a/run.sh b/run.sh new file mode 100755 index 0000000..d9d61ee --- /dev/null +++ b/run.sh @@ -0,0 +1,37 @@ +#!/bin/bash + +set -e + +echo "setting up kind" +pushd kind + +./delete-kind.sh || true +./create-kind.sh + +popd + +echo "setting up boostrap cluster api" + +pushd clusterapi + +./initialize.sh +./load-secret.sh +./initialize-hetzner.sh + +./get-config.sh +./add-cni.sh +./add-ccm.sh +./add-csi.sh +./move-clusters.sh + +popd + +echo "installing flux" + +pushd flux + +./bootstrap.sh + +popd + +