apiVersion: apps/v1
kind: Deployment
metadata:
  name: cdi-docker-registry-host
  namespace: {{ .Namespace }}
  labels:
    cdi.kubevirt.io/testing: ""
spec:
  strategy:
    type: Recreate
  selector:
    matchLabels:
      name: cdi-docker-registry-host
  replicas: 1
  template:
    metadata:
      labels:
        name: cdi-docker-registry-host
        cdi.kubevirt.io/testing: ""
    spec:
      securityContext:
        runAsUser: 0
      serviceAccountName: cdi-testing-sa
      initContainers:
      - name: registry-init
        image: {{ .DockerRepo }}/cdi-func-test-registry-init:{{ .DockerTag }}
        imagePullPolicy: {{ .PullPolicy }}
        args: ["-certDir", "/tmp/shared/certs", "-inFile", "/tmp/source/tinyCore.iso", "-outDir", "/tmp/shared/images"]
        volumeMounts:
        - name: "images"
          mountPath: "/tmp/shared"
      containers:
      - name: registry
        image: {{ .DockerRepo }}/cdi-func-test-registry:{{ .DockerTag }}
        command: ["/start-registry.sh", "/etc/docker/registry/registry-config.yml"]
        imagePullPolicy: {{ .PullPolicy }}
        ports:
          - name: sec-docker-reg
            containerPort: 443
        resources: {}
        volumeMounts:
        - name: "health"
          mountPath: "/tmp/health"
        - name: "images"
          mountPath: "/tmp/shared"
        - name: "registry-storage"
          mountPath: "/var/lib/registry"
        readinessProbe:
          exec:
            command:
             - cat
             - /tmp/health/ready
          initialDelaySeconds: 20
          periodSeconds: 20
      - name: registry-auth
        image: {{ .DockerRepo }}/cdi-func-test-registry:{{ .DockerTag }}
        command: ["/start-registry.sh", "/etc/docker/registry/registry-auth-config.yml"]
        imagePullPolicy: {{ .PullPolicy }}
        ports:
          - name: auth-docker-reg
            containerPort: 1443
        resources: {}
        volumeMounts:
        - name: "health"
          mountPath: "/tmp/health"
        - name: "images"
          mountPath: "/tmp/shared"
        - name: "registry-storage"
          mountPath: "/var/lib/registry"
        readinessProbe:
          exec:
            command:
              - cat
              - /tmp/health/ready
          initialDelaySeconds: 20
          periodSeconds: 20
      - name: registry-populate
        image: {{ .DockerRepo }}/cdi-func-test-registry-populate:{{ .DockerTag }}
        imagePullPolicy: {{ .PullPolicy }}
        securityContext:
          capabilities:
            add:
            # building using buildah requires a properly installed shadow-utils package (which in turn requires SETFCAP)
            # https://www.redhat.com/sysadmin/podman-inside-kubernetes
            - SETFCAP
        args: [ "/tmp/shared/images/", "/tmp/docker-images", "127.0.0.1", "443", "/tmp/health/healthy", "15", "/tmp/health/ready", "15"]
        volumeMounts:
        - name: "images"
          mountPath: "/tmp/shared"
        - name: "health"
          mountPath: "/tmp/health"
        readinessProbe:
          exec:
            command:
             - cat
             - /tmp/health/ready
          initialDelaySeconds: 20
          periodSeconds: 20
        livenessProbe:
          exec:
            command:
             - cat
             - /tmp/health/healthy
          initialDelaySeconds: 20
          periodSeconds: 20
      volumes:
      - name: "images"
        emptyDir: {}
      - name: "health"
        emptyDir: {}
      - name: "registry-storage"
        emptyDir: {}
---
apiVersion: v1
kind: Service
metadata:
  name: cdi-docker-registry-host
  namespace: {{ .Namespace }}
  labels:
    cdi.kubevirt.io/testing: ""
spec:
  selector:
    name: cdi-docker-registry-host
  ports:
  - name: sec-docker-reg
    port: 443
    targetPort: 443
  - name: alt-sec-docker-reg
    port: 5000
    targetPort: 443
  - name: auth-docker-reg
    port: 1443
    targetPort: 1443
