metadata:
  name: helmExecute
  description: Executes helm3 functionality as the package manager for Kubernetes.
  longDescription: |-
    Alpha version: please expect incompatible changes

    Executes helm functionality as the package manager for Kubernetes.

    * [Helm](https://helm.sh/)  is the package manager for Kubernetes.
    * [Helm documentation https://helm.sh/docs/intro/using_helm/ and best practies https://helm.sh/docs/chart_best_practices/conventions/]
    * [Helm Charts] (https://artifacthub.io/)
    ```
    Available Commands:
    `upgrade`, `lint`, `install`, `test`, `uninstall`, `dependency`, `publish`

      upgrade       upgrade a release
      lint          examine a chart for possible issues
      install       install a chart
      test          run tests for a release
      uninstall     uninstall a release
      dependency     package a chart directory into a chart archive
      publish       package and puslish a release

    ```

    Note: piper supports only helm3 version, since helm2 is deprecated.
spec:
  inputs:
    secrets:
      - name: kubeConfigFileCredentialsId
        description: Jenkins 'Secret file' credentials ID containing kubeconfig file. Details can be found in the [Kubernetes documentation](https://kubernetes.io/docs/concepts/configuration/organize-cluster-access-kubeconfig/).
        aliases:
          - name: kubeCredentialsId
            deprecated: true
        type: jenkins
      - name: dockerConfigJsonCredentialsId
        description: Jenkins 'Secret file' credentials ID containing Docker config.json (with registry credential(s)).
        type: jenkins
      - name: targetRepositoryCredentialsId
        description: Jenkins 'Username Password' credentials ID containing username and password for the Helm Repository authentication
        type: jenkins
    resources:
      - name: deployDescriptor
        type: stash
    params:
      - name: additionalParameters
        aliases:
          - name: helmDeploymentParameters
        type: "[]string"
        description: Defines additional parameters for Helm like  "helm install [NAME] [CHART] [flags]".
        scope:
          - PARAMETERS
          - STAGES
          - STEPS
      - name: chartPath
        aliases:
          - name: helmChartPath
        type: string
        description: Defines the chart path for helm. chartPath is mandatory for install/upgrade/publish commands.
        scope:
          - PARAMETERS
          - STAGES
          - STEPS
      - name: targetRepositoryURL
        description: "URL of the target repository where the compiled helm .tgz archive shall be uploaded - typically provided by the CI/CD environment."
        type: string
        scope:
          - PARAMETERS
          - STAGES
          - STEPS
        resourceRef:
          - name: commonPipelineEnvironment
            param: custom/helmRepositoryURL
          - name: commonPipelineEnvironment
            param: custom/repositoryUrl
      - name: targetRepositoryName
        type: string
        description: set the chart repository. The value is required for install/upgrade/uninstall commands.
        scope:
          - GENERAL
          - PARAMETERS
          - STAGES
          - STEPS
      - name: targetRepositoryUser
        aliases:
          - name: helmRepositoryUsername
        description: "Username for the chart repository where the compiled helm .tgz archive shall be uploaded - typically provided by the CI/CD environment."
        type: string
        scope:
          - PARAMETERS
          - STAGES
          - STEPS
        secret: true
        resourceRef:
          - name: targetRepositoryCredentialsId
            type: secret
            param: username
          - type: vaultSecret
            name: targetRepositoryUserSecretName
            default: publishing
          - name: commonPipelineEnvironment
            param: custom/helmRepositoryUsername
          - name: commonPipelineEnvironment
            param: custom/repositoryUsername
      - name: targetRepositoryPassword
        aliases:
          - name: helmRepositoryPassword
        description: "Password for the target repository where the compiled helm .tgz archive shall be uploaded - typically provided by the CI/CD environment."
        type: string
        scope:
          - PARAMETERS
          - STAGES
          - STEPS
        secret: true
        resourceRef:
          - name: targetRepositoryCredentialsId
            type: secret
            param: password
          - type: vaultSecret
            name: targetRepositoryPasswordSecret
            default: publishing
          - name: commonPipelineEnvironment
            param: custom/helmRepositoryPassword
          - name: commonPipelineEnvironment
            param: custom/repositoryPassword
      - name: helmDeployWaitSeconds
        type: int
        description: Number of seconds before helm deploy returns.
        scope:
          - PARAMETERS
          - STAGES
          - STEPS
        default: 300
      - name: helmValues
        type: "[]string"
        description: List of helm values as YAML file reference or URL (as per helm parameter description for `-f` / `--values`)
        scope:
          - PARAMETERS
          - STAGES
          - STEPS
      - name: image
        aliases:
          - name: deployImage
        type: string
        description: Full name of the image to be deployed.
        resourceRef:
          - name: commonPipelineEnvironment
            param: container/imageNameTag
        mandatory: true
        scope:
          - PARAMETERS
          - STAGES
          - STEPS
      - name: keepFailedDeployments
        type: bool
        description: Defines whether a failed deployment will be purged
        default: false
        scope:
          - GENERAL
          - PARAMETERS
          - STAGES
          - STEPS
      - name: kubeConfig
        type: string
        description: Defines the path to the "kubeconfig" file.
        scope:
          - GENERAL
          - PARAMETERS
          - STAGES
          - STEPS
        secret: true
        resourceRef:
          - name: kubeConfigFileCredentialsId
            type: secret
          - type: vaultSecretFile
            name: kubeConfigFileVaultSecretName
            default: kube-config
      - name: kubeContext
        type: string
        description: Defines the context to use from the "kubeconfig" file.
        scope:
          - PARAMETERS
          - STAGES
          - STEPS
      - name: namespace
        aliases:
          - name: helmDeploymentNamespace
        type: string
        description: Defines the target Kubernetes namespace for the deployment.
        scope:
          - PARAMETERS
          - STAGES
          - STEPS
        default: default
      - name: dockerConfigJSON
        type: string
        description: Path to the file `.docker/config.json` - this is typically provided by your CI/CD system. You can find more details about the Docker credentials in the [Docker documentation](https://docs.docker.com/engine/reference/commandline/login/).
        scope:
          - PARAMETERS
          - STAGES
          - STEPS
        secret: true
        resourceRef:
          - name: dockerConfigJsonCredentialsId
            type: secret
          - type: vaultSecretFile
            name: dockerConfigFileVaultSecretName
            default: docker-config
      - name: helmCommand
        type: string
        description: "Helm: defines the command `upgrade`, `lint`, `install`, `test`, `uninstall`, `dependency`, `publish`."
        scope:
          - PARAMETERS
          - STAGES
          - STEPS
        possibleValues:
          - upgrade
          - lint
          - install
          - test
          - uninstall
          - dependency
          - publish
      - name: appVersion
        type: string
        description: set the appVersion on the chart to this version
        scope:
          - GENERAL
          - PARAMETERS
          - STAGES
          - STEPS
      - name: dependency
        type: string
        description: "manage a chart's dependencies"
        scope:
          - PARAMETERS
          - STAGES
          - STEPS
        possibleValues:
          - build
          - list
          - update
      - name: packageDependencyUpdate
        type: bool
        description: update dependencies from "Chart.yaml" to dir "charts/" before packaging
        default: false
        scope:
          - GENERAL
          - PARAMETERS
          - STAGES
          - STEPS
      - name: dumpLogs
        type: bool
        description: dump the logs from test pods (this runs after all tests are complete, but before any cleanup)
        default: false
        scope:
          - GENERAL
          - PARAMETERS
          - STAGES
          - STEPS
      - name: filterTest
        type: string
        description: specify tests by attribute (currently `name`) using attribute=value syntax or `!attribute=value` to exclude a test (can specify multiple or separate values with commas `name=test1,name=test2`)
        scope:
          - GENERAL
          - PARAMETERS
          - STAGES
          - STEPS
      - name: customTlsCertificateLinks
        type: "[]string"
        description: "List of download links to custom TLS certificates. This is required to ensure trusted connections to instances with repositories (like nexus) when publish flag is set to true."
        scope:
          - GENERAL
          - PARAMETERS
          - STAGES
          - STEPS
      - name: publish
        type: bool
        description: Configures helm to run the deploy command to publish artifacts to a repository.
        default: false
        scope:
          - GENERAL
          - PARAMETERS
          - STAGES
          - STEPS
      - name: version
        type: string
        description: Defines the artifact version to use from helm package/publish commands.
        scope:
          - GENERAL
          - PARAMETERS
          - STAGES
          - STEPS
  containers:
    - image: dtzar/helm-kubectl:3.8.0
      workingDir: /config
      options:
        - name: -u
          value: "0"
  outputs:
    resources:
      - name: commonPipelineEnvironment
        type: piperEnvironment
        params:
          - name: custom/helmChartUrl
