_affinities.tpl 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. {{/* vim: set filetype=mustache: */}}
  2. {{/*
  3. Return a soft nodeAffinity definition
  4. {{ include "common.affinities.nodes.soft" (dict "key" "FOO" "values" (list "BAR" "BAZ")) -}}
  5. */}}
  6. {{- define "common.affinities.nodes.soft" -}}
  7. preferredDuringSchedulingIgnoredDuringExecution:
  8. - preference:
  9. matchExpressions:
  10. - key: {{ .key }}
  11. operator: In
  12. values:
  13. {{- range .values }}
  14. - {{ . | quote }}
  15. {{- end }}
  16. weight: 1
  17. {{- end -}}
  18. {{/*
  19. Return a hard nodeAffinity definition
  20. {{ include "common.affinities.nodes.hard" (dict "key" "FOO" "values" (list "BAR" "BAZ")) -}}
  21. */}}
  22. {{- define "common.affinities.nodes.hard" -}}
  23. requiredDuringSchedulingIgnoredDuringExecution:
  24. nodeSelectorTerms:
  25. - matchExpressions:
  26. - key: {{ .key }}
  27. operator: In
  28. values:
  29. {{- range .values }}
  30. - {{ . | quote }}
  31. {{- end }}
  32. {{- end -}}
  33. {{/*
  34. Return a nodeAffinity definition
  35. {{ include "common.affinities.nodes" (dict "type" "soft" "key" "FOO" "values" (list "BAR" "BAZ")) -}}
  36. */}}
  37. {{- define "common.affinities.nodes" -}}
  38. {{- if eq .type "soft" }}
  39. {{- include "common.affinities.nodes.soft" . -}}
  40. {{- else if eq .type "hard" }}
  41. {{- include "common.affinities.nodes.hard" . -}}
  42. {{- end -}}
  43. {{- end -}}
  44. {{/*
  45. Return a soft podAffinity/podAntiAffinity definition
  46. {{ include "common.affinities.pods.soft" (dict "component" "FOO" "context" $) -}}
  47. */}}
  48. {{- define "common.affinities.pods.soft" -}}
  49. {{- $component := default "" .component -}}
  50. preferredDuringSchedulingIgnoredDuringExecution:
  51. - podAffinityTerm:
  52. labelSelector:
  53. matchLabels: {{- (include "common.labels.matchLabels" .context) | nindent 10 }}
  54. {{- if not (empty $component) }}
  55. {{ printf "app.kubernetes.io/component: %s" $component }}
  56. {{- end }}
  57. namespaces:
  58. - {{ .context.Release.Namespace | quote }}
  59. topologyKey: kubernetes.io/hostname
  60. weight: 1
  61. {{- end -}}
  62. {{/*
  63. Return a hard podAffinity/podAntiAffinity definition
  64. {{ include "common.affinities.pods.hard" (dict "component" "FOO" "context" $) -}}
  65. */}}
  66. {{- define "common.affinities.pods.hard" -}}
  67. {{- $component := default "" .component -}}
  68. requiredDuringSchedulingIgnoredDuringExecution:
  69. - labelSelector:
  70. matchLabels: {{- (include "common.labels.matchLabels" .context) | nindent 8 }}
  71. {{- if not (empty $component) }}
  72. {{ printf "app.kubernetes.io/component: %s" $component }}
  73. {{- end }}
  74. namespaces:
  75. - {{ .context.Release.Namespace | quote }}
  76. topologyKey: kubernetes.io/hostname
  77. {{- end -}}
  78. {{/*
  79. Return a podAffinity/podAntiAffinity definition
  80. {{ include "common.affinities.pods" (dict "type" "soft" "key" "FOO" "values" (list "BAR" "BAZ")) -}}
  81. */}}
  82. {{- define "common.affinities.pods" -}}
  83. {{- if eq .type "soft" }}
  84. {{- include "common.affinities.pods.soft" . -}}
  85. {{- else if eq .type "hard" }}
  86. {{- include "common.affinities.pods.hard" . -}}
  87. {{- end -}}
  88. {{- end -}}