Skip to content

Dynamic input for GitOpsTemplates #1758

Open
@sympatheticmoose

Description

WIP

As a Template author, I want to be able to define a parameter which can be set based on a response from a query to a WGE API, for example to select a Cluster from a returned set of GitOpsCluster objects.

As a Template author, I can easily discover available APIs which would be useful in Template authoring.

As a Template user, I want to create a resource which references existing installed components available to me, to simplify filling out a template, to reduce the chance of inputting incorrect values, and to help simplify adherence to RBAC.

Example based on Pipeline Template
A Pipeline references both an Application (HelmRelease) and set of DeploymentTargets (GitOpsCluster + Application Namespace). GitOpsClusters can be hardcoded into the template, including as set options, requiring the Template author to ensure these are valid, or specified by the template user as a string value, requiring them to provide the correct name and namespace combinations (error-prone).

This feature would allow for the values to be set based on a response to an API query, therefore making it easier to correctly pass on the values into the template form.

Below is for illustrative purposes only, showing how a team could specify their Dev Cluster for the application, but staging and production remain hardcoded as more stable and shared environments.

apiVersion: clustertemplates.weave.works/v1alpha1
kind: GitOpsTemplate
metadata:
  name: pipeline
  namespace: default
annotations: 
  templates.weave.works/profiles-enabled: true
  templates.weave.works/kustomizations-enabled: true
  templates.weave.works/credentials-enabled: true
labels:
  weave.works/template-type: pipeline
spec:
  description: Creates an application Pipeline
  params:
  #metadata
    - name: PIPELINE_NAME
      description: Name of Pipeline
    - name: PIPELINE_NAMESPACE
      description: Namespace for the Pipeline
  #Appdata
    - name: APP_NAME
      description: Name of the HelmRelease for your application
    - name: APP_NAMESPACE
      description: Namespace for the HelmRelease
    - name: APP_REPO_URL
      description: URL for source of HelmRelease in Git
    - name: APP_REPO_BRANCH
      description: Branch to write updates to in Git
    - name: GIT_TOKEN_SECRET
      description: Name of the secret containing PAT for Git
 #Environments 
   - name: DEV_CLUSTER
     description: Development Cluster where the application is deployed
     query: clusters #Maps to https://<dashboard>/v1/clusters, UI shows a drop down menu similar to Add App today
     values: #based on user selection of a returned object, these values become accessible in the template
        DEV_CLUSTER.NAME: "gitopsClusters.name"
        DEV_CLUSTER.NAMESPACE: "gitopsClusters.namespace"
resourcetemplates:
- apiVersion: pipelines.weave.works/v1alpha1
  kind: ${PIPELINE_NAME}
  metadata:
    name: ${PIPELINE_NAME}
    namespace: ${PIPELINE_NAMESPACE}
  spec:
    appRef:
      apiVersion: helm.toolkit.fluxcd.io/v2beta1
      kind: HelmRelease
      name: ${APP_NAME}
    environments:
    - name: dev
      targets:
        - namespace: ${APP_NAMESPACE}
          clusterRef:
            kind: GitopsCluster
            name: ${ DEV_CLUSTER.NAME}
            namespace: ${DEV_CLUSTER.NAMESPACE}
    - name: stage
      targets:
        - namespace: ${APP_NAMESPACE}
          clusterRef:
            kind: GitopsCluster
            name: QA
            namespace: flux-system
    - name: prod
      targets:
        - namespace: ${APP_NAMESPACE}
          clusterRef:
            kind: GitopsCluster
            name: prod
            namespace: flux-system
  promotion:
    pull-request:
      branch: ${APP_REPO_BRANCH}
      secretRef:
        name: ${GIT_TOKEN_SECRET}
      url: ${APP_REPO_URL}

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions