diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index d6ae170..2255f85 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -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 diff --git a/action.yml b/action.yml index d76292d..ec12603 100644 --- a/action.yml +++ b/action.yml @@ -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 @@ -47,6 +51,7 @@ 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 }} @@ -54,7 +59,7 @@ runs: 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() diff --git a/local-k8s.sh b/local-k8s.sh index 434bb87..0edfcb3 100755 --- a/local-k8s.sh +++ b/local-k8s.sh @@ -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 @@ -158,6 +162,7 @@ if [ $# -eq 0 ]; then echo "options:" echo " setup" echo " clean" + echo " upgrade" exit 1 fi diff --git a/utilities/helpers.sh b/utilities/helpers.sh index 774cfdb..6117802 100644 --- a/utilities/helpers.sh +++ b/utilities/helpers.sh @@ -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 @@ -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 @@ -92,3 +108,4 @@ function generate_helm_values() { echo "$helm_values" } +