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
5e376fe5
Commit
5e376fe5
authored
Dec 09, 2016
by
Ritesh H Shukla
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix panic in vSphere cloud provider. Fixes #36295
parent
133117e1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
16 additions
and
64 deletions
+16
-64
vsphere.go
pkg/cloudprovider/providers/vsphere/vsphere.go
+12
-45
vsphere_test.go
pkg/cloudprovider/providers/vsphere/vsphere_test.go
+4
-19
No files found.
pkg/cloudprovider/providers/vsphere/vsphere.go
View file @
5e376fe5
...
@@ -100,8 +100,6 @@ type VSphere struct {
...
@@ -100,8 +100,6 @@ type VSphere struct {
cfg
*
VSphereConfig
cfg
*
VSphereConfig
// InstanceID of the server where this VSphere object is instantiated.
// InstanceID of the server where this VSphere object is instantiated.
localInstanceID
string
localInstanceID
string
// Cluster that VirtualMachine belongs to
clusterName
string
}
}
type
VSphereConfig
struct
{
type
VSphereConfig
struct
{
...
@@ -201,17 +199,16 @@ func init() {
...
@@ -201,17 +199,16 @@ func init() {
})
})
}
}
// Returns the name of the VM and its Cluster on which this code is running.
// Returns the name of the VM on which this code is running.
// This is done by searching for the name of virtual machine by current IP.
// Prerequisite: this code assumes VMWare vmtools or open-vm-tools to be installed in the VM.
// Prerequisite: this code assumes VMWare vmtools or open-vm-tools to be installed in the VM.
func
readInstance
(
client
*
govmomi
.
Client
,
cfg
*
VSphereConfig
)
(
string
,
string
,
error
)
{
func
getVMName
(
client
*
govmomi
.
Client
,
cfg
*
VSphereConfig
)
(
string
,
error
)
{
addrs
,
err
:=
net
.
InterfaceAddrs
()
addrs
,
err
:=
net
.
InterfaceAddrs
()
if
err
!=
nil
{
if
err
!=
nil
{
return
""
,
""
,
err
return
""
,
err
}
}
if
len
(
addrs
)
==
0
{
if
len
(
addrs
)
==
0
{
return
""
,
""
,
fmt
.
Errorf
(
"unable to retrieve Instance ID"
)
return
""
,
fmt
.
Errorf
(
"unable to retrieve Instance ID"
)
}
}
// Create context
// Create context
...
@@ -224,7 +221,7 @@ func readInstance(client *govmomi.Client, cfg *VSphereConfig) (string, string, e
...
@@ -224,7 +221,7 @@ func readInstance(client *govmomi.Client, cfg *VSphereConfig) (string, string, e
// Fetch and set data center
// Fetch and set data center
dc
,
err
:=
f
.
Datacenter
(
ctx
,
cfg
.
Global
.
Datacenter
)
dc
,
err
:=
f
.
Datacenter
(
ctx
,
cfg
.
Global
.
Datacenter
)
if
err
!=
nil
{
if
err
!=
nil
{
return
""
,
""
,
err
return
""
,
err
}
}
f
.
SetDatacenter
(
dc
)
f
.
SetDatacenter
(
dc
)
...
@@ -234,7 +231,7 @@ func readInstance(client *govmomi.Client, cfg *VSphereConfig) (string, string, e
...
@@ -234,7 +231,7 @@ func readInstance(client *govmomi.Client, cfg *VSphereConfig) (string, string, e
for
_
,
v
:=
range
addrs
{
for
_
,
v
:=
range
addrs
{
ip
,
_
,
err
:=
net
.
ParseCIDR
(
v
.
String
())
ip
,
_
,
err
:=
net
.
ParseCIDR
(
v
.
String
())
if
err
!=
nil
{
if
err
!=
nil
{
return
""
,
""
,
fmt
.
Errorf
(
"unable to parse cidr from ip"
)
return
""
,
fmt
.
Errorf
(
"unable to parse cidr from ip"
)
}
}
// Finds a virtual machine or host by IP address.
// Finds a virtual machine or host by IP address.
...
@@ -244,33 +241,15 @@ func readInstance(client *govmomi.Client, cfg *VSphereConfig) (string, string, e
...
@@ -244,33 +241,15 @@ func readInstance(client *govmomi.Client, cfg *VSphereConfig) (string, string, e
}
}
}
}
if
svm
==
nil
{
if
svm
==
nil
{
return
""
,
""
,
fmt
.
Errorf
(
"unable to retrieve vm reference from vSphere"
)
return
""
,
fmt
.
Errorf
(
"unable to retrieve vm reference from vSphere"
)
}
}
var
vm
mo
.
VirtualMachine
var
vm
mo
.
VirtualMachine
err
=
s
.
Properties
(
ctx
,
svm
.
Reference
(),
[]
string
{
"name"
,
"resourcePool"
},
&
vm
)
err
=
s
.
Properties
(
ctx
,
svm
.
Reference
(),
[]
string
{
"name"
,
"resourcePool"
},
&
vm
)
if
err
!=
nil
{
if
err
!=
nil
{
return
""
,
""
,
err
return
""
,
err
}
var
cluster
string
if
vm
.
ResourcePool
!=
nil
{
// Extract the Cluster Name if VM belongs to a ResourcePool
var
rp
mo
.
ResourcePool
err
=
s
.
Properties
(
ctx
,
*
vm
.
ResourcePool
,
[]
string
{
"parent"
},
&
rp
)
if
err
==
nil
{
var
ccr
mo
.
ComputeResource
err
=
s
.
Properties
(
ctx
,
*
rp
.
Parent
,
[]
string
{
"name"
},
&
ccr
)
if
err
==
nil
{
cluster
=
ccr
.
Name
}
else
{
glog
.
Warningf
(
"VM %s, does not belong to a vSphere Cluster, will not have FailureDomain label"
,
vm
.
Name
)
}
}
else
{
glog
.
Warningf
(
"VM %s, does not belong to a vSphere Cluster, will not have FailureDomain label"
,
vm
.
Name
)
}
}
}
return
vm
.
Name
,
cluster
,
nil
return
vm
.
Name
,
nil
}
}
func
newVSphere
(
cfg
VSphereConfig
)
(
*
VSphere
,
error
)
{
func
newVSphere
(
cfg
VSphereConfig
)
(
*
VSphere
,
error
)
{
...
@@ -292,7 +271,7 @@ func newVSphere(cfg VSphereConfig) (*VSphere, error) {
...
@@ -292,7 +271,7 @@ func newVSphere(cfg VSphereConfig) (*VSphere, error) {
return
nil
,
err
return
nil
,
err
}
}
id
,
cluster
,
err
:=
readInstanc
e
(
c
,
&
cfg
)
id
,
err
:=
getVMNam
e
(
c
,
&
cfg
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
...
@@ -301,7 +280,6 @@ func newVSphere(cfg VSphereConfig) (*VSphere, error) {
...
@@ -301,7 +280,6 @@ func newVSphere(cfg VSphereConfig) (*VSphere, error) {
client
:
c
,
client
:
c
,
cfg
:
&
cfg
,
cfg
:
&
cfg
,
localInstanceID
:
id
,
localInstanceID
:
id
,
clusterName
:
cluster
,
}
}
runtime
.
SetFinalizer
(
&
vs
,
logout
)
runtime
.
SetFinalizer
(
&
vs
,
logout
)
...
@@ -634,20 +612,9 @@ func (vs *VSphere) LoadBalancer() (cloudprovider.LoadBalancer, bool) {
...
@@ -634,20 +612,9 @@ func (vs *VSphere) LoadBalancer() (cloudprovider.LoadBalancer, bool) {
// Zones returns an implementation of Zones for Google vSphere.
// Zones returns an implementation of Zones for Google vSphere.
func
(
vs
*
VSphere
)
Zones
()
(
cloudprovider
.
Zones
,
bool
)
{
func
(
vs
*
VSphere
)
Zones
()
(
cloudprovider
.
Zones
,
bool
)
{
glog
.
V
(
1
)
.
Info
(
"
Claiming to support Z
ones"
)
glog
.
V
(
1
)
.
Info
(
"
The vSphere cloud provider does not support z
ones"
)
return
vs
,
true
return
nil
,
false
}
func
(
vs
*
VSphere
)
GetZone
()
(
cloudprovider
.
Zone
,
error
)
{
glog
.
V
(
1
)
.
Infof
(
"Current datacenter is %v, cluster is %v"
,
vs
.
cfg
.
Global
.
Datacenter
,
vs
.
clusterName
)
// The clusterName is determined from the VirtualMachine ManagedObjectReference during init
// If the VM is not created within a Cluster, this will return empty-string
return
cloudprovider
.
Zone
{
Region
:
vs
.
cfg
.
Global
.
Datacenter
,
FailureDomain
:
vs
.
clusterName
,
},
nil
}
}
// Routes returns a false since the interface is not supported for vSphere.
// Routes returns a false since the interface is not supported for vSphere.
...
...
pkg/cloudprovider/providers/vsphere/vsphere_test.go
View file @
5e376fe5
...
@@ -128,30 +128,15 @@ func TestVSphereLogin(t *testing.T) {
...
@@ -128,30 +128,15 @@ func TestVSphereLogin(t *testing.T) {
func
TestZones
(
t
*
testing
.
T
)
{
func
TestZones
(
t
*
testing
.
T
)
{
cfg
:=
VSphereConfig
{}
cfg
:=
VSphereConfig
{}
cfg
.
Global
.
Datacenter
=
"myDatacenter"
cfg
.
Global
.
Datacenter
=
"myDatacenter"
failureZone
:=
"myCluster"
// Create vSphere configuration object
// Create vSphere configuration object
vs
:=
VSphere
{
vs
:=
VSphere
{
cfg
:
&
cfg
,
cfg
:
&
cfg
,
clusterName
:
failureZone
,
}
}
z
,
ok
:=
vs
.
Zones
()
_
,
ok
:=
vs
.
Zones
()
if
!
ok
{
if
ok
{
t
.
Fatalf
(
"Zones() returned false"
)
t
.
Fatalf
(
"Zones() returned true"
)
}
zone
,
err
:=
z
.
GetZone
()
if
err
!=
nil
{
t
.
Fatalf
(
"GetZone() returned error: %s"
,
err
)
}
if
zone
.
Region
!=
vs
.
cfg
.
Global
.
Datacenter
{
t
.
Fatalf
(
"GetZone() returned wrong region (%s)"
,
zone
.
Region
)
}
if
zone
.
FailureDomain
!=
failureZone
{
t
.
Fatalf
(
"GetZone() returned wrong Failure Zone (%s)"
,
zone
.
FailureDomain
)
}
}
}
}
...
...
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