crossplane-function-pythonic 0.6.3__tar.gz → 0.7.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (26) hide show
  1. crossplane_function_pythonic-0.6.3/README.md → crossplane_function_pythonic-0.7.1/PKG-INFO +66 -2
  2. crossplane_function_pythonic-0.6.3/PKG-INFO → crossplane_function_pythonic-0.7.1/README.md +44 -24
  3. {crossplane_function_pythonic-0.6.3 → crossplane_function_pythonic-0.7.1}/pyproject.toml +17 -9
  4. {crossplane_function_pythonic-0.6.3 → crossplane_function_pythonic-0.7.1}/pyproject.toml.orig +17 -9
  5. crossplane_function_pythonic-0.7.1/src/crossplane/pythonic/__about__.py +6 -0
  6. {crossplane_function_pythonic-0.6.3 → crossplane_function_pythonic-0.7.1}/src/crossplane/pythonic/auto_ready.py +31 -22
  7. {crossplane_function_pythonic-0.6.3 → crossplane_function_pythonic-0.7.1}/src/crossplane/pythonic/command.py +37 -24
  8. crossplane_function_pythonic-0.7.1/src/crossplane/pythonic/composite.py +1317 -0
  9. {crossplane_function_pythonic-0.6.3 → crossplane_function_pythonic-0.7.1}/src/crossplane/pythonic/function.py +136 -110
  10. {crossplane_function_pythonic-0.6.3 → crossplane_function_pythonic-0.7.1}/src/crossplane/pythonic/grpc.py +7 -4
  11. {crossplane_function_pythonic-0.6.3 → crossplane_function_pythonic-0.7.1}/src/crossplane/pythonic/main.py +7 -3
  12. {crossplane_function_pythonic-0.6.3 → crossplane_function_pythonic-0.7.1}/src/crossplane/pythonic/packages.py +27 -19
  13. crossplane_function_pythonic-0.7.1/src/crossplane/pythonic/proto/v1/run_function_pb2.pyi +1172 -0
  14. {crossplane_function_pythonic-0.6.3 → crossplane_function_pythonic-0.7.1}/src/crossplane/pythonic/proto/v1/run_function_pb2_grpc.py +1 -1
  15. crossplane_function_pythonic-0.7.1/src/crossplane/pythonic/proto/v1/run_function_pb2_grpc.pyi +64 -0
  16. {crossplane_function_pythonic-0.6.3 → crossplane_function_pythonic-0.7.1}/src/crossplane/pythonic/protobuf.py +346 -196
  17. {crossplane_function_pythonic-0.6.3 → crossplane_function_pythonic-0.7.1}/src/crossplane/pythonic/render.py +211 -82
  18. {crossplane_function_pythonic-0.6.3 → crossplane_function_pythonic-0.7.1}/src/crossplane/pythonic/version.py +1 -1
  19. crossplane_function_pythonic-0.6.3/src/crossplane/pythonic/__about__.py +0 -8
  20. crossplane_function_pythonic-0.6.3/src/crossplane/pythonic/composite.py +0 -1111
  21. crossplane_function_pythonic-0.6.3/src/crossplane/pythonic/diff.py +0 -880
  22. crossplane_function_pythonic-0.6.3/src/crossplane/pythonic/proto/v1/run_function_pb2.pyi +0 -306
  23. {crossplane_function_pythonic-0.6.3 → crossplane_function_pythonic-0.7.1}/src/crossplane/pythonic/__init__.py +0 -0
  24. {crossplane_function_pythonic-0.6.3 → crossplane_function_pythonic-0.7.1}/src/crossplane/pythonic/__main__.py +0 -0
  25. {crossplane_function_pythonic-0.6.3 → crossplane_function_pythonic-0.7.1}/src/crossplane/pythonic/proto/v1/run_function.proto +0 -0
  26. {crossplane_function_pythonic-0.6.3 → crossplane_function_pythonic-0.7.1}/src/crossplane/pythonic/proto/v1/run_function_pb2.py +0 -0
@@ -1,3 +1,25 @@
1
+ Metadata-Version: 2.4
2
+ Name: crossplane-function-pythonic
3
+ Version: 0.7.1
4
+ Summary: A Python centric Crossplane Function
5
+ Author: Patrick J McNerthney
6
+ Author-email: Patrick J McNerthney <pat@mcnerthney.com>
7
+ License-Expression: Apache-2.0
8
+ Requires-Dist: grpcio==1.86.0
9
+ Requires-Dist: inflect==7.6.0
10
+ Requires-Dist: kr8s==0.20.15
11
+ Requires-Dist: protobuf==7.36.2
12
+ Requires-Dist: pyyaml==6.0.4
13
+ Requires-Dist: kopf==1.45.2 ; extra == 'packages'
14
+ Requires-Dist: pip==26.3 ; extra == 'pip-install'
15
+ Requires-Python: >=3.15, <3.16
16
+ Project-URL: Documentation, https://github.com/crossplane-contrib/function-pythonic#readme
17
+ Project-URL: Issues, https://github.com/crossplane-contrib/function-pythonic/issues
18
+ Project-URL: Source, https://github.com/crossplane-contrib/function-pythonic
19
+ Provides-Extra: packages
20
+ Provides-Extra: pip-install
21
+ Description-Content-Type: text/markdown
22
+
1
23
  # function-pythonic
2
24
 
3
25
  ## Introduction
@@ -173,6 +195,43 @@ subnet.spec.forProvider.cidrBlock = '10.0.0.0/20'
173
195
  ```
174
196
  Will generate the appropriate Crossplane Usage resource.
175
197
 
198
+ ### Usage replayDeletion
199
+
200
+ Generated Usages set `spec.replayDeletion` from the `usagesReplayDeletion` setting:
201
+
202
+ | Setting | Scope | Default |
203
+ | :--- | :--- | :--- |
204
+ | `--usages-replay-deletion` / `--no-usages-replay-deletion` | Command line, all compositions | True |
205
+ | `self.usagesReplayDeletion` | All resources of the composite | The command line value |
206
+ | `Resource.usagesReplayDeletion` | All Usages generated for that resource | `self.usagesReplayDeletion` |
207
+
208
+ The setting applies to every Usage generated for a resource. It cannot be set per
209
+ dependency.
210
+
211
+ With `replayDeletion: true`, Crossplane replays a blocked deletion of the protected
212
+ resource when its Usage is removed. Generated Usages are composed resources, so they are
213
+ removed during normal reconciliation: when `compose()` stops reading the dependent field,
214
+ or when the protected resource's observed name changes, since that name is part of the
215
+ Usage name. If the protected resource had a blocked deletion attempt, removing its Usage
216
+ deletes it. To avoid this, set `replayDeletion: false` for all compositions using a
217
+ Crossplane DeploymentRuntimeConfig:
218
+ ```yaml
219
+ apiVersion: pkg.crossplane.io/v1beta1
220
+ kind: DeploymentRuntimeConfig
221
+ metadata:
222
+ name: function-pythonic
223
+ spec:
224
+ deploymentTemplate:
225
+ spec:
226
+ selector: {}
227
+ template:
228
+ spec:
229
+ containers:
230
+ - name: package-runtime
231
+ args:
232
+ - --no-usages-replay-deletion
233
+ ```
234
+
176
235
  ## API Documentation
177
236
 
178
237
  - [Composite API (`composite.py`)](https://github.com/crossplane-contrib/function-pythonic/blob/main/docs/composite.md)
@@ -294,6 +353,7 @@ The BaseComposite also provides access to the following Crossplane Function leve
294
353
  | self.schemas | Schemas | Request and read CustomResourceDefinition schemas |
295
354
  | self.resources | Resources | Define and process composed resources |
296
355
  | self.usages| Boolean | Generate Crossplane Usages for resource dependencies, default False |
356
+ | self.usagesReplayDeletion | Boolean | The replayDeletion value of generated Usages, default is the `--usages-replay-deletion` command line option (True) |
297
357
  | self.autoReady | Boolean | Perform auto ready processing on all composed resources, default True |
298
358
  | self.unknownsFatal | Boolean | Terminate the composition if already created resources are assigned unknown values, default False |
299
359
 
@@ -334,7 +394,8 @@ Resource class:
334
394
  | Resource.ready | Boolean | The resource ready state |
335
395
  | Resource.addDependency | Method | Add another composed resource as a dependency |
336
396
  | Resource.setReadyCondition | Method | Set Resource.ready to the Ready Condition status |
337
- | Resource.usages | Boolean | Generate Crossplane Usages for this resource, default is Composite.autoReady |
397
+ | Resource.usages | Boolean | Generate Crossplane Usages for this resource, default is Composite.usages |
398
+ | Resource.usagesReplayDeletion | Boolean | The replayDeletion value of all Usages generated for this resource, default is Composite.usagesReplayDeletion |
338
399
  | Resource.autoReady | Boolean | Perform auto ready processing on this resource, default is Composite.autoReady |
339
400
  | Resource.unknownsFatal | Boolean | Terminate the composition if this resource has been created and is assigned unknown values, default is Composite.unknownsFatal |
340
401
 
@@ -503,7 +564,8 @@ command.
503
564
  ```shell
504
565
  $ function-pythonic render --help
505
566
  usage: Crossplane Function Pythonic render [-h] [--debug] [--log-name-width WIDTH] [--logger-level LOGGER=LEVEL] [--python-path DIRECTORY]
506
- [--render-unknowns] [--allow-oversize-protos] [--crossplane-v1] [--kube-context CONTEXT]
567
+ [--render-unknowns] [--allow-oversize-protos] [--crossplane-v1]
568
+ [--usages-replay-deletion | --no-usages-replay-deletion] [--kube-context CONTEXT]
507
569
  [--context-files KEY=PATH] [--context-values KEY=VALUE] [--observed-resources PATH]
508
570
  [--required-resources PATH] [--required-schemas PATH] [--include-full-xr] [--include-connection-xr]
509
571
  [--include-function-results] [--include-context]
@@ -527,6 +589,8 @@ options:
527
589
  --allow-oversize-protos
528
590
  Allow oversized protobuf messages
529
591
  --crossplane-v1 Enable Crossplane V1 compatibility mode
592
+ --usages-replay-deletion, --no-usages-replay-deletion
593
+ Default replayDeletion value for generated Usages (default: True)
530
594
  --kube-context, -k CONTEXT
531
595
  The kubectl context to use to obtain external resources from, such as required resources, connections, etc.
532
596
  --context-files KEY=PATH
@@ -1,25 +1,3 @@
1
- Metadata-Version: 2.4
2
- Name: crossplane-function-pythonic
3
- Version: 0.6.3
4
- Summary: A Python centric Crossplane Function
5
- Author: Patrick J McNerthney
6
- Author-email: Patrick J McNerthney <pat@mcnerthney.com>
7
- License-Expression: Apache-2.0
8
- Requires-Dist: grpcio==1.84.0
9
- Requires-Dist: inflect==7.6.0
10
- Requires-Dist: kr8s==0.20.15
11
- Requires-Dist: protobuf==7.36.2
12
- Requires-Dist: pyyaml==6.0.3
13
- Requires-Dist: kopf==1.45.1 ; extra == 'packages'
14
- Requires-Dist: pip==26.2.2 ; extra == 'pip-install'
15
- Requires-Python: >=3.12, <3.16
16
- Project-URL: Documentation, https://github.com/crossplane-contrib/function-pythonic#readme
17
- Project-URL: Issues, https://github.com/crossplane-contrib/function-pythonic/issues
18
- Project-URL: Source, https://github.com/crossplane-contrib/function-pythonic
19
- Provides-Extra: packages
20
- Provides-Extra: pip-install
21
- Description-Content-Type: text/markdown
22
-
23
1
  # function-pythonic
24
2
 
25
3
  ## Introduction
@@ -195,6 +173,43 @@ subnet.spec.forProvider.cidrBlock = '10.0.0.0/20'
195
173
  ```
196
174
  Will generate the appropriate Crossplane Usage resource.
197
175
 
176
+ ### Usage replayDeletion
177
+
178
+ Generated Usages set `spec.replayDeletion` from the `usagesReplayDeletion` setting:
179
+
180
+ | Setting | Scope | Default |
181
+ | :--- | :--- | :--- |
182
+ | `--usages-replay-deletion` / `--no-usages-replay-deletion` | Command line, all compositions | True |
183
+ | `self.usagesReplayDeletion` | All resources of the composite | The command line value |
184
+ | `Resource.usagesReplayDeletion` | All Usages generated for that resource | `self.usagesReplayDeletion` |
185
+
186
+ The setting applies to every Usage generated for a resource. It cannot be set per
187
+ dependency.
188
+
189
+ With `replayDeletion: true`, Crossplane replays a blocked deletion of the protected
190
+ resource when its Usage is removed. Generated Usages are composed resources, so they are
191
+ removed during normal reconciliation: when `compose()` stops reading the dependent field,
192
+ or when the protected resource's observed name changes, since that name is part of the
193
+ Usage name. If the protected resource had a blocked deletion attempt, removing its Usage
194
+ deletes it. To avoid this, set `replayDeletion: false` for all compositions using a
195
+ Crossplane DeploymentRuntimeConfig:
196
+ ```yaml
197
+ apiVersion: pkg.crossplane.io/v1beta1
198
+ kind: DeploymentRuntimeConfig
199
+ metadata:
200
+ name: function-pythonic
201
+ spec:
202
+ deploymentTemplate:
203
+ spec:
204
+ selector: {}
205
+ template:
206
+ spec:
207
+ containers:
208
+ - name: package-runtime
209
+ args:
210
+ - --no-usages-replay-deletion
211
+ ```
212
+
198
213
  ## API Documentation
199
214
 
200
215
  - [Composite API (`composite.py`)](https://github.com/crossplane-contrib/function-pythonic/blob/main/docs/composite.md)
@@ -316,6 +331,7 @@ The BaseComposite also provides access to the following Crossplane Function leve
316
331
  | self.schemas | Schemas | Request and read CustomResourceDefinition schemas |
317
332
  | self.resources | Resources | Define and process composed resources |
318
333
  | self.usages| Boolean | Generate Crossplane Usages for resource dependencies, default False |
334
+ | self.usagesReplayDeletion | Boolean | The replayDeletion value of generated Usages, default is the `--usages-replay-deletion` command line option (True) |
319
335
  | self.autoReady | Boolean | Perform auto ready processing on all composed resources, default True |
320
336
  | self.unknownsFatal | Boolean | Terminate the composition if already created resources are assigned unknown values, default False |
321
337
 
@@ -356,7 +372,8 @@ Resource class:
356
372
  | Resource.ready | Boolean | The resource ready state |
357
373
  | Resource.addDependency | Method | Add another composed resource as a dependency |
358
374
  | Resource.setReadyCondition | Method | Set Resource.ready to the Ready Condition status |
359
- | Resource.usages | Boolean | Generate Crossplane Usages for this resource, default is Composite.autoReady |
375
+ | Resource.usages | Boolean | Generate Crossplane Usages for this resource, default is Composite.usages |
376
+ | Resource.usagesReplayDeletion | Boolean | The replayDeletion value of all Usages generated for this resource, default is Composite.usagesReplayDeletion |
360
377
  | Resource.autoReady | Boolean | Perform auto ready processing on this resource, default is Composite.autoReady |
361
378
  | Resource.unknownsFatal | Boolean | Terminate the composition if this resource has been created and is assigned unknown values, default is Composite.unknownsFatal |
362
379
 
@@ -525,7 +542,8 @@ command.
525
542
  ```shell
526
543
  $ function-pythonic render --help
527
544
  usage: Crossplane Function Pythonic render [-h] [--debug] [--log-name-width WIDTH] [--logger-level LOGGER=LEVEL] [--python-path DIRECTORY]
528
- [--render-unknowns] [--allow-oversize-protos] [--crossplane-v1] [--kube-context CONTEXT]
545
+ [--render-unknowns] [--allow-oversize-protos] [--crossplane-v1]
546
+ [--usages-replay-deletion | --no-usages-replay-deletion] [--kube-context CONTEXT]
529
547
  [--context-files KEY=PATH] [--context-values KEY=VALUE] [--observed-resources PATH]
530
548
  [--required-resources PATH] [--required-schemas PATH] [--include-full-xr] [--include-connection-xr]
531
549
  [--include-function-results] [--include-context]
@@ -549,6 +567,8 @@ options:
549
567
  --allow-oversize-protos
550
568
  Allow oversized protobuf messages
551
569
  --crossplane-v1 Enable Crossplane V1 compatibility mode
570
+ --usages-replay-deletion, --no-usages-replay-deletion
571
+ Default replayDeletion value for generated Usages (default: True)
552
572
  --kube-context, -k CONTEXT
553
573
  The kubectl context to use to obtain external resources from, such as required resources, connections, etc.
554
574
  --context-files KEY=PATH
@@ -1,16 +1,16 @@
1
1
  [project]
2
2
  name = "crossplane-function-pythonic"
3
- version = "0.6.3"
3
+ version = "0.7.1"
4
4
  description = "A Python centric Crossplane Function"
5
5
  license = "Apache-2.0"
6
6
  readme = "README.md"
7
- requires-python = ">=3.12,<3.16"
7
+ requires-python = ">=3.15,<3.16"
8
8
  dependencies = [
9
- "grpcio==1.84.0",
9
+ "grpcio==1.86.0",
10
10
  "inflect==7.6.0",
11
11
  "kr8s==0.20.15",
12
12
  "protobuf==7.36.2",
13
- "pyyaml==6.0.3",
13
+ "pyyaml==6.0.4",
14
14
  ]
15
15
 
16
16
  [[project.authors]]
@@ -18,8 +18,8 @@ name = "Patrick J McNerthney"
18
18
  email = "pat@mcnerthney.com"
19
19
 
20
20
  [project.optional-dependencies]
21
- packages = ["kopf==1.45.1"]
22
- pip-install = ["pip==26.2.2"]
21
+ packages = ["kopf==1.45.2"]
22
+ pip-install = ["pip==26.3"]
23
23
 
24
24
  [project.urls]
25
25
  Documentation = "https://github.com/crossplane-contrib/function-pythonic#readme"
@@ -30,24 +30,32 @@ Source = "https://github.com/crossplane-contrib/function-pythonic"
30
30
  function-pythonic = "crossplane.pythonic.main:main"
31
31
 
32
32
  [build-system]
33
- requires = ["uv_build>=0.12.23,<0.13.0"]
33
+ requires = ["uv_build>=0.13.9,<0.14.0"]
34
34
  build-backend = "uv_build"
35
35
 
36
36
  [dependency-groups]
37
37
  dev = [
38
- "grpcio-tools>=1.84.0",
38
+ "grpcio-tools==1.86.0",
39
+ "kopf==1.45.2",
40
+ "mypy-protobuf>=5.1.0",
39
41
  "poethepoet>=0.48.0",
42
+ "pip==26.3",
40
43
  "pytest>=9.1.1",
41
44
  "pytest-asyncio>=1.4.0",
42
45
  "pytest-cov>=7.1.0",
43
46
  "ruff>=0.17.0",
47
+ "ty>=0.0.107",
48
+ "types-grpcio>=1.85.0.20261028",
44
49
  ]
45
50
 
46
51
  [tool.uv.build-backend]
47
52
  module-name = "crossplane.pythonic"
48
53
 
54
+ [tool.ty.src]
55
+ exclude = ["tests/test_protobuf_messages.py"]
56
+
49
57
  [tool.poe.tasks]
50
- generate-protoc = "python -m grpc_tools.protoc --proto_path=src --python_out=src --pyi_out=src --grpc_python_out=src crossplane/pythonic/proto/v1/run_function.proto"
58
+ generate-protoc = "python -m grpc_tools.protoc --proto_path=src --python_out=src --mypy_out=src --grpc_python_out=src --mypy_grpc_out=src crossplane/pythonic/proto/v1/run_function.proto"
51
59
  test = "pytest tests -x --verbose --verbose --cov --cov-report=term --cov-report=html:reports"
52
60
  test-protobuf = "pytest tests/test_protobuf_*.py -x --verbose --verbose --cov --cov-report=term --cov-report=html:reports"
53
61
  test-ci = "pytest tests --verbose --verbose --junitxml=reports/pytest-junit.xml --cov --cov-report=term --cov-report=xml:reports/pytest-coverage.xml"
@@ -1,24 +1,24 @@
1
1
  [project]
2
2
  name = "crossplane-function-pythonic"
3
- version = "0.6.3"
3
+ version = "0.7.1"
4
4
  description = "A Python centric Crossplane Function"
5
5
  license = "Apache-2.0"
6
6
  readme = "README.md"
7
7
  authors = [
8
8
  { name = "Patrick J McNerthney", email = "pat@mcnerthney.com" }
9
9
  ]
10
- requires-python = ">=3.12,<3.16"
10
+ requires-python = ">=3.15,<3.16"
11
11
  dependencies = [
12
- "grpcio==1.84.0",
12
+ "grpcio==1.86.0",
13
13
  "inflect==7.6.0",
14
14
  "kr8s==0.20.15",
15
15
  "protobuf==7.36.2",
16
- "pyyaml==6.0.3",
16
+ "pyyaml==6.0.4",
17
17
  ]
18
18
 
19
19
  [project.optional-dependencies]
20
- packages = ["kopf==1.45.1"]
21
- pip-install = ["pip==26.2.2"]
20
+ packages = ["kopf==1.45.2"]
21
+ pip-install = ["pip==26.3"]
22
22
 
23
23
  [project.urls]
24
24
  Documentation = "https://github.com/crossplane-contrib/function-pythonic#readme"
@@ -29,24 +29,32 @@ Source = "https://github.com/crossplane-contrib/function-pythonic"
29
29
  function-pythonic = "crossplane.pythonic.main:main"
30
30
 
31
31
  [build-system]
32
- requires = ["uv_build>=0.12.23,<0.13.0"]
32
+ requires = ["uv_build>=0.13.9,<0.14.0"]
33
33
  build-backend = "uv_build"
34
34
 
35
35
  [dependency-groups]
36
36
  dev = [
37
- "grpcio-tools>=1.84.0",
37
+ "grpcio-tools==1.86.0",
38
+ "kopf==1.45.2",
39
+ "mypy-protobuf>=5.1.0",
38
40
  "poethepoet>=0.48.0",
41
+ "pip==26.3",
39
42
  "pytest>=9.1.1",
40
43
  "pytest-asyncio>=1.4.0",
41
44
  "pytest-cov>=7.1.0",
42
45
  "ruff>=0.17.0",
46
+ "ty>=0.0.107",
47
+ "types-grpcio>=1.85.0.20261028",
43
48
  ]
44
49
 
45
50
  [tool.uv.build-backend]
46
51
  module-name = "crossplane.pythonic"
47
52
 
53
+ [tool.ty.src]
54
+ exclude = ["tests/test_protobuf_messages.py"]
55
+
48
56
  [tool.poe.tasks]
49
- generate-protoc = "python -m grpc_tools.protoc --proto_path=src --python_out=src --pyi_out=src --grpc_python_out=src crossplane/pythonic/proto/v1/run_function.proto"
57
+ generate-protoc = "python -m grpc_tools.protoc --proto_path=src --python_out=src --mypy_out=src --grpc_python_out=src --mypy_grpc_out=src crossplane/pythonic/proto/v1/run_function.proto"
50
58
  test = "pytest tests -x --verbose --verbose --cov --cov-report=term --cov-report=html:reports"
51
59
  test-protobuf = "pytest tests/test_protobuf_*.py -x --verbose --verbose --cov --cov-report=term --cov-report=html:reports"
52
60
  test-ci = "pytest tests --verbose --verbose --junitxml=reports/pytest-junit.xml --cov --cov-report=term --cov-report=xml:reports/pytest-coverage.xml"
@@ -0,0 +1,6 @@
1
+ from importlib.metadata import PackageNotFoundError, version
2
+
3
+ try:
4
+ __version__ = version("crossplane-function-pythonic")
5
+ except PackageNotFoundError:
6
+ __version__ = "0.0.0"
@@ -1,4 +1,13 @@
1
- def resource_ready(resource):
1
+ from typing import TYPE_CHECKING
2
+
3
+ if TYPE_CHECKING:
4
+ from . import (
5
+ composite,
6
+ protobuf,
7
+ )
8
+
9
+
10
+ def resource_ready(resource: composite.Resource) -> protobuf.Value | None:
2
11
  if not resource.observed:
3
12
  return None
4
13
  return _checks.get(
@@ -7,9 +16,9 @@ def resource_ready(resource):
7
16
 
8
17
 
9
18
  class ReadyCondition:
10
- def ready(self, resource):
19
+ def ready(self, resource: composite.Resource) -> protobuf.Value | None:
11
20
  ready = resource.conditions.Ready
12
- if not ready._find_condition():
21
+ if not ready._get_condition():
13
22
  return None
14
23
  if ready.status:
15
24
  return resource.observed.metadata.name
@@ -18,7 +27,7 @@ class ReadyCondition:
18
27
  return resource.status.notReadyCondition
19
28
 
20
29
 
21
- _checks = {}
30
+ _checks: dict[tuple, Check] = {}
22
31
  _check_default = ReadyCondition()
23
32
 
24
33
 
@@ -29,12 +38,12 @@ class Check:
29
38
  if hasattr(cls, "apiVersion"):
30
39
  _checks[(cls.apiVersion, cls.__name__)] = cls()
31
40
 
32
- def ready(self, resource):
41
+ def ready(self, resource: composite.Resource) -> protobuf.Value | None:
33
42
  raise NotImplementedError()
34
43
 
35
44
 
36
45
  class AlwaysReady(Check):
37
- def ready(self, resource):
46
+ def ready(self, resource: composite.Resource) -> protobuf.Value:
38
47
  return resource.observed.metadata.name
39
48
 
40
49
 
@@ -53,7 +62,7 @@ class ConfigMap(AlwaysReady):
53
62
  class CronJob(Check):
54
63
  apiVersion = "batch/v1"
55
64
 
56
- def ready(self, resource):
65
+ def ready(self, resource: composite.Resource) -> protobuf.Value:
57
66
  if resource.observed.spec.suspend and len(resource.observed.spec.suspend):
58
67
  return resource.observed.metadata.name
59
68
  if not resource.status.lastScheduleTime:
@@ -72,7 +81,7 @@ class CronJob(Check):
72
81
  class DaemonSet(Check):
73
82
  apiVersion = "apps/v1"
74
83
 
75
- def ready(self, resource):
84
+ def ready(self, resource: composite.Resource) -> protobuf.Value:
76
85
  scheduled = resource.status.desiredNumberScheduled
77
86
  if not scheduled:
78
87
  return scheduled
@@ -88,7 +97,7 @@ class DaemonSet(Check):
88
97
  class Deployment(Check):
89
98
  apiVersion = "apps/v1"
90
99
 
91
- def ready(self, resource):
100
+ def ready(self, resource: composite.Resource) -> protobuf.Value:
92
101
  replicas = resource.observed.spec.replicas or 1
93
102
  for field in ("updatedReplicas", "availableReplicas"):
94
103
  value = resource.status[field]
@@ -109,7 +118,7 @@ class Deployment(Check):
109
118
  class HorizontalPodAutoscaler(Check):
110
119
  apiVersion = "autoscaling/v2"
111
120
 
112
- def ready(self, resource):
121
+ def ready(self, resource: composite.Resource) -> protobuf.Value:
113
122
  for type in (
114
123
  "FailedGetScale",
115
124
  "FailedUpdateScale",
@@ -121,22 +130,22 @@ class HorizontalPodAutoscaler(Check):
121
130
  for type in ("ScalingActive", "ScalingLimited"):
122
131
  if resource.conditions[type].status:
123
132
  return resource.observed.metadata.name
124
- return resource.status.notScalingActiveOrLimiited
133
+ return resource.status.notScalingActiveOrLimited
125
134
 
126
135
 
127
136
  class Ingress(Check):
128
137
  apiVersion = "networking.k8s.io/v1"
129
138
 
130
- def ready(self, resource):
139
+ def ready(self, resource: composite.Resource) -> protobuf.Value:
131
140
  if not len(resource.status.loadBalancer.ingress):
132
- return resource.status.noLoadBalanceIngresses
141
+ return resource.status.noLoadBalancerIngresses
133
142
  return resource.observed.metadata.name
134
143
 
135
144
 
136
145
  class Job(Check):
137
146
  apiVersion = "batch/v1"
138
147
 
139
- def ready(self, resource):
148
+ def ready(self, resource: composite.Resource) -> protobuf.Value:
140
149
  for type in ("Failed", "Suspended"):
141
150
  if resource.conditions[type].status:
142
151
  return resource.status[f"is{type}"]
@@ -157,7 +166,7 @@ class Namespace(AlwaysReady):
157
166
  class PersistentVolumeClaim(Check):
158
167
  apiVersion = "v1"
159
168
 
160
- def ready(self, resource):
169
+ def ready(self, resource: composite.Resource) -> protobuf.Value:
161
170
  if resource.status.phase != "Bound":
162
171
  return resource.status.phaseNotBound
163
172
  return resource.observed.metadata.name
@@ -166,7 +175,7 @@ class PersistentVolumeClaim(Check):
166
175
  class Pod(Check):
167
176
  apiVersion = "v1"
168
177
 
169
- def ready(self, resource):
178
+ def ready(self, resource: composite.Resource) -> protobuf.Value:
170
179
  if resource.status.phase == "Succeeded":
171
180
  return resource.observed.metadata.name
172
181
  if (
@@ -179,9 +188,9 @@ class Pod(Check):
179
188
 
180
189
 
181
190
  class ReplicaSet(Check):
182
- apiVersion = "v1"
191
+ apiVersion = "apps/v1"
183
192
 
184
- def ready(self, resource):
193
+ def ready(self, resource: composite.Resource) -> protobuf.Value:
185
194
  if int(resource.status.observedGeneration) < int(
186
195
  resource.observed.metadata.generation
187
196
  ):
@@ -195,7 +204,7 @@ class ReplicaSet(Check):
195
204
  if int(resource.status.availableReplicas) < int(
196
205
  resource.observed.spec.replicas or 1
197
206
  ):
198
- return resource.status.tooFewavailableReplicas
207
+ return resource.status.tooFewAvailableReplicas
199
208
  return resource.observed.metadata.name
200
209
 
201
210
 
@@ -214,7 +223,7 @@ class Secret(AlwaysReady):
214
223
  class Service(Check):
215
224
  apiVersion = "v1"
216
225
 
217
- def ready(self, resource):
226
+ def ready(self, resource: composite.Resource) -> protobuf.Value:
218
227
  if resource.observed.spec.type != "LoadBalancer":
219
228
  return resource.observed.metadata.name
220
229
  if not len(resource.status.loadBalancer.ingress):
@@ -229,7 +238,7 @@ class ServiceAccount(AlwaysReady):
229
238
  class StatefulSet(Check):
230
239
  apiVersion = "apps/v1"
231
240
 
232
- def ready(self, resource):
241
+ def ready(self, resource: composite.Resource) -> protobuf.Value:
233
242
  replicas = resource.observed.spec.replicas or 1
234
243
  for field in ("readyReplicas", "currentReplicas"):
235
244
  value = resource.status[field]
@@ -238,5 +247,5 @@ class StatefulSet(Check):
238
247
  if replicas != value:
239
248
  return resource.status[f"{field}NotReplicas"]
240
249
  if resource.status.currentRevision != resource.status.updateRevision:
241
- return resource.status.currentRevisionNotUpdateReivsion
250
+ return resource.status.currentRevisionNotUpdateRevision
242
251
  return resource.observed.metadata.name
@@ -1,27 +1,32 @@
1
+ import argparse
1
2
  import logging
2
3
  import pathlib
3
4
  import sys
4
5
 
5
6
 
6
7
  class Command:
7
- name = None
8
- command = None
9
- description = None
8
+ name: str | None = None
9
+ command: str | None = None
10
+ help: str | None = None
11
+ description: str | None = None
10
12
 
11
13
  @classmethod
12
- def create(cls, subparsers):
13
- parser = subparsers.add_parser(
14
- cls.name, help=cls.help, description=cls.description
15
- )
16
- parser.set_defaults(command=cls)
17
- cls.add_parser_arguments(parser)
14
+ def create(
15
+ cls, subparsers: argparse._SubParsersAction[argparse.ArgumentParser]
16
+ ) -> None:
17
+ if cls.name is not None:
18
+ parser: argparse.ArgumentParser = subparsers.add_parser(
19
+ cls.name, help=cls.help, description=cls.description
20
+ )
21
+ parser.set_defaults(command=cls)
22
+ cls.add_parser_arguments(parser)
18
23
 
19
24
  @classmethod
20
- def add_parser_arguments(cls, parser):
25
+ def add_parser_arguments(cls, parser: argparse.ArgumentParser) -> None:
21
26
  pass
22
27
 
23
28
  @classmethod
24
- def add_function_arguments(cls, parser):
29
+ def add_function_arguments(cls, parser: argparse.ArgumentParser) -> None:
25
30
  parser.add_argument(
26
31
  "--debug",
27
32
  "-d",
@@ -65,15 +70,21 @@ class Command:
65
70
  action="store_true",
66
71
  help="Enable Crossplane V1 compatibility mode",
67
72
  )
73
+ parser.add_argument(
74
+ "--usages-replay-deletion",
75
+ action=argparse.BooleanOptionalAction,
76
+ default=True,
77
+ help="Default replayDeletion value for generated Usages (default: %(default)s)",
78
+ )
68
79
 
69
- def __init__(self, args=None):
70
- self.args = args
80
+ def __init__(self, args: argparse.Namespace | None = None) -> None:
81
+ self.args = args if args is not None else argparse.Namespace()
71
82
  self.initialize()
72
83
 
73
- def initialize(self):
84
+ def initialize(self) -> None:
74
85
  pass
75
86
 
76
- def initialize_function(self):
87
+ def initialize_function(self) -> None:
77
88
  formatter = Formatter(self.args.log_name_width)
78
89
  handler = logging.StreamHandler(sys.stdout)
79
90
  handler.setFormatter(formatter)
@@ -98,15 +109,16 @@ class Command:
98
109
  if self.args.allow_oversize_protos:
99
110
  from google.protobuf.internal import api_implementation
100
111
 
101
- if api_implementation._c_module:
102
- api_implementation._c_module.SetAllowOversizeProtos(True)
112
+ c_module = getattr(api_implementation, "_c_module", None)
113
+ if c_module:
114
+ c_module.SetAllowOversizeProtos(True)
103
115
 
104
- async def run(self):
116
+ async def run(self) -> None:
105
117
  raise NotImplementedError()
106
118
 
107
119
 
108
120
  class Formatter(logging.Formatter):
109
- def __init__(self, name_width):
121
+ def __init__(self, name_width: int):
110
122
  super().__init__(
111
123
  f"[{{asctime}}.{{msecs:03.0f}}] {{sname:{name_width}.{name_width}}} [{{levelname:8.8}}] {{message}}",
112
124
  "%Y-%m-%d %H:%M:%S",
@@ -114,16 +126,17 @@ class Formatter(logging.Formatter):
114
126
  )
115
127
  self.name_width = name_width
116
128
 
117
- def format(self, record):
118
- record.sname = record.name
119
- extra = len(record.sname) - self.name_width
129
+ def format(self, record: logging.LogRecord):
130
+ sname = record.name
131
+ extra = len(sname) - self.name_width
120
132
  if extra > 0:
121
- names = record.sname.split(".")
133
+ names = sname.split(".")
122
134
  for ix, name in enumerate(names):
123
135
  if len(name) > extra:
124
136
  names[ix] = name[extra:]
125
137
  break
126
138
  names[ix] = name[:1]
127
139
  extra -= len(name) - 1
128
- record.sname = ".".join(names)
140
+ sname = ".".join(names)
141
+ record.sname = sname
129
142
  return super().format(record)