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
6b9de2bd
Unverified
Commit
6b9de2bd
authored
Oct 10, 2018
by
k8s-ci-robot
Committed by
GitHub
Oct 10, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #69388 from cheftako/GetClusters
Differentiate multizone zonal from Regional Cluster.
parents
a8c7a3fd
8b3099ce
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
53 additions
and
13 deletions
+53
-13
configure-helper.sh
cluster/gce/gci/configure-helper.sh
+9
-0
gce.go
pkg/cloudprovider/providers/gce/gce.go
+10
-1
gce_clusters.go
pkg/cloudprovider/providers/gce/gce_clusters.go
+17
-12
gce_test.go
pkg/cloudprovider/providers/gce/gce_test.go
+17
-0
No files found.
cluster/gce/gci/configure-helper.sh
View file @
6b9de2bd
...
@@ -663,6 +663,15 @@ EOF
...
@@ -663,6 +663,15 @@ EOF
multizone =
${
MULTIZONE
}
multizone =
${
MULTIZONE
}
EOF
EOF
fi
fi
# Multimaster indicates that the cluster is HA.
# Currently the only HA clusters are regional.
# If we introduce zonal multimaster this will need to be revisited.
if
[[
-n
"
${
MULTIMASTER
:-}
"
]]
;
then
use_cloud_config
=
"true"
cat
<<
EOF
>>/etc/gce.conf
regional =
${
MULTIMASTER
}
EOF
fi
if
[[
-n
"
${
GCE_ALPHA_FEATURES
:-}
"
]]
;
then
if
[[
-n
"
${
GCE_ALPHA_FEATURES
:-}
"
]]
;
then
use_cloud_config
=
"true"
use_cloud_config
=
"true"
# split GCE_ALPHA_FEATURES into an array by comma.
# split GCE_ALPHA_FEATURES into an array by comma.
...
...
pkg/cloudprovider/providers/gce/gce.go
View file @
6b9de2bd
...
@@ -114,6 +114,7 @@ type GCECloud struct {
...
@@ -114,6 +114,7 @@ type GCECloud struct {
eventRecorder
record
.
EventRecorder
eventRecorder
record
.
EventRecorder
projectID
string
projectID
string
region
string
region
string
regional
bool
localZone
string
// The zone in which we are running
localZone
string
// The zone in which we are running
// managedZones will be set to the 1 zone if running a single zone cluster
// managedZones will be set to the 1 zone if running a single zone cluster
// it will be set to ALL zones in region for any multi-zone cluster
// it will be set to ALL zones in region for any multi-zone cluster
...
@@ -174,6 +175,7 @@ type ConfigGlobal struct {
...
@@ -174,6 +175,7 @@ type ConfigGlobal struct {
SecondaryRangeName
string
`gcfg:"secondary-range-name"`
SecondaryRangeName
string
`gcfg:"secondary-range-name"`
NodeTags
[]
string
`gcfg:"node-tags"`
NodeTags
[]
string
`gcfg:"node-tags"`
NodeInstancePrefix
string
`gcfg:"node-instance-prefix"`
NodeInstancePrefix
string
`gcfg:"node-instance-prefix"`
Regional
bool
`gcfg:"regional"`
Multizone
bool
`gcfg:"multizone"`
Multizone
bool
`gcfg:"multizone"`
// ApiEndpoint is the GCE compute API endpoint to use. If this is blank,
// ApiEndpoint is the GCE compute API endpoint to use. If this is blank,
// then the default endpoint is used.
// then the default endpoint is used.
...
@@ -202,6 +204,7 @@ type CloudConfig struct {
...
@@ -202,6 +204,7 @@ type CloudConfig struct {
ProjectID
string
ProjectID
string
NetworkProjectID
string
NetworkProjectID
string
Region
string
Region
string
Regional
bool
Zone
string
Zone
string
ManagedZones
[]
string
ManagedZones
[]
string
NetworkName
string
NetworkName
string
...
@@ -332,9 +335,14 @@ func generateCloudConfig(configFile *ConfigFile) (cloudConfig *CloudConfig, err
...
@@ -332,9 +335,14 @@ func generateCloudConfig(configFile *ConfigFile) (cloudConfig *CloudConfig, err
return
nil
,
err
return
nil
,
err
}
}
// Determine if its a regional cluster
if
configFile
!=
nil
&&
configFile
.
Global
.
Regional
{
cloudConfig
.
Regional
=
true
}
// generate managedZones
// generate managedZones
cloudConfig
.
ManagedZones
=
[]
string
{
cloudConfig
.
Zone
}
cloudConfig
.
ManagedZones
=
[]
string
{
cloudConfig
.
Zone
}
if
configFile
!=
nil
&&
configFile
.
Global
.
Multizone
{
if
configFile
!=
nil
&&
(
configFile
.
Global
.
Multizone
||
configFile
.
Global
.
Regional
)
{
cloudConfig
.
ManagedZones
=
nil
// Use all zones in region
cloudConfig
.
ManagedZones
=
nil
// Use all zones in region
}
}
...
@@ -512,6 +520,7 @@ func CreateGCECloud(config *CloudConfig) (*GCECloud, error) {
...
@@ -512,6 +520,7 @@ func CreateGCECloud(config *CloudConfig) (*GCECloud, error) {
networkProjectID
:
netProjID
,
networkProjectID
:
netProjID
,
onXPN
:
onXPN
,
onXPN
:
onXPN
,
region
:
config
.
Region
,
region
:
config
.
Region
,
regional
:
config
.
Regional
,
localZone
:
config
.
Zone
,
localZone
:
config
.
Zone
,
managedZones
:
config
.
ManagedZones
,
managedZones
:
config
.
ManagedZones
,
networkURL
:
networkURL
,
networkURL
:
networkURL
,
...
...
pkg/cloudprovider/providers/gce/gce_clusters.go
View file @
6b9de2bd
...
@@ -45,22 +45,27 @@ func (gce *GCECloud) ListClusters(ctx context.Context) ([]string, error) {
...
@@ -45,22 +45,27 @@ func (gce *GCECloud) ListClusters(ctx context.Context) ([]string, error) {
}
}
func
(
gce
*
GCECloud
)
GetManagedClusters
(
ctx
context
.
Context
)
([]
*
container
.
Cluster
,
error
)
{
func
(
gce
*
GCECloud
)
GetManagedClusters
(
ctx
context
.
Context
)
([]
*
container
.
Cluster
,
error
)
{
var
location
string
managedClusters
:=
[]
*
container
.
Cluster
{}
if
len
(
gce
.
managedZones
)
>
1
{
// Multiple managed zones means this is a regional cluster
if
gce
.
regional
{
// so use the regional location and not the zone.
var
err
error
location
=
gce
.
region
managedClusters
,
err
=
gce
.
getClustersInLocation
(
gce
.
region
)
}
else
if
len
(
gce
.
managedZones
)
==
1
{
if
err
!=
nil
{
location
=
gce
.
managedZones
[
0
]
return
nil
,
err
}
}
else
if
len
(
gce
.
managedZones
)
>=
1
{
for
_
,
zone
:=
range
gce
.
managedZones
{
clusters
,
err
:=
gce
.
getClustersInLocation
(
zone
)
if
err
!=
nil
{
return
nil
,
err
}
managedClusters
=
append
(
managedClusters
,
clusters
...
)
}
}
else
{
}
else
{
return
nil
,
errors
.
New
(
fmt
.
Sprintf
(
"no zones associated with this cluster(%s)"
,
gce
.
ProjectID
()))
return
nil
,
errors
.
New
(
fmt
.
Sprintf
(
"no zones associated with this cluster(%s)"
,
gce
.
ProjectID
()))
}
}
clusters
,
err
:=
gce
.
getClustersInLocation
(
location
)
if
err
!=
nil
{
return
nil
,
err
}
return
c
lusters
,
nil
return
managedC
lusters
,
nil
}
}
func
(
gce
*
GCECloud
)
Master
(
ctx
context
.
Context
,
clusterName
string
)
(
string
,
error
)
{
func
(
gce
*
GCECloud
)
Master
(
ctx
context
.
Context
,
clusterName
string
)
(
string
,
error
)
{
...
...
pkg/cloudprovider/providers/gce/gce_test.go
View file @
6b9de2bd
...
@@ -39,6 +39,7 @@ secondary-range-name = my-secondary-range
...
@@ -39,6 +39,7 @@ secondary-range-name = my-secondary-range
node-tags = my-node-tag1
node-tags = my-node-tag1
node-instance-prefix = my-prefix
node-instance-prefix = my-prefix
multizone = true
multizone = true
regional = true
`
`
reader
:=
strings
.
NewReader
(
s
)
reader
:=
strings
.
NewReader
(
s
)
config
,
err
:=
readConfig
(
reader
)
config
,
err
:=
readConfig
(
reader
)
...
@@ -57,6 +58,7 @@ multizone = true
...
@@ -57,6 +58,7 @@ multizone = true
NodeTags
:
[]
string
{
"my-node-tag1"
},
NodeTags
:
[]
string
{
"my-node-tag1"
},
NodeInstancePrefix
:
"my-prefix"
,
NodeInstancePrefix
:
"my-prefix"
,
Multizone
:
true
,
Multizone
:
true
,
Regional
:
true
,
}}
}}
if
!
reflect
.
DeepEqual
(
expected
,
config
)
{
if
!
reflect
.
DeepEqual
(
expected
,
config
)
{
...
@@ -328,6 +330,7 @@ func TestGenerateCloudConfigs(t *testing.T) {
...
@@ -328,6 +330,7 @@ func TestGenerateCloudConfigs(t *testing.T) {
NodeTags
:
[]
string
{
"node-tag"
},
NodeTags
:
[]
string
{
"node-tag"
},
NodeInstancePrefix
:
"node-prefix"
,
NodeInstancePrefix
:
"node-prefix"
,
Multizone
:
false
,
Multizone
:
false
,
Regional
:
false
,
ApiEndpoint
:
""
,
ApiEndpoint
:
""
,
LocalZone
:
"us-central1-a"
,
LocalZone
:
"us-central1-a"
,
AlphaFeatures
:
[]
string
{},
AlphaFeatures
:
[]
string
{},
...
@@ -447,6 +450,20 @@ func TestGenerateCloudConfigs(t *testing.T) {
...
@@ -447,6 +450,20 @@ func TestGenerateCloudConfigs(t *testing.T) {
},
},
},
},
{
{
name
:
"Regional"
,
config
:
func
()
ConfigGlobal
{
v
:=
configBoilerplate
v
.
Regional
=
true
return
v
},
cloud
:
func
()
CloudConfig
{
v
:=
cloudBoilerplate
v
.
Regional
=
true
v
.
ManagedZones
=
nil
return
v
},
},
{
name
:
"Secondary Range Name"
,
name
:
"Secondary Range Name"
,
config
:
func
()
ConfigGlobal
{
config
:
func
()
ConfigGlobal
{
v
:=
configBoilerplate
v
:=
configBoilerplate
...
...
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