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
ca69c2e3
Commit
ca69c2e3
authored
Jan 21, 2016
by
Alex Mohr
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #19967 from justinsb/fix_gce_npe
Fix for panic when instance not found
parents
cd2e0c49
2201c631
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
9 additions
and
3 deletions
+9
-3
gce.go
pkg/cloudprovider/providers/gce/gce.go
+9
-3
No files found.
pkg/cloudprovider/providers/gce/gce.go
View file @
ca69c2e3
...
@@ -1815,6 +1815,7 @@ type gceDisk struct {
...
@@ -1815,6 +1815,7 @@ type gceDisk struct {
Kind
string
Kind
string
}
}
// Gets the named instances, returning cloudprovider.InstanceNotFound if any instance is not found
func
(
gce
*
GCECloud
)
getInstancesByNames
(
names
[]
string
)
([]
*
gceInstance
,
error
)
{
func
(
gce
*
GCECloud
)
getInstancesByNames
(
names
[]
string
)
([]
*
gceInstance
,
error
)
{
instances
:=
make
(
map
[
string
]
*
gceInstance
)
instances
:=
make
(
map
[
string
]
*
gceInstance
)
...
@@ -1863,7 +1864,8 @@ func (gce *GCECloud) getInstancesByNames(names []string) ([]*gceInstance, error)
...
@@ -1863,7 +1864,8 @@ func (gce *GCECloud) getInstancesByNames(names []string) ([]*gceInstance, error)
for
i
,
name
:=
range
names
{
for
i
,
name
:=
range
names
{
instance
:=
instances
[
name
]
instance
:=
instances
[
name
]
if
instance
==
nil
{
if
instance
==
nil
{
return
nil
,
fmt
.
Errorf
(
"failed to retrieve instance: %q"
,
name
)
glog
.
Errorf
(
"Failed to retrieve instance: %q"
,
name
)
return
nil
,
cloudprovider
.
InstanceNotFound
}
}
instanceArray
[
i
]
=
instances
[
name
]
instanceArray
[
i
]
=
instances
[
name
]
}
}
...
@@ -1871,6 +1873,7 @@ func (gce *GCECloud) getInstancesByNames(names []string) ([]*gceInstance, error)
...
@@ -1871,6 +1873,7 @@ func (gce *GCECloud) getInstancesByNames(names []string) ([]*gceInstance, error)
return
instanceArray
,
nil
return
instanceArray
,
nil
}
}
// Gets the named instance, returning cloudprovider.InstanceNotFound if the instance is not found
func
(
gce
*
GCECloud
)
getInstanceByName
(
name
string
)
(
*
gceInstance
,
error
)
{
func
(
gce
*
GCECloud
)
getInstanceByName
(
name
string
)
(
*
gceInstance
,
error
)
{
// Avoid changing behaviour when not managing multiple zones
// Avoid changing behaviour when not managing multiple zones
if
len
(
gce
.
managedZones
)
==
1
{
if
len
(
gce
.
managedZones
)
==
1
{
...
@@ -1878,9 +1881,11 @@ func (gce *GCECloud) getInstanceByName(name string) (*gceInstance, error) {
...
@@ -1878,9 +1881,11 @@ func (gce *GCECloud) getInstanceByName(name string) (*gceInstance, error) {
zone
:=
gce
.
managedZones
[
0
]
zone
:=
gce
.
managedZones
[
0
]
res
,
err
:=
gce
.
service
.
Instances
.
Get
(
gce
.
projectID
,
zone
,
name
)
.
Do
()
res
,
err
:=
gce
.
service
.
Instances
.
Get
(
gce
.
projectID
,
zone
,
name
)
.
Do
()
if
err
!=
nil
{
if
err
!=
nil
{
if
!
isHTTPErrorCode
(
err
,
http
.
StatusNotFound
)
{
glog
.
Errorf
(
"Failed to retrieve TargetInstance resource for instance: %s"
,
name
)
return
nil
,
err
if
isHTTPErrorCode
(
err
,
http
.
StatusNotFound
)
{
return
nil
,
cloudprovider
.
InstanceNotFound
}
}
return
nil
,
err
}
}
return
&
gceInstance
{
return
&
gceInstance
{
Zone
:
lastComponent
(
res
.
Zone
),
Zone
:
lastComponent
(
res
.
Zone
),
...
@@ -1895,6 +1900,7 @@ func (gce *GCECloud) getInstanceByName(name string) (*gceInstance, error) {
...
@@ -1895,6 +1900,7 @@ func (gce *GCECloud) getInstanceByName(name string) (*gceInstance, error) {
return
nil
,
err
return
nil
,
err
}
}
if
len
(
instances
)
!=
1
||
instances
[
0
]
==
nil
{
if
len
(
instances
)
!=
1
||
instances
[
0
]
==
nil
{
// getInstancesByNames not obeying its contract
return
nil
,
fmt
.
Errorf
(
"unexpected return value from getInstancesByNames: %v"
,
instances
)
return
nil
,
fmt
.
Errorf
(
"unexpected return value from getInstancesByNames: %v"
,
instances
)
}
}
return
instances
[
0
],
nil
return
instances
[
0
],
nil
...
...
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