apiVersion: core.oam.dev/v1beta1
kind: TraitDefinition
metadata:
  annotations:
    definition.oam.dev/description: "Add virtual group labels"
  name: virtualgroup
spec:
  appliesToWorkloads:
    - deployments.apps
  podDisruptive: true
  extension:
    template: |-
      patch: {
          spec: template: {
              metadata: labels: {
                  if parameter.type == "namespace" {
                      "app.namespace.virtual.group": parameter.group
                  }
                  if parameter.type == "cluster" {
                      "app.cluster.virtual.group": parameter.group
                  }
              }
          }
      }
      parameter: {
          group: *"default" | string
          type:  *"namespace" | string
      }
