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
d2ebb604
Commit
d2ebb604
authored
Jul 07, 2017
by
FengyunPan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Check opts of cloud config file
Fix #48347 Check opts when register OpenStack CloudProvider rather than returning error when use opts to create/use cloud resource.
parent
e74ef816
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
137 additions
and
4 deletions
+137
-4
openstack.go
pkg/cloudprovider/providers/openstack/openstack.go
+43
-4
openstack_test.go
pkg/cloudprovider/providers/openstack/openstack_test.go
+94
-0
No files found.
pkg/cloudprovider/providers/openstack/openstack.go
View file @
d2ebb604
...
@@ -75,10 +75,10 @@ type LoadBalancer struct {
...
@@ -75,10 +75,10 @@ type LoadBalancer struct {
}
}
type
LoadBalancerOpts
struct
{
type
LoadBalancerOpts
struct
{
LBVersion
string
`gcfg:"lb-version"`
// overrides autodetection. v1 or v2
LBVersion
string
`gcfg:"lb-version"`
// overrides autodetection. v1 or v2
SubnetId
string
`gcfg:"subnet-id"`
// required
SubnetId
string
`gcfg:"subnet-id"`
// required
FloatingNetworkId
string
`gcfg:"floating-network-id"`
FloatingNetworkId
string
`gcfg:"floating-network-id"`
// If specified, will create floating ip for loadbalancer, or do not create floating ip.
LBMethod
string
`gcfg:"lb-method"`
LBMethod
string
`gcfg:"lb-method"`
// default to ROUND_ROBIN.
CreateMonitor
bool
`gcfg:"create-monitor"`
CreateMonitor
bool
`gcfg:"create-monitor"`
MonitorDelay
MyDuration
`gcfg:"monitor-delay"`
MonitorDelay
MyDuration
`gcfg:"monitor-delay"`
MonitorTimeout
MyDuration
`gcfg:"monitor-timeout"`
MonitorTimeout
MyDuration
`gcfg:"monitor-timeout"`
...
@@ -216,6 +216,40 @@ func readInstanceID() (string, error) {
...
@@ -216,6 +216,40 @@ func readInstanceID() (string, error) {
return
md
.
Uuid
,
nil
return
md
.
Uuid
,
nil
}
}
// check opts for OpenStack
func
checkOpenStackOpts
(
openstackOpts
*
OpenStack
)
error
{
lbOpts
:=
openstackOpts
.
lbOpts
// subnet-id is required
if
len
(
lbOpts
.
SubnetId
)
==
0
{
return
fmt
.
Errorf
(
"subnet-id not set in cloud provider config"
)
}
// if need to create health monitor for Neutron LB,
// monitor-delay, monitor-timeout and monitor-max-retries should be set.
emptyDuration
:=
MyDuration
{}
if
lbOpts
.
CreateMonitor
{
if
lbOpts
.
MonitorDelay
==
emptyDuration
{
return
fmt
.
Errorf
(
"monitor-delay not set in cloud provider config"
)
}
if
lbOpts
.
MonitorTimeout
==
emptyDuration
{
return
fmt
.
Errorf
(
"monitor-timeout not set in cloud provider config"
)
}
if
lbOpts
.
MonitorMaxRetries
==
uint
(
0
)
{
return
fmt
.
Errorf
(
"monitor-max-retries not set in cloud provider config"
)
}
}
// if enable ManageSecurityGroups, node-security-group should be set.
if
lbOpts
.
ManageSecurityGroups
{
if
len
(
lbOpts
.
NodeSecurityGroupID
)
==
0
{
return
fmt
.
Errorf
(
"node-security-group not set in cloud provider config"
)
}
}
return
nil
}
func
newOpenStack
(
cfg
Config
)
(
*
OpenStack
,
error
)
{
func
newOpenStack
(
cfg
Config
)
(
*
OpenStack
,
error
)
{
provider
,
err
:=
openstack
.
NewClient
(
cfg
.
Global
.
AuthUrl
)
provider
,
err
:=
openstack
.
NewClient
(
cfg
.
Global
.
AuthUrl
)
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -260,6 +294,11 @@ func newOpenStack(cfg Config) (*OpenStack, error) {
...
@@ -260,6 +294,11 @@ func newOpenStack(cfg Config) (*OpenStack, error) {
localInstanceID
:
id
,
localInstanceID
:
id
,
}
}
err
=
checkOpenStackOpts
(
&
os
)
if
err
!=
nil
{
return
nil
,
err
}
return
&
os
,
nil
return
&
os
,
nil
}
}
...
...
pkg/cloudprovider/providers/openstack/openstack_test.go
View file @
d2ebb604
...
@@ -144,6 +144,100 @@ func TestToAuthOptions(t *testing.T) {
...
@@ -144,6 +144,100 @@ func TestToAuthOptions(t *testing.T) {
}
}
}
}
func
TestCheckOpenStackOpts
(
t
*
testing
.
T
)
{
delay
:=
MyDuration
{
60
*
time
.
Second
}
timeout
:=
MyDuration
{
30
*
time
.
Second
}
tests
:=
[]
struct
{
name
string
openstackOpts
*
OpenStack
expectedError
error
}{
{
name
:
"test1"
,
openstackOpts
:
&
OpenStack
{
provider
:
nil
,
lbOpts
:
LoadBalancerOpts
{
LBVersion
:
"v2"
,
SubnetId
:
"6261548e-ffde-4bc7-bd22-59c83578c5ef"
,
FloatingNetworkId
:
"38b8b5f9-64dc-4424-bf86-679595714786"
,
LBMethod
:
"ROUND_ROBIN"
,
CreateMonitor
:
true
,
MonitorDelay
:
delay
,
MonitorTimeout
:
timeout
,
MonitorMaxRetries
:
uint
(
3
),
ManageSecurityGroups
:
true
,
NodeSecurityGroupID
:
"b41d28c2-d02f-4e1e-8ffb-23b8e4f5c144"
,
},
},
expectedError
:
nil
,
},
{
name
:
"test2"
,
openstackOpts
:
&
OpenStack
{
provider
:
nil
,
lbOpts
:
LoadBalancerOpts
{
LBVersion
:
"v2"
,
FloatingNetworkId
:
"38b8b5f9-64dc-4424-bf86-679595714786"
,
LBMethod
:
"ROUND_ROBIN"
,
CreateMonitor
:
true
,
MonitorDelay
:
delay
,
MonitorTimeout
:
timeout
,
MonitorMaxRetries
:
uint
(
3
),
ManageSecurityGroups
:
true
,
NodeSecurityGroupID
:
"b41d28c2-d02f-4e1e-8ffb-23b8e4f5c144"
,
},
},
expectedError
:
fmt
.
Errorf
(
"subnet-id not set in cloud provider config"
),
},
{
name
:
"test3"
,
openstackOpts
:
&
OpenStack
{
provider
:
nil
,
lbOpts
:
LoadBalancerOpts
{
LBVersion
:
"v2"
,
SubnetId
:
"6261548e-ffde-4bc7-bd22-59c83578c5ef"
,
FloatingNetworkId
:
"38b8b5f9-64dc-4424-bf86-679595714786"
,
LBMethod
:
"ROUND_ROBIN"
,
CreateMonitor
:
true
,
ManageSecurityGroups
:
true
,
NodeSecurityGroupID
:
"b41d28c2-d02f-4e1e-8ffb-23b8e4f5c144"
,
},
},
expectedError
:
fmt
.
Errorf
(
"monitor-delay not set in cloud provider config"
),
},
{
name
:
"test4"
,
openstackOpts
:
&
OpenStack
{
provider
:
nil
,
lbOpts
:
LoadBalancerOpts
{
LBVersion
:
"v2"
,
SubnetId
:
"6261548e-ffde-4bc7-bd22-59c83578c5ef"
,
FloatingNetworkId
:
"38b8b5f9-64dc-4424-bf86-679595714786"
,
LBMethod
:
"ROUND_ROBIN"
,
CreateMonitor
:
true
,
MonitorDelay
:
delay
,
MonitorTimeout
:
timeout
,
MonitorMaxRetries
:
uint
(
3
),
ManageSecurityGroups
:
true
,
},
},
expectedError
:
fmt
.
Errorf
(
"node-security-group not set in cloud provider config"
),
},
}
for
_
,
testcase
:=
range
tests
{
err
:=
checkOpenStackOpts
(
testcase
.
openstackOpts
)
if
err
==
nil
&&
testcase
.
expectedError
==
nil
{
continue
}
if
(
err
!=
nil
&&
testcase
.
expectedError
==
nil
)
||
(
err
==
nil
&&
testcase
.
expectedError
!=
nil
)
||
err
.
Error
()
!=
testcase
.
expectedError
.
Error
()
{
t
.
Errorf
(
"%s failed: expected err=%q, got %q"
,
testcase
.
name
,
testcase
.
expectedError
,
err
)
}
}
}
func
TestCaller
(
t
*
testing
.
T
)
{
func
TestCaller
(
t
*
testing
.
T
)
{
called
:=
false
called
:=
false
myFunc
:=
func
()
{
called
=
true
}
myFunc
:=
func
()
{
called
=
true
}
...
...
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