{{- $version := include "imageVersion" $ }}
{{- if (ne $version "experimental-v3.0") }}
  {{- if (semverCompare "<3.0.0-0" $version) }}
    {{- fail "ERROR: This version of the Chart only supports Traefik Proxy v3" -}}
  {{- end }}
{{- end }}

{{- if .Values.certResolvers }}
  {{- fail "ERROR: certResolvers setting has been removed. See v33.0.0 Changelog." }}
{{- end }}

{{- if and .Values.hub.enabled (not (contains "traefik-hub" .Values.image.repository)) }}
  {{- fail "ERROR: traefik-hub image is required when enabling Traefik Hub" -}}
{{- end }}

{{- if and (.Values.providers.kubernetesGateway).enabled (and (semverCompare "<3.1.0-rc3" $version) (not .Values.experimental.kubernetesGateway.enabled)) }}
  {{- fail "ERROR: Before traefik v3.1.0-rc3, kubernetesGateway is experimental. Enable it by setting experimental.kubernetesGateway.enabled to true" -}}
{{- end }}

{{- if .Values.hub.token }}
  {{- if and .Values.hub.apimanagement.enabled (and .Values.rbac.enabled .Values.rbac.namespaced) }}
    {{- fail "ERROR: Currently Traefik Hub doesn't support namespaced RBACs" -}}
  {{- end }}
{{- end }}

{{- if .Values.rbac.namespaced }}
  {{- if .Values.providers.kubernetesGateway.enabled }}
    {{- fail "ERROR: Kubernetes Gateway provider requires ClusterRole. RBAC cannot be namespaced." }}
  {{- end }}
  {{- if and (not .Values.providers.kubernetesIngress.enabled) (not .Values.providers.kubernetesCRD.enabled) }}
    {{- fail "ERROR: namespaced rbac requires Kubernetes CRD or Kubernetes Ingress provider." }}
  {{- end }}
{{- end }}
