Skip to content

Commit 8d92046

Browse files
authored
Merge pull request #776 from a-hilaly/new-docs
docs: enhance RGD, SimpleSchema, and Instance documentation
2 parents 4383639 + e9923d8 commit 8d92046

File tree

3 files changed

+172
-22
lines changed

3 files changed

+172
-22
lines changed

website/docs/docs/concepts/00-resource-group-definitions.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,10 @@ correctness and set up the necessary components:
137137
- Checks that referenced values exist and are of the correct type
138138
- Confirms resource dependencies form a valid Directed Acyclic Graph(DAG)
139139
without cycles
140-
- Validates all CEL expressions in status fields and conditions
140+
- Validates all CEL expressions in status fields and conditions using CEL's native type system
141+
- Validates field references exist in the actual resource schemas
142+
- Ensures expressions return types compatible with their target fields
143+
- Checks type compatibility statically without executing expressions
141144
142145
2. **API Generation**: kro generates and registers a new CRD in your cluster
143146
based on your schema. For example, if your **ResourceGraphDefinition** defines a
@@ -149,12 +152,14 @@ correctness and set up the necessary components:
149152
- Integrates seamlessly with kubectl and other Kubernetes tools
150153

151154
3. **Controller Configuration**: kro configures itself to watch for instances of
152-
your new API and:
155+
your new API and their managed resources:
153156

154157
- Creates all required resources following the dependency order
155158
- Manages references and value passing between resources
156159
- Handles the complete lifecycle for create, update, and delete operations
157160
- Keeps status information up to date based on actual resource states
161+
- Automatically detects and reconciles drift in managed resources
162+
- Triggers reconciliation when any managed resource changes
158163

159164
For instance, when you create a `WebApplication` ResourceGraphDefinition, kro generates
160165
the `webapplications.kro.run` CRD. When users create instances of this API, kro

website/docs/docs/concepts/10-simple-schema.md

Lines changed: 61 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -268,22 +268,70 @@ username: string | minLength=3 maxLength=20 pattern="^[a-zA-Z0-9_]+$"
268268
tags: "[]string" | uniqueItems=true minItems=1 maxItems=10 description="1-10 unique tags"
269269
```
270270

271+
:::warning Floating Point Precision
272+
When using `float` or `double` types in CEL expressions (particularly in `readyWhen` or `includeWhen` conditions), be aware of floating point precision issues that could cause unexpected behavior. Avoid comparing floating point values for equality in conditional logic. Prefer using `string`, `integer`, or `boolean` types whenever possible to avoid precision-related oscillations in resource state.
273+
:::
274+
271275
## Status Fields
272276

273277
Status fields use CEL expressions to reference values from resources. kro
274278
automatically:
275279

276280
- Infers the correct types from the expressions
277-
- Validates that referenced resources exist
281+
- Validates that referenced resources exist at ResourceGraphDefinition creation time
278282
- Updates values when the underlying resources change
283+
- Validates type compatibility using CEL's native type system
279284

280285
```yaml
281286
status:
282287
# Types are inferred from the referenced fields
283-
availableReplicas: ${deployment.status.availableReplicas}
284-
endpoint: ${service.status.loadBalancer.ingress[0].hostname}
288+
availableReplicas: ${deployment.status.availableReplicas} # integer
289+
endpoint: ${service.status.loadBalancer.ingress[0].hostname} # string
290+
metadata: ${deployment.metadata} # object
291+
```
292+
293+
### Single vs Multi-Expression Fields
294+
295+
Status fields can contain either a single CEL expression or multiple expressions concatenated together:
296+
297+
**Single Expression Fields** can be any type:
298+
```yaml
299+
status:
300+
replicas: ${deployment.status.replicas} # integer
301+
metadata: ${deployment.metadata} # object
302+
name: ${deployment.metadata.name} # string
303+
ready: ${deployment.status.conditions.exists(c, c.type == 'Available')} # boolean
285304
```
286305

306+
**Multi-Expression Fields** (string templating) must contain only string expressions:
307+
```yaml
308+
status:
309+
# ✓ Valid - all expressions return strings
310+
endpoint: "https://${service.metadata.name}.${service.metadata.namespace}.svc.cluster.local"
311+
312+
# ✓ Valid - explicit string conversion
313+
summary: "Replicas: ${string(deployment.status.replicas)}, Ready: ${string(deployment.status.ready)}"
314+
315+
# ✗ Invalid - concatenating non-string types
316+
invalid: "${deployment.status.replicas}-${deployment.metadata}" # Will fail validation
317+
```
318+
319+
Multi-expression fields are useful for string templating scenarios like constructing URLs, connection strings, or IAM policies:
320+
321+
```yaml
322+
status:
323+
iamPolicy: |
324+
{
325+
"Effect": "Allow",
326+
"Resource": "arn:aws:s3:::${bucket.metadata.name}/*",
327+
"Principal": "${serviceAccount.metadata.name}"
328+
}
329+
```
330+
331+
:::tip
332+
Use explicit `string()` conversions when concatenating non-string values to ensure type compatibility.
333+
:::
334+
287335
## Default Status Fields
288336

289337
kro automatically injects two fields to every instance's status:
@@ -295,27 +343,30 @@ An array of condition objects tracking the instance's state:
295343
```yaml
296344
status:
297345
conditions:
298-
- type: string # e.g., "Ready", "Progressing"
346+
- type: string # e.g., "Ready", "InstanceManaged", "GraphResolved", "ResourcesReady"
299347
status: string # "True", "False", "Unknown"
300348
lastTransitionTime: string
349+
observedGeneration: integer
301350
reason: string
302351
message: string
303352
```
304353

305-
Common condition types:
354+
kro provides a hierarchical condition structure:
355+
356+
- `Ready`: Top-level condition indicating the instance is fully operational
357+
- `InstanceManaged`: Instance finalizers and labels are properly set
358+
- `GraphResolved`: Runtime graph has been created and resources resolved
359+
- `ResourcesReady`: All resources in the graph are created and ready
306360

307-
- `Ready`: Instance is fully reconciled
308-
- `Progressing`: Working towards desired state
309-
- `Degraded`: Operational but not optimal
310-
- `Error`: Reconciliation error occurred
361+
The `Ready` condition aggregates the state of all sub-conditions and only becomes `True` when all sub-conditions are `True`. Each condition includes an `observedGeneration` field that tracks which generation of the instance the condition reflects.
311362

312363
### 2. State
313364

314365
A high-level summary of the instance's status:
315366

316367
```yaml
317368
status:
318-
state: string # Ready, Progressing, Degraded, Unknown, Deleting
369+
state: string # ACTIVE, IN_PROGRESS, FAILED, DELETING, ERROR
319370
```
320371

321372
:::tip

website/docs/docs/concepts/15-instances.md

Lines changed: 104 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,24 @@ state, providing features like:
5252
- Consistent state management
5353
- Status tracking
5454
55+
### Reactive Reconciliation
56+
57+
kro automatically watches all resources managed by an instance and triggers
58+
reconciliation when any of them change. This means:
59+
60+
- **Child Resource Changes**: When a managed resource (like a Deployment or Service) is
61+
modified, kro detects the change and reconciles the instance to ensure it matches
62+
the desired state defined in your ResourceGraphDefinition.
63+
64+
- **Drift Detection**: If a resource is manually modified or deleted, kro will detect
65+
the drift and automatically restore it to the desired state.
66+
67+
- **Dependency Updates**: Changes to resources propagate through the dependency graph,
68+
ensuring all dependent resources are updated accordingly.
69+
70+
This reactive behavior ensures your instances maintain consistency without requiring
71+
manual intervention or periodic full reconciliations.
72+
5573
## Monitoring Your Instances
5674
5775
KRO provides rich status information for every instance:
@@ -69,11 +87,30 @@ status:
6987
state: ACTIVE # High-level instance state
7088
availableReplicas: 3 # Status from Deployment
7189
conditions: # Detailed status conditions
72-
- type: Ready
90+
- lastTransitionTime: "2025-08-08T00:03:46Z"
91+
message: instance is properly managed with finalizers and labels
92+
observedGeneration: 1
93+
reason: Managed
7394
status: "True"
74-
lastTransitionTime: "2024-07-23T01:01:59Z"
75-
reason: ResourcesAvailable
76-
message: "All resources are available and configured correctly"
95+
type: InstanceManaged
96+
- lastTransitionTime: "2025-08-08T00:03:46Z"
97+
message: runtime graph created and all resources resolved
98+
observedGeneration: 1
99+
reason: Resolved
100+
status: "True"
101+
type: GraphResolved
102+
- lastTransitionTime: "2025-08-08T00:03:46Z"
103+
message: all resources are created and ready
104+
observedGeneration: 1
105+
reason: AllResourcesReady
106+
status: "True"
107+
type: ResourcesReady
108+
- lastTransitionTime: "2025-08-08T00:03:46Z"
109+
message: ""
110+
observedGeneration: 1
111+
reason: Ready
112+
status: "True"
113+
type: Ready
77114
```
78115
79116
### Understanding Status
@@ -88,17 +125,64 @@ Every instance includes:
88125
- `DELETING`: Indicates that the instance is in the process of being deleted.
89126
- `ERROR`: Indicates that an error occurred during instance processing.
90127

91-
2. **Conditions**: Detailed status information
128+
2. **Conditions**: Detailed status information structured hierarchically
129+
130+
kro provides a top-level `Ready` condition that reflects the overall instance health. This condition is supported by three sub-conditions that track different phases of the reconciliation process:
131+
132+
- `InstanceManaged`: Instance finalizers and labels are properly set
133+
- Ensures the instance is under kro's management
134+
- Tracks whether cleanup handlers (finalizers) are configured
135+
- Confirms instance is labeled with ownership and version information
136+
137+
- `GraphResolved`: Runtime graph has been created and resources resolved
138+
- Validates that the resource graph has been successfully parsed
139+
- Confirms all resource templates have been resolved
140+
- Ensures dependencies between resources are properly understood
92141

93-
- `Ready`: Instance is fully operational
94-
- `Progressing`: Changes are being applied
95-
- `Degraded`: Operating but not optimal
96-
- `Error`: Problems detected
142+
- `ResourcesReady`: All resources in the graph are created and ready
143+
- Tracks the creation and readiness of all managed resources
144+
- Monitors the health of resources in topological order
145+
- Reports when all resources have reached their ready state
146+
147+
- `Ready`: Instance is fully operational (top-level condition)
148+
- Aggregates the state of all sub-conditions
149+
- Only becomes True when all sub-conditions are True
150+
- The primary condition to monitor for instance health
151+
152+
Each condition includes:
153+
- `observedGeneration`: Tracks which generation of the instance this condition reflects
154+
- `lastTransitionTime`: When the condition last changed state
155+
- `reason`: A programmatic identifier for the condition state
156+
- `message`: A human-readable description of the current state
97157

98158
3. **Resource Status**: Status from your resources
99159
- Values you defined in your ResourceGraphDefinition's status section
100160
- Automatically updated as resources change
101161

162+
## Debugging Instance Issues
163+
164+
When an instance is not in the expected state, the condition hierarchy helps you quickly identify where the problem occurred:
165+
166+
1. **Check the Ready condition first**
167+
```bash
168+
kubectl get <your-kind> <instance-name> -o jsonpath='{.status.conditions[?(@.type=="Ready")]}'
169+
```
170+
171+
2. **If Ready is False, check the sub-conditions** to identify which phase failed:
172+
173+
- If `InstanceManaged` is False: Check if there are issues with finalizers or instance labels
174+
- If `GraphResolved` is False: The resource graph could not be created - check the ResourceGraphDefinition for syntax errors or invalid CEL expressions
175+
- If `ResourcesReady` is False: One or more managed resources failed to become ready - check the error message for which resource failed
176+
177+
3. **Use kubectl describe** to see all conditions and recent events:
178+
```bash
179+
kubectl describe <your-kind> <instance-name>
180+
```
181+
182+
4. **Check the observedGeneration** field in conditions:
183+
- If `observedGeneration` is less than `metadata.generation`, the controller hasn't processed the latest changes yet
184+
- If they match, the conditions reflect the current state of your instance
185+
102186
## Best Practices
103187

104188
- **Version Control**: Keep your instance definitions in version control
@@ -111,7 +195,17 @@ Every instance includes:
111195

112196
- **Active Monitoring**: Regularly check instance status beyond just "Running".
113197
Watch conditions, resource status, and events to catch potential issues early
114-
and understand your application's health.
198+
and understand your application's health. Focus on the `Ready` condition and
199+
its sub-conditions to understand the reconciliation state.
200+
201+
- **Monitor observedGeneration**: When making changes to an instance, verify that
202+
`observedGeneration` in the conditions matches `metadata.generation` to ensure
203+
kro has processed your changes.
204+
205+
- **Leverage Reactive Reconciliation**: kro automatically detects and corrects drift
206+
in managed resources. If you need to make manual changes to resources, update the
207+
instance specification instead to ensure changes persist and align with your
208+
desired state.
115209

116210
- **Regular Reviews**: Periodically review your instance configurations to
117211
ensure they reflect current requirements and best practices. Update resource

0 commit comments

Comments
 (0)