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
a68cbd65
Commit
a68cbd65
authored
Feb 15, 2018
by
Jesse Haka
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
implement InstanceShutdownByProviderID to aws cloudprovider
changes according what was asked use string do not delete instance if it is in any other state than running use constants fix
parent
11387279
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
31 additions
and
8 deletions
+31
-8
aws.go
pkg/cloudprovider/providers/aws/aws.go
+31
-8
No files found.
pkg/cloudprovider/providers/aws/aws.go
View file @
a68cbd65
...
...
@@ -1336,7 +1336,7 @@ func (c *Cloud) NodeAddressesByProviderID(ctx context.Context, providerID string
return
extractNodeAddresses
(
instance
)
}
// InstanceExistsByProviderID returns true if the instance with the given provider id still exists
and is running
.
// InstanceExistsByProviderID returns true if the instance with the given provider id still exists.
// If false is returned with no error, the instance will be immediately deleted by the cloud controller manager.
func
(
c
*
Cloud
)
InstanceExistsByProviderID
(
ctx
context
.
Context
,
providerID
string
)
(
bool
,
error
)
{
instanceID
,
err
:=
kubernetesInstanceID
(
providerID
)
.
mapToAWSInstanceID
()
...
...
@@ -1359,18 +1359,41 @@ func (c *Cloud) InstanceExistsByProviderID(ctx context.Context, providerID strin
return
false
,
fmt
.
Errorf
(
"multiple instances found for instance: %s"
,
instanceID
)
}
state
:=
instances
[
0
]
.
State
.
Name
if
*
state
!=
"running"
{
glog
.
Warningf
(
"the instance %s is not running"
,
instanceID
)
return
false
,
nil
}
return
true
,
nil
}
// InstanceShutdownByProviderID returns true if the instance is in safe state to detach volumes
func
(
c
*
Cloud
)
InstanceShutdownByProviderID
(
ctx
context
.
Context
,
providerID
string
)
(
bool
,
error
)
{
return
false
,
cloudprovider
.
NotImplemented
instanceID
,
err
:=
kubernetesInstanceID
(
providerID
)
.
mapToAWSInstanceID
()
if
err
!=
nil
{
return
false
,
err
}
request
:=
&
ec2
.
DescribeInstancesInput
{
InstanceIds
:
[]
*
string
{
instanceID
.
awsString
()},
}
instances
,
err
:=
c
.
ec2
.
DescribeInstances
(
request
)
if
err
!=
nil
{
return
false
,
err
}
if
len
(
instances
)
==
0
{
glog
.
Warningf
(
"the instance %s does not exist anymore"
,
providerID
)
return
true
,
nil
}
if
len
(
instances
)
>
1
{
return
false
,
fmt
.
Errorf
(
"multiple instances found for instance: %s"
,
instanceID
)
}
instance
:=
instances
[
0
]
if
instance
.
State
!=
nil
{
state
:=
aws
.
StringValue
(
instance
.
State
.
Name
)
// valid state for detaching volumes
if
state
==
ec2
.
InstanceStateNameStopped
||
state
==
ec2
.
InstanceStateNameTerminated
{
return
true
,
nil
}
}
return
false
,
nil
}
// InstanceID returns the cloud provider ID of the node with the specified nodeName.
...
...
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