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
435303c6
Commit
435303c6
authored
May 24, 2017
by
Nick Sardo
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add subnetworkURL to GCE provider
parent
95a6f108
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
18 additions
and
3 deletions
+18
-3
gce.go
pkg/cloudprovider/providers/gce/gce.go
+18
-3
No files found.
pkg/cloudprovider/providers/gce/gce.go
View file @
435303c6
...
@@ -84,6 +84,7 @@ type GCECloud struct {
...
@@ -84,6 +84,7 @@ type GCECloud struct {
localZone
string
// The zone in which we are running
localZone
string
// The zone in which we are running
managedZones
[]
string
// List of zones we are spanning (for multi-AZ clusters, primarily when running on master)
managedZones
[]
string
// List of zones we are spanning (for multi-AZ clusters, primarily when running on master)
networkURL
string
networkURL
string
subnetworkURL
string
nodeTags
[]
string
// List of tags to use on firewall rules for load balancers
nodeTags
[]
string
// List of tags to use on firewall rules for load balancers
nodeInstancePrefix
string
// If non-"", an advisory prefix for all nodes in the cluster
nodeInstancePrefix
string
// If non-"", an advisory prefix for all nodes in the cluster
useMetadataServer
bool
useMetadataServer
bool
...
@@ -96,6 +97,7 @@ type Config struct {
...
@@ -96,6 +97,7 @@ type Config struct {
TokenBody
string
`gcfg:"token-body"`
TokenBody
string
`gcfg:"token-body"`
ProjectID
string
`gcfg:"project-id"`
ProjectID
string
`gcfg:"project-id"`
NetworkName
string
`gcfg:"network-name"`
NetworkName
string
`gcfg:"network-name"`
SubnetworkName
string
`gcfg:"subnetwork-name"`
NodeTags
[]
string
`gcfg:"node-tags"`
NodeTags
[]
string
`gcfg:"node-tags"`
NodeInstancePrefix
string
`gcfg:"node-instance-prefix"`
NodeInstancePrefix
string
`gcfg:"node-instance-prefix"`
Multizone
bool
`gcfg:"multizone"`
Multizone
bool
`gcfg:"multizone"`
...
@@ -132,6 +134,7 @@ func newGCECloud(config io.Reader) (*GCECloud, error) {
...
@@ -132,6 +134,7 @@ func newGCECloud(config io.Reader) (*GCECloud, error) {
return
nil
,
err
return
nil
,
err
}
}
networkURL
:=
gceNetworkURL
(
projectID
,
networkName
)
networkURL
:=
gceNetworkURL
(
projectID
,
networkName
)
subnetworkURL
:=
""
// By default, Kubernetes clusters only run against one zone
// By default, Kubernetes clusters only run against one zone
managedZones
:=
[]
string
{
zone
}
managedZones
:=
[]
string
{
zone
}
...
@@ -156,6 +159,13 @@ func newGCECloud(config io.Reader) (*GCECloud, error) {
...
@@ -156,6 +159,13 @@ func newGCECloud(config io.Reader) (*GCECloud, error) {
networkURL
=
gceNetworkURL
(
cfg
.
Global
.
ProjectID
,
cfg
.
Global
.
NetworkName
)
networkURL
=
gceNetworkURL
(
cfg
.
Global
.
ProjectID
,
cfg
.
Global
.
NetworkName
)
}
}
}
}
if
cfg
.
Global
.
SubnetworkName
!=
""
{
if
strings
.
Contains
(
cfg
.
Global
.
SubnetworkName
,
"/"
)
{
subnetworkURL
=
cfg
.
Global
.
SubnetworkName
}
else
{
subnetworkURL
=
gceSubnetworkURL
(
cfg
.
Global
.
ProjectID
,
region
,
cfg
.
Global
.
SubnetworkName
)
}
}
if
cfg
.
Global
.
TokenURL
!=
""
{
if
cfg
.
Global
.
TokenURL
!=
""
{
tokenSource
=
NewAltTokenSource
(
cfg
.
Global
.
TokenURL
,
cfg
.
Global
.
TokenBody
)
tokenSource
=
NewAltTokenSource
(
cfg
.
Global
.
TokenURL
,
cfg
.
Global
.
TokenBody
)
}
}
...
@@ -166,15 +176,15 @@ func newGCECloud(config io.Reader) (*GCECloud, error) {
...
@@ -166,15 +176,15 @@ func newGCECloud(config io.Reader) (*GCECloud, error) {
}
}
}
}
return
CreateGCECloud
(
projectID
,
region
,
zone
,
managedZones
,
networkURL
,
nodeTags
,
return
CreateGCECloud
(
projectID
,
region
,
zone
,
managedZones
,
networkURL
,
subnetworkURL
,
nodeInstancePrefix
,
tokenSource
,
true
/* useMetadataServer */
)
node
Tags
,
node
InstancePrefix
,
tokenSource
,
true
/* useMetadataServer */
)
}
}
// Creates a GCECloud object using the specified parameters.
// Creates a GCECloud object using the specified parameters.
// If no networkUrl is specified, loads networkName via rest call.
// If no networkUrl is specified, loads networkName via rest call.
// If no tokenSource is specified, uses oauth2.DefaultTokenSource.
// If no tokenSource is specified, uses oauth2.DefaultTokenSource.
// If managedZones is nil / empty all zones in the region will be managed.
// If managedZones is nil / empty all zones in the region will be managed.
func
CreateGCECloud
(
projectID
,
region
,
zone
string
,
managedZones
[]
string
,
networkURL
string
,
nodeTags
[]
string
,
func
CreateGCECloud
(
projectID
,
region
,
zone
string
,
managedZones
[]
string
,
networkURL
,
subnetworkURL
string
,
nodeTags
[]
string
,
nodeInstancePrefix
string
,
tokenSource
oauth2
.
TokenSource
,
useMetadataServer
bool
)
(
*
GCECloud
,
error
)
{
nodeInstancePrefix
string
,
tokenSource
oauth2
.
TokenSource
,
useMetadataServer
bool
)
(
*
GCECloud
,
error
)
{
client
,
err
:=
newOauthClient
(
tokenSource
)
client
,
err
:=
newOauthClient
(
tokenSource
)
...
@@ -227,6 +237,7 @@ func CreateGCECloud(projectID, region, zone string, managedZones []string, netwo
...
@@ -227,6 +237,7 @@ func CreateGCECloud(projectID, region, zone string, managedZones []string, netwo
localZone
:
zone
,
localZone
:
zone
,
managedZones
:
managedZones
,
managedZones
:
managedZones
,
networkURL
:
networkURL
,
networkURL
:
networkURL
,
subnetworkURL
:
subnetworkURL
,
nodeTags
:
nodeTags
,
nodeTags
:
nodeTags
,
nodeInstancePrefix
:
nodeInstancePrefix
,
nodeInstancePrefix
:
nodeInstancePrefix
,
useMetadataServer
:
useMetadataServer
,
useMetadataServer
:
useMetadataServer
,
...
@@ -287,6 +298,10 @@ func gceNetworkURL(project, network string) string {
...
@@ -287,6 +298,10 @@ func gceNetworkURL(project, network string) string {
return
fmt
.
Sprintf
(
"https://www.googleapis.com/compute/v1/projects/%s/global/networks/%s"
,
project
,
network
)
return
fmt
.
Sprintf
(
"https://www.googleapis.com/compute/v1/projects/%s/global/networks/%s"
,
project
,
network
)
}
}
func
gceSubnetworkURL
(
project
,
region
,
subnetwork
string
)
string
{
return
fmt
.
Sprintf
(
"https://www.googleapis.com/compute/v1/projects/%s/regions/%s/subnetworks/%s"
,
project
,
region
,
subnetwork
)
}
func
getNetworkNameViaMetadata
()
(
string
,
error
)
{
func
getNetworkNameViaMetadata
()
(
string
,
error
)
{
result
,
err
:=
metadata
.
Get
(
"instance/network-interfaces/0/network"
)
result
,
err
:=
metadata
.
Get
(
"instance/network-interfaces/0/network"
)
if
err
!=
nil
{
if
err
!=
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