_helpers.tpl 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. {{/*
  2. Expand the name of the chart.
  3. */}}
  4. {{- define "opentelemetry-collector.name" -}}
  5. {{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }}
  6. {{- end }}
  7. {{- define "opentelemetry-collector.lowercase_chartname" -}}
  8. {{- default .Chart.Name | lower }}
  9. {{- end }}
  10. {{/*
  11. Get component name
  12. */}}
  13. {{- define "opentelemetry-collector.component" -}}
  14. {{- if eq .Values.mode "deployment" -}}
  15. component: standalone-collector
  16. {{- end -}}
  17. {{- if eq .Values.mode "daemonset" -}}
  18. component: agent-collector
  19. {{- end -}}
  20. {{- if eq .Values.mode "statefulset" -}}
  21. component: statefulset-collector
  22. {{- end -}}
  23. {{- end }}
  24. {{/*
  25. Create a default fully qualified app name.
  26. We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
  27. If release name contains chart name it will be used as a full name.
  28. */}}
  29. {{- define "opentelemetry-collector.fullname" -}}
  30. {{- if .Values.fullnameOverride }}
  31. {{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }}
  32. {{- else }}
  33. {{- $name := default .Chart.Name .Values.nameOverride }}
  34. {{- if contains $name .Release.Name }}
  35. {{- .Release.Name | trunc 63 | trimSuffix "-" }}
  36. {{- else }}
  37. {{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }}
  38. {{- end }}
  39. {{- end }}
  40. {{- end }}
  41. {{/*
  42. Create chart name and version as used by the chart label.
  43. */}}
  44. {{- define "opentelemetry-collector.chart" -}}
  45. {{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
  46. {{- end }}
  47. {{/*
  48. Common labels
  49. */}}
  50. {{- define "opentelemetry-collector.labels" -}}
  51. helm.sh/chart: {{ include "opentelemetry-collector.chart" . }}
  52. {{ include "opentelemetry-collector.selectorLabels" . }}
  53. {{- if .Chart.AppVersion }}
  54. app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
  55. {{- end }}
  56. app.kubernetes.io/managed-by: {{ .Release.Service }}
  57. {{ include "opentelemetry-collector.additionalLabels" . }}
  58. {{- end }}
  59. {{/*
  60. Selector labels
  61. */}}
  62. {{- define "opentelemetry-collector.selectorLabels" -}}
  63. app.kubernetes.io/name: {{ include "opentelemetry-collector.name" . }}
  64. app.kubernetes.io/instance: {{ .Release.Name }}
  65. {{- end }}
  66. {{/*
  67. Create the name of the service account to use
  68. */}}
  69. {{- define "opentelemetry-collector.serviceAccountName" -}}
  70. {{- if .Values.serviceAccount.create }}
  71. {{- default (include "opentelemetry-collector.fullname" .) .Values.serviceAccount.name }}
  72. {{- else }}
  73. {{- default "default" .Values.serviceAccount.name }}
  74. {{- end }}
  75. {{- end }}
  76. {{/*
  77. Create the name of the clusterRole to use
  78. */}}
  79. {{- define "opentelemetry-collector.clusterRoleName" -}}
  80. {{- default (include "opentelemetry-collector.fullname" .) .Values.clusterRole.name }}
  81. {{- end }}
  82. {{/*
  83. Create the name of the clusterRoleBinding to use
  84. */}}
  85. {{- define "opentelemetry-collector.clusterRoleBindingName" -}}
  86. {{- default (include "opentelemetry-collector.fullname" .) .Values.clusterRole.clusterRoleBinding.name }}
  87. {{- end }}
  88. {{- define "opentelemetry-collector.podAnnotations" -}}
  89. {{- if .Values.podAnnotations }}
  90. {{- tpl (.Values.podAnnotations | toYaml) . }}
  91. {{- end }}
  92. {{- end }}
  93. {{- define "opentelemetry-collector.podLabels" -}}
  94. {{- if .Values.podLabels }}
  95. {{- tpl (.Values.podLabels | toYaml) . }}
  96. {{- end }}
  97. {{- end }}
  98. {{- define "opentelemetry-collector.additionalLabels" -}}
  99. {{- if .Values.additionalLabels }}
  100. {{- tpl (.Values.additionalLabels | toYaml) . }}
  101. {{- end }}
  102. {{- end }}
  103. {{/*
  104. Return the appropriate apiVersion for podDisruptionBudget.
  105. */}}
  106. {{- define "podDisruptionBudget.apiVersion" -}}
  107. {{- if and (.Capabilities.APIVersions.Has "policy/v1") (semverCompare ">= 1.21-0" .Capabilities.KubeVersion.Version) -}}
  108. {{- print "policy/v1" -}}
  109. {{- else -}}
  110. {{- print "policy/v1beta1" -}}
  111. {{- end -}}
  112. {{- end -}}
  113. {{/*
  114. Compute Service creation on mode
  115. */}}
  116. {{- define "opentelemetry-collector.serviceEnabled" }}
  117. {{- $serviceEnabled := true }}
  118. {{- if not (eq (toString .Values.service.enabled) "<nil>") }}
  119. {{- $serviceEnabled = .Values.service.enabled -}}
  120. {{- end }}
  121. {{- if and (eq .Values.mode "daemonset") (not .Values.service.enabled) }}
  122. {{- $serviceEnabled = false -}}
  123. {{- end }}
  124. {{- print $serviceEnabled }}
  125. {{- end -}}
  126. {{/*
  127. Compute InternalTrafficPolicy on Service creation
  128. */}}
  129. {{- define "opentelemetry-collector.serviceInternalTrafficPolicy" }}
  130. {{- if and (eq .Values.mode "daemonset") (eq .Values.service.enabled true) }}
  131. {{- print (.Values.service.internalTrafficPolicy | default "Local") -}}
  132. {{- else }}
  133. {{- print (.Values.service.internalTrafficPolicy | default "Cluster") -}}
  134. {{- end }}
  135. {{- end -}}
  136. {{/*
  137. Allow the release namespace to be overridden
  138. */}}
  139. {{- define "opentelemetry-collector.namespace" -}}
  140. {{- if .Values.namespaceOverride -}}
  141. {{- .Values.namespaceOverride -}}
  142. {{- else -}}
  143. {{- .Release.Namespace -}}
  144. {{- end -}}
  145. {{- end -}}
  146. {{/*
  147. This helper converts the input value of memory to Bytes.
  148. Input needs to be a valid value as supported by k8s memory resource field.
  149. */}}
  150. {{- define "opentelemetry-collector.convertMemToBytes" }}
  151. {{- $mem := lower . -}}
  152. {{- if hasSuffix "e" $mem -}}
  153. {{- $mem = mulf (trimSuffix "e" $mem | float64) 1e18 -}}
  154. {{- else if hasSuffix "ei" $mem -}}
  155. {{- $mem = mulf (trimSuffix "e" $mem | float64) 0x1p60 -}}
  156. {{- else if hasSuffix "p" $mem -}}
  157. {{- $mem = mulf (trimSuffix "p" $mem | float64) 1e15 -}}
  158. {{- else if hasSuffix "pi" $mem -}}
  159. {{- $mem = mulf (trimSuffix "pi" $mem | float64) 0x1p50 -}}
  160. {{- else if hasSuffix "t" $mem -}}
  161. {{- $mem = mulf (trimSuffix "t" $mem | float64) 1e12 -}}
  162. {{- else if hasSuffix "ti" $mem -}}
  163. {{- $mem = mulf (trimSuffix "ti" $mem | float64) 0x1p40 -}}
  164. {{- else if hasSuffix "g" $mem -}}
  165. {{- $mem = mulf (trimSuffix "g" $mem | float64) 1e9 -}}
  166. {{- else if hasSuffix "gi" $mem -}}
  167. {{- $mem = mulf (trimSuffix "gi" $mem | float64) 0x1p30 -}}
  168. {{- else if hasSuffix "m" $mem -}}
  169. {{- $mem = mulf (trimSuffix "m" $mem | float64) 1e6 -}}
  170. {{- else if hasSuffix "mi" $mem -}}
  171. {{- $mem = mulf (trimSuffix "mi" $mem | float64) 0x1p20 -}}
  172. {{- else if hasSuffix "k" $mem -}}
  173. {{- $mem = mulf (trimSuffix "k" $mem | float64) 1e3 -}}
  174. {{- else if hasSuffix "ki" $mem -}}
  175. {{- $mem = mulf (trimSuffix "ki" $mem | float64) 0x1p10 -}}
  176. {{- end }}
  177. {{- $mem }}
  178. {{- end }}
  179. {{- define "opentelemetry-collector.gomemlimit" }}
  180. {{- $memlimitBytes := include "opentelemetry-collector.convertMemToBytes" . | mulf 0.8 -}}
  181. {{- printf "%dMiB" (divf $memlimitBytes 0x1p20 | floor | int64) -}}
  182. {{- end }}
  183. {{/*
  184. Get HPA kind from mode.
  185. The capitalization is important for StatefulSet.
  186. */}}
  187. {{- define "opentelemetry-collector.hpaKind" -}}
  188. {{- if eq .Values.mode "deployment" -}}
  189. {{- print "Deployment" -}}
  190. {{- end -}}
  191. {{- if eq .Values.mode "statefulset" -}}
  192. {{- print "StatefulSet" -}}
  193. {{- end -}}
  194. {{- end }}
  195. {{/*
  196. Get ConfigMap name if existingName is defined, otherwise use default name for generated config.
  197. */}}
  198. {{- define "opentelemetry-collector.configName" -}}
  199. {{- if .Values.configMap.existingName -}}
  200. {{- .Values.configMap.existingName }}
  201. {{- else }}
  202. {{- printf "%s%s" (include "opentelemetry-collector.fullname" .) (.configmapSuffix) }}
  203. {{- end -}}
  204. {{- end }}