Nessuna descrizione

_helpers.tpl 7.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. {{/*
  2. Return the common name for worker components
  3. */}}
  4. {{/*
  5. Shuffle currently hardcodes the shuffle-workers:33333 address at some places.
  6. Until that can be properly configured, we make sure that the worker deployment and service
  7. are named exactly the same as the deployment and service that orborus would create.
  8. {{- define "shuffle.worker.name" -}}
  9. {{- printf "%s-worker" (include "common.names.fullname" .) | trunc 63 -}}
  10. {{- end -}}
  11. */}}
  12. {{- define "shuffle.worker.name" -}}
  13. shuffle-workers
  14. {{- end -}}
  15. {{/*
  16. Return the common labels for worker components deployed via helm.
  17. NOTE: Worker deployments and services use shuffle.workerInstance.labels instead.
  18. */}}
  19. {{- define "shuffle.worker.labels" -}}
  20. {{- include "common.labels.standard" . }}
  21. app.kubernetes.io/component: worker
  22. {{- end -}}
  23. {{/*
  24. Return the proper Shuffle worker image name
  25. */}}
  26. {{- define "shuffle.worker.image" -}}
  27. {{- include "common.images.image" ( dict "imageRoot" .Values.worker.image "global" .Values.global "chart" .Chart ) -}}
  28. {{- end -}}
  29. {{/*
  30. Return the proper Docker Image Registry Secret Names for the worker pod
  31. */}}
  32. {{- define "shuffle.worker.imagePullSecrets" -}}
  33. {{- include "common.images.renderPullSecrets" (dict "images" (list .Values.worker.image) "context" $) -}}
  34. {{- end -}}
  35. {{/*
  36. Create the name of the service account to use for Shuffle workers
  37. */}}
  38. {{- define "shuffle.worker.serviceAccount.name" -}}
  39. {{- if .Values.worker.serviceAccount.create -}}
  40. {{ default (include "shuffle.worker.name" .) .Values.worker.serviceAccount.name | trunc 63 | trimSuffix "-" }}
  41. {{- else -}}
  42. {{ default "default" .Values.worker.serviceAccount.name }}
  43. {{- end -}}
  44. {{- end -}}
  45. {{/*
  46. Return the proper Docker Image Registry Secret Names for the worker service account
  47. */}}
  48. {{- define "shuffle.worker.serviceAccount.imagePullSecrets" -}}
  49. {{- $pullSecrets := list }}
  50. {{- range .Values.global.imagePullSecrets -}}
  51. {{- if kindIs "map" . -}}
  52. {{- $pullSecrets = append $pullSecrets (include "common.tplvalues.render" (dict "value" .name "context" .)) -}}
  53. {{- else -}}
  54. {{- $pullSecrets = append $pullSecrets (include "common.tplvalues.render" (dict "value" . "context" .)) -}}
  55. {{- end -}}
  56. {{- end -}}
  57. {{- range .Values.worker.serviceAccount.imagePullSecrets -}}
  58. {{- if kindIs "map" . -}}
  59. {{- $pullSecrets = append $pullSecrets (include "common.tplvalues.render" (dict "value" .name "context" .)) -}}
  60. {{- else -}}
  61. {{- $pullSecrets = append $pullSecrets (include "common.tplvalues.render" (dict "value" . "context" .)) -}}
  62. {{- end -}}
  63. {{- end -}}
  64. {{- if (not (empty $pullSecrets)) -}}
  65. imagePullSecrets:
  66. {{- range $pullSecrets | uniq }}
  67. - name: {{ . }}
  68. {{- end }}
  69. {{- end }}
  70. {{- end -}}
  71. {{/*
  72. Return the labels to match ALL workers.
  73. These match the labels of helm-deployed workers (shuffle.workerInstance.labels),
  74. as well as orborus-deployed workers (deployk8sworker).
  75. */}}
  76. {{- define "shuffle.worker.matchLabels" -}}
  77. app.kubernetes.io/name: shuffle-worker
  78. {{- end -}}
  79. {{/*
  80. Return the labels for a specific worker instance deployed via helm.
  81. Usage:
  82. {{ include "shuffle.workerInstance.labels" (dict "customLabels" $podLabels "context" $) -}}
  83. */}}
  84. {{- define "shuffle.workerInstance.labels" -}}
  85. {{- $customLabels := mustMerge (dict "app.kubernetes.io/name" "shuffle-worker" "app.kubernetes.io/part-of" "shuffle") (include "common.tplvalues.render" (dict "value" .customLabels "context" .context) | fromYaml) -}}
  86. {{ include "common.labels.standard" (dict "customLabels" $customLabels "context" .context) }}
  87. {{- end -}}
  88. {{/*
  89. Return the labels to match a helm-deployed worker.
  90. Usage:
  91. {{ include "shuffle.workerInstance.matchLabels" (dict "customLabels" $podLabels "context" $) -}}
  92. */}}
  93. {{- define "shuffle.workerInstance.matchLabels" -}}
  94. {{- $customLabels := mustMerge (dict "app.kubernetes.io/name" "shuffle-worker" "app.kubernetes.io/part-of" "shuffle") (include "common.tplvalues.render" (dict "value" .customLabels "context" .context) | fromYaml) -}}
  95. {{ include "common.labels.matchLabels" (dict "customLabels" $customLabels "context" .context) }}
  96. {{- end -}}
  97. {{/*
  98. Return a podAffinity/podAntiAffinity definition.
  99. Usage:
  100. {{ include "shuffle.workerInstance.affinities.pods" (dict "type" "soft" "customLabels" $podLabels "context" $) -}}
  101. */}}
  102. {{- define "shuffle.workerInstance.affinities.pods" -}}
  103. {{- $customLabels := mustMerge (dict "app.kubernetes.io/name" "shuffle-worker" "app.kubernetes.io/part-of" "shuffle") (include "common.tplvalues.render" (dict "value" .customLabels "context" .context) | fromYaml) -}}
  104. {{ include "common.affinities.pods" (dict "type" .type "customLabels" $customLabels "context" .context )}}
  105. {{- end -}}
  106. {{- define "shuffle.worker.hostname" -}}
  107. {{- if .Values.worker.enableHelmDeployment -}}
  108. http://{{ include "shuffle.worker.name" . }}.{{ .Release.Namespace }}.svc.cluster.local
  109. {{- else -}}
  110. http://shuffle-workers.{{ .Release.Namespace }}.svc.cluster.local
  111. {{- end -}}
  112. {{- end -}}
  113. {{- define "shuffle.worker.baseUrl" -}}
  114. {{ include "shuffle.worker.hostname" . }}:{{ .Values.worker.containerPorts.http }}
  115. {{- end -}}
  116. {{/*
  117. Return the environment variables of shuffle-worker in the format
  118. KEY: VALUE
  119. */}}
  120. {{- define "shuffle.workerInstance.env" -}}
  121. IS_KUBERNETES: "true"
  122. KUBERNETES_NAMESPACE: "{{ .Release.Namespace }}"
  123. SHUFFLE_SWARM_CONFIG: "run" # Shuffle Worker requires this to be set even when using K8s instead of swarm
  124. BASE_URL: {{ include "shuffle.backend.baseUrl" . | quote }}
  125. SHUFFLE_APP_EXPOSED_PORT: {{ .Values.app.exposedContainerPort | quote }}
  126. WORKER_HOSTNAME: {{ include "shuffle.worker.hostname" . }}
  127. {{- if .Values.worker.manageAppDeployments }}
  128. # Shuffle app images
  129. REGISTRY_URL: "{{ .Values.shuffle.appRegistry }}"
  130. SHUFFLE_BASE_IMAGE_NAME: "{{ .Values.shuffle.appBaseImageName }}"
  131. # Shuffle app deployment configuration
  132. SHUFFLE_APP_MOUNT_TMP_VOLUME: {{ .Values.app.mountTmpVolume | quote }}
  133. SHUFFLE_APP_SERVICE_ACCOUNT_NAME: {{ include "shuffle.app.serviceAccount.name" . | quote }}
  134. {{- if .Values.app.podSecurityContext.enabled }}
  135. SHUFFLE_APP_POD_SECURITY_CONTEXT: {{ omit .Values.app.podSecurityContext "enabled" | mustToJson | quote }}
  136. {{- end }}
  137. {{- if .Values.app.containerSecurityContext.enabled }}
  138. SHUFFLE_APP_CONTAINER_SECURITY_CONTEXT: {{ include "common.compatibility.renderSecurityContext" (dict "secContext" .Values.app.containerSecurityContext "context" $) | fromYaml | mustToJson | quote }}
  139. {{- end }}
  140. # Shuffle app resources
  141. {{- $appResources := (.Values.app.resources | default (include "common.resources.preset" (dict "type" .Values.app.resourcesPreset) | fromYaml)) -}}
  142. {{- if and $appResources.requests $appResources.requests.cpu }}
  143. SHUFFLE_APP_CPU_REQUEST: {{ $appResources.requests.cpu | quote }}
  144. {{- end }}
  145. {{- if and $appResources.requests $appResources.requests.memory }}
  146. SHUFFLE_APP_MEMORY_REQUEST: {{ $appResources.requests.memory | quote }}
  147. {{- end }}
  148. {{- if and $appResources.requests (index $appResources.requests "ephemeral-storage") }}
  149. SHUFFLE_APP_EPHEMERAL_STORAGE_REQUEST: {{ (index $appResources.requests "ephemeral-storage") | quote }}
  150. {{- end }}
  151. {{- if and $appResources.limits $appResources.limits.cpu }}
  152. SHUFFLE_APP_CPU_LIMIT: {{ $appResources.limits.cpu | quote }}
  153. {{- end }}
  154. {{- if and $appResources.limits $appResources.limits.memory }}
  155. SHUFFLE_APP_MEMORY_LIMIT: {{ $appResources.limits.memory | quote }}
  156. {{- end }}
  157. {{- if and $appResources.limits (index $appResources.limits "ephemeral-storage") }}
  158. SHUFFLE_APP_EPHEMERAL_STORAGE_LIMIT: {{ (index $appResources.limits "ephemeral-storage") | quote }}
  159. {{- end }}
  160. # Include shuffle app environment variables. Worker passes them down to apps, when creating their deployment.
  161. {{ include "shuffle.appInstance.env" . }}
  162. {{- end }}
  163. {{- end -}}