apiVersion: tekton.dev/v1beta1
kind: Task
metadata:
  annotations:
    tekton.dev/displayName: ibm-pak install operator
    tekton.dev/pipelines.minVersion: 0.17.0
    tekton.dev/tags: cli
  name: ibm-pak-install-operator-0.1
  labels:
    app.kubernetes.io/version: '0.1'
spec:
  description: >-
    This task applies a CASE's catalog source and subscription using its CASE name and version
  params:
    - default: echo " "
      description: Optional extra scripts
      name: SCRIPT
      type: string
    - name: CASE_NAME
      description: IBM CASE name, from https://github.com/IBM/cloud-pak/tree/master/repo/case
      type: string
    - name: CASE_VERSION
      description: IBM CASE version, from https://github.com/IBM/cloud-pak/tree/master/repo/case
      type: string
    - name: ARCHITECTURE
      description: Optional, specific architecture for intended operator (amd64, ppc64le, s390x). This may not be required if the product supports all architectures. Check with the relevant product documentation.
      type: string
      default: ""
    - name: CATALOG_NAMESPACE
      description: Namespace to add the catalog source
      type: string
      default: openshift-marketplace
    - name: OPERATOR_NAMESPACE
      description: Namespace to add the catalog source
      type: string
      default: openshift-operators
    - name: REGISTRY
      description: Kubernetes registry to get operators from
      type: string
      default: icr.io/
    - name: CASE_INVENTORY
      description: Inventory to deploy
      type: string
  steps:
    - env:
        - name: HOME
          value: /tekton/home
        - name: CASE_NAME
          value: $(params.CASE_NAME)
        - name: CASE_VERSION
          value: $(params.CASE_VERSION)
        - name: ARCHITECTURE
          value: $(params.ARCHITECTURE)
        - name: CATALOG_NAMESPACE
          value: $(parms.CATALOG_NAMESPACE)
        - name: OPERATOR_NAMESPACE
          value: $(params.OPERATOR_NAMESPACE)
        - name: REGISTRY
          value: $(params.REGISTRY)
        - name: INVENTORY
          value: $(params.CASE_INVENTORY)
      image: >-
        quay.io/congxdev/ibm-pak-ubi:latest
      name: oc
      resources: {}
      script: |
        #!/usr/bin/env bash

        mkdir ~/case && cd ~/case

        [[ "$(workspaces.manifest-dir.bound)" == "true" ]] && \
        cd $(workspaces.manifest-dir.path)

        [[ "$(workspaces.kubeconfig-dir.bound)" == "true" ]] && \
        [[ -f $(workspaces.kubeconfig-dir.path)/kubeconfig ]] && \
        export KUBECONFIG=$(workspaces.kubeconfig-dir.path)/kubeconfig

        oc ibm-pak get $CASE_NAME --version $CASE_VERSION
        oc ibm-pak generate online-manifests $CASE_NAME --version $CASE_VERSION

        oc ibm-pak launch $CASE_NAME --version $CASE_VERSION --action install-catalog --inventory $INVENTORY --namespace $OPERATOR_NAMESPACE -r "--registry $REGISTRY"
        oc ibm-pak launch $CASE_NAME --version $CASE_VERSION --action install-operator --inventory $INVENTORY --namespace $OPERATOR_NAMESPACE

        $(params.SCRIPT)
      securityContext:
        runAsNonRoot: true
        runAsUser: 65532
  workspaces:
    - description: >-
        The workspace which contains kubernetes manifests which we want to apply
        on the cluster.
      name: manifest-dir
      optional: true
    - description: >-
        The workspace which contains the the kubeconfig file if in case we want
        to run the oc command on another cluster.
      name: kubeconfig-dir
      optional: true
