Using Metadata Labels and CEL Expressions
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.
Using Expressions with PluginPresets
Expressions are particularly powerful with PluginPresets, allowing you 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: prometheus.remoteWrite.url
expression: "https://thanos.${global.greenhouse.metadata.region}.example.com/api/v1/receive"
- name: grafana.dashboards.annotations
expression: |
cluster: ${global.greenhouse.clusterName}
region: ${global.greenhouse.metadata.region}
environment: ${global.greenhouse.metadata.environment}
This PluginPreset will:
- Select all clusters with the
metadata.greenhouse.sap/tier: premiumlabel - Create a Plugin for each matching cluster
- Resolve expressions using each cluster’s specific metadata
Available Variables
The following global.greenhouse.* variables are available in expressions:
| Variable | Description |
|---|---|
global.greenhouse.clusterName | The name of the target cluster |
global.greenhouse.organizationName | The name of the organization |
global.greenhouse.baseDomain | DNS base domain for Greenhouse |
global.greenhouse.ownedBy | The owning team of the Plugin |
global.greenhouse.metadata.* | Cluster metadata labels |
⚠️
global.greenhouse.clusterNamesandglobal.greenhouse.teamNameswere 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.