Skip to content

perf: add k8s reload secrets workflow #5

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

Merged
merged 1 commit into from
Aug 22, 2024
Merged
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
64 changes: 64 additions & 0 deletions .github/workflows/k8s_reload_secrets.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
name: 'K8: Reload Secrets'

on:
workflow_call:
inputs:
deployment_name:
description: 'Deployment Name'
required: true
type: string

# Special permissions required for OIDC authentication
permissions:
id-token: write
contents: read
actions: read

jobs:
k8-reload-secrets:
name: 'K8: Reload Secrets'
runs-on: [self-hosted, dev]
environment: dev
env:
KUBELOGIN_VERSION: "v0.0.25"
KUBERNETES_CLUSTER_NAME: "${{ vars.KUBERNETES_CLUSTER_NAME }}"
KUBERNETES_NAMESPACE: "${{ vars.KUBERNETES_NAMESPACE }}"
AZURE_RESOURCE_GROUP: "${{ vars.AZURE_RESOURCE_GROUP }}"
steps:
# Checkout the repository to the GitHub Actions runner
- name: Checkout
uses: actions/checkout@v4

- name: GitHub Configuration
run: git config --global url."https://oauth2:${{ secrets.GH_TOKEN }}@github.com".insteadOf https://github.com

- name: Clone cicd-deployment-scripts
run: git clone https://github.com/code-kern-ai/cicd-deployment-scripts.git

# Install the latest version of Kubernetes CLI and configure the Kubernetes CLI configuration file with a Kubernetes Cloud user API token
- name: Azure Cloud Login
uses: azure/login@v2
with:
client-id: ${{ secrets.AZURE_CLIENT_ID }}
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}

# Use kubelogin to configure your kubeconfig for Azure auth
- name: Set up kubelogin for non-interactive login
uses: azure/use-kubelogin@v1
with:
kubelogin-version: ${{ env.KUBELOGIN_VERSION }}

- uses: azure/aks-set-context@v3
with:
resource-group: ${{ env.AZURE_RESOURCE_GROUP }}
cluster-name: ${{ env.KUBERNETES_CLUSTER_NAME }}
admin: 'false'
use-kubelogin: 'true'

- name: Run Secret Reload
shell: bash
run: |
bash cicd-deployment-scripts/k8s/reload_secrets.sh \
-n ${{ env.KUBERNETES_NAMESPACE }} \
-d ${{ inputs.deployment_name }}
43 changes: 43 additions & 0 deletions k8s/reload_secrets.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# !/bin/bash
set -e

KUBERNETES_NAMESPACE=""
KUBERNETES_DEPLOYMENT_NAME=""

while getopts n:d: flag
do
case "${flag}" in
n) KUBERNETES_NAMESPACE=${OPTARG};;
d) KUBERNETES_DEPLOYMENT_NAME=${OPTARG};;
esac
done

declare -A secret_rename_mapping=( \
["cognition-gateway"]="cg-gateway" \
["cognition-pdf2md"]="cg-gateway" \
["cognition-task-master"]="cg-task-master" \
["gates-gateway"]="gt-gateway" \
["platform-monitoring"]="plfm-monitor" \
["refinery-commercial-proxy"]="rf-comm-proxy" \
["refinery-config"]="rf-config" \
["refinery-doc-ock"]="rf-doc-ock" \
["refinery-embedder"]="rf-embedder" \
["refinery-gateway"]="rf-gateway" \
["refinery-gateway-proxy"]="rf-gw-proxy" \
["refinery-model-provider"]="rf-mdl-prvd" \
["refinery-neural-search"]="rf-nrl-search" \
["refinery-tokenizer"]="rf-tokenizer" \
["refinery-updater"]="rf-updater" \
["refinery-weak-supervisor"]="rf-weak-supvsr" \
["refinery-websocket"]="rf-websocket" \
["refinery-zero-shot"]="rf-zero-shot" \
)

kubectl config set-context --current --namespace=$KUBERNETES_NAMESPACE
echo "Context set to namespace: \"$KUBERNETES_NAMESPACE\""

kubectl delete secret ${secret_rename_mapping[$KUBERNETES_DEPLOYMENT_NAME]}
kubectl rollout restart deployment ${KUBERNETES_DEPLOYMENT_NAME}
kubectl rollout status deployment ${KUBERNETES_DEPLOYMENT_NAME}

echo "::notice::Reloaded ${KUBERNETES_DEPLOYMENT_NAME} secret (${secret_rename_mapping[$KUBERNETES_DEPLOYMENT_NAME]}) successfully"