add labels for notebook so that gcp credentials will be injected by webhook (kubeflow/kubeflow#2853)

* add labels for gcp cred

* kfctl set flag

* review comment

* review comment
This commit is contained in:
Lun-Kai Hsu 2019-03-30 20:36:33 -07:00 committed by Kubernetes Prow Robot
parent dc69b63667
commit 9f70ca7f10
1 changed files with 19 additions and 0 deletions

View File

@ -18,6 +18,7 @@ package notebook
import (
"context"
"os"
"strings"
v1alpha1 "github.com/kubeflow/kubeflow/components/notebook-controller/pkg/apis/notebook/v1alpha1"
@ -283,6 +284,24 @@ func generateStatefulSet(instance *v1alpha1.Notebook) *appsv1.StatefulSet {
},
},
}
// Inject GCP credentials
if labels := os.Getenv("POD_LABELS"); labels != "" {
// labels should be comma separated labels, e.g. "k1=v1,k2=v2"
l := &ss.Spec.Template.ObjectMeta.Labels
labelList := strings.Split(labels, ",")
for _, label := range labelList {
// label is something like k1=v1
s := strings.Split(label, "=")
if len(s) != 2 {
log.Info("Invalid env var POD_LABELS, skip..")
continue
}
// s[0] = k1, s[1] = v1
(*l)[s[0]] = s[1]
}
}
podSpec := &ss.Spec.Template.Spec
container := &podSpec.Containers[0]
if container.WorkingDir == "" {