From 436847bda48b8b2bb3973d332a5963b03f4ddeb5 Mon Sep 17 00:00:00 2001 From: vprashar2929 Date: Thu, 22 Aug 2024 11:30:06 +0530 Subject: [PATCH 1/2] chore: Bump up model-server to v0.7.11-2 This commit bumps up model-server to `v0.7.11-2` Signed-off-by: vprashar2929 --- pkg/components/estimator/estimator.go | 6 +++--- pkg/components/modelserver/modelserver.go | 6 +++--- tests/images.yaml | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/pkg/components/estimator/estimator.go b/pkg/components/estimator/estimator.go index 87970408..af27507c 100644 --- a/pkg/components/estimator/estimator.go +++ b/pkg/components/estimator/estimator.go @@ -28,7 +28,7 @@ import ( const ( // NOTE: update tests/images.yaml when changing this image - StableImage = "quay.io/sustainable_computing_io/kepler_model_server:v0.7.11" + StableImage = "quay.io/sustainable_computing_io/kepler_model_server:v0.7.11-2" waitForSocketCommand = "until [ -e /tmp/estimator.sock ]; do sleep 1; done && %s" ) @@ -76,8 +76,8 @@ func Container(image string) corev1.Container { ImagePullPolicy: corev1.PullIfNotPresent, Name: "estimator", VolumeMounts: mounts, - Command: []string{"python3.10"}, - Args: []string{"-u", "src/estimate/estimator.py"}, + Command: []string{"estimator"}, + Args: []string{"-l", "info"}, } } diff --git a/pkg/components/modelserver/modelserver.go b/pkg/components/modelserver/modelserver.go index a35b0acb..57d4a5ad 100644 --- a/pkg/components/modelserver/modelserver.go +++ b/pkg/components/modelserver/modelserver.go @@ -38,7 +38,7 @@ const ( const ( defaultModelServer = "http://%s.%s.svc.cluster.local:%d" - StableImage = "quay.io/sustainable_computing_io/kepler_model_server:v0.7.11" + StableImage = "quay.io/sustainable_computing_io/kepler_model_server:v0.7.11-2" ) var ( @@ -86,8 +86,8 @@ func NewDeployment(deployName string, ms *v1alpha1.InternalModelServerSpec, name Name: "http", }}, VolumeMounts: mounts, - Command: []string{"python3.10"}, - Args: []string{"-u", "src/server/model_server.py"}, + Command: []string{"model-server"}, + Args: []string{"-l", "info"}, }} return &appsv1.Deployment{ diff --git a/tests/images.yaml b/tests/images.yaml index f61a7248..ab965538 100644 --- a/tests/images.yaml +++ b/tests/images.yaml @@ -1,3 +1,3 @@ images: - component: 'model-server' - image: 'quay.io/sustainable_computing_io/kepler_model_server:v0.7.11' + image: 'quay.io/sustainable_computing_io/kepler_model_server:v0.7.11-2' From d460128f921c96ac555a2851d049da1a9b34a33f Mon Sep 17 00:00:00 2001 From: vprashar2929 Date: Wed, 28 Aug 2024 19:58:19 +0530 Subject: [PATCH 2/2] chore: add wait command in kepler for model-server Signed-off-by: vprashar2929 --- pkg/components/estimator/estimator.go | 2 +- pkg/components/estimator/estimator_test.go | 2 +- pkg/components/exporter/exporter.go | 15 ++++++++++ pkg/components/modelserver/modelserver.go | 27 ++++++++++++++++-- .../modelserver/modelserver_test.go | 28 +++++++++++++++++++ 5 files changed, 70 insertions(+), 4 deletions(-) diff --git a/pkg/components/estimator/estimator.go b/pkg/components/estimator/estimator.go index af27507c..43326a51 100644 --- a/pkg/components/estimator/estimator.go +++ b/pkg/components/estimator/estimator.go @@ -33,7 +33,7 @@ const ( ) var ( - shellCommand = []string{"/bin/sh", "-c"} + shellCommand = []string{"/usr/bin/bash", "-c"} ) // NeedsEstimatorSidecar returns true if any of estimator config has sidecar enabled diff --git a/pkg/components/estimator/estimator_test.go b/pkg/components/estimator/estimator_test.go index 0dbb1c7b..94006df8 100644 --- a/pkg/components/estimator/estimator_test.go +++ b/pkg/components/estimator/estimator_test.go @@ -109,7 +109,7 @@ func TestModifiedContainer(t *testing.T) { exporterContainer := &corev1.Container{ Command: []string{"kepler", "-v=1"}, } - expectedCommand := []string{"/bin/sh", "-c"} + expectedCommand := []string{"/usr/bin/bash", "-c"} expectedArgs := []string{"until [ -e /tmp/estimator.sock ]; do sleep 1; done && kepler -v=1"} expectedVolumeMounts := []string{"cfm", "mnt", "tmp"} keplerVolumes := []corev1.Volume{k8s.VolumeFromEmptyDir("kepler-volume")} diff --git a/pkg/components/exporter/exporter.go b/pkg/components/exporter/exporter.go index df458987..cebcc4c2 100644 --- a/pkg/components/exporter/exporter.go +++ b/pkg/components/exporter/exporter.go @@ -102,6 +102,11 @@ func NewDaemonSet(detail components.Detail, k *v1alpha1.KeplerInternal) *appsv1. k8s.VolumeFromConfigMap("cfm", k.Name), } // exporter default Volumes + ms := k.Spec.ModelServer + if ms != nil && ms.Enabled { + addModelServerCommand(&exporterContainer, k.ModelServerDeploymentName(), k.Namespace(), ms) + } + if estimator.NeedsEstimatorSidecar(k.Spec.Estimator) { // add sidecar container and update kepler-exporter container // add shared volumes @@ -656,7 +661,17 @@ func newExporterContainer(kiName, dsName string, deployment v1alpha1.InternalExp func addEstimatorSidecar(estimatorImage string, exporterContainer *corev1.Container, volumes []corev1.Volume) ([]corev1.Container, []corev1.Volume) { sidecarContainer := estimator.Container(estimatorImage) volumes = append(volumes, estimator.Volumes()...) + // NOTE: if the exporter has arguments (e.g., for an estimator with model server deployment), + // update the exporter's container command with the arguments. This allows AddEstimatorDependency + // to append the necessary socket wait command to the arguments + if exporterContainer.Args != nil { + exporterContainer.Command = exporterContainer.Args + } exporterContainer = estimator.AddEstimatorDependency(exporterContainer) containers := []corev1.Container{*exporterContainer, sidecarContainer} return containers, volumes } + +func addModelServerCommand(exporterContainer *corev1.Container, deployName, deployNamespace string, ms *v1alpha1.InternalModelServerSpec) { + modelserver.AddModelServerDependency(exporterContainer, deployName, deployNamespace, ms) +} diff --git a/pkg/components/modelserver/modelserver.go b/pkg/components/modelserver/modelserver.go index 57d4a5ad..d380371e 100644 --- a/pkg/components/modelserver/modelserver.go +++ b/pkg/components/modelserver/modelserver.go @@ -18,6 +18,7 @@ package modelserver import ( "fmt" + "strings" "github.com/sustainable.computing.io/kepler-operator/api/v1alpha1" "github.com/sustainable.computing.io/kepler-operator/pkg/components" @@ -37,8 +38,9 @@ const ( ) const ( - defaultModelServer = "http://%s.%s.svc.cluster.local:%d" - StableImage = "quay.io/sustainable_computing_io/kepler_model_server:v0.7.11-2" + defaultModelServer = "http://%s.%s.svc.cluster.local:%d" + StableImage = "quay.io/sustainable_computing_io/kepler_model_server:v0.7.11-2" + waitForModelServerCommand = "until [[ \"$(curl -s -o /dev/null -w %%{http_code} %s/best-models)\" -eq 200 ]]; do sleep 1; done" ) var ( @@ -53,6 +55,10 @@ var ( }) ) +var ( + shellCommand = []string{"/usr/bin/bash", "-c"} +) + func NewDeployment(deployName string, ms *v1alpha1.InternalModelServerSpec, namespace string) *appsv1.Deployment { pvcName := deployName + PVCNameSuffix configMapName := deployName + ConfigMapSuffix @@ -218,3 +224,20 @@ func serverUrl(deployName, deployNamespace string, ms v1alpha1.InternalModelServ serviceName := deployName + ServiceSuffix return fmt.Sprintf(defaultModelServer, serviceName, deployNamespace, port) } + +func formatModelServerCommand(deployName, deployNamespace string, ms v1alpha1.InternalModelServerSpec) string { + return fmt.Sprintf(waitForModelServerCommand, serverUrl(deployName, deployNamespace, ms)) +} + +func addModelServerWaitCmd(exporterContainer *corev1.Container, deployName, deployNamespace string, ms v1alpha1.InternalModelServerSpec) *corev1.Container { + cmd := exporterContainer.Command + exporterContainer.Command = shellCommand + exporterContainer.Args = []string{fmt.Sprintf("%s && %s", formatModelServerCommand(deployName, deployNamespace, ms), strings.Join(cmd, " "))} + return exporterContainer + +} + +func AddModelServerDependency(exporterContainer *corev1.Container, deployName, deployNamespace string, ms *v1alpha1.InternalModelServerSpec) *corev1.Container { + exporterContainer = addModelServerWaitCmd(exporterContainer, deployName, deployNamespace, *ms) + return exporterContainer +} diff --git a/pkg/components/modelserver/modelserver_test.go b/pkg/components/modelserver/modelserver_test.go index eb0b3993..7cb3c0ce 100644 --- a/pkg/components/modelserver/modelserver_test.go +++ b/pkg/components/modelserver/modelserver_test.go @@ -22,6 +22,7 @@ import ( "github.com/stretchr/testify/assert" "github.com/sustainable.computing.io/kepler-operator/api/v1alpha1" "github.com/sustainable.computing.io/kepler-operator/pkg/components" + corev1 "k8s.io/api/core/v1" ) func TestConfigMap(t *testing.T) { @@ -142,3 +143,30 @@ func TestServerAPIContainer(t *testing.T) { } } + +func TestServerContainer(t *testing.T) { + exporterContainer := &corev1.Container{ + Command: []string{"kepler", "-v=1"}, + } + ms := v1alpha1.InternalModelServerSpec{ + Port: 8080, + } + deployName := "kepler-internal" + deployNamespace := "default" + expectedCommand := []string{"/usr/bin/bash", "-c"} + expectedArgs := []string{"until [[ \"$(curl -s -o /dev/null -w %{http_code} http://kepler-internal-svc.default.svc.cluster.local:8080/best-models)\" -eq 200 ]]; do sleep 1; done && kepler -v=1"} + + t.Run("server container", func(t *testing.T) { + t.Parallel() + _ = v1alpha1.KeplerInternal{ + Spec: v1alpha1.KeplerInternalSpec{ + ModelServer: &ms, + }, + } + exporterContainer := AddModelServerDependency(exporterContainer, deployName, deployNamespace, &ms) + actualCommand := exporterContainer.Command + actualArgs := exporterContainer.Args + assert.Equal(t, expectedCommand, actualCommand) + assert.Equal(t, expectedArgs, actualArgs) + }) +}