mirror of
https://github.com/kubernetes/node-problem-detector.git
synced 2026-08-19 04:06:24 +00:00
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:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user