Skip to content
This repository was archived by the owner on Dec 10, 2025. It is now read-only.

Commit 5bf908e

Browse files
author
Patrick J. McNerthney
committed
Add documentation on how to run
1 parent 377704a commit 5bf908e

File tree

4 files changed

+52
-5
lines changed

4 files changed

+52
-5
lines changed

README.md

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,17 @@ function-go-templating examples implemented using function-pythonic.
4343
The [eks-cluster](./examples/eks-cluster/composition.yaml) example is a good
4444
complex example creating the entire vpc structure needed for an EKS cluster.
4545
46+
## Installing function-pythonic
47+
48+
```yaml
49+
apiVersion: pkg.crossplane.io/v1
50+
kind: Function
51+
metadata:
52+
name: function-pythonic
53+
spec:
54+
package: ghcr.io/fortra/function-pythonic:v0.0.3
55+
```
56+
4657
## Managed Resource Dependencies
4758
4859
function-pythonic automatically handles dependencies between managed resources.
@@ -259,10 +270,10 @@ spec:
259270
self.status.composite = 'Hello, World!'
260271
```
261272
262-
## Installing Python Packages
273+
## Install Additional Python Packages
263274
264275
function-pythonic supports a `--pip-install` command line option which will run pip install
265-
with the configured pip install command. For example, the following DeploymentRuntimeConfig:
276+
with the configured pip install command. For example:
266277
```yaml
267278
apiVersion: pkg.crossplane.io/v1beta1
268279
kind: DeploymentRuntimeConfig
@@ -280,3 +291,27 @@ spec:
280291
- --pip-install
281292
- --quiet aiobotocore==2.23.2
282293
```
294+
295+
## Enable Oversize Protos
296+
297+
The Protobuf python package used by function-pythonic limits the depth of yaml
298+
elements and the total size of yaml parsed. This results in a limit of approximately
299+
30 levels of nested yaml fields. This check can be disabled using the `--allow-oversize-protos`
300+
command line option. For example:
301+
302+
```yaml
303+
apiVersion: pkg.crossplane.io/v1beta1
304+
kind: DeploymentRuntimeConfig
305+
metadata:
306+
name: function-pythonic
307+
spec:
308+
deploymentTemplate:
309+
spec:
310+
template:
311+
spec:
312+
containers:
313+
- name: package-runtime
314+
args:
315+
- --debug
316+
- --allow-oversize-protos
317+
```

function/main.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,23 @@ def main():
3838
'--pip-install',
3939
help='Pip install command to install additional Python packages.'
4040
)
41+
parser.add_argument(
42+
'--allow-oversize-protos',
43+
action='store_true',
44+
help='Allow oversized protobuf messages'
45+
)
4146
args = parser.parse_args()
4247
if not args.tls_certs_dir:
4348
args.tls_certs_dir = os.getenv('TLS_SERVER_CERTS_DIR')
4449

4550
if args.pip_install:
4651
pip._internal.cli.main.main(['install', *shlex.split(args.pip_install)])
4752

53+
if args.allow_oversize_protos:
54+
from google.protobuf.internal import api_implementation
55+
if api_implementation._c_module:
56+
api_implementation._c_module.SetAllowOversizeProtos(True)
57+
4858
logging.configure(logging.Level.DEBUG if args.debug else logging.Level.INFO)
4959
runtime.serve(
5060
function.fn.FunctionRunner(),

function/protobuf.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,8 @@ def __getitem__(self, key):
224224
value = RepeatedMessage(self, key, self._field.message_type, value, self._readOnly)
225225
else:
226226
value = Message(self, key, self._field.message_type, value, self._readOnly)
227+
elif self._field.type == self._field.TYPE_BYTES and isinstance(value, bytes):
228+
value = value.decode('utf-8')
227229
self._cache[key] = value
228230
return value
229231

@@ -308,8 +310,8 @@ def __setitem__(self, key, message):
308310
self._messages = self._parent._create_child(self._key)
309311
if isinstance(message, Message):
310312
message = message._message
311-
if isinstance(message, str) and self._field.type == self._field.TYPE_BYTES:
312-
message = message.encode()
313+
if self._field.type == self._field.TYPE_BYTES and isinstance(message, str):
314+
message = message.encode('utf-8')
313315
self._messages[key] = message
314316
self._cache.pop(key, None)
315317

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ type = "virtual"
4444
path = ".venv-default"
4545
dependencies = ["ipython==9.1.0"]
4646
[tool.hatch.envs.default.scripts]
47-
development = "python function/main.py --insecure --debug"
47+
development = "python function/main.py --insecure --debug --allow-oversize-protos"
4848

4949
[tool.hatch.envs.lint]
5050
type = "virtual"

0 commit comments

Comments
 (0)