services.yaml 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. {{- $name := .Chart.Name }}
  2. {{- range $index, $val := .Values.items }}
  3. {{- if eq $val.type "service" }}
  4. {{- if $val.services | required " For '.type: service' ned .service ! " }}
  5. apiVersion: v1
  6. kind: Service
  7. metadata:
  8. name: {{ $val.name | default (print $name "-service-" $index) }}
  9. labels:
  10. app: {{ $name }}
  11. tier: {{ $val.name | default (print $name "-service") }}
  12. spec:
  13. {{- range $_, $Val := $val.services }}
  14. type: {{ $Val.type | default (print "ClusterIP") }}
  15. ports:
  16. {{- toYaml $Val.ports | nindent 2 }}
  17. {{- if .selector | required " For services need services.selecor! " }}
  18. selector:
  19. {{- toYaml $Val.selector | nindent 4 }}
  20. {{- end }}
  21. {{- end }}
  22. {{ print "---" }}
  23. {{- end }}{{- end }}{{- end }}
  24. {{- range $index, $val := .Values.items }}
  25. {{- if not (empty $val.containers) }}
  26. {{- range $Index, $Containers := $val.containers }}
  27. {{- if $Containers.url }}
  28. apiVersion: v1
  29. kind: Service
  30. metadata:
  31. name: {{ $val.name | default (print $name "-service-" $index "-" $Index) }}
  32. labels:
  33. app: {{ $name }}
  34. tier: {{ $val.name | default (print $name "-service") }}
  35. spec:
  36. type: {{ print "ClusterIP" }}
  37. ports:
  38. {{- range $indexPorts, $Ports := $Containers.ports }}
  39. - name: {{ $Ports.name | default (printf "3%v%v%v-%v" $index $Index $indexPorts $name) }}
  40. port: {{ printf "3%v%v%v" $index $Index $indexPorts }}
  41. protocol: {{ $Ports.protocol | default (print "TCP") }}
  42. targetPort: {{ $Ports.containerPort }}
  43. {{- end }}
  44. selector:
  45. app: {{ $name }}
  46. tier: {{ $val.name | default (print $name "-" $val.type "-" $index) }}
  47. {{ print "---" }}
  48. {{- end }}{{- end }}{{- end }}{{- end }}