|
| 1 | +""" |
| 2 | +This module provides schemas and utility functions for writing safer and more productive Crossplane Functions in KCL. |
| 3 | +""" |
| 4 | +type Resource = any |
| 5 | + |
| 6 | +schema Composite: |
| 7 | + """A composed resource in Crossplane.""" |
| 8 | + Resource: Resource |
| 9 | + |
| 10 | +schema Params: |
| 11 | + """ |
| 12 | + Params are the input parameters for the function pipeline. |
| 13 | + |
| 14 | + Attributes |
| 15 | + ---------- |
| 16 | + oxr : Resource, default is None |
| 17 | + Observed composite resource (XR). |
| 18 | + ocds : {str:Composite}, default is None |
| 19 | + Key-value of the observed state of a composed resource. The key is the name of the composed resource. |
| 20 | + Note: A composed resource is not just a managed resource - it can also be a ProviderConfig, another composite resource, or any other Crossplane resource. |
| 21 | + dxr : Resource, default is None |
| 22 | + Desired composite resource (XR). |
| 23 | + dcds : {str:Composite}, default is None |
| 24 | + Key-value of the desired state of a composed resource. The key is the name of the composed resource. |
| 25 | + Note: A composed resource is not just a managed resource - it can also be a ProviderConfig, another composite resource, or any other Crossplane resource. |
| 26 | + ctx : any, default is None |
| 27 | + Function pipeline's context |
| 28 | + extraResources : {str:[Composite]}, default is None |
| 29 | + Extra resources. The key is the name of the resource and the value is a list of resources. |
| 30 | + |
| 31 | + Examples |
| 32 | + -------- |
| 33 | + params = get_params() |
| 34 | + print(params.oxr) |
| 35 | + print(params.ocds) |
| 36 | + print(params.dxr) |
| 37 | + print(params.dcds) |
| 38 | + print(params.ctx) |
| 39 | + print(params.extraResources) |
| 40 | + """ |
| 41 | + oxr: Resource |
| 42 | + ocds: {str:Composite} |
| 43 | + dxr: Resource |
| 44 | + dcds: {str:Composite} |
| 45 | + ctx: any |
| 46 | + extraResources: {str:[Composite]} |
| 47 | + |
| 48 | +get_params = lambda -> Params { |
| 49 | + """ |
| 50 | + Get type-safe access to the function pipeline's parameters. |
| 51 | + |
| 52 | + Returns |
| 53 | + ------- |
| 54 | + Params |
| 55 | + A strongly-typed Params schema containing the function pipeline's parameters. |
| 56 | + |
| 57 | + Examples |
| 58 | + -------- |
| 59 | + params = get_params() |
| 60 | + xr = params.oxr # Type-safe access to observed XR |
| 61 | + """ |
| 62 | + params = option("params") |
| 63 | + Params { |
| 64 | + oxr = params.oxr |
| 65 | + ocds = params.ocds |
| 66 | + dxr = params.dxr |
| 67 | + dcds = params.dcds |
| 68 | + ctx = params.ctx |
| 69 | + extraResources = params.extraResources |
| 70 | + } |
| 71 | +} |
0 commit comments