From 9300e0aa4491d108490d4633c4417c4814a664c4 Mon Sep 17 00:00:00 2001 From: vsoch Date: Tue, 5 Aug 2025 18:42:09 -0700 Subject: [PATCH] save state for instance selection Signed-off-by: vsoch --- Makefile | 5 +++++ python/setup.py | 4 ++++ python/state_machine_operator/analysis/manager.py | 13 ++++++++++--- python/state_machine_operator/defaults.py | 5 +++++ .../tracker/kubernetes/utils.py | 7 +++---- 5 files changed, 27 insertions(+), 7 deletions(-) diff --git a/Makefile b/Makefile index 63c9ffe..e0f8604 100644 --- a/Makefile +++ b/Makefile @@ -44,6 +44,7 @@ IMG ?= ghcr.io/converged-computing/state-machine-operator:latest ARMIMG ?= ghcr.io/converged-computing/state-machine-operator:arm DEVIMG ?= ghcr.io/converged-computing/state-machine-operator:test MANAGER_IMG ?= ghcr.io/converged-computing/state-machine-operator:manager +INSTANCE_SELECT_IMG ?= ghcr.io/converged-computing/state-machine-operator:instance-select # ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary. ENVTEST_K8S_VERSION = 1.30.0 @@ -146,6 +147,10 @@ docker-push: ## Push docker image with the manager. manager: $(CONTAINER_TOOL) build -f docker/manager/Dockerfile -t ${MANAGER_IMG} . +.PHONY: instance-select +instance-select: + $(CONTAINER_TOOL) build -f docker/instance-select/Dockerfile -t ${INSTANCE_SELECT_IMG} . + .PHONY: kind kind: manager ## Build docker image with the manager and load into kind kind load docker-image ${MANAGER_IMG} diff --git a/python/setup.py b/python/setup.py index 512c628..42e48cd 100644 --- a/python/setup.py +++ b/python/setup.py @@ -40,6 +40,9 @@ "river", "kubernetes", ], + extras_require={ + 'instance-select': ['pandas', 'requests', "grpcio", "grpcio-tools"], + }, tests_require=["pytest", "pytest-cov"], classifiers=[ "Intended Audience :: Science/Research", @@ -55,6 +58,7 @@ entry_points={ "console_scripts": [ "state-machine-manager=state_machine_operator.manager:main", + "instance-select-server=state_machine_operator.instances.server:main", ] }, ) diff --git a/python/state_machine_operator/analysis/manager.py b/python/state_machine_operator/analysis/manager.py index 6262ea0..defeefb 100644 --- a/python/state_machine_operator/analysis/manager.py +++ b/python/state_machine_operator/analysis/manager.py @@ -54,7 +54,14 @@ def generate_colors(self, items): colors[item] = hexcolors.pop(0) return colors - def to_gantt(self, outfile, title="Node Uptimes for Static vs Autoscaling", colors=None): + def to_gantt( + self, + outfile, + title="Node Uptimes for Static vs Autoscaling", + colors=None, + width=8, + height=20, + ): """ Make a gantt chart of nodes over time """ @@ -83,7 +90,7 @@ def to_gantt(self, outfile, title="Node Uptimes for Static vs Autoscaling", colo patches.append(matplotlib.patches.Patch(color=color)) # Each needs its own plot - fig, axs = plt.subplots(number_plots, figsize=(8, 20)) + fig, axs = plt.subplots(number_plots, figsize=(width, height)) idx = 0 for experiment in self.df.experiment.unique(): exp_subset = self.df[self.df.experiment == experiment] @@ -105,7 +112,7 @@ def to_gantt(self, outfile, title="Node Uptimes for Static vs Autoscaling", colo idx += 1 plt.subplots_adjust(top=0.95) - fig.suptitle(title, fontsize=11) + fig.suptitle(title, fontsize=11, x=0.025, y=0.98, ha="left") fig.legend(handles=patches, labels=colors.keys(), fontsize=11) plt.savefig(outfile) diff --git a/python/state_machine_operator/defaults.py b/python/state_machine_operator/defaults.py index 825ccb3..0c96b35 100644 --- a/python/state_machine_operator/defaults.py +++ b/python/state_machine_operator/defaults.py @@ -1,5 +1,10 @@ scheduler = "kubernetes" registry = "registry-0.state-machine.default.svc.cluster.local:5000" +service_account_file = "/var/run/secrets/kubernetes.io/serviceaccount/namespace" + +# Insance select server +workers = 8 +port = 8080 # Operator label for the jobid operator_label = "jobid" diff --git a/python/state_machine_operator/tracker/kubernetes/utils.py b/python/state_machine_operator/tracker/kubernetes/utils.py index 9a45c7b..33ce579 100644 --- a/python/state_machine_operator/tracker/kubernetes/utils.py +++ b/python/state_machine_operator/tracker/kubernetes/utils.py @@ -1,15 +1,14 @@ import os from kubernetes import client - +import state_machine_operator.default as defaults def get_namespace(): """ Get the current namespace the workflow manager is running in. """ - ns_path = "/var/run/secrets/kubernetes.io/serviceaccount/namespace" - if os.path.exists(ns_path): - with open(ns_path) as f: + if os.path.exists(defaults.service_account_file): + with open(defaults.service_account_file) as f: return f.read().strip()