Skip to content

Commit ba43322

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

File tree

2 files changed

+99
-4
lines changed

2 files changed

+99
-4
lines changed

README.md

Lines changed: 97 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,98 @@ 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 `from example.pythonic import 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+
# this is the features python module
322+
```
323+
This requires enabling the the packages support using the `--packages` command
324+
line option in the DeploymentRuntimeConfig and configuring the required
325+
Kubernetes RBAC permissions. For example:
326+
```yaml
327+
apiVersion: pkg.crossplane.io/v1
328+
kind: Function
329+
metadata:
330+
name: function-pythonic
331+
spec:
332+
package: ghcr.io/fortra/function-pythonic:v0.0.6
333+
runtimeConfigRef:
334+
name: function-pythonic
335+
---
336+
apiVersion: pkg.crossplane.io/v1beta1
337+
kind: DeploymentRuntimeConfig
338+
metadata:
339+
name: function-pythonic
340+
spec:
341+
deploymentTemplate:
342+
spec:
343+
selector: {}
344+
template:
345+
spec:
346+
containers:
347+
- name: package-runtime
348+
args:
349+
- --debug
350+
- --packages
351+
serviceAccountName: function-pythonic
352+
serviceAccountTemplate:
353+
metadata:
354+
name: function-pythonic
355+
---
356+
apiVersion: rbac.authorization.k8s.io/v1
357+
kind: ClusterRole
358+
metadata:
359+
name: function-pythonic
360+
rules:
361+
- apiGroups:
362+
- ''
363+
resources:
364+
- events
365+
verbs:
366+
- create
367+
- apiGroups:
368+
- ''
369+
resources:
370+
- configmaps
371+
- secrets
372+
verbs:
373+
- list
374+
- watch
375+
- patch
376+
---
377+
apiVersion: rbac.authorization.k8s.io/v1
378+
kind: ClusterRoleBinding
379+
metadata:
380+
name: function-pythonic
381+
roleRef:
382+
apiGroup: rbac.authorization.k8s.io
383+
kind: ClusterRole
384+
name: function-pythonic
385+
subjects:
386+
- kind: ServiceAccount
387+
namespace: crossplane-system
388+
name: function-pythonic
389+
```
390+
When enabled, labeled ConfigMaps and Secrets are obtained from cluster wide,
391+
requiring the above ClusterRole permissions. The `--packages-name` command
392+
line option will restrict to only using the supplied namespaces. Per namespace
393+
RBAC permissions are then required.
394+
395+
## Filing System Packages
301396

302397
Composition Composite implementations can be coded in a stand alone python files
303398
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)