_helpers.tpl 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. {{/*
  2. Expand the name of the chart.
  3. */}}
  4. {{- define "kafka.name" -}}
  5. {{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }}
  6. {{- end }}
  7. {{/*
  8. Create a default fully qualified app name.
  9. We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
  10. If release name contains chart name it will be used as a full name.
  11. */}}
  12. {{- define "kafka.fullname" -}}
  13. {{- if .Values.fullnameOverride }}
  14. {{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }}
  15. {{- else }}
  16. {{- $name := default .Chart.Name .Values.nameOverride }}
  17. {{- if contains $name .Release.Name }}
  18. {{- .Release.Name | trunc 63 | trimSuffix "-" }}
  19. {{- else }}
  20. {{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }}
  21. {{- end }}
  22. {{- end }}
  23. {{- end }}
  24. {{/*
  25. Create chart name and version as used by the chart label.
  26. */}}
  27. {{- define "kafka.chart" -}}
  28. {{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
  29. {{- end }}
  30. {{/*
  31. Common labels
  32. */}}
  33. {{- define "kafka.labels" -}}
  34. helm.sh/chart: {{ include "kafka.chart" . }}
  35. {{ include "kafka.selectorLabels" . }}
  36. {{- if .Chart.AppVersion }}
  37. app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
  38. {{- end }}
  39. app.kubernetes.io/managed-by: {{ .Release.Service }}
  40. {{- end }}
  41. {{/*
  42. Selector labels
  43. */}}
  44. {{- define "kafka.selectorLabels" -}}
  45. app: {{ .Release.Name }}-{{ include "kafka.name" . }}
  46. app.kubernetes.io/name: {{ include "kafka.name" . }}
  47. app.kubernetes.io/instance: {{ .Release.Name }}
  48. {{- end }}
  49. {{/*
  50. Create a default kafka fully qualified domain name.
  51. We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
  52. */}}
  53. {{- define "kafka.listener" -}}
  54. {{- $namespace := .Release.Namespace }}
  55. {{- printf "${POD_NAME}.%s-headless.%s.svc.cluster.local" (include "kafka.fullname" .) $namespace | trimSuffix "-" -}}
  56. {{- end -}}
  57. {{/*
  58. Create a default kafka bootstrap server name.
  59. We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
  60. */}}
  61. {{- define "kafka.bootstrap.server" -}}
  62. {{- $namespace := .Release.Namespace }}
  63. {{- printf "%s-0.%s-headless.%s.svc.cluster.local" (include "kafka.fullname" .) (include "kafka.fullname" .) $namespace | trimSuffix "-" -}}
  64. {{- end -}}
  65. {{/*
  66. Create a default fully qualified zookeeper name.
  67. We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
  68. */}}
  69. {{- define "kafka.zookeeper.fullname" -}}
  70. {{- $name := default "zookeeper" (index .Values "zookeeper" "nameOverride") -}}
  71. {{- printf "%s-%s-headless" .Release.Name $name | trunc 63 | trimSuffix "-" -}}
  72. {{- end -}}
  73. {{/*
  74. Form the Zookeeper URL. If zookeeper is installed as part of this chart, use k8s service discovery,
  75. else use user-provided URL
  76. */}}
  77. {{- define "kafka.zookeeper.ensemble" }}
  78. {{- if (index .Values "zookeeper" "enabled") -}}
  79. {{- $clientPort := default 2181 (index .Values "zookeeper" "port" "client") | int -}}
  80. {{- printf "%s:%d" (include "kafka.zookeeper.fullname" .) $clientPort }}
  81. {{- else -}}
  82. {{- printf "%s" (index .Values "zookeeper" "url") }}
  83. {{- end -}}
  84. {{- end -}}