Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
790ca234
Commit
790ca234
authored
Jun 18, 2015
by
Satnam Singh
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #9728 from justinsb/aws_id_as_name
Allow nodename to be != hostname, use AWS instance ID on AWS
parents
1ba90909
77e1bd3f
Hide whitespace changes
Inline
Side-by-side
Showing
17 changed files
with
166 additions
and
113 deletions
+166
-113
server.go
cmd/kubelet/app/server.go
+28
-4
service.go
contrib/mesos/pkg/executor/service/service.go
+3
-0
aws.go
pkg/cloudprovider/aws/aws.go
+41
-59
aws_test.go
pkg/cloudprovider/aws/aws_test.go
+14
-14
cloud.go
pkg/cloudprovider/cloud.go
+3
-0
fake.go
pkg/cloudprovider/fake/fake.go
+5
-0
gce.go
pkg/cloudprovider/gce/gce.go
+5
-0
mesos.go
pkg/cloudprovider/mesos/mesos.go
+5
-0
openstack.go
pkg/cloudprovider/openstack/openstack.go
+5
-0
ovirt.go
pkg/cloudprovider/ovirt/ovirt.go
+5
-0
rackspace.go
pkg/cloudprovider/rackspace/rackspace.go
+5
-0
vagrant.go
pkg/cloudprovider/vagrant/vagrant.go
+5
-0
apiserver.go
pkg/kubelet/config/apiserver.go
+2
-2
common.go
pkg/kubelet/config/common.go
+7
-7
file.go
pkg/kubelet/config/file.go
+4
-4
http.go
pkg/kubelet/config/http.go
+4
-4
kubelet.go
pkg/kubelet/kubelet.go
+25
-19
No files found.
cmd/kubelet/app/server.go
View file @
790ca234
...
@@ -565,8 +565,30 @@ func SimpleKubelet(client *client.Client,
...
@@ -565,8 +565,30 @@ func SimpleKubelet(client *client.Client,
// Eventually, #2 will be replaced with instances of #3
// Eventually, #2 will be replaced with instances of #3
func
RunKubelet
(
kcfg
*
KubeletConfig
,
builder
KubeletBuilder
)
error
{
func
RunKubelet
(
kcfg
*
KubeletConfig
,
builder
KubeletBuilder
)
error
{
kcfg
.
Hostname
=
nodeutil
.
GetHostname
(
kcfg
.
HostnameOverride
)
kcfg
.
Hostname
=
nodeutil
.
GetHostname
(
kcfg
.
HostnameOverride
)
if
kcfg
.
NodeName
==
""
{
// Query the cloud provider for our node name, default to Hostname
nodeName
:=
kcfg
.
Hostname
if
kcfg
.
Cloud
!=
nil
{
var
err
error
instances
,
ok
:=
kcfg
.
Cloud
.
Instances
()
if
!
ok
{
return
fmt
.
Errorf
(
"failed to get instances from cloud provider"
)
}
nodeName
,
err
=
instances
.
CurrentNodeName
(
kcfg
.
Hostname
)
if
err
!=
nil
{
return
fmt
.
Errorf
(
"error fetching current instance name from cloud provider: %v"
,
err
)
}
glog
.
V
(
2
)
.
Infof
(
"cloud provider determined current node name to be %s"
,
nodeName
)
}
kcfg
.
NodeName
=
nodeName
}
eventBroadcaster
:=
record
.
NewBroadcaster
()
eventBroadcaster
:=
record
.
NewBroadcaster
()
kcfg
.
Recorder
=
eventBroadcaster
.
NewRecorder
(
api
.
EventSource
{
Component
:
"kubelet"
,
Host
:
kcfg
.
Hostn
ame
})
kcfg
.
Recorder
=
eventBroadcaster
.
NewRecorder
(
api
.
EventSource
{
Component
:
"kubelet"
,
Host
:
kcfg
.
NodeN
ame
})
eventBroadcaster
.
StartLogging
(
glog
.
Infof
)
eventBroadcaster
.
StartLogging
(
glog
.
Infof
)
if
kcfg
.
KubeClient
!=
nil
{
if
kcfg
.
KubeClient
!=
nil
{
glog
.
V
(
4
)
.
Infof
(
"Sending events to api server."
)
glog
.
V
(
4
)
.
Infof
(
"Sending events to api server."
)
...
@@ -625,17 +647,17 @@ func makePodSourceConfig(kc *KubeletConfig) *config.PodConfig {
...
@@ -625,17 +647,17 @@ func makePodSourceConfig(kc *KubeletConfig) *config.PodConfig {
// define file config source
// define file config source
if
kc
.
ConfigFile
!=
""
{
if
kc
.
ConfigFile
!=
""
{
glog
.
Infof
(
"Adding manifest file: %v"
,
kc
.
ConfigFile
)
glog
.
Infof
(
"Adding manifest file: %v"
,
kc
.
ConfigFile
)
config
.
NewSourceFile
(
kc
.
ConfigFile
,
kc
.
Hostn
ame
,
kc
.
FileCheckFrequency
,
cfg
.
Channel
(
kubelet
.
FileSource
))
config
.
NewSourceFile
(
kc
.
ConfigFile
,
kc
.
NodeN
ame
,
kc
.
FileCheckFrequency
,
cfg
.
Channel
(
kubelet
.
FileSource
))
}
}
// define url config source
// define url config source
if
kc
.
ManifestURL
!=
""
{
if
kc
.
ManifestURL
!=
""
{
glog
.
Infof
(
"Adding manifest url: %v"
,
kc
.
ManifestURL
)
glog
.
Infof
(
"Adding manifest url: %v"
,
kc
.
ManifestURL
)
config
.
NewSourceURL
(
kc
.
ManifestURL
,
kc
.
Hostn
ame
,
kc
.
HTTPCheckFrequency
,
cfg
.
Channel
(
kubelet
.
HTTPSource
))
config
.
NewSourceURL
(
kc
.
ManifestURL
,
kc
.
NodeN
ame
,
kc
.
HTTPCheckFrequency
,
cfg
.
Channel
(
kubelet
.
HTTPSource
))
}
}
if
kc
.
KubeClient
!=
nil
{
if
kc
.
KubeClient
!=
nil
{
glog
.
Infof
(
"Watching apiserver"
)
glog
.
Infof
(
"Watching apiserver"
)
config
.
NewSourceApiserver
(
kc
.
KubeClient
,
kc
.
Hostn
ame
,
cfg
.
Channel
(
kubelet
.
ApiserverSource
))
config
.
NewSourceApiserver
(
kc
.
KubeClient
,
kc
.
NodeN
ame
,
cfg
.
Channel
(
kubelet
.
ApiserverSource
))
}
}
return
cfg
return
cfg
}
}
...
@@ -656,6 +678,7 @@ type KubeletConfig struct {
...
@@ -656,6 +678,7 @@ type KubeletConfig struct {
FileCheckFrequency
time
.
Duration
FileCheckFrequency
time
.
Duration
HTTPCheckFrequency
time
.
Duration
HTTPCheckFrequency
time
.
Duration
Hostname
string
Hostname
string
NodeName
string
PodInfraContainerImage
string
PodInfraContainerImage
string
SyncFrequency
time
.
Duration
SyncFrequency
time
.
Duration
RegistryPullQPS
float64
RegistryPullQPS
float64
...
@@ -715,6 +738,7 @@ func createAndInitKubelet(kc *KubeletConfig) (k KubeletBootstrap, pc *config.Pod
...
@@ -715,6 +738,7 @@ func createAndInitKubelet(kc *KubeletConfig) (k KubeletBootstrap, pc *config.Pod
pc
=
makePodSourceConfig
(
kc
)
pc
=
makePodSourceConfig
(
kc
)
k
,
err
=
kubelet
.
NewMainKubelet
(
k
,
err
=
kubelet
.
NewMainKubelet
(
kc
.
Hostname
,
kc
.
Hostname
,
kc
.
NodeName
,
kc
.
DockerClient
,
kc
.
DockerClient
,
kubeClient
,
kubeClient
,
kc
.
RootDirectory
,
kc
.
RootDirectory
,
...
...
contrib/mesos/pkg/executor/service/service.go
View file @
790ca234
...
@@ -259,6 +259,8 @@ func (s *KubeletExecutorServer) Run(hks hyperkube.Interface, _ []string) error {
...
@@ -259,6 +259,8 @@ func (s *KubeletExecutorServer) Run(hks hyperkube.Interface, _ []string) error {
DockerExecHandler
:
dockerExecHandler
,
DockerExecHandler
:
dockerExecHandler
,
}
}
kcfg
.
NodeName
=
kcfg
.
Hostname
err
=
app
.
RunKubelet
(
&
kcfg
,
app
.
KubeletBuilder
(
func
(
kc
*
app
.
KubeletConfig
)
(
app
.
KubeletBootstrap
,
*
kconfig
.
PodConfig
,
error
)
{
err
=
app
.
RunKubelet
(
&
kcfg
,
app
.
KubeletBuilder
(
func
(
kc
*
app
.
KubeletConfig
)
(
app
.
KubeletBootstrap
,
*
kconfig
.
PodConfig
,
error
)
{
return
s
.
createAndInitKubelet
(
kc
,
hks
,
clientConfig
,
shutdownCloser
)
return
s
.
createAndInitKubelet
(
kc
,
hks
,
clientConfig
,
shutdownCloser
)
}))
}))
...
@@ -319,6 +321,7 @@ func (ks *KubeletExecutorServer) createAndInitKubelet(
...
@@ -319,6 +321,7 @@ func (ks *KubeletExecutorServer) createAndInitKubelet(
klet
,
err
:=
kubelet
.
NewMainKubelet
(
klet
,
err
:=
kubelet
.
NewMainKubelet
(
kc
.
Hostname
,
kc
.
Hostname
,
kc
.
NodeName
,
kc
.
DockerClient
,
kc
.
DockerClient
,
kubeClient
,
kubeClient
,
kc
.
RootDirectory
,
kc
.
RootDirectory
,
...
...
pkg/cloudprovider/aws/aws.go
View file @
790ca234
...
@@ -234,6 +234,14 @@ func (self *AWSCloud) AddSSHKeyToAllInstances(user string, keyData []byte) error
...
@@ -234,6 +234,14 @@ func (self *AWSCloud) AddSSHKeyToAllInstances(user string, keyData []byte) error
return
errors
.
New
(
"unimplemented"
)
return
errors
.
New
(
"unimplemented"
)
}
}
func
(
a
*
AWSCloud
)
CurrentNodeName
(
hostname
string
)
(
string
,
error
)
{
selfInstance
,
err
:=
a
.
getSelfAWSInstance
()
if
err
!=
nil
{
return
""
,
err
}
return
selfInstance
.
awsID
,
nil
}
// Implementation of EC2.Instances
// Implementation of EC2.Instances
func
(
self
*
awsSdkEC2
)
DescribeInstances
(
request
*
ec2
.
DescribeInstancesInput
)
([]
*
ec2
.
Instance
,
error
)
{
func
(
self
*
awsSdkEC2
)
DescribeInstances
(
request
*
ec2
.
DescribeInstancesInput
)
([]
*
ec2
.
Instance
,
error
)
{
// Instances are paged
// Instances are paged
...
@@ -547,7 +555,7 @@ func (aws *AWSCloud) Routes() (cloudprovider.Routes, bool) {
...
@@ -547,7 +555,7 @@ func (aws *AWSCloud) Routes() (cloudprovider.Routes, bool) {
// NodeAddresses is an implementation of Instances.NodeAddresses.
// NodeAddresses is an implementation of Instances.NodeAddresses.
func
(
aws
*
AWSCloud
)
NodeAddresses
(
name
string
)
([]
api
.
NodeAddress
,
error
)
{
func
(
aws
*
AWSCloud
)
NodeAddresses
(
name
string
)
([]
api
.
NodeAddress
,
error
)
{
instance
,
err
:=
aws
.
getInstanceBy
DnsName
(
name
)
instance
,
err
:=
aws
.
getInstanceBy
Id
(
name
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
...
@@ -581,7 +589,8 @@ func (aws *AWSCloud) NodeAddresses(name string) ([]api.NodeAddress, error) {
...
@@ -581,7 +589,8 @@ func (aws *AWSCloud) NodeAddresses(name string) ([]api.NodeAddress, error) {
// ExternalID returns the cloud provider ID of the specified instance (deprecated).
// ExternalID returns the cloud provider ID of the specified instance (deprecated).
func
(
aws
*
AWSCloud
)
ExternalID
(
name
string
)
(
string
,
error
)
{
func
(
aws
*
AWSCloud
)
ExternalID
(
name
string
)
(
string
,
error
)
{
inst
,
err
:=
aws
.
getInstanceByDnsName
(
name
)
// TODO: Do we need to verify it exists, or can we just return name
inst
,
err
:=
aws
.
getInstanceById
(
name
)
if
err
!=
nil
{
if
err
!=
nil
{
return
""
,
err
return
""
,
err
}
}
...
@@ -590,7 +599,8 @@ func (aws *AWSCloud) ExternalID(name string) (string, error) {
...
@@ -590,7 +599,8 @@ func (aws *AWSCloud) ExternalID(name string) (string, error) {
// InstanceID returns the cloud provider ID of the specified instance.
// InstanceID returns the cloud provider ID of the specified instance.
func
(
aws
*
AWSCloud
)
InstanceID
(
name
string
)
(
string
,
error
)
{
func
(
aws
*
AWSCloud
)
InstanceID
(
name
string
)
(
string
,
error
)
{
inst
,
err
:=
aws
.
getInstanceByDnsName
(
name
)
// TODO: Do we need to verify it exists, or can we just construct it knowing our AZ (or via caching?)
inst
,
err
:=
aws
.
getInstanceById
(
name
)
if
err
!=
nil
{
if
err
!=
nil
{
return
""
,
err
return
""
,
err
}
}
...
@@ -599,46 +609,6 @@ func (aws *AWSCloud) InstanceID(name string) (string, error) {
...
@@ -599,46 +609,6 @@ func (aws *AWSCloud) InstanceID(name string) (string, error) {
return
"/"
+
orEmpty
(
inst
.
Placement
.
AvailabilityZone
)
+
"/"
+
orEmpty
(
inst
.
InstanceID
),
nil
return
"/"
+
orEmpty
(
inst
.
Placement
.
AvailabilityZone
)
+
"/"
+
orEmpty
(
inst
.
InstanceID
),
nil
}
}
// Return the instances matching the relevant private dns name.
func
(
s
*
AWSCloud
)
getInstanceByDnsName
(
name
string
)
(
*
ec2
.
Instance
,
error
)
{
filters
:=
[]
*
ec2
.
Filter
{
newEc2Filter
(
"private-dns-name"
,
name
),
}
filters
=
s
.
addFilters
(
filters
)
request
:=
&
ec2
.
DescribeInstancesInput
{
Filters
:
filters
,
}
instances
,
err
:=
s
.
ec2
.
DescribeInstances
(
request
)
if
err
!=
nil
{
return
nil
,
err
}
matchingInstances
:=
[]
*
ec2
.
Instance
{}
for
_
,
instance
:=
range
instances
{
// TODO: Push running logic down into filter?
if
!
isAlive
(
instance
)
{
continue
}
if
orEmpty
(
instance
.
PrivateDNSName
)
!=
name
{
// TODO: Should we warn here? - the filter should have caught this
// (this will happen in the tests if they don't fully mock the EC2 API)
continue
}
matchingInstances
=
append
(
matchingInstances
,
instance
)
}
if
len
(
matchingInstances
)
==
0
{
return
nil
,
fmt
.
Errorf
(
"no instances found for host: %s"
,
name
)
}
if
len
(
matchingInstances
)
>
1
{
return
nil
,
fmt
.
Errorf
(
"multiple instances found for host: %s"
,
name
)
}
return
matchingInstances
[
0
],
nil
}
// Check if the instance is alive (running or pending)
// Check if the instance is alive (running or pending)
// We typically ignore instances that are not alive
// We typically ignore instances that are not alive
func
isAlive
(
instance
*
ec2
.
Instance
)
bool
{
func
isAlive
(
instance
*
ec2
.
Instance
)
bool
{
...
@@ -698,16 +668,9 @@ func (s *AWSCloud) getInstancesByRegex(regex string) ([]string, error) {
...
@@ -698,16 +668,9 @@ func (s *AWSCloud) getInstancesByRegex(regex string) ([]string, error) {
continue
continue
}
}
privateDNSName
:=
orEmpty
(
instance
.
PrivateDNSName
)
if
privateDNSName
==
""
{
glog
.
V
(
2
)
.
Infof
(
"skipping EC2 instance (no PrivateDNSName): %s"
,
orEmpty
(
instance
.
InstanceID
))
continue
}
for
_
,
tag
:=
range
instance
.
Tags
{
for
_
,
tag
:=
range
instance
.
Tags
{
if
orEmpty
(
tag
.
Key
)
==
"Name"
&&
re
.
MatchString
(
orEmpty
(
tag
.
Value
))
{
if
orEmpty
(
tag
.
Key
)
==
"Name"
&&
re
.
MatchString
(
orEmpty
(
tag
.
Value
))
{
matchingInstances
=
append
(
matchingInstances
,
privateDNSName
)
matchingInstances
=
append
(
matchingInstances
,
orEmpty
(
instance
.
InstanceID
)
)
break
break
}
}
}
}
...
@@ -724,7 +687,7 @@ func (aws *AWSCloud) List(filter string) ([]string, error) {
...
@@ -724,7 +687,7 @@ func (aws *AWSCloud) List(filter string) ([]string, error) {
// GetNodeResources implements Instances.GetNodeResources
// GetNodeResources implements Instances.GetNodeResources
func
(
aws
*
AWSCloud
)
GetNodeResources
(
name
string
)
(
*
api
.
NodeResources
,
error
)
{
func
(
aws
*
AWSCloud
)
GetNodeResources
(
name
string
)
(
*
api
.
NodeResources
,
error
)
{
instance
,
err
:=
aws
.
getInstanceBy
DnsName
(
name
)
instance
,
err
:=
aws
.
getInstanceBy
Id
(
name
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
...
@@ -1197,7 +1160,7 @@ func (aws *AWSCloud) getAwsInstance(instanceName string) (*awsInstance, error) {
...
@@ -1197,7 +1160,7 @@ func (aws *AWSCloud) getAwsInstance(instanceName string) (*awsInstance, error) {
return
nil
,
fmt
.
Errorf
(
"error getting self-instance: %v"
,
err
)
return
nil
,
fmt
.
Errorf
(
"error getting self-instance: %v"
,
err
)
}
}
}
else
{
}
else
{
instance
,
err
:=
aws
.
getInstanceBy
DnsName
(
instanceName
)
instance
,
err
:=
aws
.
getInstanceBy
Id
(
instanceName
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"error finding instance: %v"
,
err
)
return
nil
,
fmt
.
Errorf
(
"error finding instance: %v"
,
err
)
}
}
...
@@ -1664,7 +1627,7 @@ func (s *AWSCloud) CreateTCPLoadBalancer(name, region string, publicIP net.IP, p
...
@@ -1664,7 +1627,7 @@ func (s *AWSCloud) CreateTCPLoadBalancer(name, region string, publicIP net.IP, p
return
nil
,
fmt
.
Errorf
(
"publicIP cannot be specified for AWS ELB"
)
return
nil
,
fmt
.
Errorf
(
"publicIP cannot be specified for AWS ELB"
)
}
}
instances
,
err
:=
s
.
getInstancesBy
DnsName
s
(
hosts
)
instances
,
err
:=
s
.
getInstancesBy
Id
s
(
hosts
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
...
@@ -2076,7 +2039,7 @@ func (s *AWSCloud) EnsureTCPLoadBalancerDeleted(name, region string) error {
...
@@ -2076,7 +2039,7 @@ func (s *AWSCloud) EnsureTCPLoadBalancerDeleted(name, region string) error {
// UpdateTCPLoadBalancer implements TCPLoadBalancer.UpdateTCPLoadBalancer
// UpdateTCPLoadBalancer implements TCPLoadBalancer.UpdateTCPLoadBalancer
func
(
s
*
AWSCloud
)
UpdateTCPLoadBalancer
(
name
,
region
string
,
hosts
[]
string
)
error
{
func
(
s
*
AWSCloud
)
UpdateTCPLoadBalancer
(
name
,
region
string
,
hosts
[]
string
)
error
{
instances
,
err
:=
s
.
getInstancesBy
DnsName
s
(
hosts
)
instances
,
err
:=
s
.
getInstancesBy
Id
s
(
hosts
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
...
@@ -2151,21 +2114,40 @@ func (s *AWSCloud) UpdateTCPLoadBalancer(name, region string, hosts []string) er
...
@@ -2151,21 +2114,40 @@ func (s *AWSCloud) UpdateTCPLoadBalancer(name, region string, hosts []string) er
}
}
// TODO: Make efficient
// TODO: Make efficient
func
(
a
*
AWSCloud
)
getInstancesBy
DnsNames
(
name
s
[]
string
)
([]
*
ec2
.
Instance
,
error
)
{
func
(
a
*
AWSCloud
)
getInstancesBy
Ids
(
id
s
[]
string
)
([]
*
ec2
.
Instance
,
error
)
{
instances
:=
[]
*
ec2
.
Instance
{}
instances
:=
[]
*
ec2
.
Instance
{}
for
_
,
name
:=
range
name
s
{
for
_
,
id
:=
range
id
s
{
instance
,
err
:=
a
.
getInstanceBy
DnsName
(
name
)
instance
,
err
:=
a
.
getInstanceBy
Id
(
id
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
if
instance
==
nil
{
if
instance
==
nil
{
return
nil
,
fmt
.
Errorf
(
"unable to find instance "
+
name
)
return
nil
,
fmt
.
Errorf
(
"unable to find instance "
+
id
)
}
}
instances
=
append
(
instances
,
instance
)
instances
=
append
(
instances
,
instance
)
}
}
return
instances
,
nil
return
instances
,
nil
}
}
// Returns the instance with the specified ID
func
(
a
*
AWSCloud
)
getInstanceById
(
instanceID
string
)
(
*
ec2
.
Instance
,
error
)
{
request
:=
&
ec2
.
DescribeInstancesInput
{
InstanceIDs
:
[]
*
string
{
&
instanceID
},
}
instances
,
err
:=
a
.
ec2
.
DescribeInstances
(
request
)
if
err
!=
nil
{
return
nil
,
err
}
if
len
(
instances
)
==
0
{
return
nil
,
fmt
.
Errorf
(
"no instances found for instance: %s"
,
instanceID
)
}
if
len
(
instances
)
>
1
{
return
nil
,
fmt
.
Errorf
(
"multiple instances found for instance: %s"
,
instanceID
)
}
return
instances
[
0
],
nil
}
// Add additional filters, to match on our tags
// Add additional filters, to match on our tags
// This lets us run multiple k8s clusters in a single EC2 AZ
// This lets us run multiple k8s clusters in a single EC2 AZ
func
(
s
*
AWSCloud
)
addFilters
(
filters
[]
*
ec2
.
Filter
)
[]
*
ec2
.
Filter
{
func
(
s
*
AWSCloud
)
addFilters
(
filters
[]
*
ec2
.
Filter
)
[]
*
ec2
.
Filter
{
...
...
pkg/cloudprovider/aws/aws_test.go
View file @
790ca234
...
@@ -412,7 +412,7 @@ func TestList(t *testing.T) {
...
@@ -412,7 +412,7 @@ func TestList(t *testing.T) {
Value
:
aws
.
String
(
"foo"
),
Value
:
aws
.
String
(
"foo"
),
}
}
instance0
.
Tags
=
[]
*
ec2
.
Tag
{
&
tag0
}
instance0
.
Tags
=
[]
*
ec2
.
Tag
{
&
tag0
}
instance0
.
PrivateDNSName
=
aws
.
String
(
"instance1
"
)
instance0
.
InstanceID
=
aws
.
String
(
"instance0
"
)
state0
:=
ec2
.
InstanceState
{
state0
:=
ec2
.
InstanceState
{
Name
:
aws
.
String
(
"running"
),
Name
:
aws
.
String
(
"running"
),
}
}
...
@@ -424,7 +424,7 @@ func TestList(t *testing.T) {
...
@@ -424,7 +424,7 @@ func TestList(t *testing.T) {
Value
:
aws
.
String
(
"bar"
),
Value
:
aws
.
String
(
"bar"
),
}
}
instance1
.
Tags
=
[]
*
ec2
.
Tag
{
&
tag1
}
instance1
.
Tags
=
[]
*
ec2
.
Tag
{
&
tag1
}
instance1
.
PrivateDNSName
=
aws
.
String
(
"instance2
"
)
instance1
.
InstanceID
=
aws
.
String
(
"instance1
"
)
state1
:=
ec2
.
InstanceState
{
state1
:=
ec2
.
InstanceState
{
Name
:
aws
.
String
(
"running"
),
Name
:
aws
.
String
(
"running"
),
}
}
...
@@ -436,7 +436,7 @@ func TestList(t *testing.T) {
...
@@ -436,7 +436,7 @@ func TestList(t *testing.T) {
Value
:
aws
.
String
(
"baz"
),
Value
:
aws
.
String
(
"baz"
),
}
}
instance2
.
Tags
=
[]
*
ec2
.
Tag
{
&
tag2
}
instance2
.
Tags
=
[]
*
ec2
.
Tag
{
&
tag2
}
instance2
.
PrivateDNSName
=
aws
.
String
(
"instance3
"
)
instance2
.
InstanceID
=
aws
.
String
(
"instance2
"
)
state2
:=
ec2
.
InstanceState
{
state2
:=
ec2
.
InstanceState
{
Name
:
aws
.
String
(
"running"
),
Name
:
aws
.
String
(
"running"
),
}
}
...
@@ -448,7 +448,7 @@ func TestList(t *testing.T) {
...
@@ -448,7 +448,7 @@ func TestList(t *testing.T) {
Value
:
aws
.
String
(
"quux"
),
Value
:
aws
.
String
(
"quux"
),
}
}
instance3
.
Tags
=
[]
*
ec2
.
Tag
{
&
tag3
}
instance3
.
Tags
=
[]
*
ec2
.
Tag
{
&
tag3
}
instance3
.
PrivateDNSName
=
aws
.
String
(
"instance4
"
)
instance3
.
InstanceID
=
aws
.
String
(
"instance3
"
)
state3
:=
ec2
.
InstanceState
{
state3
:=
ec2
.
InstanceState
{
Name
:
aws
.
String
(
"running"
),
Name
:
aws
.
String
(
"running"
),
}
}
...
@@ -462,8 +462,8 @@ func TestList(t *testing.T) {
...
@@ -462,8 +462,8 @@ func TestList(t *testing.T) {
expect
[]
string
expect
[]
string
}{
}{
{
"blahonga"
,
[]
string
{}},
{
"blahonga"
,
[]
string
{}},
{
"quux"
,
[]
string
{
"instance
4
"
}},
{
"quux"
,
[]
string
{
"instance
3
"
}},
{
"a"
,
[]
string
{
"instance
2"
,
"instance3
"
}},
{
"a"
,
[]
string
{
"instance
1"
,
"instance2
"
}},
}
}
for
_
,
item
:=
range
table
{
for
_
,
item
:=
range
table
{
...
@@ -493,7 +493,7 @@ func TestNodeAddresses(t *testing.T) {
...
@@ -493,7 +493,7 @@ func TestNodeAddresses(t *testing.T) {
var
instance1
ec2
.
Instance
var
instance1
ec2
.
Instance
//0
//0
instance0
.
PrivateDNSName
=
aws
.
String
(
"instance1
"
)
instance0
.
InstanceID
=
aws
.
String
(
"instance-same
"
)
instance0
.
PrivateIPAddress
=
aws
.
String
(
"192.168.0.1"
)
instance0
.
PrivateIPAddress
=
aws
.
String
(
"192.168.0.1"
)
instance0
.
PublicIPAddress
=
aws
.
String
(
"1.2.3.4"
)
instance0
.
PublicIPAddress
=
aws
.
String
(
"1.2.3.4"
)
instance0
.
InstanceType
=
aws
.
String
(
"c3.large"
)
instance0
.
InstanceType
=
aws
.
String
(
"c3.large"
)
...
@@ -503,7 +503,7 @@ func TestNodeAddresses(t *testing.T) {
...
@@ -503,7 +503,7 @@ func TestNodeAddresses(t *testing.T) {
instance0
.
State
=
&
state0
instance0
.
State
=
&
state0
//1
//1
instance1
.
PrivateDNSName
=
aws
.
String
(
"instance1
"
)
instance1
.
InstanceID
=
aws
.
String
(
"instance-same
"
)
instance1
.
PrivateIPAddress
=
aws
.
String
(
"192.168.0.2"
)
instance1
.
PrivateIPAddress
=
aws
.
String
(
"192.168.0.2"
)
instance1
.
InstanceType
=
aws
.
String
(
"c3.large"
)
instance1
.
InstanceType
=
aws
.
String
(
"c3.large"
)
state1
:=
ec2
.
InstanceState
{
state1
:=
ec2
.
InstanceState
{
...
@@ -514,19 +514,19 @@ func TestNodeAddresses(t *testing.T) {
...
@@ -514,19 +514,19 @@ func TestNodeAddresses(t *testing.T) {
instances
:=
[]
*
ec2
.
Instance
{
&
instance0
,
&
instance1
}
instances
:=
[]
*
ec2
.
Instance
{
&
instance0
,
&
instance1
}
aws1
:=
mockInstancesResp
([]
*
ec2
.
Instance
{})
aws1
:=
mockInstancesResp
([]
*
ec2
.
Instance
{})
_
,
err1
:=
aws1
.
NodeAddresses
(
"instance"
)
_
,
err1
:=
aws1
.
NodeAddresses
(
"instance
-mismatch
"
)
if
err1
==
nil
{
if
err1
==
nil
{
t
.
Errorf
(
"Should error when no instance found"
)
t
.
Errorf
(
"Should error when no instance found"
)
}
}
aws2
:=
mockInstancesResp
(
instances
)
aws2
:=
mockInstancesResp
(
instances
)
_
,
err2
:=
aws2
.
NodeAddresses
(
"instance
1
"
)
_
,
err2
:=
aws2
.
NodeAddresses
(
"instance
-same
"
)
if
err2
==
nil
{
if
err2
==
nil
{
t
.
Errorf
(
"Should error when multiple instances found"
)
t
.
Errorf
(
"Should error when multiple instances found"
)
}
}
aws3
:=
mockInstancesResp
(
instances
[
0
:
1
])
aws3
:=
mockInstancesResp
(
instances
[
0
:
1
])
addrs3
,
err3
:=
aws3
.
NodeAddresses
(
"instance
1
"
)
addrs3
,
err3
:=
aws3
.
NodeAddresses
(
"instance
-same
"
)
if
err3
!=
nil
{
if
err3
!=
nil
{
t
.
Errorf
(
"Should not error when instance found"
)
t
.
Errorf
(
"Should not error when instance found"
)
}
}
...
@@ -562,7 +562,7 @@ func TestGetResources(t *testing.T) {
...
@@ -562,7 +562,7 @@ func TestGetResources(t *testing.T) {
var
instance2
ec2
.
Instance
var
instance2
ec2
.
Instance
//0
//0
instance0
.
PrivateDNSName
=
aws
.
String
(
"m3.medium"
)
instance0
.
InstanceID
=
aws
.
String
(
"m3.medium"
)
instance0
.
InstanceType
=
aws
.
String
(
"m3.medium"
)
instance0
.
InstanceType
=
aws
.
String
(
"m3.medium"
)
state0
:=
ec2
.
InstanceState
{
state0
:=
ec2
.
InstanceState
{
Name
:
aws
.
String
(
"running"
),
Name
:
aws
.
String
(
"running"
),
...
@@ -570,7 +570,7 @@ func TestGetResources(t *testing.T) {
...
@@ -570,7 +570,7 @@ func TestGetResources(t *testing.T) {
instance0
.
State
=
&
state0
instance0
.
State
=
&
state0
//1
//1
instance1
.
PrivateDNSName
=
aws
.
String
(
"r3.8xlarge"
)
instance1
.
InstanceID
=
aws
.
String
(
"r3.8xlarge"
)
instance1
.
InstanceType
=
aws
.
String
(
"r3.8xlarge"
)
instance1
.
InstanceType
=
aws
.
String
(
"r3.8xlarge"
)
state1
:=
ec2
.
InstanceState
{
state1
:=
ec2
.
InstanceState
{
Name
:
aws
.
String
(
"running"
),
Name
:
aws
.
String
(
"running"
),
...
@@ -578,7 +578,7 @@ func TestGetResources(t *testing.T) {
...
@@ -578,7 +578,7 @@ func TestGetResources(t *testing.T) {
instance1
.
State
=
&
state1
instance1
.
State
=
&
state1
//2
//2
instance2
.
PrivateDNSName
=
aws
.
String
(
"unknown.type"
)
instance2
.
InstanceID
=
aws
.
String
(
"unknown.type"
)
instance2
.
InstanceType
=
aws
.
String
(
"unknown.type"
)
instance2
.
InstanceType
=
aws
.
String
(
"unknown.type"
)
state2
:=
ec2
.
InstanceState
{
state2
:=
ec2
.
InstanceState
{
Name
:
aws
.
String
(
"running"
),
Name
:
aws
.
String
(
"running"
),
...
...
pkg/cloudprovider/cloud.go
View file @
790ca234
...
@@ -111,6 +111,9 @@ type Instances interface {
...
@@ -111,6 +111,9 @@ type Instances interface {
// AddSSHKeyToAllInstances adds an SSH public key as a legal identity for all instances
// AddSSHKeyToAllInstances adds an SSH public key as a legal identity for all instances
// expected format for the key is standard ssh-keygen format: <protocol> <blob>
// expected format for the key is standard ssh-keygen format: <protocol> <blob>
AddSSHKeyToAllInstances
(
user
string
,
keyData
[]
byte
)
error
AddSSHKeyToAllInstances
(
user
string
,
keyData
[]
byte
)
error
// Returns the name of the node we are currently running on
// On most clouds (e.g. GCE) this is the hostname, so we provide the hostname
CurrentNodeName
(
hostname
string
)
(
string
,
error
)
}
}
// Route is a representation of an advanced routing rule.
// Route is a representation of an advanced routing rule.
...
...
pkg/cloudprovider/fake/fake.go
View file @
790ca234
...
@@ -149,6 +149,11 @@ func (f *FakeCloud) AddSSHKeyToAllInstances(user string, keyData []byte) error {
...
@@ -149,6 +149,11 @@ func (f *FakeCloud) AddSSHKeyToAllInstances(user string, keyData []byte) error {
return
errors
.
New
(
"unimplemented"
)
return
errors
.
New
(
"unimplemented"
)
}
}
// Implementation of Instances.CurrentNodeName
func
(
f
*
FakeCloud
)
CurrentNodeName
(
hostname
string
)
(
string
,
error
)
{
return
hostname
,
nil
}
// NodeAddresses is a test-spy implementation of Instances.NodeAddresses.
// NodeAddresses is a test-spy implementation of Instances.NodeAddresses.
// It adds an entry "node-addresses" into the internal method call record.
// It adds an entry "node-addresses" into the internal method call record.
func
(
f
*
FakeCloud
)
NodeAddresses
(
instance
string
)
([]
api
.
NodeAddress
,
error
)
{
func
(
f
*
FakeCloud
)
NodeAddresses
(
instance
string
)
([]
api
.
NodeAddress
,
error
)
{
...
...
pkg/cloudprovider/gce/gce.go
View file @
790ca234
...
@@ -483,6 +483,11 @@ func (gce *GCECloud) getInstanceByName(name string) (*compute.Instance, error) {
...
@@ -483,6 +483,11 @@ func (gce *GCECloud) getInstanceByName(name string) (*compute.Instance, error) {
return
res
,
nil
return
res
,
nil
}
}
// Implementation of Instances.CurrentNodeName
func
(
gce
*
GCECloud
)
CurrentNodeName
(
hostname
string
)
(
string
,
error
)
{
return
hostname
,
nil
}
func
(
gce
*
GCECloud
)
AddSSHKeyToAllInstances
(
user
string
,
keyData
[]
byte
)
error
{
func
(
gce
*
GCECloud
)
AddSSHKeyToAllInstances
(
user
string
,
keyData
[]
byte
)
error
{
return
wait
.
Poll
(
2
*
time
.
Second
,
30
*
time
.
Second
,
func
()
(
bool
,
error
)
{
return
wait
.
Poll
(
2
*
time
.
Second
,
30
*
time
.
Second
,
func
()
(
bool
,
error
)
{
project
,
err
:=
gce
.
service
.
Projects
.
Get
(
gce
.
projectID
)
.
Do
()
project
,
err
:=
gce
.
service
.
Projects
.
Get
(
gce
.
projectID
)
.
Do
()
...
...
pkg/cloudprovider/mesos/mesos.go
View file @
790ca234
...
@@ -78,6 +78,11 @@ func newMesosCloud(configReader io.Reader) (*MesosCloud, error) {
...
@@ -78,6 +78,11 @@ func newMesosCloud(configReader io.Reader) (*MesosCloud, error) {
}
}
}
}
// Implementation of Instances.CurrentNodeName
func
(
c
*
MesosCloud
)
CurrentNodeName
(
hostname
string
)
(
string
,
error
)
{
return
hostname
,
nil
}
func
(
c
*
MesosCloud
)
AddSSHKeyToAllInstances
(
user
string
,
keyData
[]
byte
)
error
{
func
(
c
*
MesosCloud
)
AddSSHKeyToAllInstances
(
user
string
,
keyData
[]
byte
)
error
{
return
errors
.
New
(
"unimplemented"
)
return
errors
.
New
(
"unimplemented"
)
}
}
...
...
pkg/cloudprovider/openstack/openstack.go
View file @
790ca234
...
@@ -317,6 +317,11 @@ func getAddressByName(api *gophercloud.ServiceClient, name string) (string, erro
...
@@ -317,6 +317,11 @@ func getAddressByName(api *gophercloud.ServiceClient, name string) (string, erro
return
s
,
nil
return
s
,
nil
}
}
// Implementation of Instances.CurrentNodeName
func
(
i
*
Instances
)
CurrentNodeName
(
hostname
string
)
(
string
,
error
)
{
return
hostname
,
nil
}
func
(
i
*
Instances
)
AddSSHKeyToAllInstances
(
user
string
,
keyData
[]
byte
)
error
{
func
(
i
*
Instances
)
AddSSHKeyToAllInstances
(
user
string
,
keyData
[]
byte
)
error
{
return
errors
.
New
(
"unimplemented"
)
return
errors
.
New
(
"unimplemented"
)
}
}
...
...
pkg/cloudprovider/ovirt/ovirt.go
View file @
790ca234
...
@@ -275,6 +275,11 @@ func (v *OVirtCloud) GetNodeResources(name string) (*api.NodeResources, error) {
...
@@ -275,6 +275,11 @@ func (v *OVirtCloud) GetNodeResources(name string) (*api.NodeResources, error) {
return
nil
,
nil
return
nil
,
nil
}
}
// Implementation of Instances.CurrentNodeName
func
(
v
*
OVirtCloud
)
CurrentNodeName
(
hostname
string
)
(
string
,
error
)
{
return
hostname
,
nil
}
func
(
v
*
OVirtCloud
)
AddSSHKeyToAllInstances
(
user
string
,
keyData
[]
byte
)
error
{
func
(
v
*
OVirtCloud
)
AddSSHKeyToAllInstances
(
user
string
,
keyData
[]
byte
)
error
{
return
errors
.
New
(
"unimplemented"
)
return
errors
.
New
(
"unimplemented"
)
}
}
pkg/cloudprovider/rackspace/rackspace.go
View file @
790ca234
...
@@ -380,6 +380,11 @@ func (i *Instances) AddSSHKeyToAllInstances(user string, keyData []byte) error {
...
@@ -380,6 +380,11 @@ func (i *Instances) AddSSHKeyToAllInstances(user string, keyData []byte) error {
return
errors
.
New
(
"unimplemented"
)
return
errors
.
New
(
"unimplemented"
)
}
}
// Implementation of Instances.CurrentNodeName
func
(
i
*
Instances
)
CurrentNodeName
(
hostname
string
)
(
string
,
error
)
{
return
hostname
,
nil
}
func
(
i
*
Instances
)
GetNodeResources
(
name
string
)
(
*
api
.
NodeResources
,
error
)
{
func
(
i
*
Instances
)
GetNodeResources
(
name
string
)
(
*
api
.
NodeResources
,
error
)
{
glog
.
V
(
2
)
.
Infof
(
"GetNodeResources(%v) called"
,
name
)
glog
.
V
(
2
)
.
Infof
(
"GetNodeResources(%v) called"
,
name
)
...
...
pkg/cloudprovider/vagrant/vagrant.go
View file @
790ca234
...
@@ -135,6 +135,11 @@ func (v *VagrantCloud) AddSSHKeyToAllInstances(user string, keyData []byte) erro
...
@@ -135,6 +135,11 @@ func (v *VagrantCloud) AddSSHKeyToAllInstances(user string, keyData []byte) erro
return
errors
.
New
(
"unimplemented"
)
return
errors
.
New
(
"unimplemented"
)
}
}
// Implementation of Instances.CurrentNodeName
func
(
v
*
VagrantCloud
)
CurrentNodeName
(
hostname
string
)
(
string
,
error
)
{
return
hostname
,
nil
}
// NodeAddresses returns the NodeAddresses of a particular machine instance.
// NodeAddresses returns the NodeAddresses of a particular machine instance.
func
(
v
*
VagrantCloud
)
NodeAddresses
(
instance
string
)
([]
api
.
NodeAddress
,
error
)
{
func
(
v
*
VagrantCloud
)
NodeAddresses
(
instance
string
)
([]
api
.
NodeAddress
,
error
)
{
// Due to vagrant not running with a dedicated DNS setup, we return the IP address of a minion as its hostname at this time
// Due to vagrant not running with a dedicated DNS setup, we return the IP address of a minion as its hostname at this time
...
...
pkg/kubelet/config/apiserver.go
View file @
790ca234
...
@@ -26,8 +26,8 @@ import (
...
@@ -26,8 +26,8 @@ import (
)
)
// NewSourceApiserver creates a config source that watches and pulls from the apiserver.
// NewSourceApiserver creates a config source that watches and pulls from the apiserver.
func
NewSourceApiserver
(
c
*
client
.
Client
,
hostn
ame
string
,
updates
chan
<-
interface
{})
{
func
NewSourceApiserver
(
c
*
client
.
Client
,
nodeN
ame
string
,
updates
chan
<-
interface
{})
{
lw
:=
cache
.
NewListWatchFromClient
(
c
,
"pods"
,
api
.
NamespaceAll
,
fields
.
OneTermEqualSelector
(
client
.
PodHost
,
hostn
ame
))
lw
:=
cache
.
NewListWatchFromClient
(
c
,
"pods"
,
api
.
NamespaceAll
,
fields
.
OneTermEqualSelector
(
client
.
PodHost
,
nodeN
ame
))
newSourceApiserverFromLW
(
lw
,
updates
)
newSourceApiserverFromLW
(
lw
,
updates
)
}
}
...
...
pkg/kubelet/config/common.go
View file @
790ca234
...
@@ -33,16 +33,16 @@ import (
...
@@ -33,16 +33,16 @@ import (
"github.com/golang/glog"
"github.com/golang/glog"
)
)
// Generate a pod name that is unique among nodes by appending the
hostn
ame.
// Generate a pod name that is unique among nodes by appending the
nodeN
ame.
func
generatePodName
(
name
,
hostn
ame
string
)
string
{
func
generatePodName
(
name
,
nodeN
ame
string
)
string
{
return
fmt
.
Sprintf
(
"%s-%s"
,
name
,
hostn
ame
)
return
fmt
.
Sprintf
(
"%s-%s"
,
name
,
nodeN
ame
)
}
}
func
applyDefaults
(
pod
*
api
.
Pod
,
source
string
,
isFile
bool
,
hostn
ame
string
)
error
{
func
applyDefaults
(
pod
*
api
.
Pod
,
source
string
,
isFile
bool
,
nodeN
ame
string
)
error
{
if
len
(
pod
.
UID
)
==
0
{
if
len
(
pod
.
UID
)
==
0
{
hasher
:=
md5
.
New
()
hasher
:=
md5
.
New
()
if
isFile
{
if
isFile
{
fmt
.
Fprintf
(
hasher
,
"host:%s"
,
hostn
ame
)
fmt
.
Fprintf
(
hasher
,
"host:%s"
,
nodeN
ame
)
fmt
.
Fprintf
(
hasher
,
"file:%s"
,
source
)
fmt
.
Fprintf
(
hasher
,
"file:%s"
,
source
)
}
else
{
}
else
{
fmt
.
Fprintf
(
hasher
,
"url:%s"
,
source
)
fmt
.
Fprintf
(
hasher
,
"url:%s"
,
source
)
...
@@ -57,7 +57,7 @@ func applyDefaults(pod *api.Pod, source string, isFile bool, hostname string) er
...
@@ -57,7 +57,7 @@ func applyDefaults(pod *api.Pod, source string, isFile bool, hostname string) er
if
len
(
pod
.
Name
)
==
0
{
if
len
(
pod
.
Name
)
==
0
{
pod
.
Name
=
string
(
pod
.
UID
)
pod
.
Name
=
string
(
pod
.
UID
)
}
}
pod
.
Name
=
generatePodName
(
pod
.
Name
,
hostn
ame
)
pod
.
Name
=
generatePodName
(
pod
.
Name
,
nodeN
ame
)
glog
.
V
(
5
)
.
Infof
(
"Generated Name %q for UID %q from URL %s"
,
pod
.
Name
,
pod
.
UID
,
source
)
glog
.
V
(
5
)
.
Infof
(
"Generated Name %q for UID %q from URL %s"
,
pod
.
Name
,
pod
.
UID
,
source
)
if
pod
.
Namespace
==
""
{
if
pod
.
Namespace
==
""
{
...
@@ -66,7 +66,7 @@ func applyDefaults(pod *api.Pod, source string, isFile bool, hostname string) er
...
@@ -66,7 +66,7 @@ func applyDefaults(pod *api.Pod, source string, isFile bool, hostname string) er
glog
.
V
(
5
)
.
Infof
(
"Using namespace %q for pod %q from %s"
,
pod
.
Namespace
,
pod
.
Name
,
source
)
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.
// Set the Host field to indicate this pod is scheduled on the current node.
pod
.
Spec
.
NodeName
=
hostn
ame
pod
.
Spec
.
NodeName
=
nodeN
ame
pod
.
ObjectMeta
.
SelfLink
=
getSelfLink
(
pod
.
Name
,
pod
.
Namespace
)
pod
.
ObjectMeta
.
SelfLink
=
getSelfLink
(
pod
.
Name
,
pod
.
Namespace
)
return
nil
return
nil
...
...
pkg/kubelet/config/file.go
View file @
790ca234
...
@@ -34,14 +34,14 @@ import (
...
@@ -34,14 +34,14 @@ import (
type
sourceFile
struct
{
type
sourceFile
struct
{
path
string
path
string
hostn
ame
string
nodeN
ame
string
updates
chan
<-
interface
{}
updates
chan
<-
interface
{}
}
}
func
NewSourceFile
(
path
string
,
hostn
ame
string
,
period
time
.
Duration
,
updates
chan
<-
interface
{})
{
func
NewSourceFile
(
path
string
,
nodeN
ame
string
,
period
time
.
Duration
,
updates
chan
<-
interface
{})
{
config
:=
&
sourceFile
{
config
:=
&
sourceFile
{
path
:
path
,
path
:
path
,
hostname
:
hostn
ame
,
nodeName
:
nodeN
ame
,
updates
:
updates
,
updates
:
updates
,
}
}
glog
.
V
(
1
)
.
Infof
(
"Watching path %q"
,
path
)
glog
.
V
(
1
)
.
Infof
(
"Watching path %q"
,
path
)
...
@@ -55,7 +55,7 @@ func (s *sourceFile) run() {
...
@@ -55,7 +55,7 @@ func (s *sourceFile) run() {
}
}
func
(
s
*
sourceFile
)
applyDefaults
(
pod
*
api
.
Pod
,
source
string
)
error
{
func
(
s
*
sourceFile
)
applyDefaults
(
pod
*
api
.
Pod
,
source
string
)
error
{
return
applyDefaults
(
pod
,
source
,
true
,
s
.
hostn
ame
)
return
applyDefaults
(
pod
,
source
,
true
,
s
.
nodeN
ame
)
}
}
func
(
s
*
sourceFile
)
extractFromPath
()
error
{
func
(
s
*
sourceFile
)
extractFromPath
()
error
{
...
...
pkg/kubelet/config/http.go
View file @
790ca234
...
@@ -33,15 +33,15 @@ import (
...
@@ -33,15 +33,15 @@ import (
type
sourceURL
struct
{
type
sourceURL
struct
{
url
string
url
string
hostn
ame
string
nodeN
ame
string
updates
chan
<-
interface
{}
updates
chan
<-
interface
{}
data
[]
byte
data
[]
byte
}
}
func
NewSourceURL
(
url
,
hostn
ame
string
,
period
time
.
Duration
,
updates
chan
<-
interface
{})
{
func
NewSourceURL
(
url
,
nodeN
ame
string
,
period
time
.
Duration
,
updates
chan
<-
interface
{})
{
config
:=
&
sourceURL
{
config
:=
&
sourceURL
{
url
:
url
,
url
:
url
,
hostname
:
hostn
ame
,
nodeName
:
nodeN
ame
,
updates
:
updates
,
updates
:
updates
,
data
:
nil
,
data
:
nil
,
}
}
...
@@ -56,7 +56,7 @@ func (s *sourceURL) run() {
...
@@ -56,7 +56,7 @@ func (s *sourceURL) run() {
}
}
func
(
s
*
sourceURL
)
applyDefaults
(
pod
*
api
.
Pod
)
error
{
func
(
s
*
sourceURL
)
applyDefaults
(
pod
*
api
.
Pod
)
error
{
return
applyDefaults
(
pod
,
s
.
url
,
false
,
s
.
hostn
ame
)
return
applyDefaults
(
pod
,
s
.
url
,
false
,
s
.
nodeN
ame
)
}
}
func
(
s
*
sourceURL
)
extractFromURL
()
error
{
func
(
s
*
sourceURL
)
extractFromURL
()
error
{
...
...
pkg/kubelet/kubelet.go
View file @
790ca234
...
@@ -114,6 +114,7 @@ func waitUntilRuntimeIsUp(cr kubecontainer.Runtime, timeout time.Duration) error
...
@@ -114,6 +114,7 @@ func waitUntilRuntimeIsUp(cr kubecontainer.Runtime, timeout time.Duration) error
// New creates a new Kubelet for use in main
// New creates a new Kubelet for use in main
func
NewMainKubelet
(
func
NewMainKubelet
(
hostname
string
,
hostname
string
,
nodeName
string
,
dockerClient
dockertools
.
DockerInterface
,
dockerClient
dockertools
.
DockerInterface
,
kubeClient
client
.
Interface
,
kubeClient
client
.
Interface
,
rootDirectory
string
,
rootDirectory
string
,
...
@@ -179,7 +180,7 @@ func NewMainKubelet(
...
@@ -179,7 +180,7 @@ func NewMainKubelet(
if
kubeClient
!=
nil
{
if
kubeClient
!=
nil
{
// TODO: cache.NewListWatchFromClient is limited as it takes a client implementation rather
// 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.
// than an interface. There is no way to construct a list+watcher using resource name.
fieldSelector
:=
fields
.
Set
{
client
.
ObjectNameField
:
hostn
ame
}
.
AsSelector
()
fieldSelector
:=
fields
.
Set
{
client
.
ObjectNameField
:
nodeN
ame
}
.
AsSelector
()
listWatch
:=
&
cache
.
ListWatch
{
listWatch
:=
&
cache
.
ListWatch
{
ListFunc
:
func
()
(
runtime
.
Object
,
error
)
{
ListFunc
:
func
()
(
runtime
.
Object
,
error
)
{
return
kubeClient
.
Nodes
()
.
List
(
labels
.
Everything
(),
fieldSelector
)
return
kubeClient
.
Nodes
()
.
List
(
labels
.
Everything
(),
fieldSelector
)
...
@@ -197,8 +198,8 @@ func NewMainKubelet(
...
@@ -197,8 +198,8 @@ func NewMainKubelet(
// TODO: what is namespace for node?
// TODO: what is namespace for node?
nodeRef
:=
&
api
.
ObjectReference
{
nodeRef
:=
&
api
.
ObjectReference
{
Kind
:
"Node"
,
Kind
:
"Node"
,
Name
:
hostn
ame
,
Name
:
nodeN
ame
,
UID
:
types
.
UID
(
hostn
ame
),
UID
:
types
.
UID
(
nodeN
ame
),
Namespace
:
""
,
Namespace
:
""
,
}
}
...
@@ -224,6 +225,7 @@ func NewMainKubelet(
...
@@ -224,6 +225,7 @@ func NewMainKubelet(
klet
:=
&
Kubelet
{
klet
:=
&
Kubelet
{
hostname
:
hostname
,
hostname
:
hostname
,
nodeName
:
nodeName
,
dockerClient
:
dockerClient
,
dockerClient
:
dockerClient
,
kubeClient
:
kubeClient
,
kubeClient
:
kubeClient
,
rootDirectory
:
rootDirectory
,
rootDirectory
:
rootDirectory
,
...
@@ -362,6 +364,7 @@ type nodeLister interface {
...
@@ -362,6 +364,7 @@ type nodeLister interface {
// Kubelet is the main kubelet implementation.
// Kubelet is the main kubelet implementation.
type
Kubelet
struct
{
type
Kubelet
struct
{
hostname
string
hostname
string
nodeName
string
dockerClient
dockertools
.
DockerInterface
dockerClient
dockertools
.
DockerInterface
runtimeCache
kubecontainer
.
RuntimeCache
runtimeCache
kubecontainer
.
RuntimeCache
kubeClient
client
.
Interface
kubeClient
client
.
Interface
...
@@ -637,13 +640,13 @@ func (kl *Kubelet) GetNode() (*api.Node, error) {
...
@@ -637,13 +640,13 @@ func (kl *Kubelet) GetNode() (*api.Node, error) {
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
errors
.
New
(
"cannot list nodes"
)
return
nil
,
errors
.
New
(
"cannot list nodes"
)
}
}
host
:=
kl
.
GetHostname
()
nodeName
:=
kl
.
nodeName
for
_
,
n
:=
range
l
.
Items
{
for
_
,
n
:=
range
l
.
Items
{
if
n
.
Name
==
host
{
if
n
.
Name
==
nodeName
{
return
&
n
,
nil
return
&
n
,
nil
}
}
}
}
return
nil
,
fmt
.
Errorf
(
"node %v not found"
,
host
)
return
nil
,
fmt
.
Errorf
(
"node %v not found"
,
nodeName
)
}
}
// Starts garbage collection theads.
// Starts garbage collection theads.
...
@@ -709,7 +712,7 @@ func (kl *Kubelet) Run(updates <-chan PodUpdate) {
...
@@ -709,7 +712,7 @@ func (kl *Kubelet) Run(updates <-chan PodUpdate) {
func
(
kl
*
Kubelet
)
initialNodeStatus
()
(
*
api
.
Node
,
error
)
{
func
(
kl
*
Kubelet
)
initialNodeStatus
()
(
*
api
.
Node
,
error
)
{
node
:=
&
api
.
Node
{
node
:=
&
api
.
Node
{
ObjectMeta
:
api
.
ObjectMeta
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
kl
.
hostn
ame
,
Name
:
kl
.
nodeN
ame
,
Labels
:
map
[
string
]
string
{
"kubernetes.io/hostname"
:
kl
.
hostname
},
Labels
:
map
[
string
]
string
{
"kubernetes.io/hostname"
:
kl
.
hostname
},
},
},
}
}
...
@@ -718,18 +721,20 @@ func (kl *Kubelet) initialNodeStatus() (*api.Node, error) {
...
@@ -718,18 +721,20 @@ func (kl *Kubelet) initialNodeStatus() (*api.Node, error) {
if
!
ok
{
if
!
ok
{
return
nil
,
fmt
.
Errorf
(
"failed to get instances from cloud provider"
)
return
nil
,
fmt
.
Errorf
(
"failed to get instances from cloud provider"
)
}
}
// TODO(roberthbailey): Can we do this without having credentials to talk
// TODO(roberthbailey): Can we do this without having credentials to talk
// to the cloud provider?
// to the cloud provider?
// TODO: ExternalID is deprecated, we'll have to drop this code
// TODO: ExternalID is deprecated, we'll have to drop this code
externalID
,
err
:=
instances
.
ExternalID
(
kl
.
hostn
ame
)
externalID
,
err
:=
instances
.
ExternalID
(
kl
.
nodeN
ame
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"failed to get external ID from cloud provider: %v"
,
err
)
return
nil
,
fmt
.
Errorf
(
"failed to get external ID from cloud provider: %v"
,
err
)
}
}
node
.
Spec
.
ExternalID
=
externalID
node
.
Spec
.
ExternalID
=
externalID
// TODO: We can't assume that the node has credentials to talk to the
// 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
// cloudprovider from arbitrary nodes. At most, we should talk to a
// local metadata server here.
// local metadata server here.
node
.
Spec
.
ProviderID
,
err
=
cloudprovider
.
GetInstanceProviderID
(
kl
.
cloud
,
kl
.
hostn
ame
)
node
.
Spec
.
ProviderID
,
err
=
cloudprovider
.
GetInstanceProviderID
(
kl
.
cloud
,
kl
.
nodeN
ame
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
...
@@ -760,13 +765,13 @@ func (kl *Kubelet) registerWithApiserver() {
...
@@ -760,13 +765,13 @@ func (kl *Kubelet) registerWithApiserver() {
glog
.
V
(
2
)
.
Infof
(
"Attempting to register node %s"
,
node
.
Name
)
glog
.
V
(
2
)
.
Infof
(
"Attempting to register node %s"
,
node
.
Name
)
if
_
,
err
:=
kl
.
kubeClient
.
Nodes
()
.
Create
(
node
);
err
!=
nil
{
if
_
,
err
:=
kl
.
kubeClient
.
Nodes
()
.
Create
(
node
);
err
!=
nil
{
if
apierrors
.
IsAlreadyExists
(
err
)
{
if
apierrors
.
IsAlreadyExists
(
err
)
{
currentNode
,
err
:=
kl
.
kubeClient
.
Nodes
()
.
Get
(
kl
.
hostn
ame
)
currentNode
,
err
:=
kl
.
kubeClient
.
Nodes
()
.
Get
(
kl
.
nodeN
ame
)
if
err
!=
nil
{
if
err
!=
nil
{
glog
.
Errorf
(
"error getting node %q: %v"
,
kl
.
hostn
ame
,
err
)
glog
.
Errorf
(
"error getting node %q: %v"
,
kl
.
nodeN
ame
,
err
)
continue
continue
}
}
if
currentNode
==
nil
{
if
currentNode
==
nil
{
glog
.
Errorf
(
"no node instance returned for %q"
,
kl
.
hostn
ame
)
glog
.
Errorf
(
"no node instance returned for %q"
,
kl
.
nodeN
ame
)
continue
continue
}
}
if
currentNode
.
Spec
.
ExternalID
==
node
.
Spec
.
ExternalID
{
if
currentNode
.
Spec
.
ExternalID
==
node
.
Spec
.
ExternalID
{
...
@@ -1830,10 +1835,10 @@ func (kl *Kubelet) updateNodeStatus() error {
...
@@ -1830,10 +1835,10 @@ func (kl *Kubelet) updateNodeStatus() error {
}
}
func
(
kl
*
Kubelet
)
recordNodeStatusEvent
(
event
string
)
{
func
(
kl
*
Kubelet
)
recordNodeStatusEvent
(
event
string
)
{
glog
.
V
(
2
)
.
Infof
(
"Recording %s event message for node %s"
,
event
,
kl
.
hostn
ame
)
glog
.
V
(
2
)
.
Infof
(
"Recording %s event message for node %s"
,
event
,
kl
.
nodeN
ame
)
// TODO: This requires a transaction, either both node status is updated
// TODO: This requires a transaction, either both node status is updated
// and event is recorded or neither should happen, see issue #6055.
// and event is recorded or neither should happen, see issue #6055.
kl
.
recorder
.
Eventf
(
kl
.
nodeRef
,
event
,
"Node %s status is now: %s"
,
kl
.
hostn
ame
,
event
)
kl
.
recorder
.
Eventf
(
kl
.
nodeRef
,
event
,
"Node %s status is now: %s"
,
kl
.
nodeN
ame
,
event
)
}
}
// Maintains Node.Spec.Unschedulable value from previous run of tryUpdateNodeStatus()
// Maintains Node.Spec.Unschedulable value from previous run of tryUpdateNodeStatus()
...
@@ -1850,7 +1855,8 @@ func (kl *Kubelet) setNodeStatus(node *api.Node) error {
...
@@ -1850,7 +1855,8 @@ func (kl *Kubelet) setNodeStatus(node *api.Node) error {
}
}
// TODO(roberthbailey): Can we do this without having credentials to talk
// TODO(roberthbailey): Can we do this without having credentials to talk
// to the cloud provider?
// to the cloud provider?
nodeAddresses
,
err
:=
instances
.
NodeAddresses
(
kl
.
hostname
)
// TODO(justinsb): We can if CurrentNodeName() was actually CurrentNode() and returned an interface
nodeAddresses
,
err
:=
instances
.
NodeAddresses
(
kl
.
nodeName
)
if
err
!=
nil
{
if
err
!=
nil
{
return
fmt
.
Errorf
(
"failed to get node address from cloud provider: %v"
,
err
)
return
fmt
.
Errorf
(
"failed to get node address from cloud provider: %v"
,
err
)
}
}
...
@@ -1904,7 +1910,7 @@ func (kl *Kubelet) setNodeStatus(node *api.Node) error {
...
@@ -1904,7 +1910,7 @@ func (kl *Kubelet) setNodeStatus(node *api.Node) error {
// TODO: This requires a transaction, either both node status is updated
// TODO: This requires a transaction, either both node status is updated
// and event is recorded or neither should happen, see issue #6055.
// and event is recorded or neither should happen, see issue #6055.
kl
.
recorder
.
Eventf
(
kl
.
nodeRef
,
"rebooted"
,
kl
.
recorder
.
Eventf
(
kl
.
nodeRef
,
"rebooted"
,
"Node %s has been rebooted, boot id: %s"
,
kl
.
hostn
ame
,
info
.
BootID
)
"Node %s has been rebooted, boot id: %s"
,
kl
.
nodeN
ame
,
info
.
BootID
)
}
}
node
.
Status
.
NodeInfo
.
BootID
=
info
.
BootID
node
.
Status
.
NodeInfo
.
BootID
=
info
.
BootID
}
}
...
@@ -1993,12 +1999,12 @@ func (kl *Kubelet) setNodeStatus(node *api.Node) error {
...
@@ -1993,12 +1999,12 @@ func (kl *Kubelet) setNodeStatus(node *api.Node) error {
// tryUpdateNodeStatus tries to update node status to master. If ReconcileCBR0
// tryUpdateNodeStatus tries to update node status to master. If ReconcileCBR0
// is set, this function will also confirm that cbr0 is configured correctly.
// is set, this function will also confirm that cbr0 is configured correctly.
func
(
kl
*
Kubelet
)
tryUpdateNodeStatus
()
error
{
func
(
kl
*
Kubelet
)
tryUpdateNodeStatus
()
error
{
node
,
err
:=
kl
.
kubeClient
.
Nodes
()
.
Get
(
kl
.
hostn
ame
)
node
,
err
:=
kl
.
kubeClient
.
Nodes
()
.
Get
(
kl
.
nodeN
ame
)
if
err
!=
nil
{
if
err
!=
nil
{
return
fmt
.
Errorf
(
"error getting node %q: %v"
,
kl
.
hostn
ame
,
err
)
return
fmt
.
Errorf
(
"error getting node %q: %v"
,
kl
.
nodeN
ame
,
err
)
}
}
if
node
==
nil
{
if
node
==
nil
{
return
fmt
.
Errorf
(
"no node instance returned for %q"
,
kl
.
hostn
ame
)
return
fmt
.
Errorf
(
"no node instance returned for %q"
,
kl
.
nodeN
ame
)
}
}
if
err
:=
kl
.
setNodeStatus
(
node
);
err
!=
nil
{
if
err
:=
kl
.
setNodeStatus
(
node
);
err
!=
nil
{
return
err
return
err
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment