diff --git a/README.md b/README.md index 236ee1e..ad5b923 100644 --- a/README.md +++ b/README.md @@ -71,6 +71,20 @@ NAME STATUS ROLES AGE VERSION opsv Ready control-plane,master 4h58m v1.29.6+k3s1 ``` +## (Optional) Add block storage rook + +``` +multipass exec opsv -- bash -c 'export KUBECONFIG=/home/ubuntu/.kube/config && /home/ubuntu/add-rook' + +``` + +## (Optional) Add block storage longhorn + +``` +multipass exec opsv -- bash -c 'export KUBECONFIG=/home/ubuntu/.kube/config && /home/ubuntu/add-longhorn' + +``` + # Development Environment Overview If you only want to test OpenServerless, stop here. You should have a working environment. diff --git a/cloud-init.yaml b/cloud-init.yaml index d0e0244..8f00f83 100644 --- a/cloud-init.yaml +++ b/cloud-init.yaml @@ -91,7 +91,121 @@ write_files: bash direnv-init.sh # TODO add a .git-hooks directory with hooks #git config core.hooksPath .git-hooks - + + - path: /home/ubuntu/add-rook + permissions: '0755' + defer: true + owner: ubuntu:ubuntu + content: | + #!/bin/bash + set -e + + ROOK_VERSION="v1.14.6" + RAW_BASE="https://raw.githubusercontent.com/rook/rook/${ROOK_VERSION}/deploy/examples" + + echo "๐Ÿ“ฆ Installing Rook ${ROOK_VERSION}" + echo "๐Ÿ“„ Applying CRDs and operator..." + kubectl apply -f ${RAW_BASE}/crds.yaml + kubectl apply -f ${RAW_BASE}/common.yaml + kubectl apply -f ${RAW_BASE}/operator.yaml + sleep 10 + + if ! command -v yq >/dev/null 2>&1; then + echo "๐Ÿ“ฅ Installing yq..." + mkdir -p /home/ubuntu/bin + curl -sL https://github.com/mikefarah/yq/releases/latest/download/yq_linux_amd64 -o /home/ubuntu/bin/yq + chmod +x /home/ubuntu/bin/yq + export PATH=/home/ubuntu/bin:$PATH + else + echo "โœ… yq already installed." + fi + + echo "๐Ÿ› ๏ธ Patching and applying Ceph cluster for single-node setup..." + curl -sL ${RAW_BASE}/cluster.yaml | \ + yq e '.spec.mon.count = 1 | .spec.mon.allowMultiplePerNode = true' - | \ + kubectl apply -f - + sleep 30 + + echo "๐Ÿ“„ Applying Ceph client..." + kubectl apply -f ${RAW_BASE}/ceph-client.yaml + + echo "๐Ÿ” Waiting for Rook to be Ready..." + for i in {1..90}; do + status=$(kubectl -n rook-ceph get cephcluster rook-ceph -o jsonpath='{.status.phase}' 2>/dev/null || echo "notfound") + echo "โณ Attempt $i: Rook status = $status" + if [[ "$status" == "Ready" ]]; then + echo "โœ… Rook is healthy!" + break + fi + sleep 15 + done + + if [[ "$status" != "Ready" ]]; then + echo "โŒ Timeout waiting for Rook to become healthy." + exit 1 + fi + + echo "๐Ÿ“„ Installing VolumeSnapshot CRDs..." + kubectl apply -f https://raw.githubusercontent.com/kubernetes-csi/external-snapshotter/v6.3.3/client/config/crd/snapshot.storage.k8s.io_volumesnapshotclasses.yaml + kubectl apply -f https://raw.githubusercontent.com/kubernetes-csi/external-snapshotter/v6.3.3/client/config/crd/snapshot.storage.k8s.io_volumesnapshotcontents.yaml + kubectl apply -f https://raw.githubusercontent.com/kubernetes-csi/external-snapshotter/v6.3.3/client/config/crd/snapshot.storage.k8s.io_volumesnapshots.yaml + + echo "๐Ÿงน Re-creating rook-ceph-block StorageClass..." + kubectl delete storageclass rook-ceph-block --ignore-not-found=true + + cat </dev/null 2>&1; then + kubectl annotate storageclass longhorn storageclass.kubernetes.io/is-default-class=true --overwrite || true + fi + runcmd: - | cd /home/ubuntu @@ -100,4 +214,4 @@ runcmd: curl -sL https://raw.githubusercontent.com/sciabarracom/openserverless/refs/heads/main/bash_aliases -o ".bash_aliases" echo 'source $HOME/.z.sh' >> .bashrc chown ubuntu:ubuntu .z.sh .bashrc .bash_aliases - echo -e '#!/bin/bash\n/etc/cloud-init.sh 2>&1 >/tmp/cloud-init.log\n' | at now + echo -e '#!/bin/bash\n/etc/cloud-init.sh 2>&1 >/tmp/cloud-init.log\n' | at now \ No newline at end of file