From 292eac7fd62ee82e26c57801c866d39a7c0f36cf Mon Sep 17 00:00:00 2001 From: Aayush Senapati Date: Tue, 29 Apr 2025 14:22:43 +0530 Subject: [PATCH 1/3] add setup scripts --- cluster-setup/cluster-setup.sh | 0 examples/operator-2.9.yaml | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) mode change 100644 => 100755 cluster-setup/cluster-setup.sh diff --git a/cluster-setup/cluster-setup.sh b/cluster-setup/cluster-setup.sh old mode 100644 new mode 100755 diff --git a/examples/operator-2.9.yaml b/examples/operator-2.9.yaml index 170da22..bdf2228 100644 --- a/examples/operator-2.9.yaml +++ b/examples/operator-2.9.yaml @@ -219,7 +219,7 @@ spec: - name: additional-prometheus-labels - name: separate-cluster-name-and-namespace value: "true" - image: ghcr.io/cb-vanilla/operator:2.9.0-155 + image: ghcr.io/cb-vanilla/operator:2.9.0-156 imagePullPolicy: IfNotPresent name: couchbase-operator ports: From e9cbfe51acea51dc66aca5d525729d820774def3 Mon Sep 17 00:00:00 2001 From: Aayush Senapati Date: Tue, 29 Apr 2025 14:23:00 +0530 Subject: [PATCH 2/3] add setup scripts --- cluster-setup/apply-manifests.sh | 67 ++++++++++++++++++++++++++++++++ cluster-setup/load-images.sh | 55 ++++++++++++++++++++++++++ cluster-setup/prod.sh | 59 ++++++++++++++++++++++++++++ 3 files changed, 181 insertions(+) create mode 100755 cluster-setup/apply-manifests.sh create mode 100755 cluster-setup/load-images.sh create mode 100755 cluster-setup/prod.sh diff --git a/cluster-setup/apply-manifests.sh b/cluster-setup/apply-manifests.sh new file mode 100755 index 0000000..e35a3c1 --- /dev/null +++ b/cluster-setup/apply-manifests.sh @@ -0,0 +1,67 @@ +#!/bin/bash + +set -e + +# Define paths to YAML files (adjust if necessary) +CRD_FILE="/Users/aayush.senapati/development/cod/cluster-setup/ymls/crd.yaml" +ADMISSION_FILE="/Users/aayush.senapati/development/cod/cluster-setup/ymls/admission.yaml" +OPERATOR_FILE="/Users/aayush.senapati/development/cod/cluster-setup/ymls/operator.yaml" +CLUSTER_FILE="/Users/aayush.senapati/development/cod/cluster-setup/ymls/couchbase-cluster.yaml" + +# Check if cluster name is provided +if [ -z "$1" ]; then + echo "Usage: $0 " + exit 1 +fi + +CLUSTER_NAME=$1 +K3D_CONTEXT="k3d-$CLUSTER_NAME" + +echo "Setting kubectl context to $K3D_CONTEXT..." +if ! kubectl config use-context "$K3D_CONTEXT"; then + echo "Error: Failed to set kubectl context to $K3D_CONTEXT." + echo "Make sure the cluster '$CLUSTER_NAME' exists and the context is configured correctly." + exit 1 +fi + +echo "Applying Kubernetes manifests to cluster '$CLUSTER_NAME'..." + +# Check if files exist before applying +if [ ! -f "$CRD_FILE" ] || [ ! -f "$ADMISSION_FILE" ] || [ ! -f "$OPERATOR_FILE" ] || [ ! -f "$CLUSTER_FILE" ]; then + echo "Error: One or more YAML manifest files not found. Please check the paths:" + echo "CRD: $CRD_FILE" + echo "Admission: $ADMISSION_FILE" + echo "Operator: $OPERATOR_FILE" + echo "Cluster: $CLUSTER_FILE" + exit 1 +fi + +kube_apply() { + local file=$1 + echo "Applying $file..." + if ! kubectl apply -f "$file"; then + echo "Error applying $file." + exit 1 + fi +} + +kube_apply "$CRD_FILE" +kube_apply "$ADMISSION_FILE" +kube_apply "$OPERATOR_FILE" + +echo "Waiting for operator pods to be ready..." +# Use the default namespace unless specified otherwise by the operator manifest +OPERATOR_NAMESPACE="default" +if kubectl wait --namespace "$OPERATOR_NAMESPACE" --for=condition=ready pod -l app=couchbase-operator --timeout=300s; then + echo "Operator pods are ready. Waiting a few seconds for network/services to stabilize..." + sleep 10 # Give some extra time + kube_apply "$CLUSTER_FILE" + echo "Successfully applied all manifests." +else + echo "Error: Operator pods (in namespace '$OPERATOR_NAMESPACE' with label app=couchbase-operator) did not become ready within 5 minutes." + echo "Please check the operator pod logs for errors: +kubectl logs -n $OPERATOR_NAMESPACE -l app=couchbase-operator" + exit 1 +fi + +echo "Manifest application process completed for cluster '$CLUSTER_NAME'." \ No newline at end of file diff --git a/cluster-setup/load-images.sh b/cluster-setup/load-images.sh new file mode 100755 index 0000000..51194fc --- /dev/null +++ b/cluster-setup/load-images.sh @@ -0,0 +1,55 @@ +#!/bin/bash + +set -e + +# List of images to import into the k3d cluster +IMAGES=( + "couchbase/server:7.6.0" + "ghcr.io/cb-vanilla/operator:2.8.1-142" + "ghcr.io/cb-vanilla/admission-controller:2.8.1-142" + "cod:latest" +) + +# Check if cluster name is provided +if [ -z "$1" ]; then + echo "Usage: $0 " + exit 1 +fi + +CLUSTER_NAME=$1 +K3D_CONTEXT="k3d-$CLUSTER_NAME" + +echo "Setting kubectl context to $K3D_CONTEXT..." +if ! kubectl config use-context "$K3D_CONTEXT"; then + echo "Error: Failed to set kubectl context to $K3D_CONTEXT." + echo "Make sure the cluster '$CLUSTER_NAME' exists and the context is configured correctly." + exit 1 +fi + +echo "Importing images into cluster '$CLUSTER_NAME'..." + +for IMAGE in "${IMAGES[@]}"; do + echo "Processing image: $IMAGE" + # Check if the image exists locally + if ! docker image inspect "$IMAGE" &> /dev/null; then + echo "Warning: Docker image '$IMAGE' not found locally. Pulling..." + if ! docker pull "$IMAGE"; then + echo "Error: Failed to pull image '$IMAGE'. Please ensure it exists or build it if necessary (e.g., cod:latest)." + # Decide whether to exit or continue with other images + # exit 1 + continue # Continue to the next image + fi + fi + + # Import the image into the k3d cluster + echo "Importing $IMAGE into $CLUSTER_NAME..." + if ! k3d image import "$IMAGE" -c "$CLUSTER_NAME"; then + echo "Error: Failed to import image '$IMAGE' into cluster '$CLUSTER_NAME'." + # Decide whether to exit or continue + # exit 1 + else + echo "Successfully imported $IMAGE." + fi +done + +echo "Image loading process completed for cluster '$CLUSTER_NAME'." \ No newline at end of file diff --git a/cluster-setup/prod.sh b/cluster-setup/prod.sh new file mode 100755 index 0000000..a5023c9 --- /dev/null +++ b/cluster-setup/prod.sh @@ -0,0 +1,59 @@ +#!/bin/bash + +set -e + +CONFIG_FILE="/Users/aayush.senapati/development/cod/cluster-setup/ymls/k3.yaml" + +create_cluster() { + local name=$1 + local num_servers=${2:-1} + local num_agents=${3:-2} + local k3d_context="k3d-$name" + + if ! k3d cluster list | grep -q "$name"; then + cat < $CONFIG_FILE +apiVersion: k3d.io/v1alpha5 +kind: Simple +metadata: + name: $name +servers: $num_servers +agents: $num_agents +volumes: + - volume: /Users/aayush.senapati/development:/mnt/development + nodeFilters: + - agent:* + - server:* +EOF + + k3d cluster create -i rancher/k3s:latest --config $CONFIG_FILE + + docker pull couchbase/server:7.6.0 || true + k3d image import couchbase/server:7.6.0 -c $name + + + + # Check if cod:latest image exists locally + if ! docker image inspect cod:latest &> /dev/null; then + echo "Error: Docker image 'cod:latest' not found locally." + echo "Please build the image using the provided Dockerfile before running this script." + exit 1 + fi + k3d image import cod:latest -c $name + + echo "Setting kubectl context to $k3d_context..." + kubectl config use-context "$k3d_context" + fi +} + +delete_cluster() { + local name=$1 + k3d cluster delete $name +} + +if [ "$1" == "create" ]; then + create_cluster "$2" "$3" "$4" +elif [ "$1" == "delete" ]; then + delete_cluster "$2" +else + echo "Usage: $0 {create|delete} [num_servers] [num_agents]" +fi \ No newline at end of file From 4fd36bd4749592cbdc04ee3b00978721bc9a8c4e Mon Sep 17 00:00:00 2001 From: Aayush Senapati Date: Wed, 30 Apr 2025 14:50:21 +0530 Subject: [PATCH 3/3] readme update --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 158c73b..18c68d5 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ This repository contains a dashboard application for monitoring and managing Cou To compile the dashboard binary, run the following command in the root of the project: ```bash -GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -tags debug -a -installsuffix cgo -o dashboard cmd/cod/main.go +GOOS=linux GOARCH=arm64 CGO_ENABLED=0 go build -tags debug -a -installsuffix cgo -o dashboard cmd/cod/main.go ``` ## Building the Docker Image