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 becb466
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 9 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
17 changes: 11 additions & 6 deletions local-k8s.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,20 @@ GRAFANA_PORT=3000
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"
git clone -b $HELM_BRANCH https://github.com/weaviate/weaviate-helm.git "/tmp/weaviate-helm"

# Package Weaviate Helm chart
helm package -d /tmp/weaviate-helm /tmp/weaviate-helm/weaviate

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

echo "upgrade # Upgrading Weaviate"
HELM_VALUES=$(generate_helm_values)
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)

$HELM_VALUES

# 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 @@ -158,6 +162,7 @@ if [ $# -eq 0 ]; then
echo "options:"
echo " setup"
echo " clean"
echo " upgrade"
exit 1
fi

Expand Down
21 changes: 19 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,4 @@ function generate_helm_values() {

echo "$helm_values"
}

0 comments on commit becb466

Please sign in to comment.