Skip to content

Commit 9b0a4aa

Browse files
committed
Implement python packages from EnvironmentConfigs and from Compositions
Add support for Capabilities and Required Schemas Signed-off-by: Patrick J. McNerthney <pat@mcnerthney.com>
1 parent 4861f71 commit 9b0a4aa

14 files changed

Lines changed: 1050 additions & 136 deletions

File tree

README.md

Lines changed: 97 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ kind: Function
5757
metadata:
5858
name: function-pythonic
5959
spec:
60-
package: xpkg.upbound.io/crossplane-contrib/function-pythonic:v0.4.2
60+
package: xpkg.crossplane.io/crossplane-contrib/function-pythonic:v0.6.0
6161
```
6262
6363
### Crossplane V1
@@ -69,7 +69,7 @@ kind: Function
6969
metadata:
7070
name: function-pythonic
7171
spec:
72-
package: xpkg.upbound.io/crossplane-contrib/function-pythonic:v0.4.2
72+
package: xpkg.crossplane.io/crossplane-contrib/function-pythonic:v0.6.0
7373
runtimeConfigRef:
7474
name: function-pythonic
7575
--
@@ -266,6 +266,7 @@ The BaseComposite class provides the following fields for manipulating the Compo
266266
| self.metadata | Map | The composite observed metadata |
267267
| self.spec | Map | The composite observed spec |
268268
| self.status | Map | The composite desired and observed status, read from observed if not in desired |
269+
| self.output | Map | The step output, only used during Operations |
269270
| self.conditions | Conditions | The composite desired and observed conditions, read from observed if not in desired |
270271
| self.results | Results | Returned results applied to the Composite and optionally on the Claim |
271272
| self.connectionSecret | Map | The name, namespace, and resourceName to use when generating the connection secret in Crossplane v2 |
@@ -286,6 +287,7 @@ The BaseComposite also provides access to the following Crossplane Function leve
286287
| self.context | Map | The response context, initialized from the request context |
287288
| self.environment | Map | The response environment, initialized from the request context environment |
288289
| self.requireds | Requireds | Request and read additional local Kubernetes resources |
290+
| self.schemas | Schemas | Request and read CustomResourceDefinition schemas |
289291
| self.resources | Resources | Define and process composed resources |
290292
| self.usages| Boolean | Generate Crossplane Usages for resource dependencies, default False |
291293
| self.autoReady | Boolean | Perform auto ready processing on all composed resources, default True |
@@ -324,7 +326,7 @@ Resource class:
324326

325327
Creating and accessing required resources is performed using the `BaseComposite.requireds` field.
326328
`BaseComposite.requireds` is a dictionary of the required resources whose key is the required
327-
resource name. The value returned when getting a required resource from BaseComposite is the
329+
schema name. The value returned when getting a required resource from BaseComposite is the
328330
following RequiredResources class:
329331

330332
| Field | Type | Description |
@@ -337,9 +339,6 @@ following RequiredResources class:
337339
| RequiredResources.matchName | String | The names to match when returning the required resources |
338340
| RequiredResources.matchLabels | Map | The labels to match when returning the required resources |
339341

340-
The current version of crossplane-sdk-python used by function-pythonic does not support namespace
341-
selection. For now, use matchLabels and filter the results if required.
342-
343342
RequiredResources acts like a Python list to provide access to the found required resources.
344343
Each resource in the list is the following RequiredResource class:
345344

@@ -356,6 +355,22 @@ Each resource in the list is the following RequiredResource class:
356355
| RequiredResource.conditions | Map | The required resource conditions |
357356
| RequiredResource.connection | Map | The required resource connection details |
358357

358+
### Required Schemas
359+
360+
Creating and accessing required schemas is performed using the `BaseComposite.schemas` field.
361+
`BaseComposite.schemas` is a dictionary of the required schema whose key is the required
362+
resource name. The value returned when getting a required resource from BaseComposite is the
363+
following Schema class:
364+
365+
| Field | Type | Description |
366+
| ----- | ---- | ----------- |
367+
| Schema(apiVersion,kind) | Schema | Reset the required schema and set the optional parameters |
368+
| Schema.name | String | The required schema name |
369+
| Schema.apiVersion | String | The required schema selector apiVersion |
370+
| Schema.kind | String | The required schema selector kind |
371+
| Schema.\_\_getitem\_\_ | Map | The required schema openAPIV3Schema |
372+
| Schema.\_\_getattr\_\_ | Map | The required schema openAPIV3Schema |
373+
359374
### Conditions
360375

361376
The `BaseComposite.conditions`, `Resource.conditions`, and `RequiredResource.conditions` fields
@@ -474,7 +489,7 @@ $ function-pythonic render --help
474489
usage: Crossplane Function Pythonic render [-h] [--debug] [--log-name-width WIDTH] [--logger-level LOGGER=LEVEL] [--python-path DIRECTORY]
475490
[--render-unknowns] [--allow-oversize-protos] [--crossplane-v1] [--kube-context CONTEXT]
476491
[--context-files KEY=PATH] [--context-values KEY=VALUE] [--observed-resources PATH]
477-
[--required-resources PATH] [--secret-store PATH] [--include-full-xr] [--include-connection-xr]
492+
[--required-resources PATH] [--required-schemas PATH] [--include-full-xr] [--include-connection-xr]
478493
[--include-function-results] [--include-context]
479494
COMPOSITE [COMPOSITION]
480495
@@ -506,8 +521,8 @@ options:
506521
A YAML file or directory of YAML files specifying the observed state of composed resources.
507522
--required-resources, -e PATH
508523
A YAML file or directory of YAML files specifying required resources to pass to the Function pipeline.
509-
--secret-store, -s PATH
510-
A YAML file or directory of YAML files specifying Secrets to use to resolve connections and credentials.
524+
--required-schemas, -s PATH
525+
A JSON file or directory of JSON files specifying required schemas to pass to the Function pipeline.
511526
--include-full-xr, -x
512527
Include a direct copy of the input XR's spedc and metadata fields in the rendered output.
513528
--include-connection-xr
@@ -576,9 +591,15 @@ status:
576591
Most of the examples contain a `render.sh` command which uses `function-pythonic render` to
577592
render the example.
578593

579-
## ConfigMap Packages
594+
## Shared Python Packages
595+
596+
Python packages and modules can be added to the function-pythonic runtime
597+
by including the python code in any of the following resources: ConfigMap,
598+
Secret, EnvironmentConfig, or Composition
580599

581-
ConfigMap based python packages are enable using the `--packages` and
600+
### ConfigMap Packages
601+
602+
ConfigMap based python packages are enable using the `--packages-configmaps` and
582603
`--packages-namespace` command line options. ConfigMaps with the label
583604
`function-pythonic.package` will be incorporated in the python path at
584605
the location configured in the label value. For example, the following
@@ -640,7 +661,7 @@ data:
640661
composite: example.pythonic.features.FeatureOneComposite
641662
...
642663
```
643-
This requires enabling the the packages support using the `--packages` command
664+
This requires enabling the the packages support using the `--packages-configmaps` command
644665
line option in the DeploymentRuntimeConfig and configuring the required
645666
Kubernetes RBAC permissions. For example:
646667
```yaml
@@ -649,7 +670,7 @@ kind: Function
649670
metadata:
650671
name: function-pythonic
651672
spec:
652-
package: xpkg.upbound.io/crossplane-contrib/function-pythonic:v0.4.2
673+
package: xpkg.crossplane.io/crossplane-contrib/function-pythonic:v0.6.0
653674
runtimeConfigRef:
654675
name: function-pythonic
655676
---
@@ -711,9 +732,71 @@ ClusterRole permissions. The `--packages-namespace` command line option will res
711732
to only using the supplied namespace. This option can be invoked multiple times.
712733
The above RBAC permission can then be per namespace RBAC Role permissions.
713734

735+
### Secret Packages
736+
714737
Secrets can also be used in an identical manner as ConfigMaps by enabling the
715738
`--packages-secrets` command line option. Secrets permissions need to be
716-
added to the above RBAC configuration.
739+
added to the above RBAC configuration. Secret based python packages also enable
740+
provisioning files with binary data.
741+
742+
### EnvironmentConfig Packages
743+
744+
EnvironmentConfig based provisioning enable an entire package and module
745+
directory structure. Use the `--packages-environmentconfigs` command line option
746+
and configure the ClusterRole RBAC access.
747+
```yaml
748+
apiVersion: apiextensions.crossplane.io/v1beta1
749+
kind: EnvironmentConfig
750+
metadata:
751+
name: test
752+
labels:
753+
function-pythonic.package: 'true'
754+
data:
755+
arootpackage:
756+
asubpackage:
757+
bmodule.py: |
758+
def hello(where):
759+
return f"Hello, {where}!"
760+
amodule.py: |
761+
def goodby(where):
762+
return f"Goodby, {where}!"
763+
```
764+
### Composition Packages
765+
766+
Composition based provisioning works just like EnvironmentConfig where a
767+
directory structure is created. Use the `--packages-compositions` command line option
768+
and configure the ClusterRole RBAC access. The main reason to use Composition
769+
based provision is because Compositions can be included in a Crossplane
770+
Configuration Package.
771+
```yaml
772+
apiVersion: apiextensions.crossplane.io/v1
773+
kind: Composition
774+
metadata:
775+
labels:
776+
function-pythonic.package: 'true'
777+
name: test
778+
spec:
779+
compositeTypeRef:
780+
apiVersion: code.pythoni.com/v1alpha1
781+
kind: Code
782+
mode: Pipeline
783+
pipeline:
784+
- step: render
785+
functionRef:
786+
name: function-pythonic
787+
input:
788+
apiVersion: pythonic.fn.crossplane.io/v1alpha1
789+
kind: Composite
790+
packages:
791+
arootpackage:
792+
asubpackage:
793+
bmodule.py: |
794+
def hello(where):
795+
return f"Hello, {where}!"
796+
amodule.py: |
797+
def goodby(where):
798+
return f"Goodby, {where}!"
799+
```
717800

718801
## Step Parameters
719802

0 commit comments

Comments
 (0)