-
Notifications
You must be signed in to change notification settings - Fork 11
110 lines (98 loc) · 4.12 KB
/
Copy pathcluster-status.yaml
File metadata and controls
110 lines (98 loc) · 4.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
name: Cluster Status
on:
workflow_dispatch:
permissions:
id-token: write
contents: read
env:
AWS_REGION: us-east-1
EKS_CLUSTER: ce-registry-eks
jobs:
status:
if: ${{ github.repository_owner == 'CredentialEngine' }}
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: arn:aws:iam::${{ secrets.AWS_ACCOUNT }}:role/github-oidc-widget
aws-region: ${{ env.AWS_REGION }}
- name: Install kubectl
uses: azure/setup-kubectl@v4
with:
version: v1.29.6
- name: Update kubeconfig
run: |
aws eks update-kubeconfig --name "${{ env.EKS_CLUSTER }}" --region "${{ env.AWS_REGION }}"
- name: Show nodes summary
run: |
kubectl get nodes -o wide -L env || true
- name: Show credreg-staging status
run: |
NS=credreg-staging
echo "===== Namespace: $NS ====="
{
echo "# Pods";
kubectl -n $NS get pods;
echo;
echo "# Deployments";
kubectl -n $NS get deploy;
echo;
echo "# Images";
echo -n "main-app image: "; kubectl -n $NS get deploy/main-app -o jsonpath='{.spec.template.spec.containers[?(@.name=="main-app")].image}'; echo;
echo -n "worker-app image: "; kubectl -n $NS get deploy/worker-app -o jsonpath='{.spec.template.spec.containers[?(@.name=="worker")].image}'; echo;
} | tee status-staging.txt
- name: Show credreg-sandbox status
run: |
NS=credreg-sandbox
echo "===== Namespace: $NS ====="
{
echo "# Pods";
kubectl -n $NS get pods;
echo;
echo "# Deployments";
kubectl -n $NS get deploy;
echo;
echo "# Images";
echo -n "main-app image: "; kubectl -n $NS get deploy/main-app -o jsonpath='{.spec.template.spec.containers[?(@.name=="main-app")].image}'; echo;
echo -n "worker-app image: "; kubectl -n $NS get deploy/worker-app -o jsonpath='{.spec.template.spec.containers[?(@.name=="worker")].image}'; echo;
} | tee status-sandbox.txt
- name: Show credreg-prod status
run: |
NS=credreg-prod
echo "===== Namespace: $NS ====="
{
echo "# Pods";
kubectl -n $NS get pods;
echo;
echo "# Deployments";
kubectl -n $NS get deploy;
} | tee status-prod.txt
- name: Notify Slack (cluster status)
if: always()
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
REPO: ${{ github.repository }}
RUN_URL: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}
run: |
if [ -z "${SLACK_WEBHOOK_URL}" ]; then
echo "SLACK_WEBHOOK_URL not set; skipping notification";
exit 0;
fi
STATUS="${{ job.status }}"; EMOJI=✅; [ "$STATUS" = "failure" ] && EMOJI=❌
MSG="$EMOJI Cluster status job ${STATUS} for ${REPO}. ${RUN_URL}"
STAGING=$(sed -n '1,80p' status-staging.txt 2>/dev/null | sed 's/"/\"/g')
SANDBOX=$(sed -n '1,80p' status-sandbox.txt 2>/dev/null | sed 's/"/\"/g')
PRODUCTION=$(sed -n '1,80p' status-prod.txt 2>/dev/null | sed 's/"/\"/g')
payload=$(jq -nc --arg text "$MSG" --arg staging "$STAGING" --arg sandbox "$SANDBOX" --arg production "$PRODUCTION" '{
text: $text,
blocks: [
{type:"section", text:{type:"mrkdwn", text:$text}},
{type:"section", text:{type:"mrkdwn", text:("*credreg-staging*\n```\n"+$staging+"\n```")}},
{type:"section", text:{type:"mrkdwn", text:("*credreg-sandbox*\n```\n"+$sandbox+"\n```")}},
{type:"section", text:{type:"mrkdwn", text:("*credreg-prod*\n```\n"+$production+"\n```")}}
]
}')
curl -sS -X POST -H 'Content-type: application/json' --data "$payload" "$SLACK_WEBHOOK_URL" || true