-
Notifications
You must be signed in to change notification settings - Fork 12
189 lines (162 loc) · 8.12 KB
/
validate.yaml
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
name: Validate Kubernetes Resources
on:
pull_request:
branches: ["main"]
jobs:
validate:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Check if Services have changed
id: changed-services
uses: tj-actions/changed-files@e9772d140489982e0e3704fea5ee93d536f1e275 # v45
with:
files: |
apps/**/svc.yaml
apps/**/*-svc.yaml
- name: Check if Deployments/Statefulsets have changed
id: changed-workloads
uses: tj-actions/changed-files@e9772d140489982e0e3704fea5ee93d536f1e275 # v45
with:
files: |
apps/**/deployment.yaml
apps/**/statefulset.yaml
- name: Check if configMap/Secrets have changed
id: changed-configs
uses: tj-actions/changed-files@e9772d140489982e0e3704fea5ee93d536f1e275 # v45
with:
files: |
apps/**/cm.yaml
apps/**/secret.yaml
- name: Check if Permissions have changed
id: changed-rbac
uses: tj-actions/changed-files@e9772d140489982e0e3704fea5ee93d536f1e275 # v45
with:
files: |
apps/**/rb.yaml
apps/**/crb.yaml
apps/**/role.yaml
apps/**/cr.yaml
- name: Check if Storage resources have changed
id: changed-storage
uses: tj-actions/changed-files@e9772d140489982e0e3704fea5ee93d536f1e275 # v45
with:
files: |
apps/**/pvc.yaml
apps/**/class.yaml
apps/**/pv.yaml
- name: Install Kubeconform
run: |
(wget -qO- https://github.com/yannh/kubeconform/releases/download/v0.5.0/kubeconform-linux-amd64.tar.gz | sudo tar xvz -C /usr/bin) && sudo chmod +x /usr/bin/kubeconform
- name: Validate new Services
id: validate-service
uses: mathiasvr/command-output@v1
if: steps.changed-services.outputs.any_changed == 'true'
with:
run: |
find . -maxdepth 15 -name svc.yaml -exec kubeconform --verbose -exit-on-error -ignore-missing-schemas -kubernetes-version "1.26.0" -schema-location default {} \;
- name: Validate new Workloads
id: validate-workloads
uses: mathiasvr/command-output@v1
if: steps.changed-workloads.outputs.any_changed == 'true'
with:
run: |
find . -maxdepth 15 -name deployment.yaml -exec kubeconform --verbose -exit-on-error -ignore-missing-schemas -kubernetes-version "1.26.0" -schema-location default {} \;
find . -maxdepth 15 -name statefulset.yaml -exec kubeconform --verbose -exit-on-error -ignore-missing-schemas -kubernetes-version "1.26.0" -schema-location default {} \;
- name: Validate new configMaps or Secrets
id: validate-configs
uses: mathiasvr/command-output@v1
if: steps.changed-configs.outputs.any_changed == 'true'
with:
run: |
find . -maxdepth 15 -name cm.yaml -exec kubeconform --verbose -exit-on-error -ignore-missing-schemas -kubernetes-version "1.26.0" -schema-location default {} \;
find . -maxdepth 15 -name secret.yaml -exec kubeconform --verbose -exit-on-error -ignore-missing-schemas -kubernetes-version "1.26.0" -schema-location default {} \;
- name: Validate new Permissions and RBAC resources
id: validate-configs
uses: mathiasvr/command-output@v1
if: steps.changed-rbac.outputs.any_changed == 'true'
with:
run: |
find . -maxdepth 15 -name rb.yaml -exec kubeconform --verbose -exit-on-error -ignore-missing-schemas -kubernetes-version "1.26.0" -schema-location default {} \;
find . -maxdepth 15 -name crb.yaml -exec kubeconform --verbose -exit-on-error -ignore-missing-schemas -kubernetes-version "1.26.0" -schema-location default {} \;
find . -maxdepth 15 -name role.yaml -exec kubeconform --verbose -exit-on-error -ignore-missing-schemas -kubernetes-version "1.26.0" -schema-location default {} \;
find . -maxdepth 15 -name cr.yaml -exec kubeconform --verbose -exit-on-error -ignore-missing-schemas -kubernetes-version "1.26.0" -schema-location default {} \;
- name: Validate new Storage resources
id: validate-configs
uses: mathiasvr/command-output@v1
if: steps.changed-storage.outputs.any_changed == 'true'
with:
run: |
find . -maxdepth 15 -name pvc.yaml -exec kubeconform --verbose -exit-on-error -ignore-missing-schemas -kubernetes-version "1.26.0" -schema-location default {} \;
find . -maxdepth 15 -name pv.yaml -exec kubeconform --verbose -exit-on-error -ignore-missing-schemas -kubernetes-version "1.26.0" -schema-location default {} \;
find . -maxdepth 15 -name clas.yaml -exec kubeconform --verbose -exit-on-error -ignore-missing-schemas -kubernetes-version "1.26.0" -schema-location default {} \;
- name: Find Comment
uses: peter-evans/find-comment@d5fe37641ad8451bdd80312415672ba26c86575e # v3
id: fc
with:
issue-number: ${{ github.event.pull_request.number }}
comment-author: 'github-actions[bot]'
body: |
## List of Kubernetes resources schema validation
- name: Update comment with Service resouces
uses: peter-evans/create-or-update-comment@71345be0265236311c031f5c7866368bd1eff043 # v4
if: steps.changed-services.outputs.any_changed == 'true'
with:
comment-id: ${{ steps.fc.outputs.comment-id }}
issue-number: ${{ github.event.pull_request.number }}
body: |
<details>
<summary><b>Kubernetes `Service` resources</b></summary>
> ${{ steps.validate-service.outputs.stdout }}
</details>
edit-mode: append
- name: Update comment with workload resouces
uses: peter-evans/create-or-update-comment@71345be0265236311c031f5c7866368bd1eff043 # v4
if: steps.changed-workloads.outputs.any_changed == 'true'
with:
comment-id: ${{ steps.fc.outputs.comment-id }}
issue-number: ${{ github.event.pull_request.number }}
body: |
<details>
<summary><b>Kubernetes Deployment/Statefulset resources</b></summary>
> ${{ steps.validate-workloads.outputs.stdout }}
</details>
edit-mode: append
- name: Update comment with config resouces
uses: peter-evans/create-or-update-comment@71345be0265236311c031f5c7866368bd1eff043 # v4
if: steps.changed-configs.outputs.any_changed == 'true'
with:
comment-id: ${{ steps.fc.outputs.comment-id }}
issue-number: ${{ github.event.pull_request.number }}
body: |
<details>
<summary><b>Kubernetes `configMap` and `Secret` resources</b></summary>
> ${{ steps.validate-configs.outputs.stdout }}
</details>
edit-mode: append
- name: Update comment with RBAC resouces
uses: peter-evans/create-or-update-comment@71345be0265236311c031f5c7866368bd1eff043 # v4
if: steps.changed-rbac.outputs.any_changed == 'true'
with:
comment-id: ${{ steps.fc.outputs.comment-id }}
issue-number: ${{ github.event.pull_request.number }}
body: |
<details>
<summary><b>Kubernetes `RoleBinding`, `ClusteRoleBinding`, `Role` and `ClusterRole` resources</b></summary>
> ${{ steps.validate-rbac.outputs.stdout }}
</details>
edit-mode: append
- name: Update comment with Storage resouces
uses: peter-evans/create-or-update-comment@71345be0265236311c031f5c7866368bd1eff043 # v4
if: steps.changed-storage.outputs.any_changed == 'true'
with:
comment-id: ${{ steps.fc.outputs.comment-id }}
issue-number: ${{ github.event.pull_request.number }}
body: |
<details>
<summary><b>Kubernetes `PersistentVolume`, `PersistentVolumeClaim`, and `StorageClass` resources</b></summary>
> ${{ steps.validate-storage.outputs.stdout }}
</details>
edit-mode: append