webhook_test.yaml 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503
  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. - notExists:
  97. path: spec.privateKey
  98. - notExists:
  99. path: spec.signatureAlgorithm
  100. - hasDocuments:
  101. count: 1
  102. templates:
  103. - webhook-certificate.yaml
  104. - it: should create a certificate CRD with privateKey and signatureAlgorithm
  105. set:
  106. webhook:
  107. certManager:
  108. enabled: true
  109. cert:
  110. privateKey:
  111. algorithm: RSA
  112. rotationPolicy: Always
  113. size: 2048
  114. signatureAlgorithm: SHA256WithRSA
  115. asserts:
  116. - equal:
  117. path: spec.privateKey.algorithm
  118. value: "RSA"
  119. - equal:
  120. path: spec.privateKey.rotationPolicy
  121. value: "Always"
  122. - equal:
  123. path: spec.privateKey.size
  124. value: 2048
  125. - equal:
  126. path: spec.signatureAlgorithm
  127. value: "SHA256WithRSA"
  128. - hasDocuments:
  129. count: 1
  130. templates:
  131. - webhook-certificate.yaml
  132. - it: should not create the webhook secret
  133. set:
  134. webhook.certManager.enabled: true
  135. asserts:
  136. - hasDocuments:
  137. count: 0
  138. template: webhook-secret.yaml
  139. - it: should not create the secret nor the certificate
  140. set:
  141. webhook.certManager.enabled: true
  142. webhook.certManager.cert.create: false
  143. asserts:
  144. - hasDocuments:
  145. count: 0
  146. templates:
  147. - webhook-secret.yaml
  148. - webhook-certificate.yaml
  149. - it: should
  150. set:
  151. webhook.certManager.enabled: true
  152. asserts:
  153. - equal:
  154. path: metadata.name
  155. value: "RELEASE-NAME-external-secrets-webhook"
  156. - hasDocuments:
  157. count: 1
  158. template: webhook-certificate.yaml
  159. - it: should allow using a cluster issuer
  160. set:
  161. webhook.certManager.enabled: true
  162. webhook.certManager.cert.issuerRef.kind: ClusterIssuer
  163. webhook.certManager.cert.issuerRef.name: my-other-issuer
  164. asserts:
  165. - equal:
  166. path: spec.issuerRef.kind
  167. value: "ClusterIssuer"
  168. - equal:
  169. path: spec.issuerRef.name
  170. value: "my-other-issuer"
  171. templates:
  172. - webhook-certificate.yaml
  173. - it: should add annotations to the webhook
  174. set:
  175. webhook.create: true
  176. crds.conversion.enabled: true
  177. webhook.certManager.enabled: true
  178. webhook.certManager.addInjectorAnnotations: true
  179. asserts:
  180. - equal:
  181. path: metadata.annotations["cert-manager.io/inject-ca-from"]
  182. value: "NAMESPACE/RELEASE-NAME-external-secrets-webhook"
  183. templates:
  184. - validatingwebhook.yaml
  185. - crds/externalsecret.yaml
  186. - it: should not add annotations to the webhook
  187. set:
  188. webhook.create: true
  189. webhook.certManager.enabled: true
  190. webhook.certManager.addInjectorAnnotations: false
  191. asserts:
  192. - isNull:
  193. path: metadata.annotations["cert-manager.io/inject-ca-from"]
  194. # value: "NAMESPACE/RELEASE-NAME-external-secrets-webhook"
  195. templates:
  196. - validatingwebhook.yaml
  197. - crds/externalsecret.yaml
  198. - it: should have the correct labels
  199. set:
  200. webhook.create: true
  201. templates:
  202. - validatingwebhook.yaml
  203. asserts:
  204. - equal:
  205. path: metadata.labels["app.kubernetes.io/name"]
  206. value: "external-secrets-webhook"
  207. - equal:
  208. path: metadata.labels["app.kubernetes.io/instance"]
  209. value: "RELEASE-NAME"
  210. - it: should override metrics port
  211. set:
  212. webhook.metrics.listen.port: 8888
  213. templates:
  214. - webhook-deployment.yaml
  215. asserts:
  216. - equal:
  217. path: spec.template.spec.containers[0].args[5]
  218. value: "--metrics-addr=:8888"
  219. - it: should override image flavour
  220. set:
  221. webhook.image.repository: ghcr.io/external-secrets/external-secrets
  222. webhook.image.tag: v0.9.8
  223. webhook.image.flavour: ubi-boringssl
  224. templates:
  225. - webhook-deployment.yaml
  226. asserts:
  227. - equal:
  228. path: spec.template.spec.containers[0].image
  229. value: ghcr.io/external-secrets/external-secrets:v0.9.8-ubi-boringssl
  230. - it: should override image flavour
  231. set:
  232. webhook.image.repository: example.com/external-secrets/external-secrets
  233. webhook.image.tag: v0.9.9-ubi
  234. templates:
  235. - webhook-deployment.yaml
  236. asserts:
  237. - equal:
  238. path: spec.template.spec.containers[0].image
  239. value: example.com/external-secrets/external-secrets:v0.9.9-ubi
  240. - it: should expose metrics port when metrics are enabled
  241. set:
  242. webhook.metrics.service.enabled: true
  243. templates:
  244. - webhook-service.yaml
  245. asserts:
  246. - equal:
  247. path: spec.ports[1].name
  248. value: metrics
  249. - it: should expose metrics port and metrics label when APIVersions is present and serviceMonitor is enabled
  250. set:
  251. serviceMonitor.enabled: true
  252. capabilities:
  253. apiVersions:
  254. - "monitoring.coreos.com/v1/ServiceMonitor"
  255. templates:
  256. - webhook-service.yaml
  257. asserts:
  258. - equal:
  259. path: spec.ports[1].name
  260. value: metrics
  261. - equal:
  262. path: metadata.labels["app.kubernetes.io/metrics"]
  263. value: "webhook"
  264. - it: should expose metrics port and metrics label when APIVersions is not present, serviceMonitor is enabled, and serviceMonitor.renderMode is alwaysRender
  265. set:
  266. serviceMonitor.enabled: true
  267. serviceMonitor.renderMode: alwaysRender
  268. templates:
  269. - webhook-service.yaml
  270. asserts:
  271. - equal:
  272. path: spec.ports[1].name
  273. value: metrics
  274. - equal:
  275. path: metadata.labels["app.kubernetes.io/metrics"]
  276. value: "webhook"
  277. - it: should fail if APIVersions is missing, serviceMonitor is enabled, and serviceMonitor.renderMode is failIfMissing
  278. set:
  279. serviceMonitor.enabled: true
  280. serviceMonitor.renderMode: failIfMissing
  281. templates:
  282. - webhook-service.yaml
  283. asserts:
  284. - failedTemplate: {}
  285. - it: should not expose metrics port nor metrics label when APIVersions is not present, serviceMonitor is enabled, and serviceMonitor.renderMode is skipIfMissing
  286. set:
  287. serviceMonitor.enabled: true
  288. serviceMonitor.renderMode: skipIfMissing
  289. templates:
  290. - webhook-service.yaml
  291. asserts:
  292. - lengthEqual:
  293. path: spec.ports
  294. count: 1
  295. - isNull:
  296. path: metadata.labels["app.kubernetes.io/metrics"]
  297. - it: should not expose metrics port nor metrics label when APIVersions is not present but serviceMonitor is enabled
  298. set:
  299. serviceMonitor.enabled: true
  300. templates:
  301. - webhook-service.yaml
  302. asserts:
  303. - lengthEqual:
  304. path: spec.ports
  305. count: 1
  306. - isNull:
  307. path: metadata.labels["app.kubernetes.io/metrics"]
  308. - it: should not expose metrics port nor metrics label when APIVersions is present and serviceMonitor is disabled
  309. set:
  310. serviceMonitor.enabled: false
  311. capabilities:
  312. apiVersions:
  313. - "monitoring.coreos.com/v1/ServiceMonitor"
  314. templates:
  315. - webhook-service.yaml
  316. asserts:
  317. - lengthEqual:
  318. path: spec.ports
  319. count: 1
  320. - isNull:
  321. path: metadata.labels["app.kubernetes.io/metrics"]
  322. - it: should not expose metrics port nor metrics annotation when APIVersions is not present and serviceMonitor is disabled
  323. set:
  324. serviceMonitor.enabled: false
  325. templates:
  326. - webhook-service.yaml
  327. asserts:
  328. - lengthEqual:
  329. path: spec.ports
  330. count: 1
  331. - isNull:
  332. path: metadata.labels["app.kubernetes.io/metrics"]
  333. - it: should have no annotations when nothing configured
  334. templates:
  335. - webhook-service.yaml
  336. asserts:
  337. - isNull:
  338. path: metadata.annotations
  339. - it: should have only service annotations when only they are configured
  340. set:
  341. webhook.service.annotations:
  342. custom.annotation: value
  343. templates:
  344. - webhook-service.yaml
  345. asserts:
  346. - equal:
  347. path: metadata.annotations["custom.annotation"]
  348. value: value
  349. - it: should have no annotations when only metrics enabled without annotations
  350. set:
  351. webhook.metrics.service.enabled: true
  352. templates:
  353. - webhook-service.yaml
  354. asserts:
  355. - isNull:
  356. path: metadata.annotations
  357. - it: should have only service annotations when metrics enabled without metrics annotations
  358. set:
  359. webhook.service.annotations:
  360. custom.annotation: value
  361. webhook.metrics.service.enabled: true
  362. templates:
  363. - webhook-service.yaml
  364. asserts:
  365. - equal:
  366. path: metadata.annotations["custom.annotation"]
  367. value: value
  368. - it: should have no annotations when metrics annotations exist but metrics disabled
  369. set:
  370. webhook.metrics.service.annotations:
  371. prometheus.io/scrape: "true"
  372. templates:
  373. - webhook-service.yaml
  374. asserts:
  375. - isNull:
  376. path: metadata.annotations
  377. - it: should have only service annotations when metrics annotations exist but metrics disabled
  378. set:
  379. webhook.service.annotations:
  380. custom.annotation: value
  381. webhook.metrics.service.annotations:
  382. prometheus.io/scrape: "true"
  383. templates:
  384. - webhook-service.yaml
  385. asserts:
  386. - equal:
  387. path: metadata.annotations["custom.annotation"]
  388. value: value
  389. - isNull:
  390. path: metadata.annotations["prometheus.io/scrape"]
  391. - it: should have only metrics annotations when metrics enabled and only metrics annotations configured
  392. set:
  393. webhook.metrics.service.enabled: true
  394. webhook.metrics.service.annotations:
  395. prometheus.io/scrape: "true"
  396. templates:
  397. - webhook-service.yaml
  398. asserts:
  399. - equal:
  400. path: metadata.annotations["prometheus.io/scrape"]
  401. value: "true"
  402. - it: should have both annotations when everything is configured and enabled
  403. set:
  404. webhook.service.annotations:
  405. custom.annotation: value
  406. webhook.metrics.service.enabled: true
  407. webhook.metrics.service.annotations:
  408. prometheus.io/scrape: "true"
  409. templates:
  410. - webhook-service.yaml
  411. asserts:
  412. - equal:
  413. path: metadata.annotations["custom.annotation"]
  414. value: value
  415. - equal:
  416. path: metadata.annotations["prometheus.io/scrape"]
  417. value: "true"
  418. - it: should add a init container
  419. templates:
  420. - webhook-deployment.yaml
  421. set:
  422. webhook.extraInitContainers:
  423. - name: foo
  424. image: example.com/external-secrets/init-image:{{ .Chart.Version }}
  425. restartPolicy: Always
  426. asserts:
  427. - equal:
  428. path: spec.template.spec.initContainers[0].name
  429. value: foo
  430. - matchRegex:
  431. path: spec.template.spec.initContainers[0].image
  432. pattern: ^example\.com/external-secrets/init-image:[0-9]+\.[0-9]+\.[0-9]+$
  433. - equal:
  434. path: spec.template.spec.initContainers[0].restartPolicy
  435. value: Always
  436. - it: should override the deployment strategy
  437. templates:
  438. - webhook-deployment.yaml
  439. set:
  440. webhook.strategy:
  441. rollingUpdate:
  442. maxSurge: 1
  443. maxUnavailable: 0
  444. asserts:
  445. - equal:
  446. path: spec.strategy.rollingUpdate.maxSurge
  447. value: 1
  448. - equal:
  449. path: spec.strategy.rollingUpdate.maxUnavailable
  450. value: 0
  451. - it: should update args with enableHTTP2=true
  452. set:
  453. enableHTTP2: true
  454. templates:
  455. - webhook-deployment.yaml
  456. asserts:
  457. - contains:
  458. path: spec.template.spec.containers[0].args
  459. content: "--enable-http2=true"
  460. - it: should default to hostUsers absent
  461. set:
  462. webhook.create: true
  463. capabilities:
  464. majorVersion: '1'
  465. minorVersion: '33'
  466. templates:
  467. - webhook-deployment.yaml
  468. asserts:
  469. - notExists:
  470. path: spec.template.spec.hostUsers
  471. - it: should permit override of hostUsers
  472. set:
  473. webhook.create: true
  474. webhook.hostUsers: false
  475. capabilities:
  476. majorVersion: '1'
  477. minorVersion: '33'
  478. templates:
  479. - webhook-deployment.yaml
  480. asserts:
  481. - equal:
  482. path: spec.template.spec.hostUsers
  483. value: false
  484. - it: should ignore hostUsers on older k8s
  485. set:
  486. webhook.create: true
  487. webhook.hostUsers: false
  488. capabilities:
  489. majorVersion: '1'
  490. minorVersion: '32'
  491. templates:
  492. - webhook-deployment.yaml
  493. asserts:
  494. - notExists:
  495. path: spec.template.spec.hostUsers