Skip to content

Commit 226c162

Browse files
pcrespovAndrei Neagu
andauthored
🐛⚠️ New R_CLONE_ENABLED env var and fix contraints in compose-spec for side-car (ITISFoundation#3084)
Co-authored-by: Andrei Neagu <[email protected]>
1 parent f82060a commit 226c162

File tree

9 files changed

+44
-5
lines changed

9 files changed

+44
-5
lines changed

packages/settings-library/src/settings_library/r_clone.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,17 @@ class S3Provider(str, Enum):
1313

1414

1515
class RCloneSettings(BaseCustomSettings):
16+
# TODO: PC this flag is actually ONLY used by the dynamic sidecar.
17+
# It determines how the dynamic sidecar sets up node-ports storage
18+
# mechanism. I propose it is added as an extra independent variable in
19+
# simcore_service_dynamic_idecar.core.settings.Settings instead of here.
20+
R_CLONE_ENABLED: bool = Field(
21+
True,
22+
description=(
23+
"simple way to enable/disable the usage of rclone "
24+
"in parts of the system where it is optional "
25+
"eg: dynamic-sidecar"
26+
),
27+
)
1628
R_CLONE_S3: S3Settings = Field(auto_default_from_env=True)
1729
R_CLONE_PROVIDER: S3Provider

services/director-v2/src/simcore_service_director_v2/core/settings.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060

6161
SUPPORTED_TRAEFIK_LOG_LEVELS: Set[str] = {"info", "debug", "warn", "error"}
6262

63-
PlacementConstraint = constr(
63+
PlacementConstraintStr = constr(
6464
strip_whitespace=True, regex=r"^[a-zA-Z0-9. ]*(!=|==){1}[a-zA-Z0-9. ]*$"
6565
)
6666

@@ -443,7 +443,7 @@ class AppSettings(BaseCustomSettings, MixinLoggingSettings):
443443

444444
# This is just a service placement constraint, see
445445
# https://docs.docker.com/engine/swarm/services/#control-service-placement.
446-
DIRECTOR_V2_SERVICES_CUSTOM_CONSTRAINTS: List[PlacementConstraint] = Field(
446+
DIRECTOR_V2_SERVICES_CUSTOM_CONSTRAINTS: List[PlacementConstraintStr] = Field(
447447
default_factory=list,
448448
example='["node.labels.region==east", "one!=yes"]',
449449
)

services/director-v2/src/simcore_service_director_v2/modules/dynamic_sidecar/docker_service_specs/settings.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ def _parse_env_settings(settings: List[str]) -> Dict:
7373

7474

7575
# pylint: disable=too-many-branches
76+
# TODO: PC->ANE: i tend to agree with pylint, perhaps we can refactor this together
7677
def update_service_params_from_settings(
7778
labels_service_settings: SimcoreServiceSettingsLabel,
7879
create_service_params: Dict[str, Any],
@@ -122,13 +123,17 @@ def update_service_params_from_settings(
122123

123124
# placement constraints
124125
elif param.name == "constraints": # python-API compatible
126+
125127
create_service_params["task_template"]["Placement"][
126128
"Constraints"
127129
] += param.value
130+
128131
elif param.setting_type == "Constraints": # REST-API compatible
132+
129133
create_service_params["task_template"]["Placement"][
130134
"Constraints"
131135
] += param.value
136+
132137
elif param.name == "env":
133138
log.debug("Found env parameter %s", param.value)
134139
env_settings = _parse_env_settings(param.value)
@@ -153,6 +158,13 @@ def update_service_params_from_settings(
153158
create_service_params["task_template"]["Resources"]["Limits"]["MemoryBytes"]
154159
)
155160

161+
# Cleanup repeated constraints.
162+
# Observed in deploy how constraint 'node.platform.os == linux' was appended many many times
163+
constraints = create_service_params["task_template"]["Placement"]["Constraints"]
164+
if constraints:
165+
assert isinstance(constraints, list) # nosec
166+
constraints = list(set(constraints))
167+
156168

157169
def _assemble_key(service_key: str, service_tag: str) -> str:
158170
return f"{service_key}:{service_tag}"

services/director-v2/src/simcore_service_director_v2/modules/dynamic_sidecar/docker_service_specs/sidecar.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ def _get_environment_variables(
7373
"S3_BUCKET_NAME": r_clone_settings.R_CLONE_S3.S3_BUCKET_NAME,
7474
"S3_SECURE": f"{r_clone_settings.R_CLONE_S3.S3_SECURE}",
7575
"R_CLONE_PROVIDER": r_clone_settings.R_CLONE_PROVIDER,
76+
"R_CLONE_ENABLED": f"{r_clone_settings.R_CLONE_ENABLED}",
7677
}
7778

7879

services/director-v2/tests/unit/test_modules_dynamic_sidecar_docker_service_specs.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,7 @@ def expected_dynamic_sidecar_spec() -> dict[str, Any]:
202202
"REGISTRY_URL": "registry.osparc-master.speag.com",
203203
"REGISTRY_USER": "test",
204204
"R_CLONE_PROVIDER": "MINIO",
205+
"R_CLONE_ENABLED": "True",
205206
"S3_ACCESS_KEY": "12345678",
206207
"S3_BUCKET_NAME": "simcore",
207208
"S3_ENDPOINT": "http://172.17.0.1:9001",

services/director-v2/tests/unit/test_modules_dynamic_sidecar_docker_service_specs_sidecar.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
"SIMCORE_HOST_NAME",
6161
"STORAGE_ENDPOINT",
6262
"R_CLONE_PROVIDER",
63+
"R_CLONE_ENABLED",
6364
"S3_ENDPOINT",
6465
"S3_ACCESS_KEY",
6566
"S3_SECRET_KEY",

services/dynamic-sidecar/src/simcore_service_dynamic_sidecar/core/settings.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,18 @@ def is_development_mode(self) -> bool:
105105
def loglevel(self) -> int:
106106
return int(getattr(logging, self.LOG_LEVEL))
107107

108+
@property
109+
def rclone_settings_for_nodeports(self) -> Optional[RCloneSettings]:
110+
"""
111+
If R_CLONE_ENABLED is False it returns None which indicates
112+
nodeports to disable rclone and fallback to the previous storage mechanim.
113+
"""
114+
return (
115+
self.DY_SIDECAR_R_CLONE_SETTINGS
116+
if self.DY_SIDECAR_R_CLONE_SETTINGS.R_CLONE_ENABLED
117+
else None
118+
)
119+
108120

109121
@lru_cache
110122
def get_settings() -> DynamicSidecarSettings:

services/dynamic-sidecar/src/simcore_service_dynamic_sidecar/modules/data_manager.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,6 @@ async def upload_path_if_exists(path: Path, state_exclude: List[str]) -> None:
7676
project_id=str(settings.DY_SIDECAR_PROJECT_ID),
7777
node_uuid=str(settings.DY_SIDECAR_NODE_ID),
7878
file_or_folder=path,
79-
r_clone_settings=settings.DY_SIDECAR_R_CLONE_SETTINGS,
79+
r_clone_settings=settings.rclone_settings_for_nodeports,
8080
)
8181
logger.info("Finished upload of %s", path)

services/dynamic-sidecar/src/simcore_service_dynamic_sidecar/modules/nodeports.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ async def upload_outputs(outputs_path: Path, port_keys: list[str]) -> None:
6161
user_id=settings.DY_SIDECAR_USER_ID,
6262
project_id=str(settings.DY_SIDECAR_PROJECT_ID),
6363
node_uuid=str(settings.DY_SIDECAR_NODE_ID),
64-
r_clone_settings=settings.DY_SIDECAR_R_CLONE_SETTINGS,
64+
r_clone_settings=settings.rclone_settings_for_nodeports,
6565
)
6666

6767
# let's gather the tasks
@@ -254,7 +254,7 @@ async def download_target_ports(
254254
user_id=settings.DY_SIDECAR_USER_ID,
255255
project_id=str(settings.DY_SIDECAR_PROJECT_ID),
256256
node_uuid=str(settings.DY_SIDECAR_NODE_ID),
257-
r_clone_settings=settings.DY_SIDECAR_R_CLONE_SETTINGS,
257+
r_clone_settings=settings.rclone_settings_for_nodeports,
258258
)
259259

260260
# let's gather all the data

0 commit comments

Comments
 (0)