_service.tpl 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. {{- /* Create the name for VM service */ -}}
  2. {{- define "vm.service" -}}
  3. {{- include "vm.validate.args" . -}}
  4. {{- $Values := (.helm).Values | default .Values -}}
  5. {{- $nameTpl := "vm.fullname" }}
  6. {{- if eq .style "managed" -}}
  7. {{- $nameTpl = "vm.managed.fullname" }}
  8. {{- else if eq .style "plain" -}}
  9. {{- $nameTpl = "vm.plain.fullname" }}
  10. {{- end -}}
  11. {{- include $nameTpl . -}}
  12. {{- end }}
  13. {{- define "vm.fqdn" -}}
  14. {{- $name := (include "vm.service" .) -}}
  15. {{- if hasKey . "appIdx" -}}
  16. {{- $name = (printf "%s-%d.%s" $name .appIdx $name) -}}
  17. {{- end -}}
  18. {{- $Values := (.helm).Values | default .Values -}}
  19. {{- $ns := (include "vm.namespace" .) -}}
  20. {{- $fqdn := printf "%s.%s.svc" $name $ns -}}
  21. {{- with (($Values.global).cluster).dnsDomain -}}
  22. {{- $fqdn = printf "%s.%s" $fqdn . -}}
  23. {{- end -}}
  24. {{- $fqdn -}}
  25. {{- end -}}
  26. {{- define "vm.host" -}}
  27. {{- $fqdn := (include "vm.fqdn" .) -}}
  28. {{- $port := 80 -}}
  29. {{- $isSecure := ternary false true (empty .appSecure) -}}
  30. {{- $Values := (.helm).Values | default .Values -}}
  31. {{- if .appKey -}}
  32. {{- $appKey := ternary (list .appKey) .appKey (kindIs "string" .appKey) -}}
  33. {{- $spec := $Values -}}
  34. {{- range $ak := $appKey -}}
  35. {{- if index $spec $ak -}}
  36. {{- $spec = (index $spec $ak) -}}
  37. {{- end -}}
  38. {{- if and (kindIs "map" $spec) (hasKey $spec "spec") -}}
  39. {{- $spec = $spec.spec -}}
  40. {{- end -}}
  41. {{- end -}}
  42. {{- $isSecure = (eq ($spec.extraArgs).tls "true") | default $isSecure -}}
  43. {{- $port = (ternary 443 80 $isSecure) -}}
  44. {{- $port = $spec.port | default ($spec.service).servicePort | default $port -}}
  45. {{- end }}
  46. {{- $fqdn }}:{{ $port }}
  47. {{- end -}}
  48. {{- define "vm.url" -}}
  49. {{- $host := (include "vm.host" .) -}}
  50. {{- $Values := (.helm).Values | default .Values -}}
  51. {{- $proto := "http" -}}
  52. {{- $path := .appRoute | default "/" -}}
  53. {{- $isSecure := ternary false true (empty .appSecure) -}}
  54. {{- if .appKey -}}
  55. {{- $appKey := ternary (list .appKey) .appKey (kindIs "string" .appKey) -}}
  56. {{- $spec := $Values -}}
  57. {{- range $ak := $appKey -}}
  58. {{- if index $spec $ak -}}
  59. {{- $spec = (index $spec $ak) -}}
  60. {{- end -}}
  61. {{- if and (kindIs "map" $spec) (hasKey $spec "spec") -}}
  62. {{- $spec = $spec.spec -}}
  63. {{- end -}}
  64. {{- end -}}
  65. {{- $isSecure = (eq ($spec.extraArgs).tls "true") | default $isSecure -}}
  66. {{- $proto = (ternary "https" "http" $isSecure) -}}
  67. {{- $path = dig "http.pathPrefix" $path ($spec.extraArgs | default dict) -}}
  68. {{- end -}}
  69. {{- printf "%s://%s%s" $proto $host (trimSuffix "/" $path) -}}
  70. {{- end -}}