-
Notifications
You must be signed in to change notification settings - Fork 12
doc: add the label override doc #71
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -98,9 +98,14 @@ Each override rule contains the following fields: | |||||||||||||||||
|
|
||||||||||||||||||
| There is a list of reserved variables that will be replaced by the actual values used in the `value` of the JSON patch override rule: | ||||||||||||||||||
|
|
||||||||||||||||||
| - `${MEMBER-CLUSTER-NAME}`: this will be replaced by the name of the `memberCluster` that represents this cluster. | ||||||||||||||||||
| - `${MEMBER-CLUSTER-NAME}`: this will be replaced by the name of the `memberCluster` that represents this cluster. | ||||||||||||||||||
| - `${MEMBER-CLUSTER-LABEL-KEY-<label-key>}`: this will be replaced by the value of the label with the key `<label-key>` on the `memberCluster`. For example, `${MEMBER-CLUSTER-LABEL-KEY-region}` will be replaced by the value of the `region` label on the target member cluster. If the label does not exist on the cluster, the override will fail with an error. | ||||||||||||||||||
|
|
||||||||||||||||||
| For example, to add a label to the `ClusterRole` named `secret-reader` on clusters with the label `env: prod`, | ||||||||||||||||||
| These variables are supported in both `ClusterResourceOverride` and `ResourceOverride`. | ||||||||||||||||||
|
|
||||||||||||||||||
| #### Example: Using `${MEMBER-CLUSTER-NAME}` in a `ClusterResourceOverride` | ||||||||||||||||||
|
|
||||||||||||||||||
| To add a label to the `ClusterRole` named `secret-reader` on clusters with the label `env: prod`, | ||||||||||||||||||
| you can use the following configuration: | ||||||||||||||||||
|
|
||||||||||||||||||
| ```yaml | ||||||||||||||||||
|
|
@@ -132,6 +137,84 @@ spec: | |||||||||||||||||
|
|
||||||||||||||||||
| The `ClusterResourceOverride` object above will add a label `cluster-name` with the value of the `memberCluster` name to the `ClusterRole` named `secret-reader` on clusters with the label `env: prod`. | ||||||||||||||||||
|
|
||||||||||||||||||
| #### Example: Using `${MEMBER-CLUSTER-LABEL-KEY-...}` in a `ClusterResourceOverride` | ||||||||||||||||||
|
|
||||||||||||||||||
| Suppose you have member clusters with a `region` label (e.g., `region: us-west`, `region: eu-central`) and you want | ||||||||||||||||||
| to add a label reflecting the cluster's region to a `ClusterRole`: | ||||||||||||||||||
|
|
||||||||||||||||||
| ```yaml | ||||||||||||||||||
| apiVersion: placement.kubernetes-fleet.io/v1alpha1 | ||||||||||||||||||
| kind: ClusterResourceOverride | ||||||||||||||||||
| metadata: | ||||||||||||||||||
| name: cro-region-label | ||||||||||||||||||
| spec: | ||||||||||||||||||
| placement: | ||||||||||||||||||
| name: crp-example | ||||||||||||||||||
| clusterResourceSelectors: | ||||||||||||||||||
| - group: rbac.authorization.k8s.io | ||||||||||||||||||
| kind: ClusterRole | ||||||||||||||||||
| version: v1 | ||||||||||||||||||
| name: secret-reader | ||||||||||||||||||
| policy: | ||||||||||||||||||
| overrideRules: | ||||||||||||||||||
| - clusterSelector: | ||||||||||||||||||
| clusterSelectorTerms: [] | ||||||||||||||||||
| jsonPatchOverrides: | ||||||||||||||||||
| - op: add | ||||||||||||||||||
| path: /metadata/labels/cluster-region | ||||||||||||||||||
| value: "${MEMBER-CLUSTER-LABEL-KEY-region}" | ||||||||||||||||||
| ``` | ||||||||||||||||||
|
|
||||||||||||||||||
| When applied to a cluster with the label `region: us-west`, the `ClusterRole` will receive the label | ||||||||||||||||||
| `cluster-region: us-west`. When applied to a cluster with `region: eu-central`, the label will be | ||||||||||||||||||
| `cluster-region: eu-central`. | ||||||||||||||||||
|
|
||||||||||||||||||
| #### Example: Using `${MEMBER-CLUSTER-LABEL-KEY-...}` in a `ResourceOverride` | ||||||||||||||||||
|
|
||||||||||||||||||
| You can also use cluster label variables in a `ResourceOverride` to customize namespace-scoped resources. | ||||||||||||||||||
| For example, suppose you have a `Deployment` named `my-app` in the namespace `app-ns`, and your member clusters | ||||||||||||||||||
| have `region` and `env` labels. You can inject those values as annotations: | ||||||||||||||||||
|
|
||||||||||||||||||
| ```yaml | ||||||||||||||||||
| apiVersion: placement.kubernetes-fleet.io/v1alpha1 | ||||||||||||||||||
| kind: ResourceOverride | ||||||||||||||||||
| metadata: | ||||||||||||||||||
| name: ro-label-vars | ||||||||||||||||||
| namespace: app-ns | ||||||||||||||||||
| spec: | ||||||||||||||||||
| placement: | ||||||||||||||||||
| name: crp-example | ||||||||||||||||||
| resourceSelectors: | ||||||||||||||||||
| - group: apps | ||||||||||||||||||
| kind: Deployment | ||||||||||||||||||
| version: v1 | ||||||||||||||||||
| name: my-app | ||||||||||||||||||
| policy: | ||||||||||||||||||
| overrideRules: | ||||||||||||||||||
| - clusterSelector: | ||||||||||||||||||
| clusterSelectorTerms: [] | ||||||||||||||||||
| jsonPatchOverrides: | ||||||||||||||||||
| - op: add | ||||||||||||||||||
| path: /metadata/annotations | ||||||||||||||||||
| value: | ||||||||||||||||||
| {"target-region":"${MEMBER-CLUSTER-LABEL-KEY-region}", "target-env":"${MEMBER-CLUSTER-LABEL-KEY-env}"} | ||||||||||||||||||
|
Comment on lines
+198
to
+200
|
||||||||||||||||||
| path: /metadata/annotations | |
| value: | |
| {"target-region":"${MEMBER-CLUSTER-LABEL-KEY-region}", "target-env":"${MEMBER-CLUSTER-LABEL-KEY-env}"} | |
| path: /metadata/annotations/target-region | |
| value: "${MEMBER-CLUSTER-LABEL-KEY-region}" | |
| - op: add | |
| path: /metadata/annotations/target-env | |
| value: "${MEMBER-CLUSTER-LABEL-KEY-env}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
where did you get this? This is actually wrong
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -133,7 +133,8 @@ The jsonPatchOverrides field supports the following fields: | |||||||||||||||||
| - `value`: The value to be set. | ||||||||||||||||||
| - If the `op` is `remove`, the value cannot be set. | ||||||||||||||||||
| - There is a list of reserved variables that will be replaced by the actual values: | ||||||||||||||||||
| - `${MEMBER-CLUSTER-NAME}`: this will be replaced by the name of the `memberCluster` that represents this cluster. | ||||||||||||||||||
| - `${MEMBER-CLUSTER-NAME}`: this will be replaced by the name of the `memberCluster` that represents this cluster. | ||||||||||||||||||
| - `${MEMBER-CLUSTER-LABEL-KEY-<label-key>}`: this will be replaced by the value of the label with the key `<label-key>` on the `memberCluster`. For example, `${MEMBER-CLUSTER-LABEL-KEY-region}` will be replaced by the value of the `region` label on the target member cluster. If the label does not exist on the cluster, the override will fail with an error. | ||||||||||||||||||
|
|
||||||||||||||||||
| ##### Example: Override Labels | ||||||||||||||||||
|
|
||||||||||||||||||
|
|
@@ -177,6 +178,49 @@ spec: | |||||||||||||||||
|
|
||||||||||||||||||
| The `ClusterResourceOverride` object above will add a label `cluster-name` with the value of the `memberCluster` name to the `ClusterRole` named `secret-reader` on clusters with the label `env: prod`. | ||||||||||||||||||
|
|
||||||||||||||||||
| ##### Example: Override Using Cluster Label Variables | ||||||||||||||||||
|
|
||||||||||||||||||
| To dynamically set a label based on a member cluster's `region` label, you can use the `${MEMBER-CLUSTER-LABEL-KEY-<label-key>}` variable. | ||||||||||||||||||
| For instance, if your member clusters have a label `region` with values like `us-west` or `eu-central`: | ||||||||||||||||||
|
|
||||||||||||||||||
| ```yaml | ||||||||||||||||||
| apiVersion: placement.kubernetes-fleet.io/v1alpha1 | ||||||||||||||||||
| kind: ClusterResourceOverride | ||||||||||||||||||
| metadata: | ||||||||||||||||||
| name: cro-region | ||||||||||||||||||
| spec: | ||||||||||||||||||
| placement: | ||||||||||||||||||
| name: crp-example | ||||||||||||||||||
| clusterResourceSelectors: | ||||||||||||||||||
| - group: rbac.authorization.k8s.io | ||||||||||||||||||
| kind: ClusterRole | ||||||||||||||||||
| version: v1 | ||||||||||||||||||
| name: secret-reader | ||||||||||||||||||
| policy: | ||||||||||||||||||
| overrideRules: | ||||||||||||||||||
| - clusterSelector: | ||||||||||||||||||
| clusterSelectorTerms: [] | ||||||||||||||||||
| jsonPatchOverrides: | ||||||||||||||||||
| - op: add | ||||||||||||||||||
| path: /metadata/labels/cluster-region | ||||||||||||||||||
| value: "${MEMBER-CLUSTER-LABEL-KEY-region}" | ||||||||||||||||||
| ``` | ||||||||||||||||||
|
|
||||||||||||||||||
| When applied to a cluster with the label `region: us-west`, the `ClusterRole` will receive the label `cluster-region: us-west`. | ||||||||||||||||||
|
|
||||||||||||||||||
| You can also use multiple label variables together. For example, to add annotations sourced from cluster labels: | ||||||||||||||||||
|
|
||||||||||||||||||
| ```yaml | ||||||||||||||||||
| jsonPatchOverrides: | ||||||||||||||||||
| - op: add | ||||||||||||||||||
| path: /metadata/annotations | ||||||||||||||||||
| value: | ||||||||||||||||||
| {"target-region":"${MEMBER-CLUSTER-LABEL-KEY-region}", "target-env":"${MEMBER-CLUSTER-LABEL-KEY-env}"} | ||||||||||||||||||
|
Comment on lines
+216
to
+218
|
||||||||||||||||||
| path: /metadata/annotations | |
| value: | |
| {"target-region":"${MEMBER-CLUSTER-LABEL-KEY-region}", "target-env":"${MEMBER-CLUSTER-LABEL-KEY-env}"} | |
| path: /metadata/annotations/target-region | |
| value: "${MEMBER-CLUSTER-LABEL-KEY-region}" | |
| - op: add | |
| path: /metadata/annotations/target-env | |
| value: "${MEMBER-CLUSTER-LABEL-KEY-env}" |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -171,7 +171,8 @@ The `jsonPatchOverrides` field supports the following fields: | |||||||||||||||||
| - `value`: The value to be set. | ||||||||||||||||||
| - If the `op` is `remove`, the value cannot be set. | ||||||||||||||||||
| - There is a list of reserved variables that will be replaced by the actual values: | ||||||||||||||||||
| - `${MEMBER-CLUSTER-NAME}`: this will be replaced by the name of the `memberCluster` that represents this cluster. | ||||||||||||||||||
| - `${MEMBER-CLUSTER-NAME}`: this will be replaced by the name of the `memberCluster` that represents this cluster. | ||||||||||||||||||
| - `${MEMBER-CLUSTER-LABEL-KEY-<label-key>}`: this will be replaced by the value of the label with the key `<label-key>` on the `memberCluster`. For example, `${MEMBER-CLUSTER-LABEL-KEY-region}` will be replaced by the value of the `region` label on the target member cluster. If the label does not exist on the cluster, the override will fail with an error. | ||||||||||||||||||
|
|
||||||||||||||||||
| ##### Example: Override Labels | ||||||||||||||||||
|
|
||||||||||||||||||
|
|
@@ -216,6 +217,53 @@ spec: | |||||||||||||||||
|
|
||||||||||||||||||
| The `ResourceOverride` object above will add a label `cluster-name` with the value of the `memberCluster` name to the `Deployment` named `example-ro` on clusters with the label `env: prod`. | ||||||||||||||||||
|
|
||||||||||||||||||
| ##### Example: Override Using Cluster Label Variables | ||||||||||||||||||
|
|
||||||||||||||||||
| To dynamically customize resources based on member cluster labels, you can use the `${MEMBER-CLUSTER-LABEL-KEY-<label-key>}` variable. | ||||||||||||||||||
| For instance, if your member clusters have labels such as `region: us-west` and `env: production`, you can inject | ||||||||||||||||||
| those values into a deployment's annotations: | ||||||||||||||||||
|
|
||||||||||||||||||
| ```yaml | ||||||||||||||||||
| apiVersion: placement.kubernetes-fleet.io/v1alpha1 | ||||||||||||||||||
| kind: ResourceOverride | ||||||||||||||||||
| metadata: | ||||||||||||||||||
| name: ro-label-vars | ||||||||||||||||||
| namespace: test-namespace | ||||||||||||||||||
| spec: | ||||||||||||||||||
| placement: | ||||||||||||||||||
| name: crp-example | ||||||||||||||||||
| resourceSelectors: | ||||||||||||||||||
| - group: apps | ||||||||||||||||||
|
||||||||||||||||||
| - group: apps | |
| - group: apps |
Copilot
AI
Feb 11, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This JSONPatch uses op: add at path /metadata/annotations with an object value, which will set/replace the entire annotations map and may unintentionally drop any existing annotations on the resource. If the intent is to add these keys non-destructively, patch individual keys (e.g., /metadata/annotations/target-region and /metadata/annotations/target-env) or explicitly call out in the text that existing annotations will be overwritten.
| path: /metadata/annotations | |
| value: | |
| {"target-region":"${MEMBER-CLUSTER-LABEL-KEY-region}", "target-env":"${MEMBER-CLUSTER-LABEL-KEY-env}"} | |
| path: /metadata/annotations/target-region | |
| value: "${MEMBER-CLUSTER-LABEL-KEY-region}" | |
| - op: add | |
| path: /metadata/annotations/target-env | |
| value: "${MEMBER-CLUSTER-LABEL-KEY-env}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These docs introduce
${MEMBER-CLUSTER-LABEL-KEY-<label-key>}, but the generated API reference pages still list only${MEMBER-CLUSTER-NAME}as a supported reserved variable (e.g.,content/en/docs/api-reference/placement.kubernetes-fleet.io/v1.mdandv1beta1.md). Please update/regenerate the API reference so it matches the documented behavior and users can discover the new variable from the type docs.