cert_controller_test.yaml 12 KB

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