From 1cf036a80de5ef5cf41b18d5c64f0849e0ab592b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Fern=C3=A1ndez?= <7312236+fernandezcuesta@users.noreply.github.com> Date: Fri, 11 Sep 2026 23:39:23 +0200 Subject: [PATCH] feat: leverage reusable cli standard options MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jesús Fernández <7312236+fernandezcuesta@users.noreply.github.com> --- Dockerfile | 2 +- function/main.py | 42 ++++-------------------------------------- pyproject.toml | 2 +- 3 files changed, 6 insertions(+), 40 deletions(-) diff --git a/Dockerfile b/Dockerfile index 21c60a7..c668646 100644 --- a/Dockerfile +++ b/Dockerfile @@ -31,7 +31,7 @@ RUN --mount=type=cache,target=/root/.cache/pip \ # Copy the function venv to our runtime stage. It's important that the path be # the same as in the build stage, to avoid shebang paths and symlinks breaking. -FROM gcr.io/distroless/python3-debian12 AS image +FROM gcr.io/distroless/python3-debian13 AS image WORKDIR / COPY --from=build /venv/fn /venv/fn EXPOSE 9443 diff --git a/function/main.py b/function/main.py index 7ea1197..1b049a4 100644 --- a/function/main.py +++ b/function/main.py @@ -1,50 +1,16 @@ """The composition function's main CLI.""" import click -from crossplane.function import logging, runtime +from crossplane.function import cli as sdkcli from function import fn @click.command() -@click.option( - "--debug", - "-d", - is_flag=True, - help="Emit debug logs.", -) -@click.option( - "--address", - default="0.0.0.0:9443", - show_default=True, - help="Address at which to listen for gRPC connections", -) -@click.option( - "--tls-certs-dir", - help="Serve using mTLS certificates.", - envvar="TLS_SERVER_CERTS_DIR", -) -@click.option( - "--insecure", - is_flag=True, - help="Run without mTLS credentials. " - "If you supply this flag --tls-certs-dir will be ignored.", -) -def cli(debug: bool, address: str, tls_certs_dir: str, insecure: bool) -> None: # noqa:FBT001 # We only expect callers via the CLI. +@sdkcli.standard_options +def cli(**kwargs): """A Crossplane composition function.""" - try: - level = logging.Level.INFO - if debug: - level = logging.Level.DEBUG - logging.configure(level=level) - runtime.serve( - fn.FunctionRunner(), - address, - creds=runtime.load_credentials(tls_certs_dir), - insecure=insecure, - ) - except Exception as e: - click.echo(f"Cannot run function: {e}") + sdkcli.run(fn.FunctionRunner(), **kwargs) if __name__ == "__main__": diff --git a/pyproject.toml b/pyproject.toml index 0c04510..e6b1d75 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -17,7 +17,7 @@ classifiers = [ ] dependencies = [ - "crossplane-function-sdk-python==0.14.0", + "crossplane-function-sdk-python==0.15.0", "click==8.5.0", "grpcio>=1.73.1", ]