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
5a6cf15c
Commit
5a6cf15c
authored
Feb 01, 2016
by
k8s-merge-robot
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #19874 from justinsb/aws_fix_findinstancesbynodenames
Auto commit by PR queue bot
parents
32ab64ce
9f44c72b
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
41 additions
and
8 deletions
+41
-8
aws.go
pkg/cloudprovider/providers/aws/aws.go
+41
-8
No files found.
pkg/cloudprovider/providers/aws/aws.go
View file @
5a6cf15c
...
@@ -2181,22 +2181,55 @@ func (a *AWSCloud) getInstancesByIDs(instanceIDs []*string) (map[string]*ec2.Ins
...
@@ -2181,22 +2181,55 @@ func (a *AWSCloud) getInstancesByIDs(instanceIDs []*string) (map[string]*ec2.Ins
return
instancesByID
,
nil
return
instancesByID
,
nil
}
}
// TODO: Make efficient
// Fetches instances by node names; returns an error if any cannot be found.
// This is currently implemented by fetching all the instances, because this is currently called for all nodes (i.e. the majority)
// In practice, the breakeven vs looping through and calling getInstanceByNodeName is probably around N=2.
func
(
a
*
AWSCloud
)
getInstancesByNodeNames
(
nodeNames
[]
string
)
([]
*
ec2
.
Instance
,
error
)
{
func
(
a
*
AWSCloud
)
getInstancesByNodeNames
(
nodeNames
[]
string
)
([]
*
ec2
.
Instance
,
error
)
{
instances
:=
[]
*
ec2
.
Instance
{}
allInstances
,
err
:=
a
.
getAllInstances
()
for
_
,
nodeName
:=
range
nodeNames
{
if
err
!=
nil
{
instance
,
err
:=
a
.
getInstanceByNodeName
(
nodeName
)
return
nil
,
err
if
err
!=
nil
{
}
return
nil
,
err
nodeNamesMap
:=
make
(
map
[
string
]
int
,
len
(
nodeNames
))
for
i
,
nodeName
:=
range
nodeNames
{
nodeNamesMap
[
nodeName
]
=
i
}
instances
:=
make
([]
*
ec2
.
Instance
,
len
(
nodeNames
))
for
_
,
instance
:=
range
allInstances
{
nodeName
:=
aws
.
StringValue
(
instance
.
PrivateDnsName
)
if
nodeName
==
""
{
glog
.
V
(
2
)
.
Infof
(
"ignoring ec2 instance with no PrivateDnsName: %q"
,
aws
.
StringValue
(
instance
.
InstanceId
))
continue
}
i
,
found
:=
nodeNamesMap
[
nodeName
]
if
!
found
{
continue
}
}
instances
[
i
]
=
instance
}
for
i
,
instance
:=
range
instances
{
if
instance
==
nil
{
if
instance
==
nil
{
return
nil
,
fmt
.
Errorf
(
"unable to find instance "
+
nodeName
)
nodeName
:=
nodeNames
[
i
]
return
nil
,
fmt
.
Errorf
(
"unable to find instance %q"
,
nodeName
)
}
}
instances
=
append
(
instances
,
instance
)
}
}
return
instances
,
nil
return
instances
,
nil
}
}
// Returns all instances that are tagged as being in this cluster.
func
(
a
*
AWSCloud
)
getAllInstances
()
([]
*
ec2
.
Instance
,
error
)
{
filters
:=
[]
*
ec2
.
Filter
{}
filters
=
a
.
addFilters
(
filters
)
request
:=
&
ec2
.
DescribeInstancesInput
{
Filters
:
filters
,
}
return
a
.
ec2
.
DescribeInstances
(
request
)
}
// Returns the instance with the specified node name
// Returns the instance with the specified node name
// Returns nil if it does not exist
// Returns nil if it does not exist
func
(
a
*
AWSCloud
)
findInstanceByNodeName
(
nodeName
string
)
(
*
ec2
.
Instance
,
error
)
{
func
(
a
*
AWSCloud
)
findInstanceByNodeName
(
nodeName
string
)
(
*
ec2
.
Instance
,
error
)
{
...
...
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