File tree Expand file tree Collapse file tree 7 files changed +57
-43
lines changed Expand file tree Collapse file tree 7 files changed +57
-43
lines changed Original file line number Diff line number Diff line change 14
14
15
15
env :
16
16
# Common versions
17
- PYTHON_VERSION : ' 3.11.5'
17
+ PYTHON_VERSION : ' 3.11'
18
+ HATCH_VERSION : ' 1.12.0'
18
19
DOCKER_BUILDX_VERSION : ' v0.11.2'
19
20
20
21
# These environment variables are important to the Crossplane CLI install.sh
@@ -47,10 +48,10 @@ jobs:
47
48
python-version : ${{ env.PYTHON_VERSION }}
48
49
49
50
- name : Setup Hatch
50
- run : pipx install hatch==1.7.0
51
+ run : pipx install hatch==${{ env.HATCH_VERSION }}
51
52
52
53
- name : Lint
53
- run : hatch run lint:check
54
+ run : hatch fmt
54
55
55
56
unit-test :
56
57
runs-on : ubuntu-22.04
@@ -64,10 +65,10 @@ jobs:
64
65
python-version : ${{ env.PYTHON_VERSION }}
65
66
66
67
- name : Setup Hatch
67
- run : pipx install hatch==1.7.0
68
+ run : pipx install hatch==${{ env.HATCH_VERSION }}
68
69
69
70
- name : Run Unit Tests
70
- run : hatch run test:unit
71
+ run : hatch test --all --randomize
71
72
72
73
# We want to build most packages for the amd64 and arm64 architectures. To
73
74
# speed this up we build single-platform packages in parallel. We then upload
Original file line number Diff line number Diff line change @@ -25,11 +25,11 @@ CLI][cli] to build functions.
25
25
# Run the code in development mode, for crossplane beta render
26
26
hatch run development
27
27
28
- # Lint the code - see pyproject.toml
29
- hatch run lint:check
28
+ # Lint and format the code - see pyproject.toml
29
+ hatch fmt
30
30
31
31
# Run unit tests - see tests/test_fn.py
32
- hatch run test:unit
32
+ hatch test
33
33
34
34
# Build the function's runtime image - see Dockerfile
35
35
$ docker build . --tag=runtime
Original file line number Diff line number Diff line change 14
14
input :
15
15
apiVersion : template.fn.crossplane.io/v1beta1
16
16
kind : Input
17
- example : " Hello world "
17
+ version : v1beta2
Original file line number Diff line number Diff line change 1
1
"""A Crossplane composition function."""
2
2
3
3
import grpc
4
- from crossplane .function import logging , response
4
+ from crossplane .function import logging , resource , response
5
5
from crossplane .function .proto .v1 import run_function_pb2 as fnv1
6
6
from crossplane .function .proto .v1 import run_function_pb2_grpc as grpcv1
7
7
@@ -22,12 +22,18 @@ async def RunFunction(
22
22
23
23
rsp = response .to (req )
24
24
25
- example = ""
26
- if "example" in req .input :
27
- example = req .input ["example" ]
28
-
29
- # TODO: Add your function logic here!
30
- response .normal (rsp , f"I was run with input { example } !" )
31
- log .info ("I was run!" , input = example )
25
+ version = req .input ["version" ]
26
+ region = req .observed .composite .resource ["spec" ]["region" ]
27
+
28
+ resource .update (
29
+ rsp .desired .resources ["bucket" ],
30
+ {
31
+ "apiVersion" : f"s3.aws.upbound.io/{ version } " ,
32
+ "kind" : "Bucket" ,
33
+ "spec" : {
34
+ "forProvider" : {"region" : region },
35
+ },
36
+ },
37
+ )
32
38
33
39
return rsp
Original file line number Diff line number Diff line change 24
24
of an object. Servers should convert recognized schemas to the latest
25
25
internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources'
26
26
type : string
27
- example :
28
- description : Example is an example field. Replace it with whatever input
29
- you need. :)
27
+ version :
28
+ description : The bucket version to compose (e.g. v1beta2).
30
29
type : string
31
30
kind :
32
31
description : ' Kind is a string value representing the REST resource this
36
35
metadata :
37
36
type : object
38
37
required :
39
- - example
38
+ - version
40
39
type : object
41
40
served : true
42
41
storage : true
Original file line number Diff line number Diff line change @@ -48,21 +48,10 @@ dependencies = ["ipython==8.28.0"]
48
48
[tool .hatch .envs .default .scripts ]
49
49
development = " python function/main.py --insecure --debug"
50
50
51
- [tool .hatch .envs .lint ]
52
- type = " virtual"
53
- detached = true
54
- path = " .venv-lint"
51
+ # This special environment is used by hatch fmt.
52
+ [tool .hatch .envs .hatch-static-analysis ]
55
53
dependencies = [" ruff==0.6.9" ]
56
-
57
- [tool .hatch .envs .lint .scripts ]
58
- check = " ruff check function tests && ruff format --diff function tests"
59
-
60
- [tool .hatch .envs .test ]
61
- type = " virtual"
62
- path = " .venv-test"
63
-
64
- [tool .hatch .envs .test .scripts ]
65
- unit = " python -m unittest tests/*.py"
54
+ config-path = " none" # Disable Hatch's default Ruff config.
66
55
67
56
[tool .ruff ]
68
57
target-version = " py311"
Original file line number Diff line number Diff line change @@ -28,17 +28,36 @@ class TestCase:
28
28
TestCase (
29
29
reason = "The function should return the input as a result." ,
30
30
req = fnv1 .RunFunctionRequest (
31
- input = resource .dict_to_struct ({"example" : "Hello, world" })
31
+ input = resource .dict_to_struct ({"version" : "v1beta2" }),
32
+ observed = fnv1 .State (
33
+ composite = fnv1 .Resource (
34
+ resource = resource .dict_to_struct (
35
+ {
36
+ "apiVersion" : "example.crossplane.io/v1" ,
37
+ "kind" : "XR" ,
38
+ "spec" : {"region" : "us-west-2" },
39
+ }
40
+ ),
41
+ ),
42
+ ),
32
43
),
33
44
want = fnv1 .RunFunctionResponse (
34
45
meta = fnv1 .ResponseMeta (ttl = durationpb .Duration (seconds = 60 )),
35
- desired = fnv1 .State (),
36
- results = [
37
- fnv1 .Result (
38
- severity = fnv1 .SEVERITY_NORMAL ,
39
- message = "I was run with input Hello, world!" ,
40
- )
41
- ],
46
+ desired = fnv1 .State (
47
+ resources = {
48
+ "bucket" : fnv1 .Resource (
49
+ resource = resource .dict_to_struct (
50
+ {
51
+ "apiVersion" : "s3.aws.upbound.io/v1beta2" ,
52
+ "kind" : "Bucket" ,
53
+ "spec" : {
54
+ "forProvider" : {"region" : "us-west-2" },
55
+ },
56
+ }
57
+ ),
58
+ ),
59
+ },
60
+ ),
42
61
context = structpb .Struct (),
43
62
),
44
63
),
You can’t perform that action at this time.
0 commit comments