Skip to content

Commit 216f778

Browse files
author
Patrick J. McNerthney
committed
Documentation of ConfigMap and Secret based packages
1 parent f8aba76 commit 216f778

File tree

2 files changed

+115
-4
lines changed

2 files changed

+115
-4
lines changed

README.md

Lines changed: 113 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,12 @@ spec:
3535
vpc.spec.forProvider.cidrBlock = self.spec.cidr
3636
self.status.vpcId = vpc.status.atProvider.vpcId
3737
```
38+
3839
In addtion to an inline script, the python implementation can be specified
39-
as the complete path to a python class. See [Filing system Composites](#filing-system-composites).
40+
as the complete path to a python class. Python packages can be deployed using
41+
ConfigMaps or Secrets enabling the use of your IDE of choice for writting
42+
the code. See [ConfigMap and Secret Packages](#configmap-and-secret-packages)
43+
and [Filing System Packages](#filing-system-packages).
4044
4145
## Examples
4246
@@ -297,7 +301,114 @@ spec:
297301
self.status.composite = 'Hello, World!'
298302
```
299303

300-
## Filing system Composites
304+
## ConfigMap and Secret Packages
305+
306+
ConfigMap and Secret based python packages are enable using the `--packages`
307+
and `--packages-namespace` command line options. ConfigMaps and Secrets
308+
with the label `function-pythonic.package` will be incorporated in the python
309+
path at the location configured in the label value. For example, the following
310+
ConfigMap will enable python to use `import example.pythonic.features`
311+
```yaml
312+
apiVersion: v1
313+
kind: ConfigMap
314+
metadata:
315+
namespace: crossplane-system
316+
name: example-pythonic
317+
labels:
318+
function-pythonic.package: example.pythonic
319+
data:
320+
features.py: |
321+
def anything():
322+
return 'something'
323+
```
324+
Then, in your Composition:
325+
```yaml
326+
...
327+
- step: pythonic
328+
functionRef:
329+
name: function-pythonic
330+
input:
331+
apiVersion: pythonic.fn.fortra.com/v1alpha1
332+
kind: Composite
333+
composite: |
334+
from example.pythonic import features
335+
class Composite(BaseComposite):
336+
def compose(self):
337+
anything = features.anything()
338+
```
339+
This requires enabling the the packages support using the `--packages` command
340+
line option in the DeploymentRuntimeConfig and configuring the required
341+
Kubernetes RBAC permissions. For example:
342+
```yaml
343+
apiVersion: pkg.crossplane.io/v1
344+
kind: Function
345+
metadata:
346+
name: function-pythonic
347+
spec:
348+
package: ghcr.io/fortra/function-pythonic:v0.0.6
349+
runtimeConfigRef:
350+
name: function-pythonic
351+
---
352+
apiVersion: pkg.crossplane.io/v1beta1
353+
kind: DeploymentRuntimeConfig
354+
metadata:
355+
name: function-pythonic
356+
spec:
357+
deploymentTemplate:
358+
spec:
359+
selector: {}
360+
template:
361+
spec:
362+
containers:
363+
- name: package-runtime
364+
args:
365+
- --debug
366+
- --packages
367+
serviceAccountName: function-pythonic
368+
serviceAccountTemplate:
369+
metadata:
370+
name: function-pythonic
371+
---
372+
apiVersion: rbac.authorization.k8s.io/v1
373+
kind: ClusterRole
374+
metadata:
375+
name: function-pythonic
376+
rules:
377+
- apiGroups:
378+
- ''
379+
resources:
380+
- events
381+
verbs:
382+
- create
383+
- apiGroups:
384+
- ''
385+
resources:
386+
- configmaps
387+
- secrets
388+
verbs:
389+
- list
390+
- watch
391+
- patch
392+
---
393+
apiVersion: rbac.authorization.k8s.io/v1
394+
kind: ClusterRoleBinding
395+
metadata:
396+
name: function-pythonic
397+
roleRef:
398+
apiGroup: rbac.authorization.k8s.io
399+
kind: ClusterRole
400+
name: function-pythonic
401+
subjects:
402+
- kind: ServiceAccount
403+
namespace: crossplane-system
404+
name: function-pythonic
405+
```
406+
When enabled, labeled ConfigMaps and Secrets are obtained cluster wide,
407+
requiring the above ClusterRole permissions. The `--packages-name` command
408+
line option will restrict to only using the supplied namespaces. Per namespace
409+
RBAC permissions are then required.
410+
411+
## Filing System Packages
301412

302413
Composition Composite implementations can be coded in a stand alone python files
303414
by configuring the function-pythonic deployment with the code mounted into

crossplane/pythonic/packages.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ async def update(body, old, logger, **_):
5656
for name, text in body.get('data', {}).items():
5757
package_file = package_dir / name
5858
if package_dir == old_package_dir and text == old_data.get(name, None):
59-
action = 'Same'
59+
action = 'Unchanged'
6060
else:
6161
if secret:
6262
package_file.write_bytes(base64.b64decode(text.encode('utf-8')))
@@ -65,7 +65,7 @@ async def update(body, old, logger, **_):
6565
action = 'Updated' if package_dir == old_package_dir and name in old_names else 'Created'
6666
if package_file.suffixes == ['.py']:
6767
module = '.'.join(package + [package_file.stem])
68-
if action != 'Same':
68+
if action != 'Unchanged':
6969
GRPC_RUNNER.invalidate_module(module)
7070
logger.info(f"{action} module: {module}")
7171
else:

0 commit comments

Comments
 (0)