{{- if .Values.openshift }}
apiVersion: apps.openshift.io/v1
kind: DeploymentConfig
{{- else }}
apiVersion: apps/v1
kind: Deployment
{{- end}}
metadata:
  name: cic-k8s-ingress-controller
spec:
  selector:
{{- if .Values.openshift }}
     router: cic-k8s-ingress-controller
{{- else }}
    matchLabels:
      app: cic-k8s-ingress-controller
{{- end}}
  replicas: 1
{{- if .Values.openshift }}
  strategy:
    resources: {}
    rollingParams:
      intervalSeconds: 1
      maxSurge: 0
      maxUnavailable: 25%
      timeoutSeconds: 600
      updatePeriodSeconds: 1
    type: Rolling
{{- end}}
  template:
    metadata:
      name: cic-k8s-ingress-controller
      labels:
{{- if .Values.openshift }}
        router: cic-k8s-ingress-controller
{{- else }}
        app: cic-k8s-ingress-controller
{{- end}}
    spec:
      serviceAccountName: cic-k8s-role
      containers:
      - name: cic-k8s-ingress-controller
        image: "{{ .Values.cic.image }}"
        imagePullPolicy: {{ .Values.cic.pullPolicy }}
        args:
          - --default-ssl-certificate
            {{ .Values.defaultSSLCert | default "{{ .Release.Namespace }}/default-cert" }}
{{- if .Values.ingressClass }}
          - --ingress-class
{{- range .Values.ingressClass}}
            {{.}}
{{- end }}
{{- end }}
          - --feature-node-watch
            {{.Values.nodeWatch}}
        env:
        - name: "NS_IP"
          value: "{{ .Values.nsIP }}"
{{- if .Values.nsVIP }}
        - name: "NS_VIP"
          value: "{{ .Values.nsVIP }}"
{{- end}}
        - name: "NS_USER"
          valueFrom:
            secretKeyRef:
              name: {{ .Values.loginFileName | default "nslogin"}}
              key: username
        - name: "NS_PASSWORD"
          valueFrom:
            secretKeyRef:
              name: {{ .Values.loginFileName | default "nslogin"}}
              key: password
        - name: "EULA"
          value: "{{ .Values.license.accept }}"
        - name: "LOGLEVEL"
          value: "{{ .Values.logLevel}}"
        - name: "NS_PROTOCOL"
          value: "{{ .Values.nsProtocol }}"
        - name: "NS_PORT"
          value: "{{ .Values.nsPort}}"
        - name: "NS_APPS_NAME_PREFIX"
          value: {{ .Values.nsNamespace | default "k8s"}}
{{- if .Values.kubernetesURL }}
        - name: "kubernetes_url"
          value: "{{ .Values.kubernetesURL }}"
{{- end}}
{{- if .Values.exporter.required }}
      - name: exporter
        image: "{{ .Values.exporter.image }}"
        args:
          - "--secure=YES"
          - "--username=$(NS_USERNAME)"
          - "--password=$(NS_PASSWORD)"
          - "--target-nsip={{ .Values.nsIP }}"
          - "--port={{ .Values.exporter.ports.containerPort }}"
        env:
          - name: NS_USERNAME
            valueFrom:
              secretKeyRef:
                name: {{ .Values.loginFileName | default "nslogin"}}
                key: username
          - name: NS_PASSWORD
            valueFrom:
              secretKeyRef:
                name: {{ .Values.loginFileName | default "nslogin"}}
                key: password
        imagePullPolicy: {{ .Values.exporter.pullPolicy }}
{{- end }}
---

{{- if .Values.exporter.required }}


apiVersion: v1
kind: Service
metadata:
   name: exporter
   labels:
     app: exporter
     service-type: citrix-adc-monitor
spec:
   type: ClusterIP
   ports:
   - port: {{ .Values.exporter.ports.containerPort }}
     targetPort: {{ .Values.exporter.ports.containerPort }}
     name: exporter-port
   selector:
     app: cic-k8s-ingress-controller

---

apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
 name: citrix-adc-servicemonitor
 labels:
   servicemonitor: citrix-adc
spec:
 endpoints:
 - interval: 30s
   port: exporter-port
 selector:
   matchLabels:
     service-type: citrix-adc-monitor
 namespaceSelector:
   matchNames:
   - monitoring
   - default
   - {{ .Release.Namespace }}

{{- end }}
