_helpers.tpl 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. {{/* vim: set filetype=mustache: */}}
  2. {{/*
  3. Expand the name of the chart.
  4. */}}
  5. {{- define "grafana.name" -}}
  6. {{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" -}}
  7. {{- end -}}
  8. {{/*
  9. Create a default fully qualified app name.
  10. We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
  11. If release name contains chart name it will be used as a full name.
  12. */}}
  13. {{- define "grafana.fullname" -}}
  14. {{- if .Values.fullnameOverride -}}
  15. {{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" -}}
  16. {{- else -}}
  17. {{- $name := default .Chart.Name .Values.nameOverride -}}
  18. {{- if contains $name .Release.Name -}}
  19. {{- .Release.Name | trunc 63 | trimSuffix "-" -}}
  20. {{- else -}}
  21. {{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" -}}
  22. {{- end -}}
  23. {{- end -}}
  24. {{- end -}}
  25. {{/*
  26. Create chart name and version as used by the chart label.
  27. */}}
  28. {{- define "grafana.chart" -}}
  29. {{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}}
  30. {{- end -}}
  31. {{/*
  32. Create the name of the service account
  33. */}}
  34. {{- define "grafana.serviceAccountName" -}}
  35. {{- if .Values.serviceAccount.create -}}
  36. {{ default (include "grafana.fullname" .) .Values.serviceAccount.name }}
  37. {{- else -}}
  38. {{ default "default" .Values.serviceAccount.name }}
  39. {{- end -}}
  40. {{- end -}}
  41. {{- define "grafana.serviceAccountNameTest" -}}
  42. {{- if .Values.serviceAccount.create -}}
  43. {{ default (print (include "grafana.fullname" .) "-test") .Values.serviceAccount.nameTest }}
  44. {{- else -}}
  45. {{ default "default" .Values.serviceAccount.nameTest }}
  46. {{- end -}}
  47. {{- end -}}
  48. {{/*
  49. Allow the release namespace to be overridden for multi-namespace deployments in combined charts
  50. */}}
  51. {{- define "grafana.namespace" -}}
  52. {{- if .Values.namespaceOverride -}}
  53. {{- .Values.namespaceOverride -}}
  54. {{- else -}}
  55. {{- .Release.Namespace -}}
  56. {{- end -}}
  57. {{- end -}}
  58. {{/*
  59. Common labels
  60. */}}
  61. {{- define "grafana.labels" -}}
  62. helm.sh/chart: {{ include "grafana.chart" . }}
  63. {{ include "grafana.selectorLabels" . }}
  64. {{- if or .Chart.AppVersion .Values.image.tag }}
  65. app.kubernetes.io/version: {{ .Values.image.tag | default .Chart.AppVersion | quote }}
  66. {{- end }}
  67. app.kubernetes.io/managed-by: {{ .Release.Service }}
  68. {{- if .Values.extraLabels }}
  69. {{ toYaml .Values.extraLabels }}
  70. {{- end }}
  71. {{- end -}}
  72. {{/*
  73. Selector labels
  74. */}}
  75. {{- define "grafana.selectorLabels" -}}
  76. app.kubernetes.io/name: {{ include "grafana.name" . }}
  77. app.kubernetes.io/instance: {{ .Release.Name }}
  78. {{- end -}}
  79. {{/*
  80. Common labels
  81. */}}
  82. {{- define "grafana.imageRenderer.labels" -}}
  83. helm.sh/chart: {{ include "grafana.chart" . }}
  84. {{ include "grafana.imageRenderer.selectorLabels" . }}
  85. {{- if or .Chart.AppVersion .Values.image.tag }}
  86. app.kubernetes.io/version: {{ .Values.image.tag | default .Chart.AppVersion | quote }}
  87. {{- end }}
  88. app.kubernetes.io/managed-by: {{ .Release.Service }}
  89. {{- end -}}
  90. {{/*
  91. Selector labels ImageRenderer
  92. */}}
  93. {{- define "grafana.imageRenderer.selectorLabels" -}}
  94. app.kubernetes.io/name: {{ include "grafana.name" . }}-image-renderer
  95. app.kubernetes.io/instance: {{ .Release.Name }}
  96. {{- end -}}
  97. {{/*
  98. Looks if there's an existing secret and reuse its password. If not it generates
  99. new password and use it.
  100. */}}
  101. {{- define "grafana.password" -}}
  102. {{- $secret := (lookup "v1" "Secret" (include "grafana.namespace" .) (include "grafana.fullname" .) ) -}}
  103. {{- if $secret -}}
  104. {{- index $secret "data" "admin-password" -}}
  105. {{- else -}}
  106. {{- (randAlphaNum 40) | b64enc | quote -}}
  107. {{- end -}}
  108. {{- end -}}
  109. {{/*
  110. Return the appropriate apiVersion for rbac.
  111. */}}
  112. {{- define "grafana.rbac.apiVersion" -}}
  113. {{- if .Capabilities.APIVersions.Has "rbac.authorization.k8s.io/v1" }}
  114. {{- print "rbac.authorization.k8s.io/v1" -}}
  115. {{- else -}}
  116. {{- print "rbac.authorization.k8s.io/v1beta1" -}}
  117. {{- end -}}
  118. {{- end -}}
  119. {{/*
  120. Return the appropriate apiVersion for ingress.
  121. */}}
  122. {{- define "grafana.ingress.apiVersion" -}}
  123. {{- if and (.Capabilities.APIVersions.Has "networking.k8s.io/v1") (semverCompare ">= 1.19-0" .Capabilities.KubeVersion.Version) -}}
  124. {{- print "networking.k8s.io/v1" -}}
  125. {{- else if .Capabilities.APIVersions.Has "networking.k8s.io/v1beta1" -}}
  126. {{- print "networking.k8s.io/v1beta1" -}}
  127. {{- else -}}
  128. {{- print "extensions/v1beta1" -}}
  129. {{- end -}}
  130. {{- end -}}
  131. {{/*
  132. Return the appropriate apiVersion for podDisruptionBudget.
  133. */}}
  134. {{- define "grafana.podDisruptionBudget.apiVersion" -}}
  135. {{- if $.Capabilities.APIVersions.Has "policy/v1/PodDisruptionBudget" -}}
  136. {{- print "policy/v1" -}}
  137. {{- else -}}
  138. {{- print "policy/v1beta1" -}}
  139. {{- end -}}
  140. {{- end -}}
  141. {{/*
  142. Return if ingress is stable.
  143. */}}
  144. {{- define "grafana.ingress.isStable" -}}
  145. {{- eq (include "grafana.ingress.apiVersion" .) "networking.k8s.io/v1" -}}
  146. {{- end -}}
  147. {{/*
  148. Return if ingress supports ingressClassName.
  149. */}}
  150. {{- define "grafana.ingress.supportsIngressClassName" -}}
  151. {{- or (eq (include "grafana.ingress.isStable" .) "true") (and (eq (include "grafana.ingress.apiVersion" .) "networking.k8s.io/v1beta1") (semverCompare ">= 1.18-0" .Capabilities.KubeVersion.Version)) -}}
  152. {{- end -}}
  153. {{/*
  154. Return if ingress supports pathType.
  155. */}}
  156. {{- define "grafana.ingress.supportsPathType" -}}
  157. {{- or (eq (include "grafana.ingress.isStable" .) "true") (and (eq (include "grafana.ingress.apiVersion" .) "networking.k8s.io/v1beta1") (semverCompare ">= 1.18-0" .Capabilities.KubeVersion.Version)) -}}
  158. {{- end -}}