Using Metadata Labels and CEL Expressions

Use cluster metadata labels and CEL expressions to create dynamic Plugin configurations.

Overview

Greenhouse allows you to define metadata labels on Clusters and use them in PluginPreset configurations through CEL (Common Expression Language) expressions. This enables dynamic configuration of Plugins based on cluster-specific attributes like region, environment, or any custom metadata.

For information on setting metadata labels on Clusters, see Setting Metadata Labels.

Prerequisites

The feature flag pluginPreset.expressionEvaluationEnabled must be enabled in your Greenhouse installation. It is off by default, see Feature Flags.

Using Expressions with PluginPresets

Expressions can be used in the optionValues of a PluginPreset to deploy Plugins to multiple clusters with cluster-specific configurations:

apiVersion: greenhouse.sap/v1alpha1
kind: PluginPreset
metadata:
  name: monitoring-preset
  namespace: example-organization
spec:
  clusterSelector:
    matchLabels:
      metadata.greenhouse.sap/tier: premium
  plugin:
    pluginDefinitionRef:
      kind: PluginDefinition
      name: kube-monitoring
    releaseNamespace: monitoring
    optionValues:
      - name: kubeMonitoring.prometheus.ingress.enabled
        value: true
      - name: kubeMonitoring.prometheus.ingress.hosts
        expression: |
          - prometheus.${global.greenhouse.clusterName}.example.com          
      - name: global.commonLabels
        expression: |
          cluster: ${global.greenhouse.clusterName}
          region: ${global.greenhouse.metadata.region}
          environment: ${global.greenhouse.metadata.environment}          

This PluginPreset will:

  1. Select all clusters with the metadata.greenhouse.sap/tier: premium label
  2. Create a Plugin for each matching cluster
  3. Resolve expressions using each cluster’s specific metadata

The Plugin created for a cluster named cluster-a with the labels metadata.greenhouse.sap/region: eu-de-1 and metadata.greenhouse.sap/environment: production contains the resolved values:

spec:
  optionValues:
    - name: kubeMonitoring.prometheus.ingress.enabled
      value: true
    - name: kubeMonitoring.prometheus.ingress.hosts
      value:
        - prometheus.cluster-a.example.com
    - name: global.commonLabels
      value:
        cluster: cluster-a
        region: eu-de-1
        environment: production

See CEL Expressions in OptionValues for more details.

Available Variables

The following global.greenhouse.* variables are available in expressions:

VariableDescription
global.greenhouse.clusterNameThe name of the target cluster
global.greenhouse.organizationNameThe name of the organization
global.greenhouse.baseDomainDNS base domain for Greenhouse
global.greenhouse.ownedByThe owning team of the Plugin
global.greenhouse.metadata.*Cluster metadata labels

⚠️ global.greenhouse.clusterNames and global.greenhouse.teamNames were removed. An expression still referencing either of them fails to evaluate and blocks the PluginPreset from rolling out its Plugins. See Injected Greenhouse Values.

Using CEL Functions

CEL string functions can transform values:

optionValues:
  # Convert to uppercase
  - name: clusterLabel
    expression: ${global.greenhouse.clusterName.upperAscii()}

  # Split and rejoin with different delimiter
  - name: normalizedName
    expression: ${global.greenhouse.clusterName.split('-').join('_')}

  # Check if environment contains a substring
  - name: isProduction
    expression: ${global.greenhouse.metadata.environment.contains('prod')}

For a complete list of available CEL string functions, see the CEL string extension documentation.

Next Steps