Skip to content

Commit 4b91ebc

Browse files
author
Patrick J. McNerthney
committed
Add step parameters support
1 parent 8ad70c0 commit 4b91ebc

File tree

3 files changed

+40
-0
lines changed

3 files changed

+40
-0
lines changed

README.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,7 @@ The BaseComposite also provides access to the following Crossplane Function leve
214214
| self.request | Message | Low level direct access to the RunFunctionRequest message |
215215
| self.response | Message | Low level direct access to the RunFunctionResponse message |
216216
| self.logger | Logger | Python logger to log messages to the running function stdout |
217+
| self.parameters | Map | The configured step parameters |
217218
| self.ttl | Integer | Get or set the response TTL, in seconds |
218219
| self.credentials | Credentials | The request credentials |
219220
| self.context | Map | The response context, initialized from the request context |
@@ -552,6 +553,41 @@ Secrets can also be used in an identical manner as ConfigMaps by enabling the
552553
`--packages-secrets` command line option. Secrets permissions need to be
553554
added to the above RBAC configuration.
554555

556+
## Step Parameters
557+
558+
Step specific parameters can be configured to be used by the composite
559+
implementation. This is useful when setting the composite to the python class.
560+
For example:
561+
```yaml
562+
apiVersion: v1
563+
kind: ConfigMap
564+
metadata:
565+
namespace: crossplane-system
566+
name: example-pythonic
567+
labels:
568+
function-pythonic.package: example.pythonic
569+
data:
570+
features.py: |
571+
from crossplane.pythonic import BaseComposite
572+
class GreetingComposite(BaseComposite):
573+
def compose(self):
574+
cm = self.resources.ConfigMap('v1', 'ConfigMap')
575+
cm.data.greeting = f"Hello, {self.parameters.who}!"
576+
```
577+
```yaml
578+
...
579+
- step: pythonic
580+
functionRef:
581+
name: function-pythonic
582+
input:
583+
apiVersion: pythonic.fn.fortra.com/v1alpha1
584+
kind: Composite
585+
parameters:
586+
who: World
587+
composite: example.pythonic.features.GreetingComposite
588+
...
589+
```
590+
555591
## Filing System Packages
556592

557593
Composition Composite implementations can be coded in a stand alone python files

crossplane/pythonic/composite.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ def __init__(self, request, logger):
2424
)
2525
self.response = protobuf.Message(None, 'response', response.DESCRIPTOR, response)
2626
self.logger = logger
27+
self.parameters = self.request.input.parameters
2728
self.credentials = Credentials(self.request)
2829
self.context = self.response.context
2930
self.environment = self.context['apiextensions.crossplane.io/environment']

package/input-definition.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ spec:
2929
step:
3030
type: string
3131
description: Optional step name used in logging
32+
parameters:
33+
type: object
34+
x-kubernetes-preserve-unknown-fields: true
3235
composite:
3336
type: string
3437
description: 'A Python module that defines a class with the signature: class Composite(BaseComposite)'

0 commit comments

Comments
 (0)