Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make namespace available to engine #17

Merged
merged 3 commits into from
Jun 19, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down
43 changes: 43 additions & 0 deletions pkg/controller/seldondeployment/seldondeployment_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -219,6 +244,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},
Expand Down Expand Up @@ -248,17 +274,34 @@ func createEngineContainer(mlDep *machinelearningv1alpha2.SeldonDeployment, p *m
},
Resources: *engineResources,
}


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
}

Expand Down