Skip to content

Cod dev #6

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

Open
wants to merge 3 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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
67 changes: 67 additions & 0 deletions cluster-setup/apply-manifests.sh
Original file line number Diff line number Diff line change
@@ -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 <cluster_name>"
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'."
Empty file modified cluster-setup/cluster-setup.sh
100644 → 100755
Empty file.
55 changes: 55 additions & 0 deletions cluster-setup/load-images.sh
Original file line number Diff line number Diff line change
@@ -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 <cluster_name>"
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'."
59 changes: 59 additions & 0 deletions cluster-setup/prod.sh
Original file line number Diff line number Diff line change
@@ -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 <<EOF > $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} <name> [num_servers] [num_agents]"
fi
2 changes: 1 addition & 1 deletion examples/operator-2.9.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down