Skip to content

Commit

Permalink
feat: add mutex action
Browse files Browse the repository at this point in the history
  • Loading branch information
zeruk committed Mar 30, 2023
1 parent a482498 commit 93fb5b7
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 0 deletions.
56 changes: 56 additions & 0 deletions .github/actions/mutex/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
name: "Slo mutex action"
description: "Obtain or release mutex"
author: "Ilya Shevchenko <id.shev@yandex.ru>"

inputs:
KUBE_CONFIG:
description: "base64 kube config"
required: true
language:
description: "Language variant to obtain mutex by"
required: true
command:
description: "`obtain` or `release` command"
required: true

runs:
using: "composite"
steps:
- run: mkdir $HOME/.kube; echo "${{ inputs.KUBE_CONFIG }}" | base64 -d > $HOME/.kube/config
shell: bash

- name: Get existing mutex configmap
run: kubectl get configmaps slo-mutex -o=yaml
shell: bash

- name: Check if locked
if: inputs.command == 'obtain'
run: |
if test -n "`kubectl get configmaps slo-mutex -o=jsonpath={.data.busy}`"; then
echo "Locked by `kubectl get configmaps slo-mutex -o=jsonpath={.data.lockedBy}`, wait";
fi
shell: bash

- name: Wait until unlocked (maximum 30 minutes waiting)
if: inputs.command == 'obtain'
# check every 30s for 60 times = 30 minutes
run: |
for run in {1..60}; do
if test -z "`kubectl get configmaps slo-mutex -o=jsonpath={.data.busy}`"; then
echo "Mutex unlocked!"; break;
fi;
sleep 30;
done
kubectl create configmap slo-mutex --from-literal=busy=true --from-literal=lockedBy=${{ inputs.language }} -o=yaml --dry-run=client | kubectl apply -f -
shell: bash

- name: Unlock mutex
if: inputs.command == 'release'
run: >
kubectl create configmap slo-mutex -o=yaml --dry-run=client | kubectl apply -f -
shell: bash

- name: Get mutex configmap
run: kubectl get configmaps slo-mutex -o=yaml
shell: bash
23 changes: 23 additions & 0 deletions .github/workflows/slo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,18 @@ on:
concurrency: slo

jobs:
obtain-mutex:
runs-on: ubuntu-latest
steps:
- name: obtain-mutex
uses: ydb-platform/slo-tests/.github/actions/mutex@main
with:
KUBE_CONFIG: ${{ secrets.SLO_KUBE_CONFIG }}
command: obtain
language: "${{ inputs.language }}"

create-cluster:
needs: [obtain-mutex]
runs-on: ubuntu-latest
steps:
- name: create-cluster
Expand All @@ -43,6 +54,7 @@ jobs:
command: apply

build-workload:
needs: [obtain-mutex]
uses: ./.github/workflows/build-workload.yml
secrets:
DOCKER_REPO: ${{ secrets.SLO_DOCKER_REPO }}
Expand Down Expand Up @@ -149,3 +161,14 @@ jobs:
subfolder: cluster_delete_action
KUBE_CONFIG: ${{ secrets.SLO_KUBE_CONFIG }}
command: delete

release-mutex:
runs-on: ubuntu-latest
needs: [delete-cluster]
steps:
- name: release-mutex
uses: ydb-platform/slo-tests/.github/actions/mutex@main
with:
KUBE_CONFIG: ${{ secrets.SLO_KUBE_CONFIG }}
command: release
language: "${{ inputs.language }}"

0 comments on commit 93fb5b7

Please sign in to comment.