Skip to content

Commit

Permalink
Merge pull request #421 from vprashar2929/bump-model-svr
Browse files Browse the repository at this point in the history
chore: Bump up model-server to v0.7.11-2
  • Loading branch information
sthaha authored Sep 26, 2024
2 parents a895fb9 + d460128 commit e9da953
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 10 deletions.
8 changes: 4 additions & 4 deletions pkg/components/estimator/estimator.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ 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"
)

var (
shellCommand = []string{"/bin/sh", "-c"}
shellCommand = []string{"/usr/bin/bash", "-c"}
)

// NeedsEstimatorSidecar returns true if any of estimator config has sidecar enabled
Expand Down Expand Up @@ -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"},
}
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/components/estimator/estimator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")}
Expand Down
15 changes: 15 additions & 0 deletions pkg/components/exporter/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
31 changes: 27 additions & 4 deletions pkg/components/modelserver/modelserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
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 (
Expand All @@ -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
Expand Down Expand Up @@ -86,8 +92,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{
Expand Down Expand Up @@ -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
}
28 changes: 28 additions & 0 deletions pkg/components/modelserver/modelserver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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)
})
}
2 changes: 1 addition & 1 deletion tests/images.yaml
Original file line number Diff line number Diff line change
@@ -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'

0 comments on commit e9da953

Please sign in to comment.