Skip to content

Commit 0bc84e9

Browse files
committed
Add CI check for Kubernetes YAML files
1 parent 7f15c2d commit 0bc84e9

File tree

4 files changed

+66
-5
lines changed

4 files changed

+66
-5
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/bin/bash
2+
3+
set -x
4+
5+
DIR=$1
6+
kubectl kustomize "${DIR}" | kube-score score - --ignore-test pod-networkpolicy -o ci | grep -v OK

.github/workflows/kube-score.yaml

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
name: kube-score
2+
3+
on:
4+
pull_request:
5+
paths:
6+
- "k8s/**/*.yaml"
7+
8+
jobs:
9+
kube-score:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/checkout@v2
13+
14+
- name: Set up kubectl command
15+
run: |
16+
curl -LO https://storage.googleapis.com/kubernetes-release/release/v1.21.0/bin/linux/amd64/kubectl
17+
chmod +x ./kubectl
18+
sudo mv ./kubectl /usr/local/bin/kubectl
19+
kubectl version --client
20+
21+
- name: Set up kube score command
22+
run: |
23+
wget https://github.com/zegl/kube-score/releases/download/v1.11.0/kube-score_1.11.0_linux_amd64.tar.gz
24+
tar xvzf kube-score_1.11.0_linux_amd64.tar.gz
25+
chmod +x ./kube-score
26+
sudo mv ./kube-score /usr/local/bin/kube-score
27+
kube-score version
28+
29+
- name: Perform static check
30+
run: |
31+
touch check-result.txt
32+
TARGET_DIRS=$(find . | grep ".overlays/.*/kustomization.yaml" | sed 's%kustomization.yaml%%')
33+
for DIR in $TARGET_DIRS; do
34+
echo "Check Kubernetes resources in" $DIR
35+
bash ./.github/actions/calculate-kube-scores.sh $DIR >> check-result.txt
36+
done;
37+
38+
- name: Show check result
39+
run: |
40+
TOTAL_CRITICAL_ISSUE_NUM=$(cat check-result.txt | grep CRITICAL | wc -l)
41+
echo "TOTAL_CRITICAL_ISSUE_NUM:" $TOTAL_CRITICAL_ISSUE_NUM
42+
if [[ "$TOTAL_CRITICAL_ISSUE_NUM" != 0 ]]; then
43+
cat check-result.txt
44+
exit 1
45+
fi

k8s/fastapi/base/deployment.yaml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,15 @@ metadata:
55
labels:
66
app: fastapi
77
spec:
8-
replicas: 3
8+
replicas: 1
99
selector:
1010
matchLabels:
1111
app: fastapi
12+
strategy:
13+
rollingUpdate:
14+
maxSurge: 0
15+
maxUnavailable: 1
16+
type: RollingUpdate
1217
template:
1318
metadata:
1419
labels:
Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
11
namespace: api-app
2+
23
bases:
34
- ../../base
5+
46
patchesStrategicMerge:
57
- deployment.yaml
8+
69
configMapGenerator:
710
- name: fastapi-configmap
811
literals:
9-
- MYSQL_HOST=mysql-0.mysql-headless.database.svc.cluster.local
10-
- MYSQL_USER=root
11-
- MYSQL_DATABASE=test
12+
- MYSQL_HOST=mysql-0.mysql-headless.database.svc.cluster.local
13+
- MYSQL_USER=root
14+
- MYSQL_DATABASE=test
15+
1216
resources:
13-
- secret.yaml
17+
- secret.yaml
18+
- network-policy.yaml

0 commit comments

Comments
 (0)