Revert "Allow nodename to be != hostname, use AWS instance ID on AWS"

This commit is contained in:
Satnam Singh
2015-06-18 11:27:55 -07:00
parent fb07b34cb8
commit e4f5529a2d
17 changed files with 113 additions and 166 deletions

View File

@@ -26,8 +26,8 @@ import (
)
// NewSourceApiserver creates a config source that watches and pulls from the apiserver.
func NewSourceApiserver(c *client.Client, nodeName string, updates chan<- interface{}) {
lw := cache.NewListWatchFromClient(c, "pods", api.NamespaceAll, fields.OneTermEqualSelector(client.PodHost, nodeName))
func NewSourceApiserver(c *client.Client, hostname string, updates chan<- interface{}) {
lw := cache.NewListWatchFromClient(c, "pods", api.NamespaceAll, fields.OneTermEqualSelector(client.PodHost, hostname))
newSourceApiserverFromLW(lw, updates)
}

View File

@@ -33,16 +33,16 @@ import (
"github.com/golang/glog"
)
// Generate a pod name that is unique among nodes by appending the nodeName.
func generatePodName(name, nodeName string) string {
return fmt.Sprintf("%s-%s", name, nodeName)
// Generate a pod name that is unique among nodes by appending the hostname.
func generatePodName(name, hostname string) string {
return fmt.Sprintf("%s-%s", name, hostname)
}
func applyDefaults(pod *api.Pod, source string, isFile bool, nodeName string) error {
func applyDefaults(pod *api.Pod, source string, isFile bool, hostname string) error {
if len(pod.UID) == 0 {
hasher := md5.New()
if isFile {
fmt.Fprintf(hasher, "host:%s", nodeName)
fmt.Fprintf(hasher, "host:%s", hostname)
fmt.Fprintf(hasher, "file:%s", source)
} else {
fmt.Fprintf(hasher, "url:%s", source)
@@ -57,7 +57,7 @@ func applyDefaults(pod *api.Pod, source string, isFile bool, nodeName string) er
if len(pod.Name) == 0 {
pod.Name = string(pod.UID)
}
pod.Name = generatePodName(pod.Name, nodeName)
pod.Name = generatePodName(pod.Name, hostname)
glog.V(5).Infof("Generated Name %q for UID %q from URL %s", pod.Name, pod.UID, source)
if pod.Namespace == "" {
@@ -66,7 +66,7 @@ func applyDefaults(pod *api.Pod, source string, isFile bool, nodeName string) er
glog.V(5).Infof("Using namespace %q for pod %q from %s", pod.Namespace, pod.Name, source)
// Set the Host field to indicate this pod is scheduled on the current node.
pod.Spec.NodeName = nodeName
pod.Spec.NodeName = hostname
pod.ObjectMeta.SelfLink = getSelfLink(pod.Name, pod.Namespace)
return nil

View File

@@ -34,14 +34,14 @@ import (
type sourceFile struct {
path string
nodeName string
hostname string
updates chan<- interface{}
}
func NewSourceFile(path string, nodeName string, period time.Duration, updates chan<- interface{}) {
func NewSourceFile(path string, hostname string, period time.Duration, updates chan<- interface{}) {
config := &sourceFile{
path: path,
nodeName: nodeName,
hostname: hostname,
updates: updates,
}
glog.V(1).Infof("Watching path %q", path)
@@ -55,7 +55,7 @@ func (s *sourceFile) run() {
}
func (s *sourceFile) applyDefaults(pod *api.Pod, source string) error {
return applyDefaults(pod, source, true, s.nodeName)
return applyDefaults(pod, source, true, s.hostname)
}
func (s *sourceFile) extractFromPath() error {

View File

@@ -33,15 +33,15 @@ import (
type sourceURL struct {
url string
nodeName string
hostname string
updates chan<- interface{}
data []byte
}
func NewSourceURL(url, nodeName string, period time.Duration, updates chan<- interface{}) {
func NewSourceURL(url, hostname string, period time.Duration, updates chan<- interface{}) {
config := &sourceURL{
url: url,
nodeName: nodeName,
hostname: hostname,
updates: updates,
data: nil,
}
@@ -56,7 +56,7 @@ func (s *sourceURL) run() {
}
func (s *sourceURL) applyDefaults(pod *api.Pod) error {
return applyDefaults(pod, s.url, false, s.nodeName)
return applyDefaults(pod, s.url, false, s.hostname)
}
func (s *sourceURL) extractFromURL() error {

View File

@@ -114,7 +114,6 @@ func waitUntilRuntimeIsUp(cr kubecontainer.Runtime, timeout time.Duration) error
// New creates a new Kubelet for use in main
func NewMainKubelet(
hostname string,
nodeName string,
dockerClient dockertools.DockerInterface,
kubeClient client.Interface,
rootDirectory string,
@@ -180,7 +179,7 @@ func NewMainKubelet(
if kubeClient != nil {
// TODO: cache.NewListWatchFromClient is limited as it takes a client implementation rather
// than an interface. There is no way to construct a list+watcher using resource name.
fieldSelector := fields.Set{client.ObjectNameField: nodeName}.AsSelector()
fieldSelector := fields.Set{client.ObjectNameField: hostname}.AsSelector()
listWatch := &cache.ListWatch{
ListFunc: func() (runtime.Object, error) {
return kubeClient.Nodes().List(labels.Everything(), fieldSelector)
@@ -198,8 +197,8 @@ func NewMainKubelet(
// TODO: what is namespace for node?
nodeRef := &api.ObjectReference{
Kind: "Node",
Name: nodeName,
UID: types.UID(nodeName),
Name: hostname,
UID: types.UID(hostname),
Namespace: "",
}
@@ -225,7 +224,6 @@ func NewMainKubelet(
klet := &Kubelet{
hostname: hostname,
nodeName: nodeName,
dockerClient: dockerClient,
kubeClient: kubeClient,
rootDirectory: rootDirectory,
@@ -364,7 +362,6 @@ type nodeLister interface {
// Kubelet is the main kubelet implementation.
type Kubelet struct {
hostname string
nodeName string
dockerClient dockertools.DockerInterface
runtimeCache kubecontainer.RuntimeCache
kubeClient client.Interface
@@ -640,13 +637,13 @@ func (kl *Kubelet) GetNode() (*api.Node, error) {
if err != nil {
return nil, errors.New("cannot list nodes")
}
nodeName := kl.nodeName
host := kl.GetHostname()
for _, n := range l.Items {
if n.Name == nodeName {
if n.Name == host {
return &n, nil
}
}
return nil, fmt.Errorf("node %v not found", nodeName)
return nil, fmt.Errorf("node %v not found", host)
}
// Starts garbage collection theads.
@@ -712,7 +709,7 @@ func (kl *Kubelet) Run(updates <-chan PodUpdate) {
func (kl *Kubelet) initialNodeStatus() (*api.Node, error) {
node := &api.Node{
ObjectMeta: api.ObjectMeta{
Name: kl.nodeName,
Name: kl.hostname,
Labels: map[string]string{"kubernetes.io/hostname": kl.hostname},
},
}
@@ -721,20 +718,18 @@ func (kl *Kubelet) initialNodeStatus() (*api.Node, error) {
if !ok {
return nil, fmt.Errorf("failed to get instances from cloud provider")
}
// TODO(roberthbailey): Can we do this without having credentials to talk
// to the cloud provider?
// TODO: ExternalID is deprecated, we'll have to drop this code
externalID, err := instances.ExternalID(kl.nodeName)
externalID, err := instances.ExternalID(kl.hostname)
if err != nil {
return nil, fmt.Errorf("failed to get external ID from cloud provider: %v", err)
}
node.Spec.ExternalID = externalID
// TODO: We can't assume that the node has credentials to talk to the
// cloudprovider from arbitrary nodes. At most, we should talk to a
// local metadata server here.
node.Spec.ProviderID, err = cloudprovider.GetInstanceProviderID(kl.cloud, kl.nodeName)
node.Spec.ProviderID, err = cloudprovider.GetInstanceProviderID(kl.cloud, kl.hostname)
if err != nil {
return nil, err
}
@@ -765,13 +760,13 @@ func (kl *Kubelet) registerWithApiserver() {
glog.V(2).Infof("Attempting to register node %s", node.Name)
if _, err := kl.kubeClient.Nodes().Create(node); err != nil {
if apierrors.IsAlreadyExists(err) {
currentNode, err := kl.kubeClient.Nodes().Get(kl.nodeName)
currentNode, err := kl.kubeClient.Nodes().Get(kl.hostname)
if err != nil {
glog.Errorf("error getting node %q: %v", kl.nodeName, err)
glog.Errorf("error getting node %q: %v", kl.hostname, err)
continue
}
if currentNode == nil {
glog.Errorf("no node instance returned for %q", kl.nodeName)
glog.Errorf("no node instance returned for %q", kl.hostname)
continue
}
if currentNode.Spec.ExternalID == node.Spec.ExternalID {
@@ -1835,10 +1830,10 @@ func (kl *Kubelet) updateNodeStatus() error {
}
func (kl *Kubelet) recordNodeStatusEvent(event string) {
glog.V(2).Infof("Recording %s event message for node %s", event, kl.nodeName)
glog.V(2).Infof("Recording %s event message for node %s", event, kl.hostname)
// TODO: This requires a transaction, either both node status is updated
// and event is recorded or neither should happen, see issue #6055.
kl.recorder.Eventf(kl.nodeRef, event, "Node %s status is now: %s", kl.nodeName, event)
kl.recorder.Eventf(kl.nodeRef, event, "Node %s status is now: %s", kl.hostname, event)
}
// Maintains Node.Spec.Unschedulable value from previous run of tryUpdateNodeStatus()
@@ -1855,8 +1850,7 @@ func (kl *Kubelet) setNodeStatus(node *api.Node) error {
}
// TODO(roberthbailey): Can we do this without having credentials to talk
// to the cloud provider?
// TODO(justinsb): We can if CurrentNodeName() was actually CurrentNode() and returned an interface
nodeAddresses, err := instances.NodeAddresses(kl.nodeName)
nodeAddresses, err := instances.NodeAddresses(kl.hostname)
if err != nil {
return fmt.Errorf("failed to get node address from cloud provider: %v", err)
}
@@ -1910,7 +1904,7 @@ func (kl *Kubelet) setNodeStatus(node *api.Node) error {
// TODO: This requires a transaction, either both node status is updated
// and event is recorded or neither should happen, see issue #6055.
kl.recorder.Eventf(kl.nodeRef, "rebooted",
"Node %s has been rebooted, boot id: %s", kl.nodeName, info.BootID)
"Node %s has been rebooted, boot id: %s", kl.hostname, info.BootID)
}
node.Status.NodeInfo.BootID = info.BootID
}
@@ -1999,12 +1993,12 @@ func (kl *Kubelet) setNodeStatus(node *api.Node) error {
// tryUpdateNodeStatus tries to update node status to master. If ReconcileCBR0
// is set, this function will also confirm that cbr0 is configured correctly.
func (kl *Kubelet) tryUpdateNodeStatus() error {
node, err := kl.kubeClient.Nodes().Get(kl.nodeName)
node, err := kl.kubeClient.Nodes().Get(kl.hostname)
if err != nil {
return fmt.Errorf("error getting node %q: %v", kl.nodeName, err)
return fmt.Errorf("error getting node %q: %v", kl.hostname, err)
}
if node == nil {
return fmt.Errorf("no node instance returned for %q", kl.nodeName)
return fmt.Errorf("no node instance returned for %q", kl.hostname)
}
if err := kl.setNodeStatus(node); err != nil {
return err