Skip to content

Commit af2bed5

Browse files
committed
add placement cel examples
Signed-off-by: Qing Hao <[email protected]>
1 parent aab6cc7 commit af2bed5

File tree

1 file changed

+39
-3
lines changed

1 file changed

+39
-3
lines changed

content/en/docs/concepts/content-placement/placement.md

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,10 @@ sets in the hub clusters. Then we can move on and create a placement in the
6262

6363
#### Label/Claim selection
6464

65-
In the `predicates` section, you can select clusters by labels or [clusterClaims](../cluster-inventory/clusterclaim).
65+
In the `predicates` section, you can select clusters by labels, [clusterClaims](../cluster-inventory/clusterclaim), or CEL expressions.
66+
67+
1. Using labels and clusterClaims:
68+
6669
For instance, you can select 3 clusters with label `purpose=test` and
6770
clusterClaim `platform.open-cluster-management.io=aws` as seen in the following
6871
examples:
@@ -72,7 +75,7 @@ apiVersion: cluster.open-cluster-management.io/v1beta1
7275
kind: Placement
7376
metadata:
7477
name: placement1
75-
namespace: default
78+
namespace: ns1
7679
spec:
7780
numberOfClusters: 3
7881
clusterSets:
@@ -94,6 +97,39 @@ Note that the distinction between label-selecting and claim-selecting is
9497
elaborated in [this page]({{< ref "docs/scenarios/extending-managed-clusters" >}})
9598
about how to extend attributes for the managed clusters.
9699
100+
2. Using CEL expressions:
101+
102+
```yaml
103+
apiVersion: cluster.open-cluster-management.io/v1beta1
104+
kind: Placement
105+
metadata:
106+
name: placement1
107+
namespace: ns1
108+
spec:
109+
numberOfClusters: 3
110+
clusterSets:
111+
- prod
112+
predicates:
113+
- requiredClusterSelector:
114+
celSelector:
115+
celExpressions:
116+
# Select clusters by Kubernetes version listed in managedCluster.Status.version.kubernetes.
117+
- managedCluster.status.version.kubernetes == "v1.31.0"
118+
# Select clusters by info stored in clusterClaims.
119+
- managedCluster.status.clusterClaims.exists(c, c.name == "kubeversion.open-cluster-management.io" && c.value == "v1.31.0")
120+
# Use CEL Standard macros and Standard functions on the managedCluster fields.
121+
- managedCluster.metadata.labels["version"].matches('^1\\.(30|31)\\.\\d+$')
122+
# Use Kubernetes semver library functions isLessThan and isGreaterThan to select clusters by version comparison.
123+
- semver(managedCluster.metadata.labels["version"]).isGreaterThan(semver("1.30.0"))
124+
# Use OCM customized function scores to select clusters by AddonPlacementScore.
125+
- managedCluster.scores("resource-usage-score").filter(s, s.name == 'memNodeAvailable').all(e, e.value > 0)
126+
```
127+
128+
The CEL expressions provide more flexible and powerful selection capabilities with [built-in libraries](https://github.com/open-cluster-management-io/sdk-go/blob/main/pkg/cel/common/values.go). For more detailed usage of CEL expressions, refer to:
129+
130+
- [Kubernetes CEL Documentation](https://kubernetes.io/docs/reference/using-api/cel/)
131+
- [OCM CEL Library](https://github.com/open-cluster-management-io/sdk-go/tree/main/pkg/cel/library)
132+
97133
#### Taints/Tolerations
98134
99135
To support filtering unhealthy/not-reporting clusters and keep workloads from
@@ -133,7 +169,7 @@ The following example shows how to tolerate clusters with taints.
133169
timeAdded: '2022-02-21T08:11:06Z'
134170
```
135171
136-
By default, the placement wont select this cluster unless you define tolerations.
172+
By default, the placement won't select this cluster unless you define tolerations.
137173
138174
```yaml
139175
apiVersion: cluster.open-cluster-management.io/v1beta1

0 commit comments

Comments
 (0)