Skip to content

Commit

Permalink
Automate the upgrade from Non-RAFT to RAFT.
Browse files Browse the repository at this point in the history
This change improves the workflow for upgrading the local-k8s cluster
and adds an option to pass different operations to the script.
  • Loading branch information
jfrancoa committed Apr 8, 2024
1 parent fc4a9db commit 7c73822
Show file tree
Hide file tree
Showing 4 changed files with 123 additions and 29 deletions.
41 changes: 41 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -147,3 +147,44 @@ jobs:
echo "Error: Contextionary replicas count is not equal to 1. Found $contextionary"
exit 1
fi
run-weaviate-local-k8s-upgrade:
runs-on: ubuntu-latest
name: Invoke weaviate-local-k8s upgrade to RAFT with basic parameters
env:
WORKERS: '3'
REPLICAS: '5'
WEAVIATE_VERSION: '1.24.6'
steps:
- name: Create ${{ env.WEAVIATE_VERSION }} Weaviate cluster with ${{ env.WORKERS }} workers and ${{ env.REPLICAS }} replicas
id: invoke-local-k8s
uses: weaviate/weaviate-local-k8s@main
with:
workers: ${{ env.WORKERS }}
replicas: ${{ env.REPLICAS }}
weaviate-version: ${{ env.WEAVIATE_VERSION }}
- name: Upgrade cluster to RAFT.
uses: weaviate/weaviate-local-k8s@main
with:
operation: upgrade
workers: ${{ env.WORKERS }}
replicas: ${{ env.REPLICAS }}
weaviate-version: "preview--21c08df"
- name: Check the configured values
run: |
replicas=$(kubectl get sts weaviate -n weaviate -o=jsonpath="{.spec.replicas}")
if [[ "$replicas" -ne ${{ env.REPLICAS }} ]]; then
echo "Error: Replicas count is not equal to ${{ env.REPLICAS }}. Found $replicas"
exit 1
fi
workers=$(kubectl get nodes --selector=node-role.kubernetes.io/control-plane!= --no-headers | wc -l)
if [[ "$workers" -ne ${{ env.WORKERS }} ]]; then
echo "Error: Workers count is not equal to ${{ env.WORKERS }}. Found $workers"
exit 1
fi
versions=$(curl -s http://127.0.0.1:8080/v1/nodes | jq '.nodes[] | .version' | tr -d '"')
for version in `echo $versions | tr '\n' ' '`; do
if [[ "$version" != "${{ env.WEAVIATE_VERSION }}" ]]; then
echo "Error: Version is not equal to ${{ env.WEAVIATE_VERSION }}. Found $version"
exit 1
fi
done
7 changes: 6 additions & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ name: Weaviate Local K8s Action
description: Deploy Weaviate to a local Kubernetes cluster

inputs:
operation:
description: 'The operation to perform. Supported: setup, upgrade, clean. Default: setup'
required: true
default: 'setup'
weaviate-port:
description: 'The port number for Weaviate'
required: false
Expand Down Expand Up @@ -47,14 +51,15 @@ runs:
- name: Deploy local kubernetes cluster
shell: bash
env:
OPERATION: ${{ inputs.operation }}
WEAVIATE_PORT: ${{ inputs.weaviate-port }}
WEAVIATE_GRPC_PORT: ${{ inputs.weaviate-grpc-port }}
WORKERS: ${{ inputs.workers }}
REPLICAS: ${{ inputs.replicas }}
WEAVIATE_VERSION: ${{ inputs.weaviate-version }}
MODULES: ${{ inputs.modules }}
HELM_BRANCH: ${{ inputs.helm-branch }}
run: ${{ github.action_path }}/local-k8s.sh setup
run: ${{ github.action_path }}/local-k8s.sh $OPERATION
- name: Retrieve weaviate logs
shell: bash
if: failure()
Expand Down
57 changes: 31 additions & 26 deletions local-k8s.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,37 @@ REQUIREMENTS=(
WEAVIATE_PORT=${WEAVIATE_PORT:-8080}
WEAVIATE_GRPC_PORT=${WEAVIATE_GRPC_PORT:-50051}
MODULES=${MODULES:-""}
HELM_BRANCH=${HELM_BRANCH:-""}
PROMETHEUS_PORT=9091
GRAFANA_PORT=3000
TARGET=""


function upgrade_to_raft() {
echo "upgrade # Upgrading to RAFT"
rm -rf "/tmp/weaviate-helm"
git clone -b raft-configuration https://github.com/weaviate/weaviate-helm.git "/tmp/weaviate-helm"
# Package Weaviate Helm chart
helm package -d /tmp/weaviate-helm /tmp/weaviate-helm/weaviate
helm upgrade weaviate /tmp/weaviate-helm/weaviate-*.tgz \
--namespace weaviate \
--set image.tag="preview-raft-add-initial-migration-from-non-raft-to-raft-based-representation-c242ac4" \
--set replicas=$REPLICAS \
--set grpcService.enabled=true \
--set env.RAFT_BOOTSTRAP_EXPECT=$(get_voters $REPLICAS)
# This function sets up weaviate-helm and sets the global env var $TARGET
setup_helm $HELM_BRANCH

echo "upgrade # Deleting Weaviate StatefulSet"
kubectl delete sts weaviate -n weaviate

HELM_VALUES=$(generate_helm_values)

VALUES_OVERRIDE=""
# Check if values-override.yaml file exists
if [ -f "${CURRENT_DIR}/values-override.yaml" ]; then
VALUES_OVERRIDE="-f ${CURRENT_DIR}/values-override.yaml"
fi

echo -e "upgrade # Upgrading weaviate-helm with values: \n\
TARGET: $TARGET \n\
HELM_VALUES: $(echo "$HELM_VALUES" | tr -s ' ') \n\
VALUES_OVERRIDE: $VALUES_OVERRIDE"
helm upgrade weaviate $TARGET \
--namespace weaviate \
$HELM_VALUES \
$VALUES_OVERRIDE

# Wait for Weaviate to be up
kubectl wait sts/weaviate -n weaviate --for jsonpath='{.status.readyReplicas}'=${REPLICAS} --timeout=100s
port_forward_to_weaviate
Expand Down Expand Up @@ -71,21 +85,8 @@ EOF
# Create namespace
kubectl create namespace weaviate

if [ -n "${HELM_BRANCH:-}" ]; then
WEAVIATE_HELM_DIR="/tmp/weaviate-helm"
# Delete $WEAVIATE_HELM_DIR if it already exists
if [ -d "$WEAVIATE_HELM_DIR" ]; then
rm -rf "$WEAVIATE_HELM_DIR"
fi
# Download weaviate-helm repository master branch
git clone -b $HELM_BRANCH https://github.com/weaviate/weaviate-helm.git $WEAVIATE_HELM_DIR
# Package Weaviate Helm chart
helm package -d ${WEAVIATE_HELM_DIR} ${WEAVIATE_HELM_DIR}/weaviate
TARGET=${WEAVIATE_HELM_DIR}/weaviate-*.tgz
else
helm repo add weaviate https://weaviate.github.io/weaviate-helm
TARGET="weaviate/weaviate"
fi
# This function sets up weaviate-helm and sets the global env var $TARGET
setup_helm $HELM_BRANCH

VALUES_OVERRIDE=""
# Check if values-override.yaml file exists
Expand All @@ -95,7 +96,10 @@ EOF

HELM_VALUES=$(generate_helm_values)

echo "setup # Deploying weaviate-helm with values: $HELM_VALUES $VALUES_OVERRIDE"
echo -e "setup # Deploying weaviate-helm with values: \n\
TARGET: $TARGET \n\
HELM_VALUES: $(echo "$HELM_VALUES" | tr -s ' ') \n\
VALUES_OVERRIDE: $VALUES_OVERRIDE"
# Install Weaviate using Helm
helm upgrade --install weaviate $TARGET \
--namespace weaviate \
Expand Down Expand Up @@ -158,6 +162,7 @@ if [ $# -eq 0 ]; then
echo "options:"
echo " setup"
echo " clean"
echo " upgrade"
exit 1
fi

Expand Down
47 changes: 45 additions & 2 deletions utilities/helpers.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,22 @@ function wait_weaviate() {
done
}

function wait_cluster_join() {
node=$1

echo "Wait for node ${node} to join the cluster"
for _ in {1..120}; do
if curl -sf localhost:8080/v1/nodes | jq ".nodes[] | select(.name == \"${node}\" ) | select (.status == \"HEALTHY\" )" | grep -q $node; then
echo "Node ${node} has joined the cluster"
break
fi

echo "Node ${node} has not joined the cluster, trying again in 1s"
sleep 1
done

}

# This auxiliary function returns the number of voters based on the number of nodes, passing the number of nodes as an argument.
function get_voters() {
if [[ $1 -ge 10 ]]; then
Expand Down Expand Up @@ -74,8 +90,8 @@ function generate_helm_values() {
--set replicas=$REPLICAS \
--set grpcService.enabled=true \
--set env.RAFT_BOOTSTRAP_EXPECT=$(get_voters $REPLICAS) \
--set env.LOG_LEVEL=\"debug\" \
--set env.DISABLE_TELEMETRY=\"true\""
--set env.LOG_LEVEL=debug \
--set env.DISABLE_TELEMETRY=true"

# Declare MODULES_ARRAY variable
declare -a MODULES_ARRAY
Expand All @@ -92,3 +108,30 @@ function generate_helm_values() {

echo "$helm_values"
}


function setup_helm () {

if [ $# -eq 0 ]; then
HELM_BRANCH=""
else
HELM_BRANCH=$1
fi

if [ -n "${HELM_BRANCH:-}" ]; then
WEAVIATE_HELM_DIR="/tmp/weaviate-helm"
# Delete $WEAVIATE_HELM_DIR if it already exists
if [ -d "$WEAVIATE_HELM_DIR" ]; then
rm -rf "$WEAVIATE_HELM_DIR"
fi
# Download weaviate-helm repository master branch
git clone -b $HELM_BRANCH https://github.com/weaviate/weaviate-helm.git $WEAVIATE_HELM_DIR
# Package Weaviate Helm chart
helm package -d ${WEAVIATE_HELM_DIR} ${WEAVIATE_HELM_DIR}/weaviate
TARGET=${WEAVIATE_HELM_DIR}/weaviate-*.tgz
else
helm repo add weaviate https://weaviate.github.io/weaviate-helm
TARGET="weaviate/weaviate"
fi

}

0 comments on commit 7c73822

Please sign in to comment.