crossplane-contrib / crossplane-contrib/function-environment-configs

Add transform support to EnvironmentConfig label selectors

Open
#100 0 comments 0 reactions 0 assignees View on GitHub
enhancement
Dominant language
Go
Stars
28
Forks
25
Avg merge
5d 19h
Merged PRs (30d)
2

Description

### What problem are you facing?

When using `EnvironmentConfig` selectors with `valueFromFieldPath`, the raw field value is used directly as the label match value. There is no way to transform or manipulate the value before matching. This is limiting in real-world scenarios where the composite resource field values don't directly correspond to EnvironmentConfig label values.

For example, if a claim is submitted from namespace `team-alpha` and the EnvironmentConfig is labeled `config: alpha-environment-config`, there's currently no way to extract `alpha` from `team-alpha` and concatenate it with `-environment-config` to form the label match value. Users are forced to either restructure their labeling scheme or use additional intermediate resources.

`function-patch-and-transform` already supports transforms during patch resolution, but `function-environment-configs` has no equivalent capability for label selector values.

### How could this Function help solve your problem?

Add transform support to `matchLabels` selectors, allowing field path values to be transformed before being used as label match values. A subset of transforms from `function-patch-and-transform` that produce valid Kubernetes label values would cover the majority of use cases:

- **Map** — value lookup (e.g. `production` → `prod`)
- **Match** — pattern-based matching with fallback
- **String transforms** — Format, Convert (ToUpper/ToLower), TrimPrefix, TrimSuffix, Regexp (group extract + replace with backreferences), Replace

Example usage:
```yaml
matchLabels:
- key: config
valueFromFieldPath: "metadata.labels[crossplane.io/claim-namespace]"
transforms:
- type: string
string:
type: Regexp
regexp:
match: "^team-(.+)$"
replace: "${1}-environment-config"
```

This would also support reading from metadata fields using bracket notation (e.g. `metadata.labels[crossplane.io/claim-namespace]`) and handling non-string field types (booleans, numbers) by using `GetValue()` instead of `GetString()`.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.