{{- if not .Values.image.repository }}
{{ fail "[ERROR] 'image.repository' must be set. See https://github.com/open-telemetry/opentelemetry-helm-charts/blob/main/charts/opentelemetry-collector/UPGRADING.md for instructions." }}
{{ end }}

{{- if and (not (eq .Values.mode "daemonset")) (not (eq .Values.mode "deployment")) (not (eq .Values.mode "statefulset")) }}
{{ fail "[ERROR] 'mode' must be set. See https://github.com/open-telemetry/opentelemetry-helm-charts/blob/main/charts/opentelemetry-collector/UPGRADING.md for instructions." }}
{{ end }}

{{- if and (eq .Values.dnsPolicy "None") (not .Values.dnsConfig) }}
{{- fail "[ERROR] dnsConfig should be provided when dnsPolicy is None" }}
{{ end }}

{{- if .Values.presets.clusterMetrics.enabled }}
{{- if eq .Values.mode "daemonset"}}
{{- fail "Cluster Metrics preset is not suitable for daemonset mode. Please use statefulset or deployment mode with replicaCount: 1"}}
{{ end }}
{{- if gt (int .Values.replicaCount) 1 }}
{{- fail "Cluster Metrics preset is not suitable for replicaCount greater than one. Please change replica count to one." }}
{{ end }}
{{ end }}

{{/* validate extensions must include health_check */}}
{{- if not (has "health_check" .Values.config.service.extensions) }}
{{ fail "[ERROR] The opentelemetry-collector chart requires that the health_check extension to be included in the extension list." }}
{{- end}}

{{- if not .Values.configMap.create }}
[WARNING] "configMap" wil not be created and "config" will not take effect.
{{ end }}

{{- if and .Values.configMap.create .Values.configMap.existingName }}
{{ fail "[ERROR] Cannot set configMap.existingName when configMap.create is true" }}
{{ end }}

{{- if not .Values.resources }}
[WARNING] No resource limits or requests were set. Consider setter resource requests and limits for your collector(s) via the `resources` field.
{{ end }}

{{- if and (eq .Values.mode "daemonset") (eq .Values.service.internalTrafficPolicy "Cluster") }}
[WARNING] Setting internalTrafficPolicy to 'Cluster' on Daemonset is not recommended. Consider using 'Local' instead.
{{ end }}

{{- if and (.Values.useGOMEMLIMIT) (not ((((.Values.resources).limits).memory))) }}
[WARNING] "useGOMEMLIMIT" is enabled but memory limits have not been supplied, which means no GOMEMLIMIT env var was configured but the Memory Ballast Extension was removed. It is highly recommended to only use "useGOMEMLIMIT" when memory limits have been set.
{{ end }}
