crossplane-debug
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseCrossplane Composition Debugging
Crossplane 组合调试
Debug Crossplane compositions and functions by systematically identifying issues in rendering, function execution, and resource provisioning.
通过系统识别渲染、函数执行和资源供应中的问题,调试Crossplane组合与函数。
Debugging Decision Tree
调试决策树
Issue reported
|
v
Do you have composition files locally?
|
+--NO--> Extract from cluster first
| Run: scripts/extract-composition.sh
| See: "Remote Cluster Debugging"
|
+--YES--> Is the composition rendering correctly?
|
+--NO--> Run `crossplane beta render` locally
| See: "Local Render Debugging"
|
+--YES--> Are resources being created in the cluster?
|
+--NO--> Check XR/Claim status and events
| Run `crossplane beta trace`
| See: "Cluster Debugging"
|
+--YES--> Are resources in Ready state?
|
+--NO--> Check managed resource conditions
| See: "Resource Status Debugging"
|
+--YES--> Issue is external to CrossplaneIssue reported
|
v
Do you have composition files locally?
|
+--NO--> Extract from cluster first
| Run: scripts/extract-composition.sh
| See: "Remote Cluster Debugging"
|
+--YES--> Is the composition rendering correctly?
|
+--NO--> Run `crossplane beta render` locally
| See: "Local Render Debugging"
|
+--YES--> Are resources being created in the cluster?
|
+--NO--> Check XR/Claim status and events
| Run `crossplane beta trace`
| See: "Cluster Debugging"
|
+--YES--> Are resources in Ready state?
|
+--NO--> Check managed resource conditions
| See: "Resource Status Debugging"
|
+--YES--> Issue is external to CrossplaneRemote Cluster Debugging
远程集群调试
When compositions and functions are deployed to a remote cluster and you don't have the source files locally.
当组合和函数部署在远程集群且本地没有源文件时使用。
Quick Extract (Using Script)
快速提取(使用脚本)
Run the extraction script to pull all files needed for local debugging:
bash
undefined运行提取脚本以拉取本地调试所需的所有文件:
bash
undefinedExtract composition, functions, and sample XR for debugging
Extract composition, functions, and sample XR for debugging
./scripts/extract-composition.sh <composition-name> [xr-kind] [xr-name]
./scripts/extract-composition.sh <composition-name> [xr-kind] [xr-name]
Examples:
Examples:
./scripts/extract-composition.sh my-database-composition
./scripts/extract-composition.sh my-app-composition XMyApp my-app-instance
This creates a `debug-<composition-name>/` directory with all files needed for `crossplane beta render`../scripts/extract-composition.sh my-database-composition
./scripts/extract-composition.sh my-app-composition XMyApp my-app-instance
此命令会创建一个`debug-<composition-name>/`目录,包含`crossplane beta render`所需的所有文件。Manual Extraction
手动提取
1. Extract Composition
1. 提取组合
bash
undefinedbash
undefinedList available compositions
List available compositions
kubectl get compositions
kubectl get compositions
Extract specific composition
Extract specific composition
kubectl get composition <name> -o yaml > composition.yaml
undefinedkubectl get composition <name> -o yaml > composition.yaml
undefined2. Extract Function Definitions
2. 提取函数定义
bash
undefinedbash
undefinedList installed functions
List installed functions
kubectl get functions
kubectl get functions
Extract all functions to single file
Extract all functions to single file
kubectl get functions -o yaml > functions.yaml
kubectl get functions -o yaml > functions.yaml
Or extract specific function
Or extract specific function
kubectl get function <name> -o yaml >> functions.yaml
undefinedkubectl get function <name> -o yaml >> functions.yaml
undefined3. Extract Sample XR/Claim
3. 提取示例XR/Claim
bash
undefinedbash
undefinedFind XRs using this composition
Find XRs using this composition
kubectl get <xr-kind> -A
kubectl get <xr-kind> -A
Extract an XR as sample input (clean up status for render)
Extract an XR as sample input (clean up status for render)
kubectl get <xr-kind> <name> -o yaml |
yq 'del(.status) | del(.metadata.resourceVersion) | del(.metadata.uid) | del(.metadata.generation) | del(.metadata.creationTimestamp) | del(.metadata.managedFields)' \
yq 'del(.status) | del(.metadata.resourceVersion) | del(.metadata.uid) | del(.metadata.generation) | del(.metadata.creationTimestamp) | del(.metadata.managedFields)' \
xr.yaml
undefinedkubectl get <xr-kind> <name> -o yaml |
yq 'del(.status) | del(.metadata.resourceVersion) | del(.metadata.uid) | del(.metadata.generation) | del(.metadata.creationTimestamp) | del(.metadata.managedFields)' \
yq 'del(.status) | del(.metadata.resourceVersion) | del(.metadata.uid) | del(.metadata.generation) | del(.metadata.creationTimestamp) | del(.metadata.managedFields)' \
xr.yaml
undefined4. View Inline KCL Code
4. 查看内嵌KCL代码
For compositions with embedded KCL, extract and view the code:
bash
undefined对于包含内嵌KCL的组合,提取并查看代码:
bash
undefinedView all pipeline steps and their inputs
View all pipeline steps and their inputs
kubectl get composition <name> -o jsonpath='{.spec.pipeline}' | jq
kubectl get composition <name> -o jsonpath='{.spec.pipeline}' | jq
Extract KCL source from specific step (adjust index [0] as needed)
Extract KCL source from specific step (adjust index [0] as needed)
kubectl get composition <name> -o jsonpath='{.spec.pipeline[0].input.source}'
kubectl get composition <name> -o jsonpath='{.spec.pipeline[0].input.source}'
Pretty print KCL from inline composition
Pretty print KCL from inline composition
kubectl get composition <name> -o json |
jq -r '.spec.pipeline[] | select(.functionRef.name == "function-kcl") | .input.source'
jq -r '.spec.pipeline[] | select(.functionRef.name == "function-kcl") | .input.source'
undefinedkubectl get composition <name> -o json |
jq -r '.spec.pipeline[] | select(.functionRef.name == "function-kcl") | .input.source'
jq -r '.spec.pipeline[] | select(.functionRef.name == "function-kcl") | .input.source'
undefinedView Function Logs in Cluster
查看集群中的函数日志
bash
undefinedbash
undefinedFind function pods
Find function pods
kubectl get pods -n crossplane-system -l pkg.crossplane.io/function
kubectl get pods -n crossplane-system -l pkg.crossplane.io/function
Logs for specific function
Logs for specific function
kubectl logs -n crossplane-system -l pkg.crossplane.io/function=function-kcl -f --tail=100
kubectl logs -n crossplane-system -l pkg.crossplane.io/function=function-kcl -f --tail=100
All function logs
All function logs
kubectl logs -n crossplane-system -l pkg.crossplane.io/revision --tail=50
undefinedkubectl logs -n crossplane-system -l pkg.crossplane.io/revision --tail=50
undefinedDebug Without Local Functions
无本地函数时调试
If you can't run functions locally, use cluster-side debugging:
bash
undefined如果无法在本地运行函数,使用集群端调试:
bash
undefined1. Check function health
1. Check function health
kubectl get functions
kubectl describe function <name>
kubectl get functions
kubectl describe function <name>
2. Check function pod status
2. Check function pod status
kubectl get pods -n crossplane-system -l pkg.crossplane.io/function=<name>
kubectl get pods -n crossplane-system -l pkg.crossplane.io/function=<name>
3. View function errors in XR events
3. View function errors in XR events
kubectl describe <xr-kind> <xr-name> | grep -A5 "Events:"
kubectl describe <xr-kind> <xr-name> | grep -A5 "Events:"
4. Check crossplane core logs for function errors
4. Check crossplane core logs for function errors
kubectl logs -n crossplane-system deploy/crossplane --tail=100 | grep -i function
undefinedkubectl logs -n crossplane-system deploy/crossplane --tail=100 | grep -i function
undefinedLocal Render Debugging
本地渲染调试
Use to test composition rendering without applying to cluster.
crossplane beta render使用测试组合渲染,无需应用到集群。
crossplane beta renderBasic Render Command
基础渲染命令
bash
crossplane beta render <xr-file.yaml> <composition.yaml> <functions.yaml>Required files:
- - Example XR or Claim with spec values
xr-file.yaml - - The Composition to test
composition.yaml - - Function definitions (can combine multiple)
functions.yaml
bash
crossplane beta render <xr-file.yaml> <composition.yaml> <functions.yaml>所需文件:
- - 包含spec值的示例XR或Claim
xr-file.yaml - - 要测试的组合
composition.yaml - - 函数定义(可合并多个)
functions.yaml
Functions File for Cluster-Deployed Functions
集群部署函数的函数文件
When functions are in the cluster but not running locally, use runtime to pull from registry:
Defaultyaml
---
apiVersion: pkg.crossplane.io/v1beta1
kind: Function
metadata:
name: function-kcl
annotations:
render.crossplane.io/runtime: Default
---
apiVersion: pkg.crossplane.io/v1beta1
kind: Function
metadata:
name: function-auto-ready
annotations:
render.crossplane.io/runtime: Default当函数在集群中但未在本地运行时,使用运行时从镜像仓库拉取:
Defaultyaml
---
apiVersion: pkg.crossplane.io/v1beta1
kind: Function
metadata:
name: function-kcl
annotations:
render.crossplane.io/runtime: Default
---
apiVersion: pkg.crossplane.io/v1beta1
kind: Function
metadata:
name: function-auto-ready
annotations:
render.crossplane.io/runtime: DefaultFunctions File for Local Development
本地开发的函数文件
When running functions locally in Docker:
yaml
---
apiVersion: pkg.crossplane.io/v1beta1
kind: Function
metadata:
name: function-kcl
annotations:
render.crossplane.io/runtime: Development
render.crossplane.io/runtime-development-target: localhost:9443
---
apiVersion: pkg.crossplane.io/v1beta1
kind: Function
metadata:
name: function-auto-ready当在Docker中本地运行函数时:
yaml
---
apiVersion: pkg.crossplane.io/v1beta1
kind: Function
metadata:
name: function-kcl
annotations:
render.crossplane.io/runtime: Development
render.crossplane.io/runtime-development-target: localhost:9443
---
apiVersion: pkg.crossplane.io/v1beta1
kind: Function
metadata:
name: function-auto-readyRunning KCL Function Locally
本地运行KCL函数
Start the KCL function in development mode:
bash
undefined以开发模式启动KCL函数:
bash
undefinedTerminal 1: Run KCL function server
Terminal 1: Run KCL function server
docker run --rm -p 9443:9443 xpkg.upbound.io/crossplane-contrib/function-kcl:latest --insecure --debug
```bashdocker run --rm -p 9443:9443 xpkg.upbound.io/crossplane-contrib/function-kcl:latest --insecure --debug
```bashTerminal 2: Render with local function
Terminal 2: Render with local function
crossplane beta render xr.yaml composition.yaml functions.yaml
undefinedcrossplane beta render xr.yaml composition.yaml functions.yaml
undefinedInterpreting Render Output
解读渲染输出
The output shows the desired state after all functions run. Check for:
- Missing resources - Function didn't generate expected output
- Wrong resource values - Function logic error
- Function errors - Check stderr for stack traces
输出显示所有函数运行后的期望状态。检查以下内容:
- 缺失资源 - 函数未生成预期输出
- 资源值错误 - 函数逻辑错误
- 函数错误 - 检查stderr获取堆栈跟踪
Common Render Issues
常见渲染问题
| Symptom | Likely Cause | Action |
|---|---|---|
| Empty output | Function not matched or no resources generated | Check function name matches pipeline step |
| KCL syntax error | Invalid KCL in composition | See references/kcl-patterns.md |
| "function not found" | Function not in functions.yaml | Add function definition |
| Wrong resource apiVersion | KCL schema mismatch | Update KCL imports |
| 症状 | 可能原因 | 操作 |
|---|---|---|
| 空输出 | 函数未匹配或未生成资源 | 检查函数名称是否与流水线步骤匹配 |
| KCL语法错误 | 组合中的KCL无效 | 查看references/kcl-patterns.md |
| "function not found" | 函数不在functions.yaml中 | 添加函数定义 |
| 资源apiVersion错误 | KCL schema不匹配 | 更新KCL导入 |
Cluster Debugging
集群调试
Trace Resource Relationships
跟踪资源关系
bash
undefinedbash
undefinedTrace from claim to all managed resources
Trace from claim to all managed resources
crossplane beta trace <claim-kind>/<claim-name> -n <namespace>
crossplane beta trace <claim-kind>/<claim-name> -n <namespace>
Trace from XR
Trace from XR
crossplane beta trace <xr-kind>/<xr-name>
Output shows the resource tree with status of each resource.crossplane beta trace <xr-kind>/<xr-name>
输出显示资源树及每个资源的状态。Check XR Status
检查XR状态
bash
kubectl get <xr-kind> <xr-name> -o yamlKey fields to inspect:
- - Synced, Ready, and custom conditions
status.conditions - - Connection secret propagation
status.connectionDetails - - Which composition is being used
spec.compositionRef - - List of composed resources
spec.resourceRefs
bash
kubectl get <xr-kind> <xr-name> -o yaml需检查的关键字段:
- - 已同步、就绪和自定义条件
status.conditions - - 连接密钥传播
status.connectionDetails - - 当前使用的组合
spec.compositionRef - - 组合资源列表
spec.resourceRefs
Check Claim Status
检查Claim状态
bash
kubectl describe <claim-kind> <claim-name> -n <namespace>Look for:
- Events showing errors
- with False values
status.conditions - Missing
status.connectionDetails
bash
kubectl describe <claim-kind> <claim-name> -n <namespace>查找以下内容:
- 显示错误的事件
- 值为False的
status.conditions - 缺失的
status.connectionDetails
View Composition Revisions
查看组合修订版本
bash
kubectl get compositionrevision -l crossplane.io/composition-name=<composition-name>bash
kubectl get compositionrevision -l crossplane.io/composition-name=<composition-name>Resource Status Debugging
资源状态调试
Check Managed Resource
检查托管资源
bash
kubectl describe <managed-resource-kind> <name>Key sections:
- Conditions: Look for or
Synced=FalseReady=False - Events: Provider-specific errors
- Status.AtProvider: Actual state from cloud provider
bash
kubectl describe <managed-resource-kind> <name>关键部分:
- Conditions:查找或
Synced=FalseReady=False - Events:提供商特定错误
- Status.AtProvider:来自云提供商的实际状态
Common Managed Resource Issues
常见托管资源问题
| Condition | Message Pattern | Cause |
|---|---|---|
| Synced=False | "cannot create" | Missing permissions or invalid spec |
| Synced=False | "rate limit" | API throttling, retry later |
| Ready=False | "pending" | Resource still provisioning |
| Ready=False | "failed" | External creation error |
| 条件 | 消息模式 | 原因 |
|---|---|---|
| Synced=False | "cannot create" | 权限缺失或spec无效 |
| Synced=False | "rate limit" | API限流,稍后重试 |
| Ready=False | "pending" | 资源仍在供应中 |
| Ready=False | "failed" | 外部创建错误 |
Provider Logs
提供商日志
bash
undefinedbash
undefinedFind provider pod
Find provider pod
kubectl get pods -n crossplane-system | grep provider
kubectl get pods -n crossplane-system | grep provider
View logs
View logs
kubectl logs -n crossplane-system <provider-pod> -f
undefinedkubectl logs -n crossplane-system <provider-pod> -f
undefinedFunction-Specific Debugging
特定函数调试
KCL Functions
KCL函数
See references/kcl-patterns.md for:
- Common KCL syntax patterns
- Reading composite resource inputs
- Generating multiple resources
- Conditional logic
Quick KCL debugging:
bash
undefined查看references/kcl-patterns.md获取:
- 常见KCL语法模式
- 读取复合资源输入
- 生成多个资源
- 条件逻辑
快速KCL调试:
bash
undefinedExtract and validate inline KCL
Extract and validate inline KCL
kubectl get composition <name> -o json |
jq -r '.spec.pipeline[] | select(.functionRef.name == "function-kcl") | .input.source' \
jq -r '.spec.pipeline[] | select(.functionRef.name == "function-kcl") | .input.source' \
extracted.k kcl extracted.k
kubectl get composition <name> -o json |
jq -r '.spec.pipeline[] | select(.functionRef.name == "function-kcl") | .input.source' \
jq -r '.spec.pipeline[] | select(.functionRef.name == "function-kcl") | .input.source' \
extracted.k kcl extracted.k
Run with debug output
Run with debug output
crossplane beta render xr.yaml composition.yaml functions.yaml 2>&1 | head -100
undefinedcrossplane beta render xr.yaml composition.yaml functions.yaml 2>&1 | head -100
undefinedGo Template Functions
Go模板函数
Check template syntax:
- Ensure delimiters are correct
{{ }} - Verify paths
.observed.composite.resource.spec - Check for nil pointer access
检查模板语法:
- 确保分隔符正确
{{ }} - 验证路径
.observed.composite.resource.spec - 检查空指针访问
Patch and Transform
补丁与转换
Common issues:
- pointing to non-existent field
fromFieldPath - targeting immutable field
toFieldPath - Transform type mismatch
常见问题:
- 指向不存在的字段
fromFieldPath - 指向不可变字段
toFieldPath - 转换类型不匹配
Auto-Ready Function
自动就绪函数
Must be last in pipeline. Issues:
- Not detecting composed resources correctly
- Ready condition not propagating
必须位于流水线最后。问题:
- 未正确检测组合资源
- 就绪条件未传播
Validation
验证
bash
undefinedbash
undefinedValidate composition against schema
Validate composition against schema
crossplane beta validate <composition.yaml>
crossplane beta validate <composition.yaml>
Validate with extensions
Validate with extensions
crossplane beta validate <composition.yaml> --extensions=<extensions-dir>
undefinedcrossplane beta validate <composition.yaml> --extensions=<extensions-dir>
undefinedQuick Reference Commands
快速参考命令
bash
undefinedbash
undefinedRemote cluster: Extract for local debugging
Remote cluster: Extract for local debugging
kubectl get composition <name> -o yaml > composition.yaml
kubectl get functions -o yaml > functions.yaml
kubectl get <xr> <name> -o yaml > xr.yaml
kubectl get composition <name> -o yaml > composition.yaml
kubectl get functions -o yaml > functions.yaml
kubectl get <xr> <name> -o yaml > xr.yaml
Full debugging session
Full debugging session
crossplane beta trace <kind>/<name> # See resource tree
kubectl get events --field-selector involvedObject.name=<name> # Recent events
kubectl get <xr> -o jsonpath='{.status.conditions}' # XR conditions
crossplane beta trace <kind>/<name> # See resource tree
kubectl get events --field-selector involvedObject.name=<name> # Recent events
kubectl get <xr> -o jsonpath='{.status.conditions}' # XR conditions
Function debugging
Function debugging
crossplane beta render xr.yaml comp.yaml funcs.yaml # Local render
crossplane beta render xr.yaml comp.yaml funcs.yaml -o json | jq # Parse output
crossplane beta render xr.yaml comp.yaml funcs.yaml # Local render
crossplane beta render xr.yaml comp.yaml funcs.yaml -o json | jq # Parse output
View inline KCL
View inline KCL
kubectl get composition <name> -o json | jq -r '.spec.pipeline[].input.source'
kubectl get composition <name> -o json | jq -r '.spec.pipeline[].input.source'
Provider debugging
Provider debugging
kubectl logs -n crossplane-system deploy/<provider> --tail=100
undefinedkubectl logs -n crossplane-system deploy/<provider> --tail=100
undefinedReferences
参考资料
- references/kcl-patterns.md - KCL syntax patterns for compositions
- references/common-errors.md - Error messages and solutions
- references/kcl-patterns.md - 组合的KCL语法模式
- references/common-errors.md - 错误消息与解决方案