Skip to content

Commit a0fdf43

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

File tree

1 file changed

+38
-4
lines changed

1 file changed

+38
-4
lines changed

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

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,10 @@ sets in the hub clusters. Then we can move on and create a placement in the
6060

6161
### Predicates
6262

63-
#### Label/Claim selection
63+
In the `predicates` section, you can select clusters by labels, [clusterClaims](../cluster-inventory/clusterclaim), or CEL expressions.
64+
65+
#### Label or ClusterClaim Selection
6466

65-
In the `predicates` section, you can select clusters by labels or [clusterClaims](../cluster-inventory/clusterclaim).
6667
For instance, you can select 3 clusters with label `purpose=test` and
6768
clusterClaim `platform.open-cluster-management.io=aws` as seen in the following
6869
examples:
@@ -72,7 +73,7 @@ apiVersion: cluster.open-cluster-management.io/v1beta1
7273
kind: Placement
7374
metadata:
7475
name: placement1
75-
namespace: default
76+
namespace: ns1
7677
spec:
7778
numberOfClusters: 3
7879
clusterSets:
@@ -94,6 +95,39 @@ Note that the distinction between label-selecting and claim-selecting is
9495
elaborated in [this page]({{< ref "docs/scenarios/extending-managed-clusters" >}})
9596
about how to extend attributes for the managed clusters.
9697
98+
#### CEL Expression Selection
99+
100+
```yaml
101+
apiVersion: cluster.open-cluster-management.io/v1beta1
102+
kind: Placement
103+
metadata:
104+
name: placement1
105+
namespace: ns1
106+
spec:
107+
numberOfClusters: 3
108+
clusterSets:
109+
- prod
110+
predicates:
111+
- requiredClusterSelector:
112+
celSelector:
113+
celExpressions:
114+
# Select clusters by Kubernetes version listed in managedCluster.Status.version.kubernetes.
115+
- managedCluster.status.version.kubernetes == "v1.31.0"
116+
# Select clusters by info stored in clusterClaims.
117+
- managedCluster.status.clusterClaims.exists(c, c.name == "kubeversion.open-cluster-management.io" && c.value == "v1.31.0")
118+
# Use CEL Standard macros and Standard functions on the managedCluster fields.
119+
- managedCluster.metadata.labels["version"].matches('^1\\.(30|31)\\.\\d+$')
120+
# Use Kubernetes semver library functions isLessThan and isGreaterThan to select clusters by version comparison.
121+
- semver(managedCluster.metadata.labels["version"]).isGreaterThan(semver("1.30.0"))
122+
# Use OCM customized function scores to select clusters by AddonPlacementScore.
123+
- managedCluster.scores("resource-usage-score").filter(s, s.name == 'memNodeAvailable').all(e, e.value > 0)
124+
```
125+
126+
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:
127+
128+
- [Kubernetes CEL Documentation](https://kubernetes.io/docs/reference/using-api/cel/)
129+
- [OCM CEL Library](https://github.com/open-cluster-management-io/sdk-go/tree/main/pkg/cel/library)
130+
97131
#### Taints/Tolerations
98132
99133
To support filtering unhealthy/not-reporting clusters and keep workloads from
@@ -133,7 +167,7 @@ The following example shows how to tolerate clusters with taints.
133167
timeAdded: '2022-02-21T08:11:06Z'
134168
```
135169
136-
By default, the placement wont select this cluster unless you define tolerations.
170+
By default, the placement won't select this cluster unless you define tolerations.
137171
138172
```yaml
139173
apiVersion: cluster.open-cluster-management.io/v1beta1

0 commit comments

Comments
 (0)