crossplane-function-pythonic 0.6.3__py3-none-any.whl → 0.7.1__py3-none-any.whl
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.
- crossplane/pythonic/__about__.py +1 -3
- crossplane/pythonic/auto_ready.py +31 -22
- crossplane/pythonic/command.py +37 -24
- crossplane/pythonic/composite.py +592 -386
- crossplane/pythonic/function.py +136 -110
- crossplane/pythonic/grpc.py +7 -4
- crossplane/pythonic/main.py +7 -3
- crossplane/pythonic/packages.py +27 -19
- crossplane/pythonic/proto/v1/run_function_pb2.pyi +1121 -255
- crossplane/pythonic/proto/v1/run_function_pb2_grpc.py +1 -1
- crossplane/pythonic/proto/v1/run_function_pb2_grpc.pyi +64 -0
- crossplane/pythonic/protobuf.py +346 -196
- crossplane/pythonic/render.py +211 -82
- crossplane/pythonic/version.py +1 -1
- {crossplane_function_pythonic-0.6.3.dist-info → crossplane_function_pythonic-0.7.1.dist-info}/METADATA +50 -8
- crossplane_function_pythonic-0.7.1.dist-info/RECORD +22 -0
- {crossplane_function_pythonic-0.6.3.dist-info → crossplane_function_pythonic-0.7.1.dist-info}/WHEEL +1 -1
- crossplane/pythonic/diff.py +0 -880
- crossplane_function_pythonic-0.6.3.dist-info/RECORD +0 -22
- {crossplane_function_pythonic-0.6.3.dist-info → crossplane_function_pythonic-0.7.1.dist-info}/entry_points.txt +0 -0
crossplane/pythonic/render.py
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import argparse
|
|
1
2
|
import asyncio
|
|
2
3
|
import importlib
|
|
3
4
|
import inspect
|
|
@@ -5,10 +6,13 @@ import json
|
|
|
5
6
|
import logging
|
|
6
7
|
import pathlib
|
|
7
8
|
import sys
|
|
9
|
+
import typing
|
|
10
|
+
from typing import cast
|
|
8
11
|
|
|
9
12
|
import inflect
|
|
10
13
|
import kr8s
|
|
11
14
|
import yaml
|
|
15
|
+
from kr8s._api import Api
|
|
12
16
|
|
|
13
17
|
from . import (
|
|
14
18
|
command,
|
|
@@ -27,7 +31,7 @@ class Command(command.Command):
|
|
|
27
31
|
help = "Render a function-pythonic Composition"
|
|
28
32
|
|
|
29
33
|
@classmethod
|
|
30
|
-
def add_parser_arguments(cls, parser):
|
|
34
|
+
def add_parser_arguments(cls, parser: argparse.ArgumentParser) -> None:
|
|
31
35
|
cls.add_function_arguments(parser)
|
|
32
36
|
parser.add_argument(
|
|
33
37
|
"composite",
|
|
@@ -113,16 +117,16 @@ class Command(command.Command):
|
|
|
113
117
|
help="Include the context in the rendered output as a resource of kind: Context.",
|
|
114
118
|
)
|
|
115
119
|
|
|
116
|
-
def initialize(self):
|
|
117
|
-
if self.args:
|
|
120
|
+
def initialize(self) -> None:
|
|
121
|
+
if vars(self.args):
|
|
118
122
|
self.initialize_function()
|
|
119
123
|
self.logger = logging.getLogger(__name__)
|
|
120
124
|
|
|
121
|
-
async def run(self):
|
|
125
|
+
async def run(self) -> None:
|
|
122
126
|
if self.args.kube_context:
|
|
123
|
-
api = await kr8s.asyncio.api(context=self.args.kube_context)
|
|
127
|
+
api: Api | None = await kr8s.asyncio.api(context=self.args.kube_context)
|
|
124
128
|
else:
|
|
125
|
-
api = None
|
|
129
|
+
api: Api | None = None
|
|
126
130
|
composite = await self.setup_composite(api)
|
|
127
131
|
observed = self.collect_resources(self.args.observed_resources)
|
|
128
132
|
composition = await self.setup_composition(composite, api)
|
|
@@ -140,6 +144,7 @@ class Command(command.Command):
|
|
|
140
144
|
api,
|
|
141
145
|
self.args.render_unknowns,
|
|
142
146
|
self.args.crossplane_v1,
|
|
147
|
+
usages_replay_deletion=self.args.usages_replay_deletion,
|
|
143
148
|
)
|
|
144
149
|
if not render:
|
|
145
150
|
sys.exit(1)
|
|
@@ -180,13 +185,14 @@ class Command(command.Command):
|
|
|
180
185
|
print("---")
|
|
181
186
|
print(str(render.context), end="")
|
|
182
187
|
|
|
183
|
-
async def setup_composite(self, api=None):
|
|
188
|
+
async def setup_composite(self, api=Api | None) -> protobuf.Value:
|
|
184
189
|
# Obtain the Composite to render.
|
|
185
190
|
if self.args.composite.is_file():
|
|
186
|
-
return protobuf.Yaml(self.args.composite.read_text())
|
|
191
|
+
return cast(protobuf.Value, protobuf.Yaml(self.args.composite.read_text()))
|
|
187
192
|
if not api:
|
|
188
193
|
print(f'Composite "{self.args.composite}" is not a file', file=sys.stderr)
|
|
189
194
|
sys.exit(1)
|
|
195
|
+
return
|
|
190
196
|
composite = str(self.args.composite).split(":")
|
|
191
197
|
if len(composite) == 3:
|
|
192
198
|
namespace = None
|
|
@@ -202,14 +208,16 @@ class Command(command.Command):
|
|
|
202
208
|
)
|
|
203
209
|
sys.exit(1)
|
|
204
210
|
composite = await self.kr8s_get(
|
|
205
|
-
api, composite[0], composite[1], namespace, composite[-1]
|
|
211
|
+
cast(Api, api), composite[0], composite[1], namespace, composite[-1]
|
|
206
212
|
)
|
|
207
213
|
if not composite:
|
|
208
214
|
print(f'Composite "{self.args.composite}" not found', file=sys.stderr)
|
|
209
215
|
sys.exit(1)
|
|
210
216
|
return composite
|
|
211
217
|
|
|
212
|
-
async def setup_composition(
|
|
218
|
+
async def setup_composition(
|
|
219
|
+
self, composite: protobuf.Value, api: Api | None = None
|
|
220
|
+
) -> protobuf.Value | None:
|
|
213
221
|
# Obtain the Composition that will be used to render the Composite.
|
|
214
222
|
if not self.args.composition:
|
|
215
223
|
return None
|
|
@@ -217,7 +225,7 @@ class Command(command.Command):
|
|
|
217
225
|
composition = self.args.composition.read_text()
|
|
218
226
|
if self.args.composition.suffix == ".py":
|
|
219
227
|
return self.create_composition(composite, composition)
|
|
220
|
-
composition = protobuf.Yaml(composition)
|
|
228
|
+
composition = cast(protobuf.Value, protobuf.Yaml(composition))
|
|
221
229
|
if not len(composition.spec.pipeline):
|
|
222
230
|
print(
|
|
223
231
|
f"Composition file does not contain any pipeline steps: {self.args.composition}",
|
|
@@ -262,7 +270,9 @@ class Command(command.Command):
|
|
|
262
270
|
sys.exit(1)
|
|
263
271
|
return self.create_composition(composite, self.args.composition)
|
|
264
272
|
|
|
265
|
-
def create_composition(
|
|
273
|
+
def create_composition(
|
|
274
|
+
self, composite: protobuf.Value, module: str = ""
|
|
275
|
+
) -> protobuf.Value:
|
|
266
276
|
composition = protobuf.Map()
|
|
267
277
|
composition.apiVersion = "apiextensions.crossplane.io/v1"
|
|
268
278
|
composition.kind = "Composition"
|
|
@@ -279,7 +289,7 @@ class Command(command.Command):
|
|
|
279
289
|
composition.spec.pipeline[0].input.composite = str(module)
|
|
280
290
|
return composition
|
|
281
291
|
|
|
282
|
-
def collect_resources(self, entries):
|
|
292
|
+
def collect_resources(self, entries: list[pathlib.Path]) -> list[protobuf.Value]:
|
|
283
293
|
resources = []
|
|
284
294
|
for entry in entries:
|
|
285
295
|
if entry.is_file():
|
|
@@ -299,7 +309,7 @@ class Command(command.Command):
|
|
|
299
309
|
resources.sort(key=lambda resource: str(resource.metadata.name))
|
|
300
310
|
return resources
|
|
301
311
|
|
|
302
|
-
def collect_schemas(self, entries):
|
|
312
|
+
def collect_schemas(self, entries: list[pathlib.Path]) -> list[protobuf.Value]:
|
|
303
313
|
schemas = []
|
|
304
314
|
for entry in entries:
|
|
305
315
|
if entry.is_file():
|
|
@@ -318,7 +328,7 @@ class Command(command.Command):
|
|
|
318
328
|
sys.exit(1)
|
|
319
329
|
return schemas
|
|
320
330
|
|
|
321
|
-
def setup_context(self):
|
|
331
|
+
def setup_context(self) -> protobuf.Value:
|
|
322
332
|
# Load the request context with any specified command line options.
|
|
323
333
|
context = protobuf.Map()
|
|
324
334
|
for entry in self.args.context_files:
|
|
@@ -341,17 +351,18 @@ class Command(command.Command):
|
|
|
341
351
|
|
|
342
352
|
async def render(
|
|
343
353
|
self,
|
|
344
|
-
composite,
|
|
345
|
-
observed=None,
|
|
346
|
-
composition=None,
|
|
347
|
-
resources=None,
|
|
348
|
-
schemas=None,
|
|
349
|
-
context=None,
|
|
350
|
-
api=None,
|
|
351
|
-
render_unknowns=False,
|
|
352
|
-
crossplane_v1=False,
|
|
353
|
-
composite_observeds=False,
|
|
354
|
-
|
|
354
|
+
composite: protobuf.Value,
|
|
355
|
+
observed: list[protobuf.Value] | None = None,
|
|
356
|
+
composition: protobuf.Value | None = None,
|
|
357
|
+
resources: list[protobuf.Value] | None = None,
|
|
358
|
+
schemas: list[protobuf.Value] | None = None,
|
|
359
|
+
context: protobuf.Value | None = None,
|
|
360
|
+
api: Api | None = None,
|
|
361
|
+
render_unknowns: bool = False,
|
|
362
|
+
crossplane_v1: bool = False,
|
|
363
|
+
composite_observeds: bool = False,
|
|
364
|
+
usages_replay_deletion: bool = True,
|
|
365
|
+
) -> protobuf.Value | None:
|
|
355
366
|
# Create the request used when running Composition steps.
|
|
356
367
|
if schemas is None:
|
|
357
368
|
schemas = []
|
|
@@ -369,7 +380,9 @@ class Command(command.Command):
|
|
|
369
380
|
request.context = context
|
|
370
381
|
|
|
371
382
|
# Establish the request observed composite.
|
|
372
|
-
await self.set_resource(
|
|
383
|
+
await self.set_resource(
|
|
384
|
+
composite, cast(protobuf.Value, request.observed.composite), resources, api
|
|
385
|
+
)
|
|
373
386
|
# Establish the manually configured observed resources.
|
|
374
387
|
if observed:
|
|
375
388
|
async with asyncio.TaskGroup() as group:
|
|
@@ -381,7 +394,7 @@ class Command(command.Command):
|
|
|
381
394
|
group.create_task(
|
|
382
395
|
self.set_resource(
|
|
383
396
|
resource,
|
|
384
|
-
request.observed.resources[name],
|
|
397
|
+
cast(protobuf.Value, request.observed.resources[name]),
|
|
385
398
|
resources,
|
|
386
399
|
api,
|
|
387
400
|
)
|
|
@@ -436,7 +449,9 @@ class Command(command.Command):
|
|
|
436
449
|
results = protobuf.List()
|
|
437
450
|
|
|
438
451
|
# Create a function-pythonic function runner used to run pipeline steps.
|
|
439
|
-
runner = function.FunctionRunner(
|
|
452
|
+
runner = function.FunctionRunner(
|
|
453
|
+
render_unknowns, crossplane_v1, usages_replay_deletion
|
|
454
|
+
)
|
|
440
455
|
fatal = False
|
|
441
456
|
|
|
442
457
|
# Process the composition pipeline steps.
|
|
@@ -489,34 +504,49 @@ class Command(command.Command):
|
|
|
489
504
|
for requirement in step.requirements.requiredResources:
|
|
490
505
|
await self.set_required(
|
|
491
506
|
requirement.requirementName,
|
|
492
|
-
requirement,
|
|
493
|
-
request.required_resources,
|
|
507
|
+
self.requirement_selector(requirement),
|
|
508
|
+
cast(protobuf.MapMessage, request.required_resources),
|
|
494
509
|
resources,
|
|
495
510
|
api,
|
|
496
511
|
)
|
|
497
512
|
# Fetch the required resources requested.
|
|
498
513
|
for name, selector in requirements.resources:
|
|
499
514
|
await self.set_required(
|
|
500
|
-
name,
|
|
515
|
+
name,
|
|
516
|
+
selector,
|
|
517
|
+
cast(protobuf.MapMessage, request.required_resources),
|
|
518
|
+
resources,
|
|
519
|
+
api,
|
|
501
520
|
)
|
|
502
521
|
# Fetch the now deprecated extra resources requested.
|
|
503
522
|
request.extra_resources()
|
|
504
523
|
for name, selector in requirements.extra_resources:
|
|
505
524
|
await self.set_required(
|
|
506
|
-
name,
|
|
525
|
+
name,
|
|
526
|
+
selector,
|
|
527
|
+
cast(protobuf.MapMessage, request.extra_resources),
|
|
528
|
+
resources,
|
|
529
|
+
api,
|
|
507
530
|
)
|
|
508
531
|
# Fetch the schemas requested.
|
|
509
532
|
request.required_schemas()
|
|
510
533
|
for name, selector in requirements.schemas:
|
|
511
534
|
await self.set_schema(
|
|
512
|
-
name,
|
|
535
|
+
name,
|
|
536
|
+
selector,
|
|
537
|
+
cast(protobuf.MapMessage, request.required_schemas),
|
|
538
|
+
schemas,
|
|
539
|
+
api,
|
|
513
540
|
)
|
|
514
541
|
# Run the step using the function-pythonic function runner.
|
|
515
542
|
response = protobuf.Message(
|
|
516
543
|
None,
|
|
517
544
|
"response",
|
|
518
545
|
fnv1.RunFunctionResponse.DESCRIPTOR,
|
|
519
|
-
await runner.RunFunction(
|
|
546
|
+
await runner.RunFunction(
|
|
547
|
+
cast(fnv1.RunFunctionRequest, request._message),
|
|
548
|
+
None,
|
|
549
|
+
),
|
|
520
550
|
)
|
|
521
551
|
# Copy the response context to the request context to use in subsequent steps.
|
|
522
552
|
request.context = response.context
|
|
@@ -535,9 +565,14 @@ class Command(command.Command):
|
|
|
535
565
|
|
|
536
566
|
# Copy the response desired state to the request desired state to use in subsequent steps.
|
|
537
567
|
request.desired.resources()
|
|
538
|
-
self.copy_resource(
|
|
568
|
+
self.copy_resource(
|
|
569
|
+
cast(protobuf.Message, response.desired.composite),
|
|
570
|
+
cast(protobuf.Message, request.desired.composite),
|
|
571
|
+
)
|
|
539
572
|
for name, resource in response.desired.resources:
|
|
540
|
-
self.copy_resource(
|
|
573
|
+
self.copy_resource(
|
|
574
|
+
resource, cast(protobuf.Message, request.desired.resources[name])
|
|
575
|
+
)
|
|
541
576
|
|
|
542
577
|
# Collect the step's returned conditions.
|
|
543
578
|
for condition in response.conditions:
|
|
@@ -565,8 +600,8 @@ class Command(command.Command):
|
|
|
565
600
|
break
|
|
566
601
|
|
|
567
602
|
# Collect and format all the returned desired composed resources.
|
|
568
|
-
resources = protobuf.List()
|
|
569
|
-
unready = protobuf.List()
|
|
603
|
+
resources: protobuf.Value = protobuf.List()
|
|
604
|
+
unready: protobuf.Value = protobuf.List()
|
|
570
605
|
prefix = composite.metadata.labels["crossplane.io/composite"]
|
|
571
606
|
if not prefix:
|
|
572
607
|
prefix = composite.metadata.name
|
|
@@ -580,7 +615,9 @@ class Command(command.Command):
|
|
|
580
615
|
if not ready:
|
|
581
616
|
unready[protobuf.append] = name
|
|
582
617
|
resource = resource.resource
|
|
583
|
-
observed =
|
|
618
|
+
observed: protobuf.Value = cast(
|
|
619
|
+
protobuf.Value, request.observed.resources[name].resource
|
|
620
|
+
)
|
|
584
621
|
if observed:
|
|
585
622
|
for key in ("namespace", "generateName", "name"):
|
|
586
623
|
if observed.metadata[key]:
|
|
@@ -666,7 +703,14 @@ class Command(command.Command):
|
|
|
666
703
|
response.observed[name] = resource.resource
|
|
667
704
|
return response
|
|
668
705
|
|
|
669
|
-
async def get_composite_ref(
|
|
706
|
+
async def get_composite_ref(
|
|
707
|
+
self,
|
|
708
|
+
composite: protobuf.Value,
|
|
709
|
+
ref: protobuf.Value,
|
|
710
|
+
request: protobuf.Message,
|
|
711
|
+
resources: list[protobuf.Value],
|
|
712
|
+
api: Api,
|
|
713
|
+
) -> None:
|
|
670
714
|
namespace = ref.namespace
|
|
671
715
|
if not namespace:
|
|
672
716
|
namespace = composite.metadata.namespace
|
|
@@ -680,9 +724,18 @@ class Command(command.Command):
|
|
|
680
724
|
if name:
|
|
681
725
|
destination = request.observed.resources[name]
|
|
682
726
|
if not destination: # Do not override manual observed
|
|
683
|
-
await self.set_resource(
|
|
727
|
+
await self.set_resource(
|
|
728
|
+
source, cast(protobuf.Value, destination), resources, api
|
|
729
|
+
)
|
|
684
730
|
|
|
685
|
-
async def set_required(
|
|
731
|
+
async def set_required(
|
|
732
|
+
self,
|
|
733
|
+
name: protobuf.TypeString,
|
|
734
|
+
selector: protobuf.Message,
|
|
735
|
+
requireds: protobuf.MapMessage,
|
|
736
|
+
resources: list[protobuf.Value] | None = None,
|
|
737
|
+
api: Api | None = None,
|
|
738
|
+
) -> None:
|
|
686
739
|
if resources is None:
|
|
687
740
|
resources = []
|
|
688
741
|
if not name:
|
|
@@ -718,10 +771,10 @@ class Command(command.Command):
|
|
|
718
771
|
if len(selector.match_name):
|
|
719
772
|
resource = await self.kr8s_get(
|
|
720
773
|
api,
|
|
721
|
-
selector.kind,
|
|
722
|
-
selector.api_version,
|
|
723
|
-
selector.namespace,
|
|
724
|
-
selector.match_name,
|
|
774
|
+
cast(protobuf.TypeString, selector.kind),
|
|
775
|
+
cast(protobuf.TypeString, selector.api_version),
|
|
776
|
+
cast(protobuf.TypeString, selector.namespace),
|
|
777
|
+
cast(protobuf.TypeString, selector.match_name),
|
|
725
778
|
)
|
|
726
779
|
if resource:
|
|
727
780
|
await self.set_resource(
|
|
@@ -730,16 +783,41 @@ class Command(command.Command):
|
|
|
730
783
|
elif len(selector.match_labels.labels):
|
|
731
784
|
for resource in await self.kr8s_list(
|
|
732
785
|
api,
|
|
733
|
-
selector.kind,
|
|
734
|
-
selector.api_version,
|
|
735
|
-
selector.namespace,
|
|
736
|
-
selector.match_labels.labels,
|
|
786
|
+
cast(protobuf.TypeString, selector.kind),
|
|
787
|
+
cast(protobuf.TypeString, selector.api_version),
|
|
788
|
+
cast(protobuf.TypeString, selector.namespace),
|
|
789
|
+
cast(protobuf.MapMessage, selector.match_labels.labels),
|
|
737
790
|
):
|
|
738
791
|
await self.set_resource(
|
|
739
792
|
resource, items[protobuf.append], resources, api
|
|
740
793
|
)
|
|
741
794
|
|
|
742
|
-
|
|
795
|
+
def requirement_selector(self, requirement: protobuf.Value) -> protobuf.Message:
|
|
796
|
+
# Convert a Composition step requirement into a function ResourceSelector.
|
|
797
|
+
selector = protobuf.Message(
|
|
798
|
+
None,
|
|
799
|
+
"selector",
|
|
800
|
+
fnv1.ResourceSelector.DESCRIPTOR,
|
|
801
|
+
fnv1.ResourceSelector(),
|
|
802
|
+
)
|
|
803
|
+
selector.api_version = requirement.apiVersion
|
|
804
|
+
selector.kind = requirement.kind
|
|
805
|
+
if requirement.namespace:
|
|
806
|
+
selector.namespace = requirement.namespace
|
|
807
|
+
if requirement.name:
|
|
808
|
+
selector.match_name = requirement.name
|
|
809
|
+
elif requirement.matchLabels:
|
|
810
|
+
for key, value in requirement.matchLabels:
|
|
811
|
+
selector.match_labels.labels[key] = value
|
|
812
|
+
return selector
|
|
813
|
+
|
|
814
|
+
async def set_resource(
|
|
815
|
+
self,
|
|
816
|
+
source: protobuf.Value,
|
|
817
|
+
destination: protobuf.Value,
|
|
818
|
+
resources: list[protobuf.Value] | None = None,
|
|
819
|
+
api: Api | None = None,
|
|
820
|
+
) -> None:
|
|
743
821
|
if resources is None:
|
|
744
822
|
resources = []
|
|
745
823
|
destination.resource = source
|
|
@@ -769,7 +847,14 @@ class Command(command.Command):
|
|
|
769
847
|
for key, value in connection.data:
|
|
770
848
|
destination.connection_details[key] = protobuf.B64Decode(value)
|
|
771
849
|
|
|
772
|
-
async def set_schema(
|
|
850
|
+
async def set_schema(
|
|
851
|
+
self,
|
|
852
|
+
name: protobuf.TypeString,
|
|
853
|
+
selector: protobuf.Value,
|
|
854
|
+
schemas: protobuf.MapMessage,
|
|
855
|
+
documents: list[protobuf.Value] | None = None,
|
|
856
|
+
api: Api | None = None,
|
|
857
|
+
) -> None:
|
|
773
858
|
if documents is None:
|
|
774
859
|
documents = []
|
|
775
860
|
if not name:
|
|
@@ -801,7 +886,9 @@ class Command(command.Command):
|
|
|
801
886
|
return
|
|
802
887
|
self.find_schema(gvk, document, schema)
|
|
803
888
|
|
|
804
|
-
def find_schema(
|
|
889
|
+
def find_schema(
|
|
890
|
+
self, gvk: protobuf.Value, document: protobuf.Value, schema: protobuf.Value
|
|
891
|
+
) -> bool:
|
|
805
892
|
for name, s in document.components.schemas:
|
|
806
893
|
gvks = s["x-kubernetes-group-version-kind"]
|
|
807
894
|
if len(gvks) == 1 and gvks[0] == gvk:
|
|
@@ -811,20 +898,23 @@ class Command(command.Command):
|
|
|
811
898
|
return True
|
|
812
899
|
return False
|
|
813
900
|
|
|
814
|
-
def resolve_ref(
|
|
901
|
+
def resolve_ref(
|
|
902
|
+
self,
|
|
903
|
+
document: protobuf.Value,
|
|
904
|
+
visiting: set,
|
|
905
|
+
ref: protobuf.TypeString,
|
|
906
|
+
schema: protobuf.Value,
|
|
907
|
+
) -> None:
|
|
815
908
|
if not ref:
|
|
816
909
|
return
|
|
817
910
|
ref = str(ref)
|
|
818
911
|
if ref in visiting:
|
|
819
912
|
return
|
|
820
|
-
|
|
821
|
-
for segment in ref.split("/"):
|
|
822
|
-
if segment == "#":
|
|
823
|
-
d = document
|
|
824
|
-
else:
|
|
825
|
-
d = d[segment]
|
|
826
|
-
if not d:
|
|
913
|
+
if not ref.startswith("#/"):
|
|
827
914
|
return
|
|
915
|
+
d = document
|
|
916
|
+
for segment in ref.split("/")[1:]:
|
|
917
|
+
d = d[segment]
|
|
828
918
|
visiting.add(ref)
|
|
829
919
|
try:
|
|
830
920
|
for name, value in d:
|
|
@@ -832,7 +922,14 @@ class Command(command.Command):
|
|
|
832
922
|
finally:
|
|
833
923
|
visiting.remove(ref)
|
|
834
924
|
|
|
835
|
-
def copy_schema(
|
|
925
|
+
def copy_schema(
|
|
926
|
+
self,
|
|
927
|
+
document: protobuf.Value,
|
|
928
|
+
visiting: set,
|
|
929
|
+
key: str | int,
|
|
930
|
+
value: protobuf.Value,
|
|
931
|
+
schema: protobuf.Value,
|
|
932
|
+
) -> None:
|
|
836
933
|
if key == "$ref":
|
|
837
934
|
self.resolve_ref(document, visiting, value, schema)
|
|
838
935
|
elif key == "allOf":
|
|
@@ -850,29 +947,37 @@ class Command(command.Command):
|
|
|
850
947
|
else:
|
|
851
948
|
schema[key] = value
|
|
852
949
|
|
|
853
|
-
def copy_resource(
|
|
950
|
+
def copy_resource(
|
|
951
|
+
self, source: protobuf.Message, destination: protobuf.Message
|
|
952
|
+
) -> None:
|
|
854
953
|
destination.resource = source.resource
|
|
855
954
|
destination.connection_details()
|
|
856
955
|
for key, value in source.connection_details:
|
|
857
956
|
destination.connection_details[key] = value
|
|
858
957
|
destination.ready = source.ready
|
|
859
958
|
|
|
860
|
-
def create_condition(
|
|
959
|
+
def create_condition(
|
|
960
|
+
self,
|
|
961
|
+
type: str,
|
|
962
|
+
status: protobuf.FieldMessage | bool | None,
|
|
963
|
+
reason: str,
|
|
964
|
+
message: str | None = None,
|
|
965
|
+
) -> dict[str, str]:
|
|
861
966
|
if isinstance(status, protobuf.FieldMessage):
|
|
862
967
|
if status._value == fnv1.Status.STATUS_CONDITION_TRUE:
|
|
863
|
-
status = "True"
|
|
968
|
+
status: str = "True"
|
|
864
969
|
elif status._value == fnv1.Status.STATUS_CONDITION_FALSE:
|
|
865
|
-
status = "False"
|
|
970
|
+
status: str = "False"
|
|
866
971
|
else:
|
|
867
|
-
status = "Unknown"
|
|
972
|
+
status: str = "Unknown"
|
|
868
973
|
elif isinstance(status, bool):
|
|
869
974
|
if status:
|
|
870
|
-
status = "True"
|
|
975
|
+
status: str = "True"
|
|
871
976
|
else:
|
|
872
|
-
status = "False"
|
|
977
|
+
status: str = "False"
|
|
873
978
|
elif status is None:
|
|
874
|
-
status = "Unknown"
|
|
875
|
-
condition = {
|
|
979
|
+
status: str = "Unknown"
|
|
980
|
+
condition: dict[str, str] = {
|
|
876
981
|
"type": type,
|
|
877
982
|
"status": status,
|
|
878
983
|
"reason": reason,
|
|
@@ -882,8 +987,15 @@ class Command(command.Command):
|
|
|
882
987
|
condition["message"] = message
|
|
883
988
|
return condition
|
|
884
989
|
|
|
885
|
-
async def kr8s_get(
|
|
886
|
-
|
|
990
|
+
async def kr8s_get(
|
|
991
|
+
self,
|
|
992
|
+
api: Api,
|
|
993
|
+
kind: protobuf.TypeString,
|
|
994
|
+
apiVersion: protobuf.TypeString,
|
|
995
|
+
namespace: protobuf.TypeString | None,
|
|
996
|
+
name: protobuf.TypeString,
|
|
997
|
+
) -> protobuf.Value | None:
|
|
998
|
+
namespaced = bool(namespace) and bool(len(namespace))
|
|
887
999
|
clazz = self.kr8s_class(kind, apiVersion, namespaced)
|
|
888
1000
|
try:
|
|
889
1001
|
fullName = [str(kind), str(apiVersion), str(name)]
|
|
@@ -900,15 +1012,27 @@ class Command(command.Command):
|
|
|
900
1012
|
self.logger.debug(f"Resource {result}: {':'.join(fullName)}")
|
|
901
1013
|
return resource
|
|
902
1014
|
|
|
903
|
-
async def kr8s_list(
|
|
904
|
-
|
|
1015
|
+
async def kr8s_list(
|
|
1016
|
+
self,
|
|
1017
|
+
api: Api,
|
|
1018
|
+
kind: protobuf.TypeString,
|
|
1019
|
+
apiVersion: protobuf.TypeString,
|
|
1020
|
+
namespace: protobuf.TypeString | None,
|
|
1021
|
+
labelSelector: protobuf.MapMessage,
|
|
1022
|
+
) -> list[protobuf.Value]:
|
|
1023
|
+
namespaced = bool(namespace) and bool(len(namespace))
|
|
905
1024
|
clazz = self.kr8s_class(kind, apiVersion, namespaced)
|
|
906
1025
|
resources = [
|
|
907
1026
|
protobuf.Value(None, None, resource.raw)
|
|
908
|
-
async for resource in
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
1027
|
+
async for resource in cast(
|
|
1028
|
+
typing.AsyncGenerator[kr8s.APIObject],
|
|
1029
|
+
clazz.list(
|
|
1030
|
+
namespace=str(namespace) if namespaced else None,
|
|
1031
|
+
label_selector={
|
|
1032
|
+
label: str(value) for label, value in labelSelector
|
|
1033
|
+
},
|
|
1034
|
+
api=api,
|
|
1035
|
+
),
|
|
912
1036
|
)
|
|
913
1037
|
]
|
|
914
1038
|
if self.logger.isEnabledFor(logging.DEBUG):
|
|
@@ -919,13 +1043,18 @@ class Command(command.Command):
|
|
|
919
1043
|
"&".join(f"{label}={value}" for label, value in labelSelector)
|
|
920
1044
|
)
|
|
921
1045
|
if resources:
|
|
922
|
-
result = f"found {INFLECT.number_to_words(len(resources))}"
|
|
1046
|
+
result = f"found {INFLECT.number_to_words(str(len(resources)))}"
|
|
923
1047
|
else:
|
|
924
1048
|
result = "missing"
|
|
925
1049
|
self.logger.debug(f"Resources {result}: {':'.join(fullName)}")
|
|
926
1050
|
return resources
|
|
927
1051
|
|
|
928
|
-
def kr8s_class(
|
|
1052
|
+
def kr8s_class(
|
|
1053
|
+
self,
|
|
1054
|
+
kind: protobuf.TypeString,
|
|
1055
|
+
apiVersion: protobuf.TypeString,
|
|
1056
|
+
namespaced: bool,
|
|
1057
|
+
) -> type[kr8s.APIObject]:
|
|
929
1058
|
try:
|
|
930
1059
|
return kr8s.asyncio.objects.get_class(str(kind), str(apiVersion), True)
|
|
931
1060
|
except KeyError:
|
crossplane/pythonic/version.py
CHANGED