Skip to content

Commit ae3eaf2

Browse files
committed
perf: add k8s_restart workflow
1 parent 543640b commit ae3eaf2

File tree

2 files changed

+85
-0
lines changed

2 files changed

+85
-0
lines changed

.github/workflows/k8s_restart.yml

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
name: 'K8: Restart'
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
deployment_name:
7+
description: 'Deployment Name'
8+
required: true
9+
type: string
10+
11+
# Special permissions required for OIDC authentication
12+
permissions:
13+
id-token: write
14+
contents: read
15+
actions: read
16+
17+
jobs:
18+
k8-restart:
19+
name: 'K8: Restart'
20+
runs-on: [self-hosted, dev]
21+
environment: dev
22+
env:
23+
KUBELOGIN_VERSION: "v0.0.25"
24+
KUBERNETES_CLUSTER_NAME: "${{ vars.KUBERNETES_CLUSTER_NAME }}"
25+
KUBERNETES_NAMESPACE: "${{ vars.KUBERNETES_NAMESPACE }}"
26+
AZURE_RESOURCE_GROUP: "${{ vars.AZURE_RESOURCE_GROUP }}"
27+
steps:
28+
# Checkout the repository to the GitHub Actions runner
29+
- name: Checkout
30+
uses: actions/checkout@v4
31+
32+
- name: GitHub Configuration
33+
run: git config --global url."https://oauth2:${{ secrets.GH_TOKEN }}@github.com".insteadOf https://github.com
34+
35+
- name: Clone cicd-deployment-scripts
36+
run: git clone https://github.com/code-kern-ai/cicd-deployment-scripts.git
37+
38+
# Install the latest version of Kubernetes CLI and configure the Kubernetes CLI configuration file with a Kubernetes Cloud user API token
39+
- name: Azure Cloud Login
40+
uses: azure/login@v2
41+
with:
42+
client-id: ${{ secrets.AZURE_CLIENT_ID }}
43+
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
44+
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
45+
46+
# Use kubelogin to configure your kubeconfig for Azure auth
47+
- name: Set up kubelogin for non-interactive login
48+
uses: azure/use-kubelogin@v1
49+
with:
50+
kubelogin-version: ${{ env.KUBELOGIN_VERSION }}
51+
52+
- uses: azure/aks-set-context@v3
53+
with:
54+
resource-group: ${{ env.AZURE_RESOURCE_GROUP }}
55+
cluster-name: ${{ env.KUBERNETES_CLUSTER_NAME }}
56+
admin: 'false'
57+
use-kubelogin: 'true'
58+
59+
- name: Run Restart
60+
shell: bash
61+
run: |
62+
bash cicd-deployment-scripts/k8s/restart.sh \
63+
-n ${{ env.KUBERNETES_NAMESPACE }} \
64+
-d ${{ inputs.deployment_name }}

k8s/restart.sh

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# !/bin/bash
2+
set -e
3+
4+
KUBERNETES_NAMESPACE=""
5+
KUBERNETES_DEPLOYMENT_NAME=""
6+
7+
while getopts n:d: flag
8+
do
9+
case "${flag}" in
10+
n) KUBERNETES_NAMESPACE=${OPTARG};;
11+
d) KUBERNETES_DEPLOYMENT_NAME=${OPTARG};;
12+
esac
13+
done
14+
15+
kubectl config set-context --current --namespace=$KUBERNETES_NAMESPACE
16+
echo "Context set to namespace: \"$KUBERNETES_NAMESPACE\""
17+
18+
kubectl rollout restart deployment ${KUBERNETES_DEPLOYMENT_NAME}
19+
kubectl rollout status deployment ${KUBERNETES_DEPLOYMENT_NAME}
20+
21+
echo "::notice::Restarted ${KUBERNETES_DEPLOYMENT_NAME} successfully"

0 commit comments

Comments
 (0)