webhook_test.yaml 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359
  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. webhook.certManager.enabled: true
  145. webhook.certManager.addInjectorAnnotations: true
  146. asserts:
  147. - equal:
  148. path: metadata.annotations["cert-manager.io/inject-ca-from"]
  149. value: "NAMESPACE/RELEASE-NAME-external-secrets-webhook"
  150. templates:
  151. - validatingwebhook.yaml
  152. - crds/externalsecret.yaml
  153. - it: should not add annotations to the webhook
  154. set:
  155. webhook.create: true
  156. webhook.certManager.enabled: true
  157. webhook.certManager.addInjectorAnnotations: false
  158. asserts:
  159. - isNull:
  160. path: metadata.annotations["cert-manager.io/inject-ca-from"]
  161. # value: "NAMESPACE/RELEASE-NAME-external-secrets-webhook"
  162. templates:
  163. - validatingwebhook.yaml
  164. - crds/externalsecret.yaml
  165. - it: should have the correct labels
  166. set:
  167. webhook.create: true
  168. templates:
  169. - validatingwebhook.yaml
  170. asserts:
  171. - equal:
  172. path: metadata.labels["app.kubernetes.io/name"]
  173. value: "external-secrets-webhook"
  174. - equal:
  175. path: metadata.labels["app.kubernetes.io/instance"]
  176. value: "RELEASE-NAME"
  177. - it: should override metrics port
  178. set:
  179. webhook.metrics.listen.port: 8888
  180. templates:
  181. - webhook-deployment.yaml
  182. asserts:
  183. - equal:
  184. path: spec.template.spec.containers[0].args[5]
  185. value: "--metrics-addr=:8888"
  186. - it: should override image flavour
  187. set:
  188. webhook.image.repository: ghcr.io/external-secrets/external-secrets
  189. webhook.image.tag: v0.9.8
  190. webhook.image.flavour: ubi-boringssl
  191. templates:
  192. - webhook-deployment.yaml
  193. asserts:
  194. - equal:
  195. path: spec.template.spec.containers[0].image
  196. value: ghcr.io/external-secrets/external-secrets:v0.9.8-ubi-boringssl
  197. - it: should override image flavour
  198. set:
  199. webhook.image.repository: example.com/external-secrets/external-secrets
  200. webhook.image.tag: v0.9.9-ubi
  201. templates:
  202. - webhook-deployment.yaml
  203. asserts:
  204. - equal:
  205. path: spec.template.spec.containers[0].image
  206. value: example.com/external-secrets/external-secrets:v0.9.9-ubi
  207. - it: should expose metrics port when metrics are enabled
  208. set:
  209. webhook.metrics.service.enabled: true
  210. templates:
  211. - webhook-service.yaml
  212. asserts:
  213. - equal:
  214. path: spec.ports[1].name
  215. value: metrics
  216. - it: should expose metrics port and metrics label when APIVersions is present and serviceMonitor is enabled
  217. set:
  218. serviceMonitor.enabled: true
  219. capabilities:
  220. apiVersions:
  221. - "monitoring.coreos.com/v1"
  222. templates:
  223. - webhook-service.yaml
  224. asserts:
  225. - equal:
  226. path: spec.ports[1].name
  227. value: metrics
  228. - equal:
  229. path: metadata.labels["app.kubernetes.io/metrics"]
  230. value: "webhook"
  231. - it: should not expose metrics port nor metrics label when APIVersions is not present but serviceMonitor is enabled
  232. set:
  233. serviceMonitor.enabled: true
  234. templates:
  235. - webhook-service.yaml
  236. asserts:
  237. - lengthEqual:
  238. path: spec.ports
  239. count: 1
  240. - isNull:
  241. path: metadata.labels["app.kubernetes.io/metrics"]
  242. - it: should not expose metrics port nor metrics label when APIVersions is present and serviceMonitor is disabled
  243. set:
  244. serviceMonitor.enabled: false
  245. capabilities:
  246. apiVersions:
  247. - "monitoring.coreos.com/v1"
  248. templates:
  249. - webhook-service.yaml
  250. asserts:
  251. - lengthEqual:
  252. path: spec.ports
  253. count: 1
  254. - isNull:
  255. path: metadata.labels["app.kubernetes.io/metrics"]
  256. - it: should not expose metrics port nor metrics annotation when APIVersions is not present and serviceMonitor is disabled
  257. set:
  258. serviceMonitor.enabled: false
  259. templates:
  260. - webhook-service.yaml
  261. asserts:
  262. - lengthEqual:
  263. path: spec.ports
  264. count: 1
  265. - isNull:
  266. path: metadata.labels["app.kubernetes.io/metrics"]
  267. - it: should have no annotations when nothing configured
  268. templates:
  269. - webhook-service.yaml
  270. asserts:
  271. - isNull:
  272. path: metadata.annotations
  273. - it: should have only service annotations when only they are configured
  274. set:
  275. webhook.service.annotations:
  276. custom.annotation: value
  277. templates:
  278. - webhook-service.yaml
  279. asserts:
  280. - equal:
  281. path: metadata.annotations["custom.annotation"]
  282. value: value
  283. - it: should have no annotations when only metrics enabled without annotations
  284. set:
  285. webhook.metrics.service.enabled: true
  286. templates:
  287. - webhook-service.yaml
  288. asserts:
  289. - isNull:
  290. path: metadata.annotations
  291. - it: should have only service annotations when metrics enabled without metrics annotations
  292. set:
  293. webhook.service.annotations:
  294. custom.annotation: value
  295. webhook.metrics.service.enabled: true
  296. templates:
  297. - webhook-service.yaml
  298. asserts:
  299. - equal:
  300. path: metadata.annotations["custom.annotation"]
  301. value: value
  302. - it: should have no annotations when metrics annotations exist but metrics disabled
  303. set:
  304. webhook.metrics.service.annotations:
  305. prometheus.io/scrape: "true"
  306. templates:
  307. - webhook-service.yaml
  308. asserts:
  309. - isNull:
  310. path: metadata.annotations
  311. - it: should have only service annotations when metrics annotations exist but metrics disabled
  312. set:
  313. webhook.service.annotations:
  314. custom.annotation: value
  315. webhook.metrics.service.annotations:
  316. prometheus.io/scrape: "true"
  317. templates:
  318. - webhook-service.yaml
  319. asserts:
  320. - equal:
  321. path: metadata.annotations["custom.annotation"]
  322. value: value
  323. - isNull:
  324. path: metadata.annotations["prometheus.io/scrape"]
  325. - it: should have only metrics annotations when metrics enabled and only metrics annotations configured
  326. set:
  327. webhook.metrics.service.enabled: true
  328. webhook.metrics.service.annotations:
  329. prometheus.io/scrape: "true"
  330. templates:
  331. - webhook-service.yaml
  332. asserts:
  333. - equal:
  334. path: metadata.annotations["prometheus.io/scrape"]
  335. value: "true"
  336. - it: should have both annotations when everything is configured and enabled
  337. set:
  338. webhook.service.annotations:
  339. custom.annotation: value
  340. webhook.metrics.service.enabled: true
  341. webhook.metrics.service.annotations:
  342. prometheus.io/scrape: "true"
  343. templates:
  344. - webhook-service.yaml
  345. asserts:
  346. - equal:
  347. path: metadata.annotations["custom.annotation"]
  348. value: value
  349. - equal:
  350. path: metadata.annotations["prometheus.io/scrape"]
  351. value: "true"