_affinity_app.tpl 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  1. {{/* affinity - https://kubernetes.io/docs/concepts/configuration/assign-pod-node/ */}}
  2. {{- define "appNodeaffinity" }}
  3. nodeAffinity:
  4. requiredDuringSchedulingIgnoredDuringExecution:
  5. {{- include "appNodeAffinityRequiredDuringScheduling" . }}
  6. preferredDuringSchedulingIgnoredDuringExecution:
  7. {{- include "appNodeAffinityPreferredDuringScheduling" . }}
  8. {{- end }}
  9. {{- define "appNodeAffinityRequiredDuringScheduling" }}
  10. {{- if or .Values.app.nodeAffinityLabelSelector .Values.global.nodeAffinityLabelSelector }}
  11. nodeSelectorTerms:
  12. {{- range $matchExpressionsIndex, $matchExpressionsItem := .Values.app.nodeAffinityLabelSelector }}
  13. - matchExpressions:
  14. {{- range $Index, $item := $matchExpressionsItem.matchExpressions }}
  15. - key: {{ $item.key }}
  16. operator: {{ $item.operator }}
  17. {{- if $item.values }}
  18. values:
  19. {{- $vals := split "," $item.values }}
  20. {{- range $i, $v := $vals }}
  21. - {{ $v | quote }}
  22. {{- end }}
  23. {{- end }}
  24. {{- end }}
  25. {{- end }}
  26. {{- range $matchExpressionsIndex, $matchExpressionsItem := .Values.global.nodeAffinityLabelSelector }}
  27. - matchExpressions:
  28. {{- range $Index, $item := $matchExpressionsItem.matchExpressions }}
  29. - key: {{ $item.key }}
  30. operator: {{ $item.operator }}
  31. {{- if $item.values }}
  32. values:
  33. {{- $vals := split "," $item.values }}
  34. {{- range $i, $v := $vals }}
  35. - {{ $v | quote }}
  36. {{- end }}
  37. {{- end }}
  38. {{- end }}
  39. {{- end }}
  40. {{- end }}
  41. {{- end }}
  42. {{- define "appNodeAffinityPreferredDuringScheduling" }}
  43. {{- range $weightIndex, $weightItem := .Values.app.nodeAffinityTermLabelSelector }}
  44. - weight: {{ $weightItem.weight }}
  45. preference:
  46. matchExpressions:
  47. {{- range $Index, $item := $weightItem.matchExpressions }}
  48. - key: {{ $item.key }}
  49. operator: {{ $item.operator }}
  50. {{- if $item.values }}
  51. values:
  52. {{- $vals := split "," $item.values }}
  53. {{- range $i, $v := $vals }}
  54. - {{ $v | quote }}
  55. {{- end }}
  56. {{- end }}
  57. {{- end }}
  58. {{- end }}
  59. {{- range $weightIndex, $weightItem := .Values.global.nodeAffinityTermLabelSelector }}
  60. - weight: {{ $weightItem.weight }}
  61. preference:
  62. matchExpressions:
  63. {{- range $Index, $item := $weightItem.matchExpressions }}
  64. - key: {{ $item.key }}
  65. operator: {{ $item.operator }}
  66. {{- if $item.values }}
  67. values:
  68. {{- $vals := split "," $item.values }}
  69. {{- range $i, $v := $vals }}
  70. - {{ $v | quote }}
  71. {{- end }}
  72. {{- end }}
  73. {{- end }}
  74. {{- end }}
  75. {{- end }}
  76. {{- define "appPodAffinity" }}
  77. {{- if or .Values.app.podAffinityLabelSelector .Values.app.podAffinityTermLabelSelector}}
  78. podAffinity:
  79. {{- if .Values.app.podAffinityLabelSelector }}
  80. requiredDuringSchedulingIgnoredDuringExecution:
  81. {{- include "appPodAffinityRequiredDuringScheduling" . }}
  82. {{- end }}
  83. {{- if or .Values.app.podAffinityTermLabelSelector}}
  84. preferredDuringSchedulingIgnoredDuringExecution:
  85. {{- include "appPodAffinityPreferredDuringScheduling" . }}
  86. {{- end }}
  87. {{- end }}
  88. {{- end }}
  89. {{- define "appPodAffinityRequiredDuringScheduling" }}
  90. {{- range $labelSelector, $labelSelectorItem := .Values.app.podAffinityLabelSelector }}
  91. - labelSelector:
  92. matchExpressions:
  93. {{- range $index, $item := $labelSelectorItem.labelSelector }}
  94. - key: {{ $item.key }}
  95. operator: {{ $item.operator }}
  96. {{- if $item.values }}
  97. values:
  98. {{- $vals := split "," $item.values }}
  99. {{- range $i, $v := $vals }}
  100. - {{ $v | quote }}
  101. {{- end }}
  102. {{- end }}
  103. {{- end }}
  104. topologyKey: {{ $labelSelectorItem.topologyKey }}
  105. {{- end }}
  106. {{- range $labelSelector, $labelSelectorItem := .Values.global.podAffinityLabelSelector }}
  107. - labelSelector:
  108. matchExpressions:
  109. {{- range $index, $item := $labelSelectorItem.labelSelector }}
  110. - key: {{ $item.key }}
  111. operator: {{ $item.operator }}
  112. {{- if $item.values }}
  113. values:
  114. {{- $vals := split "," $item.values }}
  115. {{- range $i, $v := $vals }}
  116. - {{ $v | quote }}
  117. {{- end }}
  118. {{- end }}
  119. {{- end }}
  120. topologyKey: {{ $labelSelectorItem.topologyKey }}
  121. {{- end }}
  122. {{- end }}
  123. {{- define "appPodAffinityPreferredDuringScheduling" }}
  124. {{- range $labelSelector, $labelSelectorItem := .Values.app.podAffinityTermLabelSelector }}
  125. - podAffinityTerm:
  126. labelSelector:
  127. matchExpressions:
  128. {{- range $index, $item := $labelSelectorItem.labelSelector }}
  129. - key: {{ $item.key }}
  130. operator: {{ $item.operator }}
  131. {{- if $item.values }}
  132. values:
  133. {{- $vals := split "," $item.values }}
  134. {{- range $i, $v := $vals }}
  135. - {{ $v | quote }}
  136. {{- end }}
  137. {{- end }}
  138. {{- end }}
  139. topologyKey: {{ $labelSelectorItem.topologyKey }}
  140. weight: {{ $labelSelectorItem.weight }}
  141. {{- end }}
  142. {{- range $labelSelector, $labelSelectorItem := .Values.global.podAffinityTermLabelSelector }}
  143. - podAffinityTerm:
  144. labelSelector:
  145. matchExpressions:
  146. {{- range $index, $item := $labelSelectorItem.labelSelector }}
  147. - key: {{ $item.key }}
  148. operator: {{ $item.operator }}
  149. {{- if $item.values }}
  150. values:
  151. {{- $vals := split "," $item.values }}
  152. {{- range $i, $v := $vals }}
  153. - {{ $v | quote }}
  154. {{- end }}
  155. {{- end }}
  156. {{- end }}
  157. topologyKey: {{ $labelSelectorItem.topologyKey }}
  158. weight: {{ $labelSelectorItem.weight }}
  159. {{- end }}
  160. {{- end }}
  161. {{- define "appPodAntiAffinity" }}
  162. {{- if or .Values.app.podAntiAffinityLabelSelector .Values.app.podAntiAffinityTermLabelSelector}}
  163. podAntiAffinity:
  164. {{- if .Values.app.podAntiAffinityLabelSelector }}
  165. requiredDuringSchedulingIgnoredDuringExecution:
  166. {{- include "appPodAntiAffinityRequiredDuringScheduling" . }}
  167. {{- end }}
  168. {{- if or .Values.app.podAntiAffinityTermLabelSelector}}
  169. preferredDuringSchedulingIgnoredDuringExecution:
  170. {{- include "appPodAntiAffinityPreferredDuringScheduling" . }}
  171. {{- end }}
  172. {{- end }}
  173. {{- end }}
  174. {{- define "appPodAntiAffinityRequiredDuringScheduling" }}
  175. {{- range $labelSelectorIndex, $labelSelectorItem := .Values.app.podAntiAffinityLabelSelector }}
  176. - labelSelector:
  177. matchExpressions:
  178. {{- range $index, $item := $labelSelectorItem.labelSelector }}
  179. - key: {{ $item.key }}
  180. operator: {{ $item.operator }}
  181. {{- if $item.values }}
  182. values:
  183. {{- $vals := split "," $item.values }}
  184. {{- range $i, $v := $vals }}
  185. - {{ $v | quote }}
  186. {{- end }}
  187. {{- end }}
  188. {{- end }}
  189. topologyKey: {{ $labelSelectorItem.topologyKey }}
  190. {{- end }}
  191. {{- range $labelSelectorIndex, $labelSelectorItem := .Values.global.podAntiAffinityLabelSelector }}
  192. - labelSelector:
  193. matchExpressions:
  194. {{- range $index, $item := $labelSelectorItem.labelSelector }}
  195. - key: {{ $item.key }}
  196. operator: {{ $item.operator }}
  197. {{- if $item.values }}
  198. values:
  199. {{- $vals := split "," $item.values }}
  200. {{- range $i, $v := $vals }}
  201. - {{ $v | quote }}
  202. {{- end }}
  203. {{- end }}
  204. {{- end }}
  205. topologyKey: {{ $labelSelectorItem.topologyKey }}
  206. {{- end }}
  207. {{- end }}
  208. {{- define "appPodAntiAffinityPreferredDuringScheduling" }}
  209. {{- range $labelSelectorIndex, $labelSelectorItem := .Values.app.podAntiAffinityTermLabelSelector }}
  210. - podAffinityTerm:
  211. labelSelector:
  212. matchExpressions:
  213. {{- range $index, $item := $labelSelectorItem.labelSelector }}
  214. - key: {{ $item.key }}
  215. operator: {{ $item.operator }}
  216. {{- if $item.values }}
  217. values:
  218. {{- $vals := split "," $item.values }}
  219. {{- range $i, $v := $vals }}
  220. - {{ $v | quote }}
  221. {{- end }}
  222. {{- end }}
  223. {{- end }}
  224. topologyKey: {{ $labelSelectorItem.topologyKey }}
  225. weight: {{ $labelSelectorItem.weight }}
  226. {{- end }}
  227. {{- range $labelSelectorIndex, $labelSelectorItem := .Values.global.podAntiAffinityTermLabelSelector }}
  228. - podAffinityTerm:
  229. labelSelector:
  230. matchExpressions:
  231. {{- range $index, $item := $labelSelectorItem.labelSelector }}
  232. - key: {{ $item.key }}
  233. operator: {{ $item.operator }}
  234. {{- if $item.values }}
  235. values:
  236. {{- $vals := split "," $item.values }}
  237. {{- range $i, $v := $vals }}
  238. - {{ $v | quote }}
  239. {{- end }}
  240. {{- end }}
  241. {{- end }}
  242. topologyKey: {{ $labelSelectorItem.topologyKey }}
  243. weight: {{ $labelSelectorItem.weight }}
  244. {{- end }}
  245. {{- end }}