_externalInterfaceAnnotations.tpl 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. {{/* External Interface Annotations that are added to podSpec */}}
  2. {{/* Call this template:
  3. {{ include "ix.v1.common.lib.metadata.externalInterfacePodAnnotations" (dict "rootCtx" $ "podShortName" $podShortName) }}
  4. rootCtx is the root context of the chart
  5. objectData is object containing the data of the pod
  6. */}}
  7. {{- define "ix.v1.common.lib.metadata.externalInterfacePodAnnotations" -}}
  8. {{- $objectData := .objectData -}}
  9. {{- $rootCtx := .rootCtx -}}
  10. {{- $ifaceIndexes := list -}}
  11. {{- range $index, $iface := $rootCtx.Values.scaleExternalInterface -}}
  12. {{/* If targetSelectAll is set append the index */}}
  13. {{- if .targetSelectAll -}}
  14. {{- $ifaceIndexes = mustAppend $ifaceIndexes $index -}}
  15. {{/* Else If targetSelector is set and pod is selected append the index */}}
  16. {{- else if and .targetSelector (mustHas $objectData.shortName .targetSelector) -}}
  17. {{- $ifaceIndexes = mustAppend $ifaceIndexes $index -}}
  18. {{/* Else If none of the above, but pod is primary append the index */}}
  19. {{- else if $objectData.primary -}}
  20. {{- $ifaceIndexes = mustAppend $ifaceIndexes $index -}}
  21. {{- end -}}
  22. {{- end -}}
  23. {{- $ifaceNames := list -}}
  24. {{- if $rootCtx.Values.ixExternalInterfacesConfiguration -}}
  25. {{- with $rootCtx.Values.ixExternalInterfacesConfigurationNames -}}
  26. {{- range $ifaceName := . -}}
  27. {{/* Get the index by splitting the iFaceName (ix-RELEASE-NAME-0) */}}
  28. {{- $index := splitList "-" $ifaceName -}}
  29. {{/* And pick the last item on the list */}}
  30. {{- $index = mustLast $index -}}
  31. {{/* If the index is in the list of indexes to be added, append the name */}}
  32. {{- if mustHas (int $index) $ifaceIndexes -}}
  33. {{- $ifaceNames = mustAppend $ifaceNames $ifaceName -}}
  34. {{- end -}}
  35. {{- end -}}
  36. {{- else -}}
  37. {{- fail "External Interface - Expected non empty <ixExternalInterfaceConfigurationNames>" -}}
  38. {{- end -}}
  39. {{- end -}}
  40. {{/* If we have ifaceNames, then add the annotations to the pod calling this template */}}
  41. {{- if $ifaceNames }}
  42. k8s.v1.cni.cncf.io/networks: {{ join ", " $ifaceNames }}
  43. {{- end -}}
  44. {{- end -}}