_helpers.tpl 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. {{/* vim: set filetype=mustache: */}}
  2. {{/*
  3. Expand the name of the chart.
  4. */}}
  5. {{- define "cloudpods.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 "cloudpods.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 "cloudpods.chart" -}}
  29. {{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
  30. {{- end }}
  31. {{/*
  32. Common labels
  33. */}}
  34. {{- define "cloudpods.labels" -}}
  35. helm.sh/chart: {{ include "cloudpods.chart" . }}
  36. {{ include "cloudpods.selectorLabels" . }}
  37. {{- if .Chart.AppVersion }}
  38. app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
  39. {{- end }}
  40. app.kubernetes.io/managed-by: {{ .Release.Service }}
  41. {{- end }}
  42. {{/*
  43. Selector labels
  44. */}}
  45. {{- define "cloudpods.selectorLabels" -}}
  46. app.kubernetes.io/name: {{ include "cloudpods.name" . }}
  47. app.kubernetes.io/instance: {{ .Release.Name }}
  48. {{- end }}
  49. {{/*
  50. Create the name of the service account to use
  51. */}}
  52. {{- define "cloudpods.serviceAccountName" -}}
  53. {{- if .Values.serviceAccount.create }}
  54. {{- default (include "cloudpods.fullname" .) .Values.serviceAccount.name }}
  55. {{- else }}
  56. {{- default "default" .Values.serviceAccount.name }}
  57. {{- end }}
  58. {{- end }}
  59. {{/*
  60. Return the appropriate apiVersion for statefulset
  61. */}}
  62. {{- define "statefulset.apiVersion" -}}
  63. {{- if semverCompare "<1.17-0" .Capabilities.KubeVersion.GitVersion -}}
  64. {{- print "apps/v1beta2" -}}
  65. {{- else -}}
  66. {{- print "apps/v1" -}}
  67. {{- end -}}
  68. {{- end -}}
  69. {{/*
  70. Return the appropriate apiVersion for cronjob APIs.
  71. */}}
  72. {{- define "cronjob.apiVersion" -}}
  73. {{- if semverCompare "< 1.8-0" .Capabilities.KubeVersion.GitVersion -}}
  74. {{- print "batch/v2alpha1" }}
  75. {{- else if semverCompare ">=1.8-0" .Capabilities.KubeVersion.GitVersion -}}
  76. {{- print "batch/v1beta1" }}
  77. {{- end -}}
  78. {{- end -}}
  79. {{/*
  80. Return the appropriate apiVersion for ingress.
  81. */}}
  82. {{- define "ingress.apiVersion" -}}
  83. {{- if semverCompare "<1.14-0" .Capabilities.KubeVersion.GitVersion -}}
  84. {{- print "extensions/v1beta1" -}}
  85. {{- else -}}
  86. {{- print "networking.k8s.io/v1beta1" -}}
  87. {{- end -}}
  88. {{- end -}}
  89. {{/*
  90. Return the cluster storageClass
  91. */}}
  92. {{- define "cloudpods.cluster.storageClass" -}}
  93. {{- if .Values.cluster.storageClass -}}
  94. {{- print .Values.cluster.storageClass -}}
  95. {{- else if .Values.localPathCSI.enabled -}}
  96. {{- print "local-path" -}}
  97. {{- else -}}
  98. {{- fail ".Values.cluster.storageClass required" -}}
  99. {{- end -}}
  100. {{- end -}}
  101. {{/*
  102. Return the local-path-csi image
  103. */}}
  104. {{- define "cloudpods.localPathCSI.image" -}}
  105. {{- if semverCompare "<1.20-0" .Capabilities.KubeVersion.GitVersion -}}
  106. {{- print "registry.cn-beijing.aliyuncs.com/yunionio/local-path-provisioner:v0.0.11" -}}
  107. {{- else -}}
  108. {{- print "registry.cn-beijing.aliyuncs.com/yunionio/local-path-provisioner:v0.0.22" -}}
  109. {{- end -}}
  110. {{- end -}}
  111. {{/*
  112. Return operator name
  113. */}}
  114. {{- define "cloudpods.operator.fullname" -}}
  115. {{- printf "%s-operator" (include "cloudpods.fullname" .) -}}
  116. {{- end -}}
  117. {{/*
  118. Return web name
  119. */}}
  120. {{- define "cloudpods.web.fullname" -}}
  121. {{- printf "%s-web" (include "cloudpods.fullname" .) -}}
  122. {{- end -}}
  123. {{/*
  124. Return web's certs name
  125. */}}
  126. {{- define "cloudpods.web.certs.fullname" -}}
  127. {{- printf "%s-certs" (include "cloudpods.fullname" .) -}}
  128. {{- end -}}
  129. {{/*
  130. Return mysql name
  131. */}}
  132. {{- define "cloudpods.mysql.fullname" -}}
  133. {{- printf "%s-mysql" (include "cloudpods.fullname" .) -}}
  134. {{- end -}}
  135. {{/*
  136. Return the mysql host
  137. */}}
  138. {{- define "cloudpods.cluster.mysql.host" -}}
  139. {{- if .Values.cluster.mysql.statefulset.enabled -}}
  140. {{- printf "%s-mysql-svc" (include "cloudpods.fullname" .) -}}
  141. {{- else -}}
  142. {{- print .Values.cluster.mysql.host -}}
  143. {{- end -}}
  144. {{- end -}}