Skip to content

Commit b246b6e

Browse files
committed
feat(k8s): adding lifecycle for datastore sidecar
1 parent 1686253 commit b246b6e

3 files changed

Lines changed: 15 additions & 2 deletions

File tree

reana_workflow_controller/k8s.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ def __init__(
8888
name=self.deployment_name, image=self.image, env=[], volume_mounts=[], ports=[client.V1ContainerPort(container_port=self.port)]
8989
)
9090
self._s3_container = client.V1Container(
91-
name="datastore", image=REANA_DATASTORE_IMAGE, env=[], volume_mounts=[], ports=[], image_pull_policy="Always"
91+
name="datastore", image=REANA_DATASTORE_IMAGE, env=[], volume_mounts=[], ports=[], image_pull_policy="Always", lifecycle=[]
9292
)
9393
self._pod_spec = client.V1PodSpec(
9494
containers=[self._session_container, self._s3_container],
@@ -268,6 +268,17 @@ def setup_s3_sidecar(self):
268268
)
269269
self._s3_container.security_context = security_context
270270

271+
# adding umount for correct termination
272+
lifecycle_dict = {
273+
"preStop": {
274+
"exec": {
275+
"command": ["/bin/sh", "-c", "xargs umount -l < /etc/active_mounts.txt || true"]
276+
}
277+
}
278+
}
279+
280+
self._s3_container.lifecycle = lifecycle_dict
281+
271282
def add_cvmfs_repo_mounts(self, cvmfs_repos):
272283
"""Add mounts for the provided CVMFS repositories to the deployment.
273284

sidecars/datastore/app.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ def createS3Mounts(aliases, base_dir):
5151
)
5252
else:
5353
print(f"Successfully mounted '{aliases[i][0]}'")
54+
with open("/etc/active_mounts.txt", "a") as f:
55+
f.write(f"{target_path}\n")
5456
os.system("rm .passwd-s3fs")
5557
except Exception as e:
5658
print(f"A error accrued during the mounting of alias {aliases[i][0]}: {e}")

sidecars/datastore/entrypoint.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ echo "Starting Python S3 Data Manager..."
55
python3 /app/app.py
66
echo "Initialization complete."
77

8-
tail -f /dev/null
8+
exec tail -f /dev/null

0 commit comments

Comments
 (0)