#
# Copyright (c) 2018-2023 Red Hat, Inc.
# This program and the accompanying materials are made
# available under the terms of the Eclipse Public License 2.0
# which is available at https://www.eclipse.org/legal/epl-2.0/
#
# SPDX-License-Identifier: EPL-2.0
#
---
apiVersion: v1
kind: Template
metadata:
  name: devspaces-devfile-registry
objects:
  - apiVersion: v1
    kind: DeploymentConfig
    metadata:
      labels:
        app: devspaces
        component: devfile-registry
      name: devfile-registry
    spec:
      replicas: 1
      selector:
        app: devspaces
        component: devfile-registry
      strategy:
        rollingParams:
          intervalSeconds: 1
          maxSurge: 25%
          maxUnavailable: 25%
          timeoutSeconds: 600
          updatePeriodSeconds: 1
        type: Rolling
      template:
        metadata:
          labels:
            app: devspaces
            component: devfile-registry
        spec:
          containers:
            - image: ${IMAGE}:${IMAGE_TAG}
              imagePullPolicy: ${PULL_POLICY}
              name: devfile-registry
              ports:
                - containerPort: 8080
              livenessProbe:
                httpGet:
                  path: /devfiles/
                  port: 8080
                initialDelaySeconds: 30
                periodSeconds: 10
                timeoutSeconds: 3
              readinessProbe:
                httpGet:
                  path: /devfiles/
                  port: 8080
                initialDelaySeconds: 3
                periodSeconds: 10
                timeoutSeconds: 3
              resources:
                requests:
                  cpu: 1m
                  memory: 5Mi
                limits:
                  cpu: 100m
                  memory: ${MEMORY_LIMIT}
              envFrom:
                - configMapRef:
                    name: devfile-registry
                    optional: true
      triggers:
        - type: ConfigChange
  - apiVersion: v1
    kind: Service
    metadata:
      name: devfile-registry
    spec:
      ports:
        - name: http
          protocol: TCP
          port: 8080
          targetPort: 8080
      selector:
        app: devspaces
        component: devfile-registry
  - apiVersion: v1
    kind: Route
    metadata:
      labels:
        app: devspaces
        component: devfile-registry
      name: devfile-registry
    spec:
      to:
        kind: Service
        name: devfile-registry
        weight: 100
      port:
        targetPort: 8080
      tls:
        termination: edge
        insecureEdgeTerminationPolicy: Redirect
  - apiVersion: v1
    kind: ConfigMap
    metadata:
      name: devfile-registry
    data:
      DS_DEVFILE_IMAGES_REGISTRY_URL: ${DS_DEVFILE_IMAGES_REGISTRY_URL}
      DS_DEVFILE_IMAGES_REGISTRY_ORGANIZATION: ${DS_DEVFILE_IMAGES_REGISTRY_ORGANIZATION}
      DS_DEVFILE_IMAGES_REGISTRY_TAG: ${DS_DEVFILE_IMAGES_REGISTRY_TAG}
parameters:
  - name: IMAGE
    value: registry.redhat.io/devspaces/devfileregistry-rhel8
    displayName: Red Hat OpenShift Dev Spaces devfile registry image
    description: Red Hat OpenShift Dev Spaces devfile registry container image. Defaults
      to registry.redhat.io/devspaces/devfileregistry-rhel8
  - name: IMAGE_TAG
    value: '3.5'
    displayName: Red Hat OpenShift Dev Spaces devfile registry version
    description: Red Hat OpenShift Dev Spaces devfile registry version
  - name: MEMORY_LIMIT
    value: 256Mi
    displayName: Memory Limit
    description: Maximum amount of memory the container can use. Defaults 256Mi
  - name: PULL_POLICY
    value: Always
    displayName: Red Hat OpenShift Dev Spaces devfile registry image pull policy
    description: Always pull by default. Can be IfNotPresent
  - name: DS_DEVFILE_IMAGES_REGISTRY_URL
    displayName: Devfile image registry URL
    description: URL of docker registry containing base images referred in devfiles;
      used to override base images in devfiles
  - name: DS_DEVFILE_IMAGES_REGISTRY_ORGANIZATION
    displayName: Devfile image registry organization
    description: Organization containing images referenced in devfiles; used to override
      base images in devfiles
  - name: DS_DEVFILE_IMAGES_REGISTRY_TAG
    displayName: Devfile image registry tag
    description: Tag used for custom devfile images; used to override base images
      in devfiles
