_getSelectedPod.tpl 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. {{/* Service - Get Selected Pod */}}
  2. {{/* Call this template:
  3. {{ include "ix.v1.common.lib.helpers.getSelectedPodValues" (dict "rootCtx" $rootCtx "objectData" $objectData) -}}
  4. objectData: The object data of the service
  5. rootCtx: The root context of the chart.
  6. */}}
  7. {{- define "ix.v1.common.lib.helpers.getSelectedPodValues" -}}
  8. {{- $rootCtx := .rootCtx -}}
  9. {{- $objectData := .objectData -}}
  10. {{- $caller := .caller -}}
  11. {{- $podValues := dict -}}
  12. {{- with $objectData.targetSelector -}}
  13. {{- $podValues = mustDeepCopy (get $rootCtx.Values.workload .) -}}
  14. {{- if not $podValues -}}
  15. {{- fail (printf "%s - Selected pod [%s] is not defined" $caller .) -}}
  16. {{- end -}}
  17. {{- if not $podValues.enabled -}}
  18. {{- fail (printf "%s - Selected pod [%s] is not enabled" $caller .) -}}
  19. {{- end -}}
  20. {{/* While we know the shortName from targetSelector, let's set it explicitly
  21. So service can reference this directly, to match the behaviour of a service
  22. without targetSelector defined (assumes "use primary") */}}
  23. {{- $_ := set $podValues "shortName" . -}}
  24. {{- else -}}
  25. {{/* If no targetSelector is defined, we assume the service is using the primary pod */}}
  26. {{/* Also no need to check for multiple primaries here, it's already done on the workload validation */}}
  27. {{- range $podName, $pod := $rootCtx.Values.workload -}}
  28. {{- if $pod.enabled -}}
  29. {{- if $pod.primary -}}
  30. {{- $podValues = mustDeepCopy $pod -}}
  31. {{/* Set the shortName so service can use this on selector */}}
  32. {{- $_ := set $podValues "shortName" $podName -}}
  33. {{- end -}}
  34. {{- end -}}
  35. {{- end -}}
  36. {{- end -}}
  37. {{/* Return values in Json, to preserve types */}}
  38. {{ $podValues | toJson }}
  39. {{- end -}}