|
19 | 19 | field_validator, |
20 | 20 | model_validator, |
21 | 21 | ) |
| 22 | +from pydantic.config import JsonDict |
22 | 23 |
|
23 | 24 | from .callbacks_mapping import CallbacksMapping |
24 | 25 | from .generics import ListModel |
@@ -490,57 +491,29 @@ def _not_allowed_in_both_specs(self): |
490 | 491 | model_config = _BaseConfig |
491 | 492 |
|
492 | 493 |
|
493 | | -class SimcoreServiceLabels(DynamicSidecarServiceLabels): |
494 | | - """ |
495 | | - Validate all the simcores.services.* labels on a service. |
496 | | -
|
497 | | - When no other fields expect `settings` are present |
498 | | - the service will be started as legacy by director-v0. |
499 | | -
|
500 | | - If `paths_mapping` is present the service will be started |
501 | | - via dynamic-sidecar by director-v2. |
502 | | -
|
503 | | - When starting via dynamic-sidecar, if `compose_spec` is |
504 | | - present, also `container_http_entry` must be present. |
505 | | - When both of these fields are missing a docker-compose |
506 | | - spec will be generated before starting the service. |
507 | | - """ |
508 | | - |
509 | | - settings: Annotated[ |
510 | | - Json[SimcoreServiceSettingsLabel], |
511 | | - Field( |
512 | | - default_factory=dict, |
513 | | - alias="simcore.service.settings", |
514 | | - description=( |
515 | | - "Json encoded. Contains setting like environment variables and " |
516 | | - "resource constraints which are required by the service. " |
517 | | - "Should be compatible with Docker REST API." |
518 | | - ), |
519 | | - ), |
520 | | - ] |
| 494 | +def _simcore_service_labels_json_schema_extra(json_schema_extra: JsonDict): |
521 | 495 |
|
522 | 496 | assert "json_schema_extra" in SimcoreServiceSettingLabelEntry.model_config # nosec |
523 | | - assert isinstance( |
| 497 | + assert isinstance( # nosec |
524 | 498 | SimcoreServiceSettingLabelEntry.model_config["json_schema_extra"], dict |
525 | | - ) # nosec |
| 499 | + ) |
526 | 500 |
|
527 | 501 | assert "json_schema_extra" in PathMappingsLabel.model_config # nosec |
528 | | - assert isinstance( |
| 502 | + assert isinstance( # nosec |
529 | 503 | PathMappingsLabel.model_config["json_schema_extra"], dict |
530 | | - ) # nosec |
531 | | - assert isinstance( |
| 504 | + ) |
| 505 | + assert isinstance( # nosec |
532 | 506 | PathMappingsLabel.model_config["json_schema_extra"]["examples"], list |
533 | | - ) # nosec |
| 507 | + ) |
534 | 508 |
|
535 | 509 | assert "json_schema_extra" in CallbacksMapping.model_config # nosec |
536 | 510 | assert isinstance(CallbacksMapping.model_config["json_schema_extra"], dict) # nosec |
537 | | - assert isinstance( |
| 511 | + assert isinstance( # nosec |
538 | 512 | CallbacksMapping.model_config["json_schema_extra"]["examples"], list |
539 | | - ) # nosec |
| 513 | + ) |
540 | 514 |
|
541 | | - model_config = _BaseConfig | ConfigDict( |
542 | | - extra="allow", |
543 | | - json_schema_extra={ |
| 515 | + json_schema_extra.update( |
| 516 | + { |
544 | 517 | "examples": [ |
545 | 518 | # WARNING: do not change order. Used in tests! |
546 | 519 | # legacy service |
@@ -623,3 +596,38 @@ class SimcoreServiceLabels(DynamicSidecarServiceLabels): |
623 | 596 | ] |
624 | 597 | }, |
625 | 598 | ) |
| 599 | + |
| 600 | + |
| 601 | +class SimcoreServiceLabels(DynamicSidecarServiceLabels): |
| 602 | + """ |
| 603 | + Validate all the simcores.services.* labels on a service. |
| 604 | +
|
| 605 | + When no other fields expect `settings` are present |
| 606 | + the service will be started as legacy by director-v0. |
| 607 | +
|
| 608 | + If `paths_mapping` is present the service will be started |
| 609 | + via dynamic-sidecar by director-v2. |
| 610 | +
|
| 611 | + When starting via dynamic-sidecar, if `compose_spec` is |
| 612 | + present, also `container_http_entry` must be present. |
| 613 | + When both of these fields are missing a docker-compose |
| 614 | + spec will be generated before starting the service. |
| 615 | + """ |
| 616 | + |
| 617 | + settings: Annotated[ |
| 618 | + Json[SimcoreServiceSettingsLabel], |
| 619 | + Field( |
| 620 | + default_factory=dict, |
| 621 | + alias="simcore.service.settings", |
| 622 | + description=( |
| 623 | + "Json encoded. Contains setting like environment variables and " |
| 624 | + "resource constraints which are required by the service. " |
| 625 | + "Should be compatible with Docker REST API." |
| 626 | + ), |
| 627 | + ), |
| 628 | + ] |
| 629 | + |
| 630 | + model_config = _BaseConfig | ConfigDict( |
| 631 | + extra="allow", |
| 632 | + json_schema_extra=_simcore_service_labels_json_schema_extra, |
| 633 | + ) |
0 commit comments