From f8b6adfdcf1bdf5f991215d964cfdef68f832150 Mon Sep 17 00:00:00 2001 From: Jeroen Galjaard Date: Tue, 7 Sep 2021 11:28:12 +0200 Subject: [PATCH] Update to dynamic image and namespace --- Dockerfile | 8 +------- README.md | 2 +- fltk/launch.py | 4 ++++ fltk/util/config/base_config.py | 29 ++++++++++++++++++++++++++++- 4 files changed, 34 insertions(+), 9 deletions(-) diff --git a/Dockerfile b/Dockerfile index b8fd373d..ac08fc4f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -6,10 +6,6 @@ MAINTAINER Jeroen Galjaard # Run build without interactive dialogue ARG DEBIAN_FRONTEND=noninteractive -# Set environment variables for GLOO and TP (needed for RPC calls) -ENV GLOO_SOCKET_IFNAME=eth0 -ENV TP_SOCKET_IFNAME=eth0 - # Define the working directory of the current Docker container WORKDIR /opt/federation-lab @@ -27,9 +23,7 @@ RUN --mount=type=cache,target=/root/.cache/pip python3 -m pip install -r require # Add FLTK and configurations ADD fltk fltk ADD configs configs - -# Expose default port 5000 to the host OS. -EXPOSE 5000 +ADD charts charts # Update relevant runtime configuration for experiment COPY configs/ configs/ diff --git a/README.md b/README.md index 8b680574..cad1ee19 100644 --- a/README.md +++ b/README.md @@ -377,7 +377,7 @@ before running into trouble later. ```bash cd charts -helm install flearner ./federator --namespace test -f fltk-values.yaml +helm install flearner ./orchestrator --namespace test -f fltk-values.yaml ``` This will spawn an `fl-server` Pod in the `test` Namespace, which will spawn Pods (using `V1PyTorchJobs`), that diff --git a/fltk/launch.py b/fltk/launch.py index 171e7c24..17725ef9 100644 --- a/fltk/launch.py +++ b/fltk/launch.py @@ -74,6 +74,10 @@ def launch_orchestrator(args: Namespace = None, conf: BareConfig = None): logging.info("Loading in cluster configuration file") config.load_incluster_config() + logging.info("Pointing configuration to in cluster configuration.") + conf.cluster_config.load_incluster_namespace() + conf.cluster_config.load_incluster_image() + arrival_generator = ExperimentGenerator() cluster_manager = ClusterManager() diff --git a/fltk/util/config/base_config.py b/fltk/util/config/base_config.py index a5cd44e2..ac65bd48 100644 --- a/fltk/util/config/base_config.py +++ b/fltk/util/config/base_config.py @@ -1,6 +1,7 @@ from dataclasses import dataclass, field from pathlib import Path +import yaml from dataclasses_json import config, dataclass_json @@ -85,8 +86,34 @@ class ClusterConfig: orchestrator: OrchestratorConfig client: ClientConfig wait_for_clients: bool = True + # TODO: Pull info from the environment (Helm chart also). namespace: str = 'test' - image: str = 'gcr.io/test-bed-distml/fltk:latest' + image: str = 'fltk:latest' + + def load_incluster_namespace(self): + with open("/var/run/secrets/kubernetes.io/serviceaccount/namespace") as f: + current_namespace = f.read() + self.namespace = current_namespace + + def load_incluster_image(self): + """ + Function to load the in-cluster image. The fltk-values.yaml file in charts is expected to have (atleast) the + following contents. + + provider: + domain: gcr.io + projectName: + imageName: fltk:latest + + @return: None + @rtype: None + """ + with open("charts/fltk-values.yaml") as f: + loaded = yaml.safe_load(f) + provider = loaded['provider'] + domain, p_name, im_name = provider['domain'], provider['projectName'], provider['imageName'] + current_image_name = f"{domain}/{p_name}/{im_name}" + self.image = current_image_name @dataclass_json @dataclass