webhook_test.yaml 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435
  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/ServiceMonitor"
  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 expose metrics port and metrics label when APIVersions is not present, serviceMonitor is enabled, and serviceMonitor.renderMode is alwaysRender
  233. set:
  234. serviceMonitor.enabled: true
  235. serviceMonitor.renderMode: alwaysRender
  236. templates:
  237. - webhook-service.yaml
  238. asserts:
  239. - equal:
  240. path: spec.ports[1].name
  241. value: metrics
  242. - equal:
  243. path: metadata.labels["app.kubernetes.io/metrics"]
  244. value: "webhook"
  245. - it: should fail if APIVersions is missing, serviceMonitor is enabled, and serviceMonitor.renderMode is failIfMissing
  246. set:
  247. serviceMonitor.enabled: true
  248. serviceMonitor.renderMode: failIfMissing
  249. templates:
  250. - webhook-service.yaml
  251. asserts:
  252. - failedTemplate: {}
  253. - it: should not expose metrics port nor metrics label when APIVersions is not present, serviceMonitor is enabled, and serviceMonitor.renderMode is skipIfMissing
  254. set:
  255. serviceMonitor.enabled: true
  256. serviceMonitor.renderMode: skipIfMissing
  257. templates:
  258. - webhook-service.yaml
  259. asserts:
  260. - lengthEqual:
  261. path: spec.ports
  262. count: 1
  263. - isNull:
  264. path: metadata.labels["app.kubernetes.io/metrics"]
  265. - it: should not expose metrics port nor metrics label when APIVersions is not present but serviceMonitor is enabled
  266. set:
  267. serviceMonitor.enabled: true
  268. templates:
  269. - webhook-service.yaml
  270. asserts:
  271. - lengthEqual:
  272. path: spec.ports
  273. count: 1
  274. - isNull:
  275. path: metadata.labels["app.kubernetes.io/metrics"]
  276. - it: should not expose metrics port nor metrics label when APIVersions is present and serviceMonitor is disabled
  277. set:
  278. serviceMonitor.enabled: false
  279. capabilities:
  280. apiVersions:
  281. - "monitoring.coreos.com/v1/ServiceMonitor"
  282. templates:
  283. - webhook-service.yaml
  284. asserts:
  285. - lengthEqual:
  286. path: spec.ports
  287. count: 1
  288. - isNull:
  289. path: metadata.labels["app.kubernetes.io/metrics"]
  290. - it: should not expose metrics port nor metrics annotation when APIVersions is not present and serviceMonitor is disabled
  291. set:
  292. serviceMonitor.enabled: false
  293. templates:
  294. - webhook-service.yaml
  295. asserts:
  296. - lengthEqual:
  297. path: spec.ports
  298. count: 1
  299. - isNull:
  300. path: metadata.labels["app.kubernetes.io/metrics"]
  301. - it: should have no annotations when nothing configured
  302. templates:
  303. - webhook-service.yaml
  304. asserts:
  305. - isNull:
  306. path: metadata.annotations
  307. - it: should have only service annotations when only they are configured
  308. set:
  309. webhook.service.annotations:
  310. custom.annotation: value
  311. templates:
  312. - webhook-service.yaml
  313. asserts:
  314. - equal:
  315. path: metadata.annotations["custom.annotation"]
  316. value: value
  317. - it: should have no annotations when only metrics enabled without annotations
  318. set:
  319. webhook.metrics.service.enabled: true
  320. templates:
  321. - webhook-service.yaml
  322. asserts:
  323. - isNull:
  324. path: metadata.annotations
  325. - it: should have only service annotations when metrics enabled without metrics annotations
  326. set:
  327. webhook.service.annotations:
  328. custom.annotation: value
  329. webhook.metrics.service.enabled: true
  330. templates:
  331. - webhook-service.yaml
  332. asserts:
  333. - equal:
  334. path: metadata.annotations["custom.annotation"]
  335. value: value
  336. - it: should have no annotations when metrics annotations exist but metrics disabled
  337. set:
  338. webhook.metrics.service.annotations:
  339. prometheus.io/scrape: "true"
  340. templates:
  341. - webhook-service.yaml
  342. asserts:
  343. - isNull:
  344. path: metadata.annotations
  345. - it: should have only service annotations when metrics annotations exist but metrics disabled
  346. set:
  347. webhook.service.annotations:
  348. custom.annotation: value
  349. webhook.metrics.service.annotations:
  350. prometheus.io/scrape: "true"
  351. templates:
  352. - webhook-service.yaml
  353. asserts:
  354. - equal:
  355. path: metadata.annotations["custom.annotation"]
  356. value: value
  357. - isNull:
  358. path: metadata.annotations["prometheus.io/scrape"]
  359. - it: should have only metrics annotations when metrics enabled and only metrics annotations configured
  360. set:
  361. webhook.metrics.service.enabled: true
  362. webhook.metrics.service.annotations:
  363. prometheus.io/scrape: "true"
  364. templates:
  365. - webhook-service.yaml
  366. asserts:
  367. - equal:
  368. path: metadata.annotations["prometheus.io/scrape"]
  369. value: "true"
  370. - it: should have both annotations when everything is configured and enabled
  371. set:
  372. webhook.service.annotations:
  373. custom.annotation: value
  374. webhook.metrics.service.enabled: true
  375. webhook.metrics.service.annotations:
  376. prometheus.io/scrape: "true"
  377. templates:
  378. - webhook-service.yaml
  379. asserts:
  380. - equal:
  381. path: metadata.annotations["custom.annotation"]
  382. value: value
  383. - equal:
  384. path: metadata.annotations["prometheus.io/scrape"]
  385. value: "true"
  386. - it: should add a init container
  387. templates:
  388. - webhook-deployment.yaml
  389. set:
  390. webhook.extraInitContainers:
  391. - name: foo
  392. image: example.com/external-secrets/init-image:{{ .Chart.Version }}
  393. restartPolicy: Always
  394. asserts:
  395. - equal:
  396. path: spec.template.spec.initContainers[0].name
  397. value: foo
  398. - matchRegex:
  399. path: spec.template.spec.initContainers[0].image
  400. pattern: ^example\.com/external-secrets/init-image:[0-9]+\.[0-9]+\.[0-9]+$
  401. - equal:
  402. path: spec.template.spec.initContainers[0].restartPolicy
  403. value: Always
  404. - it: should override the deployment strategy
  405. templates:
  406. - webhook-deployment.yaml
  407. set:
  408. webhook.strategy:
  409. rollingUpdate:
  410. maxSurge: 1
  411. maxUnavailable: 0
  412. asserts:
  413. - equal:
  414. path: spec.strategy.rollingUpdate.maxSurge
  415. value: 1
  416. - equal:
  417. path: spec.strategy.rollingUpdate.maxUnavailable
  418. value: 0
  419. - it: should update args with enableHTTP2=true
  420. set:
  421. enableHTTP2: true
  422. templates:
  423. - webhook-deployment.yaml
  424. asserts:
  425. - contains:
  426. path: spec.template.spec.containers[0].args
  427. content: "--enable-http2=true"