Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
87 changes: 85 additions & 2 deletions content/en/docs/concepts/override.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.

Comment on lines +101 to +105
Copy link

Copilot AI Feb 11, 2026

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.md and v1beta1.md). Please update/regenerate the API reference so it matches the documented behavior and users can discover the new variable from the type docs.

Copilot uses AI. Check for mistakes.
#### 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
Expand Down Expand Up @@ -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
Copy link

Copilot AI Feb 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This ResourceOverride example uses op: add at /metadata/annotations with an object value, which replaces the entire annotations map and can delete existing annotations. If the intent is to add these annotations while preserving existing ones, patch the individual keys under /metadata/annotations/... or clarify that this overwrites all annotations.

Suggested change
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}"

Copilot uses AI. Check for mistakes.
Copy link
Member Author

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

```

When applied to a cluster with labels `region: us-west` and `env: production`, the deployment will receive the
annotations `target-region: us-west` and `target-env: production`.

You can also combine multiple variables in a single value. For example:

```yaml
jsonPatchOverrides:
- op: replace
path: /spec/template/spec/containers/0/image
value: "myregistry-${MEMBER-CLUSTER-LABEL-KEY-region}.example.com/my-app:${MEMBER-CLUSTER-LABEL-KEY-env}"
```

On a cluster with `region: us-west` and `env: staging`, this would resolve to
`myregistry-us-west.example.com/my-app:staging`.

## When To Trigger Rollout

It will take the snapshot of each override change as a result of `ClusterResourceOverrideSnapshot` and
Expand Down
46 changes: 45 additions & 1 deletion content/en/docs/how-tos/cluster-resource-override.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Copy link

Copilot AI Feb 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This example adds annotations by patching /metadata/annotations with an object value. That operation sets/replaces the whole annotations map and can remove any existing annotations on the ClusterRole. If you mean to append keys, patch /metadata/annotations/target-region and /metadata/annotations/target-env (or clarify that this overwrites existing annotations).

Suggested change
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}"

Copilot uses AI. Check for mistakes.
```

On a cluster with labels `region: us-west` and `env: production`, the annotations will be set to
`target-region: us-west` and `target-env: production`.

##### Example: Remove Verbs

To remove the verb "list" in the `ClusterRole` named `secret-reader` on clusters with the label `env: prod`,
Expand Down
50 changes: 49 additions & 1 deletion content/en/docs/how-tos/resource-override.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Copy link

Copilot AI Feb 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this YAML example, the list item under resourceSelectors uses - group: apps with an extra space after -, which also misaligns the following keys (kind, version, name) and can make the snippet invalid YAML in some parsers. Use consistent indentation (e.g., - group: apps) so all keys in the mapping align.

Suggested change
- group: apps
- group: apps

Copilot uses AI. Check for mistakes.
kind: Deployment
version: v1
name: my-deployment
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 +246 to +248
Copy link

Copilot AI Feb 11, 2026

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.

Suggested change
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}"

Copilot uses AI. Check for mistakes.
```

When applied to a cluster with labels `region: us-west` and `env: production`, the deployment will receive the
annotations `target-region: us-west` and `target-env: production`.

You can also combine multiple variables in a single value. For example, to construct a container image path
from cluster labels:

```yaml
jsonPatchOverrides:
- op: replace
path: /spec/template/spec/containers/0/image
value: "myregistry-${MEMBER-CLUSTER-LABEL-KEY-region}.example.com/my-app:${MEMBER-CLUSTER-LABEL-KEY-env}"
```

On a cluster with `region: us-west` and `env: staging`, this would resolve to
`myregistry-us-west.example.com/my-app:staging`.

##### Example: Override Image

To override the image of the container in the `Deployment` named `my-deployment` on all clusters with the label `env: prod`:
Expand Down