Skip to content

Commit ff18c2d

Browse files
committed
feat: expand conditions documentation and support facetable fields
1 parent 5dfc616 commit ff18c2d

File tree

1 file changed

+68
-5
lines changed

1 file changed

+68
-5
lines changed

docs/api-design.md

Lines changed: 68 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,25 +61,88 @@ kind: ResourceIndexPolicy
6161
metadata:
6262
name: organizations
6363
spec:
64+
# Identifies the resource type this policy applies to. Uses a versioned
65+
# reference since field paths may differ between API versions.
6466
targetResource:
6567
group: resourcemanager.miloapis.com
6668
version: v1alpha1
6769
kind: Organization
70+
71+
# CEL expressions that filter which resources are indexed. Multiple
72+
# conditions can be specified and are evaluated with OR semantics - a
73+
# resource is indexed if it satisfies ANY condition. Use && within a
74+
# single expression to require multiple criteria together.
75+
#
76+
# Each condition has:
77+
# - name: A unique identifier for the condition, used in status reporting
78+
# and debugging to identify which condition(s) matched a resource.
79+
# - expression: A CEL expression that must evaluate to a boolean. The
80+
# resource is available as the root object in the expression context.
81+
#
82+
# Available CEL operations:
83+
# - Field access: spec.replicas, metadata.name, status.phase
84+
# - Map access: metadata.labels["app"], metadata.annotations["key"]
85+
# - Comparisons: ==, !=, <, <=, >, >=
86+
# - Logical operators: &&, ||, !
87+
# - String functions: contains(), startsWith(), endsWith(), matches()
88+
# - List functions: exists(), all(), size(), map(), filter()
89+
# - Membership: "value" in list, "key" in map
90+
# - Ternary: condition ? trueValue : falseValue
6891
conditions:
69-
# Only index organizations that are active
70-
- name: ready-only
71-
expression: status.conditions.exists(c, c.type == 'Ready' && c.status == 'True')
92+
# Index resources that are ready and not being deleted
93+
- name: active-resources
94+
expression: |
95+
status.conditions.exists(c, c.type == 'Ready' && c.status == 'True')
96+
&& !has(metadata.deletionTimestamp)
97+
# Also index resources in production namespaces regardless of status
98+
- name: production-resources
99+
expression: metadata.namespace.startsWith("prod-")
100+
101+
# Defines which fields from the resource are indexed and how they behave
102+
# in search operations.
72103
fields:
73-
# Index the resource name
104+
# The JSONPath to the field value in the resource. Supports nested paths
105+
# and map key access using bracket notation.
74106
- path: metadata.name
107+
# When true, the field value is included in full-text search operations.
108+
# The value is tokenized and analyzed for relevance-based matching.
75109
searchable: true
110+
# When true, the field can be used in filter expressions for exact
111+
# matching, range queries, and other structured filtering operations.
76112
filterable: true
77-
# Index the description of the resource
113+
# When true, the search service will return aggregated counts of unique
114+
# values for this field. Enables clients to discover available filter
115+
# values and build faceted navigation interfaces.
116+
facetable: true
117+
78118
- path: metadata.annotations["kubernetes.io/description"]
79119
searchable: true
80120
filterable: true
121+
facetable: false
81122
```
82123
83124
The index policy will used a versioned reference to resources since the field
84125
paths for resources may be different between versions. The system should monitor
85126
for deprecated resource versions being referenced in index policies.
127+
128+
#### Condition evaluation
129+
130+
Conditions provide fine-grained control over which resource instances are
131+
indexed. When multiple conditions are specified, they are evaluated using OR
132+
semantics - a resource is indexed if it satisfies ANY condition. This allows
133+
defining multiple independent criteria for inclusion.
134+
135+
Use `&&` within a single CEL expression when you need AND semantics:
136+
137+
```yaml
138+
conditions:
139+
- name: ready-in-production
140+
expression: |
141+
status.conditions.exists(c, c.type == 'Ready' && c.status == 'True')
142+
&& metadata.namespace.startsWith("prod-")
143+
```
144+
145+
Conditions are re-evaluated when resources change. If a resource no longer
146+
satisfies any condition (e.g., it transitions from Ready to NotReady), it will
147+
be removed from the search index. Similarly, resources that begin satisfying
148+
a condition after an update will be added to the index.

0 commit comments

Comments
 (0)