-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Backport 6.2] Add regexp.replace support in role templates (#7250)
- Loading branch information
Showing
5 changed files
with
211 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -281,8 +281,10 @@ spec: | |
# Functions transform variables. | ||
database_users: ['{{email.local(external.email)}}'] | ||
database_labels: | ||
'env': '{{regexp.replace(external.access["env"], "^(staging)$", "$1")}}' | ||
# Labels can mix template and hard-coded values | ||
# Labels can mix template and hard-coded values. | ||
node_labels: | ||
'env': '{{external.access["env"]}}' | ||
'region': 'us-west-2' | ||
|
@@ -311,14 +313,25 @@ spec: | |
# The variable external.groups gets replaced with a list. | ||
kubernetes_groups: ['devs', 'admins'] | ||
# The variable email.local will take a local part of the external.email attribute. | ||
# The function email.local will take a local part of the external.email attribute. | ||
database_users: ['alice'] | ||
# Node labels have 'env' replaced from a variable | ||
# The function regexp.replace will transform and filter only matching values. | ||
database_labels: | ||
'env': 'staging' | ||
# Node labels have 'env' replaced from a variable and 'region' hard-coded. | ||
node_labels: | ||
'env': ['prod', 'staging'] | ||
'region': 'us-west-2' | ||
kubernetes_labels: | ||
'*': '*' | ||
``` | ||
|
||
Available interpolation functions include: | ||
|
||
Function | Description | ||
--- | --- | ||
`email.local(variable)` | Extracts the local part of an email field, like `Alice <[email protected]>` or `[email protected]`. | ||
`regexp.replace(variable, expression, replacement)` | Finds all matches of `expression` and replaces them with `replacement`. This supports expansion, e.g. `regexp.replace(external.email, "^(.*)@example.com$", "$1")`. Values which do not match the expression will be filtered out. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters