service_account_name_test.yaml 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. suite: pod service account name test
  2. templates:
  3. - common.yaml
  4. tests:
  5. - it: should assign serviceAccount to primary pod
  6. set:
  7. workload:
  8. workload-name1:
  9. enabled: true
  10. primary: true
  11. type: CronJob
  12. schedule: "* * * * *"
  13. podSpec:
  14. restartPolicy: Never
  15. workload-name2:
  16. enabled: true
  17. primary: false
  18. type: Deployment
  19. podSpec: {}
  20. serviceAccount:
  21. sa-name1:
  22. enabled: true
  23. primary: true
  24. asserts:
  25. - documentIndex: &cronJobDoc 1
  26. isKind:
  27. of: CronJob
  28. - documentIndex: *cronJobDoc
  29. equal:
  30. path: metadata.name
  31. value: release-name-common-test
  32. - documentIndex: *cronJobDoc
  33. equal:
  34. path: spec.jobTemplate.spec.template.spec.serviceAccountName
  35. value: release-name-common-test
  36. - documentIndex: &otherDeploymentDoc 2
  37. isKind:
  38. of: Deployment
  39. - documentIndex: *otherDeploymentDoc
  40. equal:
  41. path: spec.template.spec.serviceAccountName
  42. value: default
  43. - it: should assign serviceAccount to all pods
  44. set:
  45. workload:
  46. workload-name1:
  47. enabled: true
  48. primary: true
  49. type: Deployment
  50. podSpec: {}
  51. workload-name2:
  52. enabled: true
  53. primary: false
  54. type: Deployment
  55. podSpec: {}
  56. serviceAccount:
  57. sa-name1:
  58. enabled: true
  59. primary: true
  60. targetSelectAll: true
  61. asserts:
  62. - documentIndex: &deploymentDoc 1
  63. isKind:
  64. of: Deployment
  65. - documentIndex: *deploymentDoc
  66. equal:
  67. path: spec.template.spec.serviceAccountName
  68. value: release-name-common-test
  69. - documentIndex: &otherDeploymentDoc 2
  70. isKind:
  71. of: Deployment
  72. - documentIndex: *otherDeploymentDoc
  73. equal:
  74. path: spec.template.spec.serviceAccountName
  75. value: release-name-common-test
  76. - it: should assign serviceAccount to selected pods
  77. set:
  78. workload:
  79. workload-name1:
  80. enabled: true
  81. primary: true
  82. type: Deployment
  83. podSpec: {}
  84. workload-name2:
  85. enabled: true
  86. primary: false
  87. type: Deployment
  88. podSpec: {}
  89. serviceAccount:
  90. sa-name1:
  91. enabled: true
  92. primary: true
  93. targetSelector:
  94. - workload-name1
  95. sa-name2:
  96. enabled: true
  97. primary: false
  98. targetSelector:
  99. - workload-name2
  100. asserts:
  101. - documentIndex: &deploymentDoc 2
  102. isKind:
  103. of: Deployment
  104. - documentIndex: *deploymentDoc
  105. equal:
  106. path: spec.template.spec.serviceAccountName
  107. value: release-name-common-test
  108. - documentIndex: &otherDeploymentDoc 3
  109. isKind:
  110. of: Deployment
  111. - documentIndex: *otherDeploymentDoc
  112. equal:
  113. path: spec.template.spec.serviceAccountName
  114. value: release-name-common-test-sa-name2
  115. - it: should assign serviceAccount to selected pods
  116. set:
  117. workload:
  118. workload-name1:
  119. enabled: true
  120. primary: true
  121. type: Deployment
  122. podSpec: {}
  123. workload-name2:
  124. enabled: true
  125. primary: false
  126. type: Deployment
  127. podSpec: {}
  128. serviceAccount:
  129. sa-name1:
  130. enabled: true
  131. primary: true
  132. targetSelector:
  133. - workload-name1
  134. - workload-name2
  135. asserts:
  136. - documentIndex: &deploymentDoc 1
  137. isKind:
  138. of: Deployment
  139. - documentIndex: *deploymentDoc
  140. equal:
  141. path: spec.template.spec.serviceAccountName
  142. value: release-name-common-test
  143. - documentIndex: &otherDeploymentDoc 2
  144. isKind:
  145. of: Deployment
  146. - documentIndex: *otherDeploymentDoc
  147. equal:
  148. path: spec.template.spec.serviceAccountName
  149. value: release-name-common-test
  150. # Failures
  151. - it: should fail with more than 1 SA assigned to a pod
  152. set:
  153. workload:
  154. workload-name1:
  155. enabled: true
  156. primary: true
  157. type: Deployment
  158. podSpec: {}
  159. serviceAccount:
  160. sa-name1:
  161. enabled: true
  162. primary: true
  163. targetSelector:
  164. - workload-name1
  165. sa-name2:
  166. enabled: true
  167. targetSelector:
  168. - workload-name1
  169. asserts:
  170. - failedTemplate:
  171. errorMessage: Expected at most 1 ServiceAccount to be assigned on a pod [workload-name1]. But [2] were assigned