Merge pull request #30 from Random-Liu/get-node-name-from-downward-api

NPD: Get node name from the downward api.
This commit is contained in:
Dawn Chen
2016-08-23 16:57:26 -07:00
committed by GitHub
4 changed files with 21 additions and 21 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
all: push
# See pod.yaml for the version currently running-- bump this ahead before rebuilding!
# See node-problem-detector.yaml for the version currently running-- bump this ahead before rebuilding!
TAG = v0.2
PROJ = google_containers
+2 -6
View File
@@ -73,14 +73,10 @@ spec:
securityContext:
privileged: true
env:
- name: POD_NAME
- name: NODE_NAME
valueFrom:
fieldRef:
fieldPath: metadata.name
- name: POD_NAMESPACE
valueFrom:
fieldRef:
fieldPath: metadata.namespace
fieldPath: spec.nodeName
volumeMounts:
- name: log
mountPath: /log
+2 -6
View File
@@ -18,14 +18,10 @@ spec:
securityContext:
privileged: true
env:
- name: POD_NAME
- name: NODE_NAME
valueFrom:
fieldRef:
fieldPath: metadata.name
- name: POD_NAMESPACE
valueFrom:
fieldRef:
fieldPath: metadata.namespace
fieldPath: spec.nodeName
volumeMounts:
- name: log
mountPath: /log
+16 -8
View File
@@ -57,15 +57,23 @@ func NewClientOrDie() Client {
}
// TODO(random-liu): Set QPS Limit
c.client = client.NewOrDie(cfg)
// Get node name from the current pod.
pod, err := c.client.Pods(os.Getenv("POD_NAMESPACE")).Get(os.Getenv("POD_NAME"))
if err != nil {
panic(err)
// Get node name from environment variable NODE_NAME
// By default, assume that the NODE_NAME env should have been set with
// downward api. We prefer it because sometimes the hostname returned
// by os.Hostname is not right because:
// 1. User may override the hostname.
// 2. For some cloud providers, os.Hostname is different from the real hostname.
c.nodeName = os.Getenv("NODE_NAME")
if c.nodeName == "" {
// For backward compatibility. If the env is not set, get the hostname
// from os.Hostname(). This may not work for all configurations and
// environments.
var err error
c.nodeName, err = os.Hostname()
if err != nil {
panic("empty node name")
}
}
if pod.Spec.NodeName == "" {
panic("empty node name")
}
c.nodeName = pod.Spec.NodeName
c.nodeRef = getNodeRef(c.nodeName)
c.recorders = make(map[string]record.EventRecorder)
return c