webhook_test.yaml 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393
  1. suite: test webhook deployment
  2. templates:
  3. - webhook-deployment.yaml
  4. - webhook-secret.yaml
  5. - webhook-service.yaml
  6. - webhook-certificate.yaml
  7. - validatingwebhook.yaml
  8. - crds/externalsecret.yaml
  9. tests:
  10. - it: should match snapshot of default values
  11. asserts:
  12. - matchSnapshot: {}
  13. templates:
  14. - webhook-deployment.yaml
  15. - webhook-secret.yaml
  16. # webhook-certificate.yaml is not rendered by default
  17. - it: should set imagePullPolicy to Always
  18. set:
  19. webhook.image.pullPolicy: Always
  20. asserts:
  21. - equal:
  22. path: spec.template.spec.containers[0].imagePullPolicy
  23. value: Always
  24. template: webhook-deployment.yaml
  25. - it: should imagePullPolicy to be default value IfNotPresent
  26. asserts:
  27. - equal:
  28. path: spec.template.spec.containers[0].imagePullPolicy
  29. value: IfNotPresent
  30. template: webhook-deployment.yaml
  31. - it: should override securityContext
  32. set:
  33. webhook.podSecurityContext:
  34. runAsUser: 2000
  35. webhook.securityContext:
  36. runAsUser: 3000
  37. asserts:
  38. - equal:
  39. path: spec.template.spec.securityContext
  40. value:
  41. runAsUser: 2000
  42. - equal:
  43. path: spec.template.spec.containers[0].securityContext
  44. value:
  45. allowPrivilegeEscalation: false
  46. capabilities:
  47. drop:
  48. - ALL
  49. readOnlyRootFilesystem: true
  50. runAsNonRoot: true
  51. runAsUser: 3000
  52. seccompProfile:
  53. type: RuntimeDefault
  54. template: webhook-deployment.yaml
  55. - it: should override hostNetwork
  56. set:
  57. webhook.hostNetwork: true
  58. asserts:
  59. - equal:
  60. path: spec.template.spec.hostNetwork
  61. value: true
  62. template: webhook-deployment.yaml
  63. - it: should create a certificate CRD
  64. set:
  65. webhook.certManager.enabled: true
  66. webhook.certManager.cert.duration: "10d"
  67. webhook.certManager.cert.renewBefore: "5d"
  68. asserts:
  69. - equal:
  70. path: metadata.name
  71. value: "RELEASE-NAME-external-secrets-webhook"
  72. - equal:
  73. path: spec.secretName
  74. value: "RELEASE-NAME-external-secrets-webhook"
  75. - equal:
  76. path: spec.commonName
  77. value: "RELEASE-NAME-external-secrets-webhook"
  78. - equal:
  79. path: spec.dnsNames[0]
  80. value: "RELEASE-NAME-external-secrets-webhook"
  81. - equal:
  82. path: spec.issuerRef.group
  83. value: "cert-manager.io"
  84. - equal:
  85. path: spec.issuerRef.kind
  86. value: "Issuer"
  87. - equal:
  88. path: spec.issuerRef.name
  89. value: "my-issuer"
  90. - equal:
  91. path: spec.duration
  92. value: "10d"
  93. - equal:
  94. path: spec.renewBefore
  95. value: "5d"
  96. - hasDocuments:
  97. count: 1
  98. templates:
  99. - webhook-certificate.yaml
  100. - it: should not create the webhook secret
  101. set:
  102. webhook.certManager.enabled: true
  103. asserts:
  104. - hasDocuments:
  105. count: 0
  106. template: webhook-secret.yaml
  107. - it: should not create the secret nor the certificate
  108. set:
  109. webhook.certManager.enabled: true
  110. webhook.certManager.cert.create: false
  111. asserts:
  112. - hasDocuments:
  113. count: 0
  114. templates:
  115. - webhook-secret.yaml
  116. - webhook-certificate.yaml
  117. - it: should
  118. set:
  119. webhook.certManager.enabled: true
  120. asserts:
  121. - equal:
  122. path: metadata.name
  123. value: "RELEASE-NAME-external-secrets-webhook"
  124. - hasDocuments:
  125. count: 1
  126. template: webhook-certificate.yaml
  127. - it: should allow using a cluster issuer
  128. set:
  129. webhook.certManager.enabled: true
  130. webhook.certManager.cert.issuerRef.kind: ClusterIssuer
  131. webhook.certManager.cert.issuerRef.name: my-other-issuer
  132. asserts:
  133. - equal:
  134. path: spec.issuerRef.kind
  135. value: "ClusterIssuer"
  136. - equal:
  137. path: spec.issuerRef.name
  138. value: "my-other-issuer"
  139. templates:
  140. - webhook-certificate.yaml
  141. - it: should add annotations to the webhook
  142. set:
  143. webhook.create: true
  144. crds.conversion.enabled: true
  145. webhook.certManager.enabled: true
  146. webhook.certManager.addInjectorAnnotations: true
  147. asserts:
  148. - equal:
  149. path: metadata.annotations["cert-manager.io/inject-ca-from"]
  150. value: "NAMESPACE/RELEASE-NAME-external-secrets-webhook"
  151. templates:
  152. - validatingwebhook.yaml
  153. - crds/externalsecret.yaml
  154. - it: should not add annotations to the webhook
  155. set:
  156. webhook.create: true
  157. webhook.certManager.enabled: true
  158. webhook.certManager.addInjectorAnnotations: false
  159. asserts:
  160. - isNull:
  161. path: metadata.annotations["cert-manager.io/inject-ca-from"]
  162. # value: "NAMESPACE/RELEASE-NAME-external-secrets-webhook"
  163. templates:
  164. - validatingwebhook.yaml
  165. - crds/externalsecret.yaml
  166. - it: should have the correct labels
  167. set:
  168. webhook.create: true
  169. templates:
  170. - validatingwebhook.yaml
  171. asserts:
  172. - equal:
  173. path: metadata.labels["app.kubernetes.io/name"]
  174. value: "external-secrets-webhook"
  175. - equal:
  176. path: metadata.labels["app.kubernetes.io/instance"]
  177. value: "RELEASE-NAME"
  178. - it: should override metrics port
  179. set:
  180. webhook.metrics.listen.port: 8888
  181. templates:
  182. - webhook-deployment.yaml
  183. asserts:
  184. - equal:
  185. path: spec.template.spec.containers[0].args[5]
  186. value: "--metrics-addr=:8888"
  187. - it: should override image flavour
  188. set:
  189. webhook.image.repository: ghcr.io/external-secrets/external-secrets
  190. webhook.image.tag: v0.9.8
  191. webhook.image.flavour: ubi-boringssl
  192. templates:
  193. - webhook-deployment.yaml
  194. asserts:
  195. - equal:
  196. path: spec.template.spec.containers[0].image
  197. value: ghcr.io/external-secrets/external-secrets:v0.9.8-ubi-boringssl
  198. - it: should override image flavour
  199. set:
  200. webhook.image.repository: example.com/external-secrets/external-secrets
  201. webhook.image.tag: v0.9.9-ubi
  202. templates:
  203. - webhook-deployment.yaml
  204. asserts:
  205. - equal:
  206. path: spec.template.spec.containers[0].image
  207. value: example.com/external-secrets/external-secrets:v0.9.9-ubi
  208. - it: should expose metrics port when metrics are enabled
  209. set:
  210. webhook.metrics.service.enabled: true
  211. templates:
  212. - webhook-service.yaml
  213. asserts:
  214. - equal:
  215. path: spec.ports[1].name
  216. value: metrics
  217. - it: should expose metrics port and metrics label when APIVersions is present and serviceMonitor is enabled
  218. set:
  219. serviceMonitor.enabled: true
  220. capabilities:
  221. apiVersions:
  222. - "monitoring.coreos.com/v1"
  223. templates:
  224. - webhook-service.yaml
  225. asserts:
  226. - equal:
  227. path: spec.ports[1].name
  228. value: metrics
  229. - equal:
  230. path: metadata.labels["app.kubernetes.io/metrics"]
  231. value: "webhook"
  232. - it: should not expose metrics port nor metrics label when APIVersions is not present but serviceMonitor is enabled
  233. set:
  234. serviceMonitor.enabled: true
  235. templates:
  236. - webhook-service.yaml
  237. asserts:
  238. - lengthEqual:
  239. path: spec.ports
  240. count: 1
  241. - isNull:
  242. path: metadata.labels["app.kubernetes.io/metrics"]
  243. - it: should not expose metrics port nor metrics label when APIVersions is present and serviceMonitor is disabled
  244. set:
  245. serviceMonitor.enabled: false
  246. capabilities:
  247. apiVersions:
  248. - "monitoring.coreos.com/v1"
  249. templates:
  250. - webhook-service.yaml
  251. asserts:
  252. - lengthEqual:
  253. path: spec.ports
  254. count: 1
  255. - isNull:
  256. path: metadata.labels["app.kubernetes.io/metrics"]
  257. - it: should not expose metrics port nor metrics annotation when APIVersions is not present and serviceMonitor is disabled
  258. set:
  259. serviceMonitor.enabled: false
  260. templates:
  261. - webhook-service.yaml
  262. asserts:
  263. - lengthEqual:
  264. path: spec.ports
  265. count: 1
  266. - isNull:
  267. path: metadata.labels["app.kubernetes.io/metrics"]
  268. - it: should have no annotations when nothing configured
  269. templates:
  270. - webhook-service.yaml
  271. asserts:
  272. - isNull:
  273. path: metadata.annotations
  274. - it: should have only service annotations when only they are configured
  275. set:
  276. webhook.service.annotations:
  277. custom.annotation: value
  278. templates:
  279. - webhook-service.yaml
  280. asserts:
  281. - equal:
  282. path: metadata.annotations["custom.annotation"]
  283. value: value
  284. - it: should have no annotations when only metrics enabled without annotations
  285. set:
  286. webhook.metrics.service.enabled: true
  287. templates:
  288. - webhook-service.yaml
  289. asserts:
  290. - isNull:
  291. path: metadata.annotations
  292. - it: should have only service annotations when metrics enabled without metrics annotations
  293. set:
  294. webhook.service.annotations:
  295. custom.annotation: value
  296. webhook.metrics.service.enabled: true
  297. templates:
  298. - webhook-service.yaml
  299. asserts:
  300. - equal:
  301. path: metadata.annotations["custom.annotation"]
  302. value: value
  303. - it: should have no annotations when metrics annotations exist but metrics disabled
  304. set:
  305. webhook.metrics.service.annotations:
  306. prometheus.io/scrape: "true"
  307. templates:
  308. - webhook-service.yaml
  309. asserts:
  310. - isNull:
  311. path: metadata.annotations
  312. - it: should have only service annotations when metrics annotations exist but metrics disabled
  313. set:
  314. webhook.service.annotations:
  315. custom.annotation: value
  316. webhook.metrics.service.annotations:
  317. prometheus.io/scrape: "true"
  318. templates:
  319. - webhook-service.yaml
  320. asserts:
  321. - equal:
  322. path: metadata.annotations["custom.annotation"]
  323. value: value
  324. - isNull:
  325. path: metadata.annotations["prometheus.io/scrape"]
  326. - it: should have only metrics annotations when metrics enabled and only metrics annotations configured
  327. set:
  328. webhook.metrics.service.enabled: true
  329. webhook.metrics.service.annotations:
  330. prometheus.io/scrape: "true"
  331. templates:
  332. - webhook-service.yaml
  333. asserts:
  334. - equal:
  335. path: metadata.annotations["prometheus.io/scrape"]
  336. value: "true"
  337. - it: should have both annotations when everything is configured and enabled
  338. set:
  339. webhook.service.annotations:
  340. custom.annotation: value
  341. webhook.metrics.service.enabled: true
  342. webhook.metrics.service.annotations:
  343. prometheus.io/scrape: "true"
  344. templates:
  345. - webhook-service.yaml
  346. asserts:
  347. - equal:
  348. path: metadata.annotations["custom.annotation"]
  349. value: value
  350. - equal:
  351. path: metadata.annotations["prometheus.io/scrape"]
  352. value: "true"
  353. - it: should add a init container
  354. templates:
  355. - webhook-deployment.yaml
  356. set:
  357. webhook.extraInitContainers:
  358. - name: foo
  359. image: example.com/external-secrets/init-image:{{ .Chart.Version }}
  360. restartPolicy: Always
  361. asserts:
  362. - equal:
  363. path: spec.template.spec.initContainers[0].name
  364. value: foo
  365. - matchRegex:
  366. path: spec.template.spec.initContainers[0].image
  367. pattern: ^example\.com/external-secrets/init-image:[0-9]+\.[0-9]+\.[0-9]+$
  368. - equal:
  369. path: spec.template.spec.initContainers[0].restartPolicy
  370. value: Always
  371. - it: should override the deployment strategy
  372. templates:
  373. - webhook-deployment.yaml
  374. set:
  375. webhook.strategy:
  376. rollingUpdate:
  377. maxSurge: 1
  378. maxUnavailable: 0
  379. asserts:
  380. - equal:
  381. path: spec.strategy.rollingUpdate.maxSurge
  382. value: 1
  383. - equal:
  384. path: spec.strategy.rollingUpdate.maxUnavailable
  385. value: 0