_objects.tpl 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. {{- define "otel-demo.deployment" }}
  2. ---
  3. apiVersion: apps/v1
  4. kind: Deployment
  5. metadata:
  6. name: {{ include "otel-demo.name" . }}-{{ .name }}
  7. labels:
  8. {{- include "otel-demo.labels" . | nindent 4 }}
  9. spec:
  10. selector:
  11. matchLabels:
  12. {{- include "otel-demo.selectorLabels" . | nindent 6 }}
  13. template:
  14. metadata:
  15. labels:
  16. {{- include "otel-demo.selectorLabels" . | nindent 8 }}
  17. {{- if .podAnnotations }}
  18. annotations:
  19. {{- toYaml .podAnnotations | nindent 8 }}
  20. {{- end }}
  21. spec:
  22. {{- if or .defaultValues.image.pullSecrets ((.imageOverride).pullSecrets) }}
  23. imagePullSecrets:
  24. {{- ((.imageOverride).pullSecrets) | default .defaultValues.image.pullSecrets | toYaml | nindent 8}}
  25. {{- end }}
  26. serviceAccountName: {{ include "otel-demo.serviceAccountName" .}}
  27. {{- $schedulingRules := .schedulingRules | default dict }}
  28. {{- if or .defaultValues.schedulingRules.nodeSelector $schedulingRules.nodeSelector}}
  29. nodeSelector:
  30. {{- $schedulingRules.nodeSelector | default .defaultValues.schedulingRules.nodeSelector | toYaml | nindent 8 }}
  31. {{- end }}
  32. {{- if or .defaultValues.schedulingRules.affinity $schedulingRules.affinity}}
  33. affinity:
  34. {{- $schedulingRules.affinity | default .defaultValues.schedulingRules.affinity | toYaml | nindent 8 }}
  35. {{- end }}
  36. {{- if or .defaultValues.schedulingRules.tolerations $schedulingRules.tolerations}}
  37. tolerations:
  38. {{- $schedulingRules.tolerations | default .defaultValues.schedulingRules.tolerations | toYaml | nindent 8 }}
  39. {{- end }}
  40. containers:
  41. - name: {{ .name }}
  42. image: '{{ ((.imageOverride).repository) | default .defaultValues.image.repository }}:{{ ((.imageOverride).tag) | default (printf "%s-%s" (default .Chart.AppVersion .defaultValues.image.tag) (replace "-" "" .name)) }}'
  43. imagePullPolicy: {{ ((.imageOverride).pullPolicy) | default .defaultValues.image.pullPolicy }}
  44. {{- if .command }}
  45. command:
  46. {{- .command | toYaml | nindent 10 -}}
  47. {{- end }}
  48. {{- if or .ports .service}}
  49. ports:
  50. {{- include "otel-demo.pod.ports" . | nindent 10 }}
  51. {{- end }}
  52. env:
  53. {{- include "otel-demo.pod.env" . | nindent 10 }}
  54. resources:
  55. {{- .resources | toYaml | nindent 12 }}
  56. {{- if or .defaultValues.securityContext .securityContext }}
  57. securityContext:
  58. {{- .securityContext | default .defaultValues.securityContext | toYaml | nindent 12 }}
  59. {{- end}}
  60. {{- if .livenessProbe }}
  61. livenessProbe:
  62. {{- .livenessProbe | toYaml | nindent 12 }}
  63. {{- end }}
  64. {{- if .configuration }}
  65. volumeMounts:
  66. - name: config
  67. mountPath: /etc/config
  68. volumes:
  69. - name: config
  70. configMap:
  71. name: {{ include "otel-demo.name" . }}-{{ .name }}-config
  72. {{- end }}
  73. {{- if .initContainers }}
  74. initContainers:
  75. {{- tpl (toYaml .initContainers) . | nindent 8 }}
  76. {{- end}}
  77. {{- end }}
  78. {{- define "otel-demo.service" }}
  79. {{- if or .ports .service}}
  80. {{- $service := .service | default dict }}
  81. ---
  82. apiVersion: v1
  83. kind: Service
  84. metadata:
  85. name: {{ include "otel-demo.name" . }}-{{ .name }}
  86. labels:
  87. {{- include "otel-demo.labels" . | nindent 4 }}
  88. {{- with $service.annotations }}
  89. annotations:
  90. {{- toYaml . | nindent 4 }}
  91. {{- end }}
  92. spec:
  93. type: {{ $service.type | default "ClusterIP" }}
  94. ports:
  95. {{- if .ports }}
  96. {{- range $port := .ports }}
  97. - port: {{ $port.value }}
  98. name: {{ $port.name}}
  99. targetPort: {{ $port.value }}
  100. {{- end }}
  101. {{- end }}
  102. {{- if $service.port }}
  103. - port: {{ $service.port}}
  104. name: service
  105. targetPort: {{ $service.port }}
  106. {{- if $service.nodePort }}
  107. nodePort: {{ $service.nodePort }}
  108. {{- end }}
  109. {{- end }}
  110. selector:
  111. {{- include "otel-demo.selectorLabels" . | nindent 4 }}
  112. {{- end}}
  113. {{- end}}
  114. {{- define "otel-demo.configmap" }}
  115. {{- if .configuration}}
  116. ---
  117. apiVersion: v1
  118. kind: ConfigMap
  119. metadata:
  120. name: {{ include "otel-demo.name" . }}-{{ .name }}-config
  121. labels:
  122. service: {{ include "otel-demo.name" . }}-{{ .name }}
  123. app: {{ include "otel-demo.name" . }}-{{ .name }}
  124. component: {{ include "otel-demo.name" . }}-{{ .name }}-config
  125. data:
  126. {{- .configuration | toYaml | nindent 2}}
  127. {{- end}}
  128. {{- end}}
  129. {{- define "otel-demo.ingress" }}
  130. {{- $hasIngress := false}}
  131. {{- if .ingress }}
  132. {{- if .ingress.enabled }}
  133. {{- $hasIngress = true }}
  134. {{- end }}
  135. {{- end }}
  136. {{- $hasServicePorts := false}}
  137. {{- if .service }}
  138. {{- if .service.port }}
  139. {{- $hasServicePorts = true }}
  140. {{- end }}
  141. {{- end }}
  142. {{- if and $hasIngress (or .ports $hasServicePorts) }}
  143. {{- $ingresses := list .ingress }}
  144. {{- if .ingress.additionalIngresses }}
  145. {{- $ingresses := concat $ingresses .ingress.additionalIngresses -}}
  146. {{- end }}
  147. {{- range $ingresses }}
  148. ---
  149. apiVersion: "networking.k8s.io/v1"
  150. kind: Ingress
  151. metadata:
  152. {{- if .name }}
  153. name: {{include "otel-demo.name" $ }}-{{ $.name }}-{{ .name }}
  154. {{- else }}
  155. name: {{include "otel-demo.name" $ }}-{{ $.name }}
  156. {{- end }}
  157. labels:
  158. {{- include "otel-demo.labels" $ | nindent 4 }}
  159. {{- if .annotations }}
  160. annotations:
  161. {{ toYaml .annotations | nindent 4 }}
  162. {{- end }}
  163. spec:
  164. {{- if .ingressClassName }}
  165. ingressClassName: {{ .ingressClassName }}
  166. {{- end -}}
  167. {{- if .tls }}
  168. tls:
  169. {{- range .tls }}
  170. - hosts:
  171. {{- range .hosts }}
  172. - {{ . | quote }}
  173. {{- end }}
  174. {{- with .secretName }}
  175. secretName: {{ . }}
  176. {{- end }}
  177. {{- end }}
  178. {{- end }}
  179. rules:
  180. {{- range .hosts }}
  181. - host: {{ .host | quote }}
  182. http:
  183. paths:
  184. {{- range .paths }}
  185. - path: {{ .path }}
  186. pathType: {{ .pathType }}
  187. backend:
  188. service:
  189. name: {{ include "otel-demo.name" $ }}-{{ $.name }}
  190. port:
  191. number: {{ .port }}
  192. {{- end }}
  193. {{- end }}
  194. {{- end}}
  195. {{- end}}
  196. {{- end}}