Skip to content

Commit

Permalink
Deprecate MY_POD_NAME and use default namespace
Browse files Browse the repository at this point in the history
  • Loading branch information
ScorpioCPH committed Feb 2, 2018
1 parent 8caa0c9 commit 9f993a8
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 18 deletions.
5 changes: 3 additions & 2 deletions cmd/tf_operator/app/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,10 @@ var (
)

func Run(opt *options.ServerOption) error {
namespace := os.Getenv("MY_POD_NAMESPACE")
namespace := os.Getenv(util.EnvKubeflowNamespace)
if len(namespace) == 0 {
glog.Fatalf("must set env MY_POD_NAMESPACE")
glog.Infof("EnvKubeflowNamespace not set, use default namespace")
namespace = metav1.NamespaceDefault
}

glog.Infof("tf_operator Version: %v", version.Version)
Expand Down
7 changes: 2 additions & 5 deletions developer_guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -136,13 +136,10 @@ a K8s cluster. Set your environment:

```sh
export KUBECONFIG=$(echo ~/.kube/config)
export MY_POD_NAMESPACE=default
export MY_POD_NAME=my-pod
export KUBEFLOW_NAMESPACE=$(your_namespace)
```

* MY_POD_NAMESPACE is used because the CRD is namespace scoped and we use the namespace of the controller to
set the corresponding namespace for the resource.
* TODO(jlewi): Do we still need to set MY_POD_NAME? Why?
* KUBEFLOW_NAMESPACE is used when deployed on Kubernetes, we use this variable to create other resources (e.g. the resource lock) internal in the same namespace. It is optional, use `default` namespace if not set.

Now we are ready to run operator locally:

Expand Down
9 changes: 7 additions & 2 deletions pkg/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@ import (
"math/rand"
"time"

log "github.com/golang/glog"
"github.com/golang/glog"
)

const (
// Environment variable for namespace when deployed on kubernetes
EnvKubeflowNamespace = "KUBEFLOW_NAMESPACE"
)

// Pformat returns a pretty format output of any value that can be marshalled to JSON.
Expand All @@ -17,7 +22,7 @@ func Pformat(value interface{}) string {
}
valueJSON, err := json.MarshalIndent(value, "", " ")
if err != nil {
log.Warningf("Couldn't pretty format %v, error: %v", value, err)
glog.Warningf("Couldn't pretty format %v, error: %v", value, err)
return fmt.Sprintf("%v", value)
}
return string(valueJSON)
Expand Down
9 changes: 0 additions & 9 deletions tf-job-operator-chart/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,6 @@ spec:
{{- end }}
- -alsologtostderr
- -v=1
env:
- name: MY_POD_NAMESPACE
valueFrom:
fieldRef:
fieldPath: metadata.namespace
- name: MY_POD_NAME
valueFrom:
fieldRef:
fieldPath: metadata.name
{{- if .Values.config.configmap }}
volumeMounts:
- name: config-volume
Expand Down

0 comments on commit 9f993a8

Please sign in to comment.