_workload.tpl 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. {{/* Workload Spawner */}}
  2. {{/* Call this template:
  3. {{ include "ix.v1.common.spawner.workload" $ -}}
  4. */}}
  5. {{- define "ix.v1.common.spawner.workload" -}}
  6. {{/* Primary validation for enabled workload. */}}
  7. {{- include "ix.v1.common.lib.workload.primaryValidation" $ -}}
  8. {{- range $name, $workload := .Values.workload -}}
  9. {{- if $workload.enabled -}}
  10. {{/* Create a copy of the workload */}}
  11. {{- $objectData := (mustDeepCopy $workload) -}}
  12. {{/* Generate the name of the workload */}}
  13. {{- $objectName := include "ix.v1.common.lib.chart.names.fullname" $ -}}
  14. {{- if not $objectData.primary -}}
  15. {{- $objectName = printf "%s-%s" (include "ix.v1.common.lib.chart.names.fullname" $) $name -}}
  16. {{- end -}}
  17. {{/* Perform validations */}}
  18. {{- include "ix.v1.common.lib.chart.names.validation" (dict "name" $objectName) -}}
  19. {{- include "ix.v1.common.lib.metadata.validation" (dict "objectData" $objectData "caller" "Workload") -}}
  20. {{/* Set the name of the workload */}}
  21. {{- $_ := set $objectData "name" $objectName -}}
  22. {{/* Short name is the one that defined on the chart, used on selectors */}}
  23. {{- $_ := set $objectData "shortName" $name -}}
  24. {{/* Set the podSpec so it doesn't fail on nil pointer */}}
  25. {{- if not (hasKey $objectData "podSpec") -}}
  26. {{- fail "Workload - Expected <podSpec> key to exist" -}}
  27. {{- end -}}
  28. {{/* Call class to create the object */}}
  29. {{- if eq $objectData.type "Deployment" -}}
  30. {{- include "ix.v1.common.class.deployment" (dict "rootCtx" $ "objectData" $objectData) -}}
  31. {{- else if eq $objectData.type "Job" -}}
  32. {{- include "ix.v1.common.class.job" (dict "rootCtx" $ "objectData" $objectData) -}}
  33. {{- else if eq $objectData.type "CronJob" -}}
  34. {{- include "ix.v1.common.class.cronjob" (dict "rootCtx" $ "objectData" $objectData) -}}
  35. {{- end -}}
  36. {{- end -}}
  37. {{- end -}}
  38. {{- end -}}