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
53e17f0f
Commit
53e17f0f
authored
Mar 03, 2015
by
Deyuan Deng
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move Node.ExternalID to CloudNodes()
parent
a0bfb62b
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
28 additions
and
23 deletions
+28
-23
nodecontroller.go
pkg/cloudprovider/controller/nodecontroller.go
+24
-19
nodecontroller_test.go
pkg/cloudprovider/controller/nodecontroller_test.go
+4
-4
No files found.
pkg/cloudprovider/controller/nodecontroller.go
View file @
53e17f0f
...
@@ -77,13 +77,20 @@ func NewNodeController(
...
@@ -77,13 +77,20 @@ func NewNodeController(
// Run creates initial node list and start syncing instances from cloudprovider if any.
// Run creates initial node list and start syncing instances from cloudprovider if any.
// It also starts syncing cluster node status.
// It also starts syncing cluster node status.
// 1. RegisterNodes() is called only once to register all initial nodes (from cloudprovider
// or from command line flag). To make cluster bootstrap faster, node controller populates
// node addresses.
// 2. SyncCloud() is called periodically (if enabled) to sync instances from cloudprovider.
// Node created here will only have specs.
// 3. SyncNodeStatus() is called periodically (if enabled) to sync node status for nodes in
// k8s cluster.
func
(
s
*
NodeController
)
Run
(
period
time
.
Duration
,
syncNodeList
,
syncNodeStatus
bool
)
{
func
(
s
*
NodeController
)
Run
(
period
time
.
Duration
,
syncNodeList
,
syncNodeStatus
bool
)
{
// Register intial set of nodes with their status set.
// Register intial set of nodes with their status set.
var
nodes
*
api
.
NodeList
var
nodes
*
api
.
NodeList
var
err
error
var
err
error
if
s
.
isRunningCloudProvider
()
{
if
s
.
isRunningCloudProvider
()
{
if
syncNodeList
{
if
syncNodeList
{
nodes
,
err
=
s
.
CloudNodes
()
nodes
,
err
=
s
.
GetCloudNodesWithSpec
()
if
err
!=
nil
{
if
err
!=
nil
{
glog
.
Errorf
(
"Error loading initial node from cloudprovider: %v"
,
err
)
glog
.
Errorf
(
"Error loading initial node from cloudprovider: %v"
,
err
)
}
}
...
@@ -91,7 +98,7 @@ func (s *NodeController) Run(period time.Duration, syncNodeList, syncNodeStatus
...
@@ -91,7 +98,7 @@ func (s *NodeController) Run(period time.Duration, syncNodeList, syncNodeStatus
nodes
=
&
api
.
NodeList
{}
nodes
=
&
api
.
NodeList
{}
}
}
}
else
{
}
else
{
nodes
,
err
=
s
.
StaticNodes
()
nodes
,
err
=
s
.
GetStaticNodesWithSpec
()
if
err
!=
nil
{
if
err
!=
nil
{
glog
.
Errorf
(
"Error loading initial static nodes: %v"
,
err
)
glog
.
Errorf
(
"Error loading initial static nodes: %v"
,
err
)
}
}
...
@@ -162,11 +169,7 @@ func (s *NodeController) RegisterNodes(nodes *api.NodeList, retryCount int, retr
...
@@ -162,11 +169,7 @@ func (s *NodeController) RegisterNodes(nodes *api.NodeList, retryCount int, retr
// SyncCloud synchronizes the list of instances from cloudprovider to master server.
// SyncCloud synchronizes the list of instances from cloudprovider to master server.
func
(
s
*
NodeController
)
SyncCloud
()
error
{
func
(
s
*
NodeController
)
SyncCloud
()
error
{
matches
,
err
:=
s
.
CloudNodes
()
matches
,
err
:=
s
.
GetCloudNodesWithSpec
()
if
err
!=
nil
{
return
err
}
matches
,
err
=
s
.
PopulateIPs
(
matches
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
...
@@ -271,12 +274,6 @@ func (s *NodeController) PopulateIPs(nodes *api.NodeList) (*api.NodeList, error)
...
@@ -271,12 +274,6 @@ func (s *NodeController) PopulateIPs(nodes *api.NodeList) (*api.NodeList, error)
}
else
{
}
else
{
node
.
Status
.
HostIP
=
hostIP
.
String
()
node
.
Status
.
HostIP
=
hostIP
.
String
()
}
}
instanceID
,
err
:=
instances
.
ExternalID
(
node
.
Name
)
if
err
!=
nil
{
glog
.
Errorf
(
"error getting instance id for %s: %v"
,
node
.
Name
,
err
)
}
else
{
node
.
Spec
.
ExternalID
=
instanceID
}
}
}
}
else
{
}
else
{
for
i
:=
range
nodes
.
Items
{
for
i
:=
range
nodes
.
Items
{
...
@@ -393,9 +390,10 @@ func (s *NodeController) deletePods(nodeID string) error {
...
@@ -393,9 +390,10 @@ func (s *NodeController) deletePods(nodeID string) error {
return
nil
return
nil
}
}
// StaticNodes constructs and returns api.NodeList for static nodes. If error
// GetStaticNodesWithSpec constructs and returns api.NodeList for static nodes. If error
// occurs, an empty NodeList will be returned with a non-nil error info.
// occurs, an empty NodeList will be returned with a non-nil error info. The
func
(
s
*
NodeController
)
StaticNodes
()
(
*
api
.
NodeList
,
error
)
{
// method only constructs spec fields for nodes.
func
(
s
*
NodeController
)
GetStaticNodesWithSpec
()
(
*
api
.
NodeList
,
error
)
{
result
:=
&
api
.
NodeList
{}
result
:=
&
api
.
NodeList
{}
for
_
,
nodeID
:=
range
s
.
nodes
{
for
_
,
nodeID
:=
range
s
.
nodes
{
node
:=
api
.
Node
{
node
:=
api
.
Node
{
...
@@ -407,9 +405,10 @@ func (s *NodeController) StaticNodes() (*api.NodeList, error) {
...
@@ -407,9 +405,10 @@ func (s *NodeController) StaticNodes() (*api.NodeList, error) {
return
result
,
nil
return
result
,
nil
}
}
// CloudNodes constructs and returns api.NodeList from cloudprovider. If error
// GetCloudNodesWithSpec constructs and returns api.NodeList from cloudprovider. If error
// occurs, an empty NodeList will be returned with a non-nil error info.
// occurs, an empty NodeList will be returned with a non-nil error info. The
func
(
s
*
NodeController
)
CloudNodes
()
(
*
api
.
NodeList
,
error
)
{
// method only constructs spec fields for nodes.
func
(
s
*
NodeController
)
GetCloudNodesWithSpec
()
(
*
api
.
NodeList
,
error
)
{
result
:=
&
api
.
NodeList
{}
result
:=
&
api
.
NodeList
{}
instances
,
ok
:=
s
.
cloud
.
Instances
()
instances
,
ok
:=
s
.
cloud
.
Instances
()
if
!
ok
{
if
!
ok
{
...
@@ -432,6 +431,12 @@ func (s *NodeController) CloudNodes() (*api.NodeList, error) {
...
@@ -432,6 +431,12 @@ func (s *NodeController) CloudNodes() (*api.NodeList, error) {
if
resources
!=
nil
{
if
resources
!=
nil
{
node
.
Spec
.
Capacity
=
resources
.
Capacity
node
.
Spec
.
Capacity
=
resources
.
Capacity
}
}
instanceID
,
err
:=
instances
.
ExternalID
(
node
.
Name
)
if
err
!=
nil
{
glog
.
Errorf
(
"error getting instance id for %s: %v"
,
node
.
Name
,
err
)
}
else
{
node
.
Spec
.
ExternalID
=
instanceID
}
result
.
Items
=
append
(
result
.
Items
,
node
)
result
.
Items
=
append
(
result
.
Items
,
node
)
}
}
return
result
,
nil
return
result
,
nil
...
...
pkg/cloudprovider/controller/nodecontroller_test.go
View file @
53e17f0f
...
@@ -247,7 +247,7 @@ func TestRegisterNodes(t *testing.T) {
...
@@ -247,7 +247,7 @@ func TestRegisterNodes(t *testing.T) {
}
}
}
}
func
TestCreate
StaticNodes
(
t
*
testing
.
T
)
{
func
TestCreate
GetStaticNodesWithSpec
(
t
*
testing
.
T
)
{
table
:=
[]
struct
{
table
:=
[]
struct
{
machines
[]
string
machines
[]
string
expectedNodes
*
api
.
NodeList
expectedNodes
*
api
.
NodeList
...
@@ -289,7 +289,7 @@ func TestCreateStaticNodes(t *testing.T) {
...
@@ -289,7 +289,7 @@ func TestCreateStaticNodes(t *testing.T) {
for
_
,
item
:=
range
table
{
for
_
,
item
:=
range
table
{
nodeController
:=
NewNodeController
(
nil
,
""
,
item
.
machines
,
&
api
.
NodeResources
{},
nil
,
nil
,
10
,
time
.
Minute
)
nodeController
:=
NewNodeController
(
nil
,
""
,
item
.
machines
,
&
api
.
NodeResources
{},
nil
,
nil
,
10
,
time
.
Minute
)
nodes
,
err
:=
nodeController
.
StaticNodes
()
nodes
,
err
:=
nodeController
.
GetStaticNodesWithSpec
()
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Errorf
(
"unexpected error: %v"
,
err
)
t
.
Errorf
(
"unexpected error: %v"
,
err
)
}
}
...
@@ -299,7 +299,7 @@ func TestCreateStaticNodes(t *testing.T) {
...
@@ -299,7 +299,7 @@ func TestCreateStaticNodes(t *testing.T) {
}
}
}
}
func
TestCreate
CloudNodes
(
t
*
testing
.
T
)
{
func
TestCreate
GetCloudNodesWithSpec
(
t
*
testing
.
T
)
{
resourceList
:=
api
.
ResourceList
{
resourceList
:=
api
.
ResourceList
{
api
.
ResourceCPU
:
*
resource
.
NewMilliQuantity
(
1000
,
resource
.
DecimalSI
),
api
.
ResourceCPU
:
*
resource
.
NewMilliQuantity
(
1000
,
resource
.
DecimalSI
),
api
.
ResourceMemory
:
*
resource
.
NewQuantity
(
3000
,
resource
.
DecimalSI
),
api
.
ResourceMemory
:
*
resource
.
NewQuantity
(
3000
,
resource
.
DecimalSI
),
...
@@ -350,7 +350,7 @@ func TestCreateCloudNodes(t *testing.T) {
...
@@ -350,7 +350,7 @@ func TestCreateCloudNodes(t *testing.T) {
for
_
,
item
:=
range
table
{
for
_
,
item
:=
range
table
{
nodeController
:=
NewNodeController
(
item
.
fakeCloud
,
".*"
,
nil
,
&
api
.
NodeResources
{},
nil
,
nil
,
10
,
time
.
Minute
)
nodeController
:=
NewNodeController
(
item
.
fakeCloud
,
".*"
,
nil
,
&
api
.
NodeResources
{},
nil
,
nil
,
10
,
time
.
Minute
)
nodes
,
err
:=
nodeController
.
CloudNodes
()
nodes
,
err
:=
nodeController
.
GetCloudNodesWithSpec
()
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Errorf
(
"unexpected error: %v"
,
err
)
t
.
Errorf
(
"unexpected error: %v"
,
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