---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: imageio-deployment
  namespace: {{ .Namespace }}
  labels:
    cdi.kubevirt.io/testing: ""
spec:
  strategy:
    type: Recreate
  replicas: 1
  selector:
    matchLabels:
      app: imageio
  template:
    metadata:
      labels:
        app: imageio
        cdi.kubevirt.io/testing: ""
    spec:
      nodeSelector:
        kubernetes.io/arch: amd64
      securityContext:
        runAsUser: 0
      serviceAccountName: cdi-testing-sa
      initContainers:
      - name: init
        image: {{ .DockerRepo }}/imageio-init:{{ .DockerTag }}
        imagePullPolicy: {{ .PullPolicy }}
        args: ["-certDir", "/tmp/certs"]
        volumeMounts:
        - name: "certs"
          mountPath: "/tmp"
      containers:
      - name: imageiotest
        image: {{ .DockerRepo }}/cdi-func-test-imageio:{{ .DockerTag }}
        imagePullPolicy: {{ .PullPolicy }}
        ports:
        - containerPort: 12345
        volumeMounts:
        - name: "certs"
          mountPath: "/tmp"
        command: ["/bin/bash"]
        args:
        - -c
        - /usr/bin/update-ca-trust && /usr/bin/update-crypto-policies &&
          openssl x509 -in /tmp/certs/tls.crt -out /tmp/certs/ca.pem && openssl x509 -in
          /tmp/certs/tls.crt -out /tmp/certs/cert.pem && ovirt-imageio& sleep 15 && ovirt-imageioctl
          add-ticket myticket.json && tail -n+1 -f /var/log/ovirt-imageio/daemon.log
      - name: fakeovirt
        # Docker file: https://github.com/machacekondra/fakeovirt
        image: quay.io/kubevirt/fakeovirt:v1.38.0
        imagePullPolicy: {{ .PullPolicy }}
        ports:
        - containerPort: 12346
        env:
          - name: NAMESPACE
            value: {{ .Namespace }}
        volumeMounts:
        - name: "certs"
          mountPath: "/tmp"
        command: ["/bin/bash"]
        args:
        - -c
        - cp /tmp/certs/tls.crt /app/imageio.crt && cp /tmp/certs/tls.key /app/server.key
          && /app/main
      volumes:
      - name: "certs"
        emptyDir: {}

---
apiVersion: v1
kind: Service
metadata:
  name: imageio
  namespace: {{ .Namespace }}
  labels:
    cdi.kubevirt.io/testing: ""
spec:
  selector:
    app: imageio
  type: NodePort
  ports:
  - name: imageio
    port: 12345
    targetPort: 12345
  - name: fakeovirt
    port: 12346
    targetPort: 12346
