{{- if and .Values.controller.enabled .Values.ingress.enabled }}
{{- $fullName := include "bp-openclaw.fullname" . -}}
{{- $svcPort := .Values.service.port -}}
{{- $host := .Values.ingress.host -}}
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: {{ $fullName }}-controller
  labels:
    {{- include "bp-openclaw.labels" . | nindent 4 }}
    catalyst.openova.io/component: controller
  annotations:
    traefik.ingress.kubernetes.io/router.entrypoints: websecure
    traefik.ingress.kubernetes.io/router.tls: "true"
    {{- if .Values.ingress.tls.enabled }}
    cert-manager.io/cluster-issuer: {{ .Values.ingress.tls.issuer | quote }}
    {{- end }}
    {{- with .Values.ingress.annotations }}
    {{- toYaml . | nindent 4 }}
    {{- end }}
spec:
  ingressClassName: {{ .Values.ingress.className }}
  {{- if .Values.ingress.tls.enabled }}
  tls:
    - hosts:
        - {{ $host }}
      secretName: {{ .Values.ingress.tls.secretName }}
  {{- end }}
  rules:
    - host: {{ $host }}
      http:
        paths:
          - path: /
            pathType: Prefix
            backend:
              service:
                name: {{ $fullName }}-controller
                port:
                  number: {{ $svcPort }}
{{- end }}
