From fbf1eac53d9a526505c826c974f5c0e03922c26b Mon Sep 17 00:00:00 2001 From: ryandawsonuk Date: Mon, 17 Jun 2019 15:29:49 +0100 Subject: [PATCH 1/3] make namespace available to engine --- pkg/controller/seldondeployment/seldondeployment_controller.go | 1 + 1 file changed, 1 insertion(+) diff --git a/pkg/controller/seldondeployment/seldondeployment_controller.go b/pkg/controller/seldondeployment/seldondeployment_controller.go index 495ae59b..8fdaf654 100644 --- a/pkg/controller/seldondeployment/seldondeployment_controller.go +++ b/pkg/controller/seldondeployment/seldondeployment_controller.go @@ -219,6 +219,7 @@ func createEngineContainer(mlDep *machinelearningv1alpha2.SeldonDeployment, p *m Env: []corev1.EnvVar{ {Name: "ENGINE_PREDICTOR", Value: predictorB64}, {Name: "DEPLOYMENT_NAME", Value: mlDep.Spec.Name}, + {Name: "DEPLOYMENT_NAMESPACE", Value: mlDep.ObjectMeta.Namespace}, {Name: "ENGINE_SERVER_PORT", Value: strconv.Itoa(engine_http_port)}, {Name: "ENGINE_SERVER_GRPC_PORT", Value: strconv.Itoa(engine_grpc_port)}, {Name: "JAVA_OPTS", Value: javaOpts}, From 198af1646d6a12871321cedc3d2609e9c4ca272b Mon Sep 17 00:00:00 2001 From: ryandawsonuk Date: Wed, 19 Jun 2019 16:14:01 +0100 Subject: [PATCH 2/3] option to set engine env vars from annotations and fix typo in jvm opts --- .../v1alpha2/seldondeployment_types.go | 2 +- .../seldondeployment_controller.go | 31 +++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/pkg/apis/machinelearning/v1alpha2/seldondeployment_types.go b/pkg/apis/machinelearning/v1alpha2/seldondeployment_types.go index cee170d8..81ed7ba3 100644 --- a/pkg/apis/machinelearning/v1alpha2/seldondeployment_types.go +++ b/pkg/apis/machinelearning/v1alpha2/seldondeployment_types.go @@ -40,7 +40,7 @@ const ( ENV_PREDICTOR_ID = "PREDICTOR_ID" ENV_SELDON_DEPLOYMENT_ID = "SELDON_DEPLOYMENT_ID" - ANNOTATION_JAVA_OPTS = "seldonio/engine-java-opts" + ANNOTATION_JAVA_OPTS = "seldon.io/engine-java-opts" ANNOTATION_SEPARATE_ENGINE = "seldon.io/engine-separate-pod" ANNOTATION_HEADLESS_SVC = "seldon.io/headless-svc" ) diff --git a/pkg/controller/seldondeployment/seldondeployment_controller.go b/pkg/controller/seldondeployment/seldondeployment_controller.go index 8fdaf654..d9f8e861 100644 --- a/pkg/controller/seldondeployment/seldondeployment_controller.go +++ b/pkg/controller/seldondeployment/seldondeployment_controller.go @@ -44,7 +44,9 @@ import ( "sigs.k8s.io/controller-runtime/pkg/reconcile" logf "sigs.k8s.io/controller-runtime/pkg/runtime/log" "sigs.k8s.io/controller-runtime/pkg/source" + "sort" "strconv" + "strings" ) const ( @@ -172,6 +174,29 @@ func getAnnotation(mlDep *machinelearningv1alpha2.SeldonDeployment, annotationKe } } +//get annotations that start with seldon.io/engine +func getEngineEnvAnnotations(mlDep *machinelearningv1alpha2.SeldonDeployment) []corev1.EnvVar { + + envVars := make([]corev1.EnvVar, 0) + var keys []string + for k, _ := range mlDep.Spec.Annotations { + keys = append(keys, k) + } + sort.Strings(keys) + + for _, k := range keys { + //prefix indicates engine annotation but "seldon.io/engine-separate-pod" isn't an env one + if strings.HasPrefix(k, "seldon.io/engine-") && k != machinelearningv1alpha2.ANNOTATION_SEPARATE_ENGINE { + name := strings.TrimPrefix(k, "seldon.io/engine-") + var replacer = strings.NewReplacer("-", "_") + name = replacer.Replace(name) + name = strings.ToUpper(name) + envVars = append(envVars, corev1.EnvVar{Name: name, Value: mlDep.Spec.Annotations[k]}) + } + } + return envVars +} + // Create the Container for the service orchestrator. func createEngineContainer(mlDep *machinelearningv1alpha2.SeldonDeployment, p *machinelearningv1alpha2.PredictorSpec, engine_http_port, engine_grpc_port int) (*corev1.Container, error) { // Get engine user @@ -249,6 +274,12 @@ func createEngineContainer(mlDep *machinelearningv1alpha2.SeldonDeployment, p *m }, Resources: *engineResources, } + + engineEnvVarsFromAnnotations := getEngineEnvAnnotations(mlDep) + for _, envVar := range engineEnvVarsFromAnnotations { + c.Env = append(c.Env, envVar) + } + if engineUser != -1 { var procMount = corev1.DefaultProcMount c.SecurityContext = &corev1.SecurityContext{RunAsUser: &engineUser, ProcMount: &procMount} From c7dc8a561cfc1b82a48f3afeb5732d560c2403de Mon Sep 17 00:00:00 2001 From: ryandawsonuk Date: Wed, 19 Jun 2019 16:47:52 +0100 Subject: [PATCH 3/3] ensure svcOrchSpec takes priority --- .../seldondeployment_controller.go | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/pkg/controller/seldondeployment/seldondeployment_controller.go b/pkg/controller/seldondeployment/seldondeployment_controller.go index d9f8e861..83d085d0 100644 --- a/pkg/controller/seldondeployment/seldondeployment_controller.go +++ b/pkg/controller/seldondeployment/seldondeployment_controller.go @@ -275,22 +275,33 @@ func createEngineContainer(mlDep *machinelearningv1alpha2.SeldonDeployment, p *m Resources: *engineResources, } - engineEnvVarsFromAnnotations := getEngineEnvAnnotations(mlDep) - for _, envVar := range engineEnvVarsFromAnnotations { - c.Env = append(c.Env, envVar) - } if engineUser != -1 { var procMount = corev1.DefaultProcMount c.SecurityContext = &corev1.SecurityContext{RunAsUser: &engineUser, ProcMount: &procMount} } + + // Environment vars if specified + svcOrchEnvMap := make(map[string]string) if p.SvcOrchSpec.Env != nil { for _, env := range p.SvcOrchSpec.Env { c.Env = append(c.Env, *env) + svcOrchEnvMap[env.Name] = env.Value } } + engineEnvVarsFromAnnotations := getEngineEnvAnnotations(mlDep) + for _, envVar := range engineEnvVarsFromAnnotations { + //don't add env vars that are already present in svcOrchSpec + if _, ok := svcOrchEnvMap[envVar.Name]; ok { + //present so don't try to overwrite + } else{ + c.Env = append(c.Env, envVar) + } + + } + return &c, nil }