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

Fix missing istio add to scheme #913

Merged
merged 1 commit into from
Oct 9, 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
2 changes: 1 addition & 1 deletion operator/controllers/ambassador.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ func getAmbassadorConfigs(mlDep *machinelearningv1alpha2.SeldonDeployment, p *ma
return "", err
}

if getEnv("AMBASSADOR_SINGLE_NAMESPACE", "false") == "true" {
if GetEnv("AMBASSADOR_SINGLE_NAMESPACE", "false") == "true" {
return YAML_SEP + cRestGlobal + YAML_SEP + cGrpcGlobal + YAML_SEP + cRestNamespaced + YAML_SEP + cGrpcNamespaced, nil
} else {
return YAML_SEP + cRestGlobal + YAML_SEP + cGrpcGlobal, nil
Expand Down
2 changes: 1 addition & 1 deletion operator/controllers/controller_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func getEngineVarJson(p *machinelearningv1alpha2.PredictorSpec) (string, error)
}

// Get an environment variable given by key or return the fallback.
func getEnv(key, fallback string) string {
func GetEnv(key, fallback string) string {
if value, ok := os.LookupEnv(key); ok {
return value
}
Expand Down
2 changes: 1 addition & 1 deletion operator/controllers/model_initializer_injector.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ const (
)

var (
ControllerNamespace = getEnv("POD_NAMESPACE", "seldon-system")
ControllerNamespace = GetEnv("POD_NAMESPACE", "seldon-system")
ControllerConfigMapName = "seldon-config"
)

Expand Down
14 changes: 7 additions & 7 deletions operator/controllers/seldondeployment_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ func createIstioResources(mlDep *machinelearningv1alpha2.SeldonDeployment,
engine_http_port int,
engine_grpc_port int) ([]*istio.VirtualService, []*istio.DestinationRule) {

istio_gateway := getEnv(ENV_ISTIO_GATEWAY, "seldon-gateway")
istio_gateway := GetEnv(ENV_ISTIO_GATEWAY, "seldon-gateway")
httpVsvc := &istio.VirtualService{
ObjectMeta: metav1.ObjectMeta{
Name: seldonId + "-http",
Expand Down Expand Up @@ -177,7 +177,7 @@ func createIstioResources(mlDep *machinelearningv1alpha2.SeldonDeployment,
Spec: istio.DestinationRuleSpec{
Host: pSvcName,
TrafficPolicy: &istio.TrafficPolicy{
TLS: &istio.TLSSettings {
TLS: &istio.TLSSettings{
Mode: istio.TLSmodeIstioMutual,
},
},
Expand Down Expand Up @@ -226,7 +226,7 @@ func createIstioResources(mlDep *machinelearningv1alpha2.SeldonDeployment,
func getEngineHttpPort() (engine_http_port int, err error) {
// Get engine http port from environment or use default
engine_http_port = DEFAULT_ENGINE_CONTAINER_PORT
var env_engine_http_port = getEnv(ENV_DEFAULT_ENGINE_SERVER_PORT, "")
var env_engine_http_port = GetEnv(ENV_DEFAULT_ENGINE_SERVER_PORT, "")
if env_engine_http_port != "" {
engine_http_port, err = strconv.Atoi(env_engine_http_port)
if err != nil {
Expand All @@ -239,7 +239,7 @@ func getEngineHttpPort() (engine_http_port int, err error) {
func getEngineGrpcPort() (engine_grpc_port int, err error) {
// Get engine grpc port from environment or use default
engine_grpc_port = DEFAULT_ENGINE_GRPC_PORT
var env_engine_grpc_port = getEnv(ENV_DEFAULT_ENGINE_SERVER_GRPC_PORT, "")
var env_engine_grpc_port = GetEnv(ENV_DEFAULT_ENGINE_SERVER_GRPC_PORT, "")
if env_engine_grpc_port != "" {
engine_grpc_port, err = strconv.Atoi(env_engine_grpc_port)
if err != nil {
Expand Down Expand Up @@ -382,7 +382,7 @@ func createComponents(r *SeldonDeploymentReconciler, mlDep *machinelearningv1alp
}

//TODO Fixme - not changed to handle per predictor scenario
if getEnv(ENV_ISTIO_ENABLED, "false") == "true" {
if GetEnv(ENV_ISTIO_ENABLED, "false") == "true" {
vsvcs, dstRule := createIstioResources(mlDep, seldonId, namespace, engine_http_port, engine_grpc_port)
c.virtualServices = append(c.virtualServices, vsvcs...)
c.destinationRules = append(c.destinationRules, dstRule...)
Expand Down Expand Up @@ -421,7 +421,7 @@ func createPredictorService(pSvcName string, seldonId string, p *machinelearning
psvc.Spec.Ports = append(psvc.Spec.Ports, corev1.ServicePort{Protocol: corev1.ProtocolTCP, Port: int32(engine_grpc_port), TargetPort: intstr.FromInt(engine_grpc_port), Name: "grpc"})
}

if getEnv("AMBASSADOR_ENABLED", "false") == "true" {
if GetEnv("AMBASSADOR_ENABLED", "false") == "true" {
psvc.Annotations = make(map[string]string)
//Create top level Service
ambassadorConfig, err := getAmbassadorConfigs(mlDep, p, pSvcName, engine_http_port, engine_grpc_port, ambassadorNameOverride)
Expand Down Expand Up @@ -1164,7 +1164,7 @@ func (r *SeldonDeploymentReconciler) SetupWithManager(mgr ctrl.Manager) error {
return err
}

if getEnv(ENV_ISTIO_ENABLED, "false") == "true" {
if GetEnv(ENV_ISTIO_ENABLED, "false") == "true" {
if err := mgr.GetFieldIndexer().IndexField(&istio.VirtualService{}, ownerKey, func(rawObj runtime.Object) []string {
// grab the deployment object, extract the owner...
vsvc := rawObj.(*istio.VirtualService)
Expand Down
12 changes: 6 additions & 6 deletions operator/controllers/seldondeployment_engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func addEngineToDeployment(mlDep *machinelearningv1alpha2.SeldonDeployment, p *m
}

deploy.Spec.Template.Spec.Containers = append(deploy.Spec.Template.Spec.Containers, *engineContainer)
//deploy.Spec.Template.Spec.ServiceAccountName = getEnv("ENGINE_CONTAINER_SERVICE_ACCOUNT_NAME", "seldon")
//deploy.Spec.Template.Spec.ServiceAccountName = GetEnv("ENGINE_CONTAINER_SERVICE_ACCOUNT_NAME", "seldon")
//deploy.Spec.Template.Spec.DeprecatedServiceAccount = deploy.Spec.Template.Spec.ServiceAccountName
//deploy.Spec.Template.Annotations = map[string]string{}
if deploy.Spec.Template.Annotations == nil {
Expand All @@ -71,7 +71,7 @@ func addEngineToDeployment(mlDep *machinelearningv1alpha2.SeldonDeployment, p *m
deploy.Spec.Template.Annotations[ann] = p.Annotations[ann]
}
// Add prometheus annotations
deploy.Spec.Template.Annotations["prometheus.io/path"] = getEnv("ENGINE_PROMETHEUS_PATH", "/prometheus")
deploy.Spec.Template.Annotations["prometheus.io/path"] = GetEnv("ENGINE_PROMETHEUS_PATH", "/prometheus")
deploy.Spec.Template.Annotations["prometheus.io/port"] = strconv.Itoa(engine_http_port)
deploy.Spec.Template.Annotations["prometheus.io/scrape"] = "true"

Expand Down Expand Up @@ -134,8 +134,8 @@ func createEngineContainer(mlDep *machinelearningv1alpha2.SeldonDeployment, p *m

c := corev1.Container{
Name: EngineContainerName,
Image: getEnv("ENGINE_CONTAINER_IMAGE_AND_VERSION", "seldonio/engine:0.4.0"),
ImagePullPolicy: corev1.PullPolicy(getEnv("ENGINE_CONTAINER_IMAGE_PULL_POLICY", "IfNotPresent")),
Image: GetEnv("ENGINE_CONTAINER_IMAGE_AND_VERSION", "seldonio/engine:0.4.0"),
ImagePullPolicy: corev1.PullPolicy(GetEnv("ENGINE_CONTAINER_IMAGE_PULL_POLICY", "IfNotPresent")),
TerminationMessagePath: "/dev/termination-log",
TerminationMessagePolicy: corev1.TerminationMessageReadFile,
VolumeMounts: []corev1.VolumeMount{
Expand Down Expand Up @@ -208,7 +208,7 @@ func createEngineContainer(mlDep *machinelearningv1alpha2.SeldonDeployment, p *m
if _, ok := svcOrchEnvMap["SELDON_LOG_MESSAGES_EXTERNALLY"]; ok {
//this env var is set already so no need to set a default
} else {
c.Env = append(c.Env, corev1.EnvVar{Name: "SELDON_LOG_MESSAGES_EXTERNALLY", Value: getEnv("ENGINE_LOG_MESSAGES_EXTERNALLY", "false")})
c.Env = append(c.Env, corev1.EnvVar{Name: "SELDON_LOG_MESSAGES_EXTERNALLY", Value: GetEnv("ENGINE_LOG_MESSAGES_EXTERNALLY", "false")})
}
return &c, nil
}
Expand Down Expand Up @@ -240,7 +240,7 @@ func createEngineDeployment(mlDep *machinelearningv1alpha2.SeldonDeployment, p *
ObjectMeta: metav1.ObjectMeta{
Labels: map[string]string{machinelearningv1alpha2.Label_seldon_app: seldonId, machinelearningv1alpha2.Label_seldon_id: seldonId, "app": depName},
Annotations: map[string]string{
"prometheus.io/path": getEnv("ENGINE_PROMETHEUS_PATH", "/prometheus"),
"prometheus.io/path": GetEnv("ENGINE_PROMETHEUS_PATH", "/prometheus"),
"prometheus.io/port": strconv.Itoa(engine_http_port),
"prometheus.io/scrape": "true",
},
Expand Down
4 changes: 2 additions & 2 deletions operator/controllers/seldondeployment_explainers.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ func createExplainer(r *SeldonDeploymentReconciler, mlDep *machinelearningv1alph
if grpcPort > 0 {
c.serviceDetails[eSvcName].GrpcEndpoint = eSvcName + "." + eSvc.Namespace + ":" + strconv.Itoa(grpcPort)
}
if getEnv(ENV_ISTIO_ENABLED, "false") == "true" {
if GetEnv(ENV_ISTIO_ENABLED, "false") == "true" {
vsvcs, dstRule := createExplainerIstioResources(eSvcName, p, mlDep, seldonId, getNamespace(mlDep), httpPort, grpcPort)
c.virtualServices = append(c.virtualServices, vsvcs...)
c.destinationRules = append(c.destinationRules, dstRule...)
Expand Down Expand Up @@ -203,7 +203,7 @@ func createExplainerIstioResources(pSvcName string, p *machinelearningv1alpha2.P
vsNameGrpc = strings.TrimSuffix(vsNameGrpc, "-")
}

istio_gateway := getEnv(ENV_ISTIO_GATEWAY, "seldon-gateway")
istio_gateway := GetEnv(ENV_ISTIO_GATEWAY, "seldon-gateway")
httpVsvc := &istio.VirtualService{
ObjectMeta: metav1.ObjectMeta{
Name: vsNameHttp,
Expand Down
4 changes: 4 additions & 0 deletions operator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"k8s.io/apimachinery/pkg/runtime"
clientgoscheme "k8s.io/client-go/kubernetes/scheme"
_ "k8s.io/client-go/plugin/pkg/client/auth/gcp"
istio "knative.dev/pkg/apis/istio/v1alpha3"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/log/zap"
// +kubebuilder:scaffold:imports
Expand All @@ -43,6 +44,9 @@ func init() {
_ = appsv1.AddToScheme(scheme)
_ = corev1.AddToScheme(scheme)
_ = machinelearningv1alpha2.AddToScheme(scheme)
if controllers.GetEnv(controllers.ENV_ISTIO_ENABLED, "false") == "true" {
istio.AddToScheme(scheme)
}
// +kubebuilder:scaffold:scheme
}

Expand Down