mirror of
https://github.com/kubernetes/node-problem-detector.git
synced 2026-08-28 01:47:20 +00:00
Get node name from the downward api.
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
all: push
|
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
|
TAG = v0.2
|
||||||
|
|
||||||
PROJ = google_containers
|
PROJ = google_containers
|
||||||
|
|||||||
@@ -73,14 +73,10 @@ spec:
|
|||||||
securityContext:
|
securityContext:
|
||||||
privileged: true
|
privileged: true
|
||||||
env:
|
env:
|
||||||
- name: POD_NAME
|
- name: NODE_NAME
|
||||||
valueFrom:
|
valueFrom:
|
||||||
fieldRef:
|
fieldRef:
|
||||||
fieldPath: metadata.name
|
fieldPath: spec.nodeName
|
||||||
- name: POD_NAMESPACE
|
|
||||||
valueFrom:
|
|
||||||
fieldRef:
|
|
||||||
fieldPath: metadata.namespace
|
|
||||||
volumeMounts:
|
volumeMounts:
|
||||||
- name: log
|
- name: log
|
||||||
mountPath: /log
|
mountPath: /log
|
||||||
|
|||||||
@@ -18,14 +18,10 @@ spec:
|
|||||||
securityContext:
|
securityContext:
|
||||||
privileged: true
|
privileged: true
|
||||||
env:
|
env:
|
||||||
- name: POD_NAME
|
- name: NODE_NAME
|
||||||
valueFrom:
|
valueFrom:
|
||||||
fieldRef:
|
fieldRef:
|
||||||
fieldPath: metadata.name
|
fieldPath: spec.nodeName
|
||||||
- name: POD_NAMESPACE
|
|
||||||
valueFrom:
|
|
||||||
fieldRef:
|
|
||||||
fieldPath: metadata.namespace
|
|
||||||
volumeMounts:
|
volumeMounts:
|
||||||
- name: log
|
- name: log
|
||||||
mountPath: /log
|
mountPath: /log
|
||||||
|
|||||||
@@ -57,15 +57,23 @@ func NewClientOrDie() Client {
|
|||||||
}
|
}
|
||||||
// TODO(random-liu): Set QPS Limit
|
// TODO(random-liu): Set QPS Limit
|
||||||
c.client = client.NewOrDie(cfg)
|
c.client = client.NewOrDie(cfg)
|
||||||
// Get node name from the current pod.
|
// Get node name from environment variable NODE_NAME
|
||||||
pod, err := c.client.Pods(os.Getenv("POD_NAMESPACE")).Get(os.Getenv("POD_NAME"))
|
// By default, assume that the NODE_NAME env should have been set with
|
||||||
if err != nil {
|
// downward api. We prefer it because sometimes the hostname returned
|
||||||
panic(err)
|
// 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.nodeRef = getNodeRef(c.nodeName)
|
||||||
c.recorders = make(map[string]record.EventRecorder)
|
c.recorders = make(map[string]record.EventRecorder)
|
||||||
return c
|
return c
|
||||||
|
|||||||
Reference in New Issue
Block a user