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
3e8b4a27
Commit
3e8b4a27
authored
Jul 07, 2017
by
Minhan Xia
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
use overrided api endpoint in gce cloud provider
parent
98ce6982
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
78 additions
and
25 deletions
+78
-25
config-default.sh
cluster/gce/config-default.sh
+3
-1
config-test.sh
cluster/gce/config-test.sh
+3
-0
gce.go
pkg/cloudprovider/providers/gce/gce.go
+18
-7
gce_disks.go
pkg/cloudprovider/providers/gce/gce_disks.go
+9
-6
gce_disks_test.go
pkg/cloudprovider/providers/gce/gce_disks_test.go
+1
-1
gce_instances.go
pkg/cloudprovider/providers/gce/gce_instances.go
+3
-3
gce_loadbalancer_external.go
pkg/cloudprovider/providers/gce/gce_loadbalancer_external.go
+4
-5
gce_loadbalancer_internal.go
pkg/cloudprovider/providers/gce/gce_loadbalancer_internal.go
+1
-1
gce_zones.go
pkg/cloudprovider/providers/gce/gce_zones.go
+2
-1
BUILD
vendor/BUILD
+1
-0
BUILD
vendor/google.golang.org/api/compute/v0.alpha/BUILD
+33
-0
No files found.
cluster/gce/config-default.sh
View file @
3e8b4a27
...
...
@@ -19,6 +19,9 @@
KUBE_ROOT
=
$(
dirname
"
${
BASH_SOURCE
}
"
)
/../..
source
"
${
KUBE_ROOT
}
/cluster/gce/config-common.sh"
# Specifying KUBE_GCE_API_ENDPOINT will override the default GCE Compute API endpoint (https://www.googleapis.com/compute/v1/).
# This endpoint has to be pointing to v1 api. For example, https://www.googleapis.com/compute/staging_v1/
GCE_API_ENDPOINT
=
${
KUBE_GCE_API_ENDPOINT
:-}
GCLOUD
=
gcloud
ZONE
=
${
KUBE_GCE_ZONE
:-
us
-central1-b
}
REGION
=
${
ZONE
%-*
}
...
...
@@ -73,7 +76,6 @@ GCI_VERSION=${KUBE_GCI_VERSION:-cos-stable-59-9460-64-0}
MASTER_IMAGE
=
${
KUBE_GCE_MASTER_IMAGE
:-}
MASTER_IMAGE_PROJECT
=
${
KUBE_GCE_MASTER_PROJECT
:-
cos
-cloud
}
NODE_IMAGE
=
${
KUBE_GCE_NODE_IMAGE
:-${
GCI_VERSION
}}
GCE_API_ENDPOINT
=
${
KUBE_GCE_API_ENDPOINT
:-}
NODE_IMAGE_PROJECT
=
${
KUBE_GCE_NODE_PROJECT
:-
cos
-cloud
}
CONTAINER_RUNTIME
=
${
KUBE_CONTAINER_RUNTIME
:-
docker
}
RKT_VERSION
=
${
KUBE_RKT_VERSION
:-
1
.23.0
}
...
...
cluster/gce/config-test.sh
View file @
3e8b4a27
...
...
@@ -19,6 +19,9 @@
KUBE_ROOT
=
$(
dirname
"
${
BASH_SOURCE
}
"
)
/../..
source
"
${
KUBE_ROOT
}
/cluster/gce/config-common.sh"
# Specifying KUBE_GCE_API_ENDPOINT will override the default GCE Compute API endpoint (https://www.googleapis.com/compute/v1/).
# This endpoint has to be pointing to v1 api. For example, https://www.googleapis.com/compute/staging_v1/
GCE_API_ENDPOINT
=
${
KUBE_GCE_API_ENDPOINT
:-}
GCLOUD
=
gcloud
ZONE
=
${
KUBE_GCE_ZONE
:-
us
-central1-b
}
REGION
=
${
ZONE
%-*
}
...
...
pkg/cloudprovider/providers/gce/gce.go
View file @
3e8b4a27
...
...
@@ -76,6 +76,8 @@ const (
gceHcHealthyThreshold
=
int64
(
1
)
// Defaults to 5 * 2 = 10 seconds before the LB will steer traffic away
gceHcUnhealthyThreshold
=
int64
(
5
)
gceComputeAPIEndpoint
=
"https://www.googleapis.com/compute/v1/"
)
// GCECloud is an implementation of Interface, LoadBalancer and Instances for Google Compute Engine.
...
...
@@ -146,7 +148,8 @@ type Config struct {
NodeTags
[]
string
`gcfg:"node-tags"`
NodeInstancePrefix
string
`gcfg:"node-instance-prefix"`
Multizone
bool
`gcfg:"multizone"`
ApiEndpoint
string
`gcfg:"api-endpoint"`
// Specifying ApiEndpoint will override the default GCE compute API endpoint.
ApiEndpoint
string
`gcfg:"api-endpoint"`
}
}
...
...
@@ -269,24 +272,33 @@ func CreateGCECloud(apiEndpoint, projectID, networkProjectID, region, zone strin
if
err
!=
nil
{
return
nil
,
err
}
service
,
err
:=
compute
.
New
(
client
)
if
err
!=
nil
{
return
nil
,
err
}
client
,
err
=
newOauthClient
(
tokenSource
)
if
err
!=
nil
{
return
nil
,
err
}
serviceBeta
,
err
:=
computebeta
.
New
(
client
)
if
err
!=
nil
{
return
nil
,
err
}
client
,
err
=
newOauthClient
(
tokenSource
)
if
err
!=
nil
{
return
nil
,
err
}
serviceAlpha
,
err
:=
computealpha
.
New
(
client
)
if
err
!=
nil
{
return
nil
,
err
}
// Expect override api endpoint to always be v1 api and follows the same pattern as prod.
// Generate alpha and beta api endpoints based on override v1 api endpoint.
// For example,
// staging API endpoint: https://www.googleapis.com/compute/staging_v1/
if
apiEndpoint
!=
""
{
service
.
BasePath
=
fmt
.
Sprintf
(
"%sprojects/"
,
apiEndpoint
)
serviceBeta
.
BasePath
=
fmt
.
Sprintf
(
"%sprojects/"
,
strings
.
Replace
(
apiEndpoint
,
"v1"
,
"beta"
,
0
))
...
...
@@ -423,16 +435,16 @@ var _ cloudprovider.Interface = (*GCECloud)(nil)
func
gceNetworkURL
(
apiEndpoint
,
project
,
network
string
)
string
{
if
apiEndpoint
==
""
{
apiEndpoint
=
"https://www.googleapis.com/compute/v1/"
apiEndpoint
=
gceComputeAPIEndpoint
}
return
fmt
.
Sprintf
(
"%vprojects/%s/global/networks/%s"
,
apiEndpoint
,
project
,
network
)
return
apiEndpoint
+
strings
.
Join
([]
string
{
"projects"
,
project
,
"global"
,
"networks"
,
network
},
"/"
)
}
func
gceSubnetworkURL
(
apiEndpoint
,
project
,
region
,
subnetwork
string
)
string
{
if
apiEndpoint
==
""
{
apiEndpoint
=
"https://www.googleapis.com/compute/v1/"
apiEndpoint
=
gceComputeAPIEndpoint
}
return
fmt
.
Sprintf
(
"%vprojects/%s/regions/%s/subnetworks/%s"
,
apiEndpoint
,
project
,
region
,
subnetwork
)
return
apiEndpoint
+
strings
.
Join
([]
string
{
"projects"
,
project
,
"regions"
,
region
,
"subnetworks"
,
subnetwork
},
"/"
)
}
// Project IDs cannot have a digit for the first characeter. If the id contains a digit,
...
...
@@ -441,7 +453,6 @@ func isProjectNumber(idOrNumber string) bool {
if
len
(
idOrNumber
)
==
0
{
return
false
}
return
idOrNumber
[
0
]
>=
'0'
&&
idOrNumber
[
0
]
<=
'9'
}
...
...
pkg/cloudprovider/providers/gce/gce_disks.go
View file @
3e8b4a27
...
...
@@ -20,7 +20,6 @@ import (
"encoding/json"
"fmt"
"net/http"
"path"
"strings"
"time"
...
...
@@ -41,7 +40,7 @@ const (
DiskTypeStandard
=
"pd-standard"
diskTypeDefault
=
DiskTypeStandard
diskTypeUriTemplate
=
"
https://www.googleapis.com/compute/v1/projects/
%s/zones/%s/diskTypes/%s"
diskTypeUriTemplate
=
"%s/zones/%s/diskTypes/%s"
)
// Disks is interface for manipulation with GCE PDs.
...
...
@@ -234,7 +233,12 @@ func (gce *GCECloud) CreateDisk(
default
:
return
fmt
.
Errorf
(
"invalid GCE disk type %q"
,
diskType
)
}
diskTypeUri
:=
fmt
.
Sprintf
(
diskTypeUriTemplate
,
gce
.
projectID
,
zone
,
diskType
)
apiEndpoint
:=
gceComputeAPIEndpoint
+
"projects/"
if
gce
.
service
!=
nil
{
apiEndpoint
=
gce
.
service
.
BasePath
}
diskTypeUri
:=
apiEndpoint
+
fmt
.
Sprintf
(
diskTypeUriTemplate
,
gce
.
projectID
,
zone
,
diskType
)
diskToCreate
:=
&
compute
.
Disk
{
Name
:
name
,
...
...
@@ -424,9 +428,8 @@ func (gce *GCECloud) convertDiskToAttachedDisk(disk *GCEDisk, readWrite string)
DeviceName
:
disk
.
Name
,
Kind
:
disk
.
Kind
,
Mode
:
readWrite
,
Source
:
"https://"
+
path
.
Join
(
"www.googleapis.com/compute/v1/projects/"
,
gce
.
projectID
,
"zones"
,
disk
.
Zone
,
"disks"
,
disk
.
Name
),
Source
:
gce
.
service
.
BasePath
+
strings
.
Join
([]
string
{
gce
.
projectID
,
"zones"
,
disk
.
Zone
,
"disks"
,
disk
.
Name
},
"/"
),
Type
:
"PERSISTENT"
,
}
}
...
...
pkg/cloudprovider/providers/gce/gce_disks_test.go
View file @
3e8b4a27
...
...
@@ -43,7 +43,7 @@ func TestCreateDisk_Basic(t *testing.T) {
tags
:=
make
(
map
[
string
]
string
)
tags
[
"test-tag"
]
=
"test-value"
diskTypeUri
:=
fmt
.
Sprintf
(
diskTypeUriTemplate
,
projectId
,
zone
,
diskType
)
diskTypeUri
:=
gceComputeAPIEndpoint
+
"projects/"
+
fmt
.
Sprintf
(
diskTypeUriTemplate
,
projectId
,
zone
,
diskType
)
expectedDescription
:=
"{
\"
test-tag
\"
:
\"
test-value
\"
}"
/* Act */
...
...
pkg/cloudprovider/providers/gce/gce_instances.go
View file @
3e8b4a27
...
...
@@ -25,7 +25,7 @@ import (
"cloud.google.com/go/compute/metadata"
"github.com/golang/glog"
compute
alph
a
"google.golang.org/api/compute/v0.beta"
compute
bet
a
"google.golang.org/api/compute/v0.beta"
compute
"google.golang.org/api/compute/v1"
"k8s.io/api/core/v1"
...
...
@@ -69,7 +69,7 @@ func getZone(n *v1.Node) string {
// ToInstanceReferences returns instance references by links
func
(
gce
*
GCECloud
)
ToInstanceReferences
(
zone
string
,
instanceNames
[]
string
)
(
refs
[]
*
compute
.
InstanceReference
)
{
for
_
,
ins
:=
range
instanceNames
{
instanceLink
:=
makeHostURL
(
gce
.
projectID
,
zone
,
ins
)
instanceLink
:=
makeHostURL
(
gce
.
service
.
BasePath
,
gce
.
projectID
,
zone
,
ins
)
refs
=
append
(
refs
,
&
compute
.
InstanceReference
{
Instance
:
instanceLink
})
}
return
refs
...
...
@@ -303,7 +303,7 @@ func (gce *GCECloud) AliasRanges(nodeName types.NodeName) (cidrs []string, err e
return
}
var
res
*
compute
alph
a
.
Instance
var
res
*
compute
bet
a
.
Instance
res
,
err
=
gce
.
serviceBeta
.
Instances
.
Get
(
gce
.
projectID
,
instance
.
Zone
,
instance
.
Name
)
.
Do
()
if
err
!=
nil
{
...
...
pkg/cloudprovider/providers/gce/gce_loadbalancer_external.go
View file @
3e8b4a27
...
...
@@ -483,7 +483,7 @@ func (gce *GCECloud) createTargetPool(name, serviceName, ipAddress, region, clus
var
instances
[]
string
for
_
,
host
:=
range
hosts
{
instances
=
append
(
instances
,
makeHostURL
(
gce
.
projectID
,
host
.
Zone
,
host
.
Name
))
instances
=
append
(
instances
,
makeHostURL
(
gce
.
service
.
BasePath
,
gce
.
projectID
,
host
.
Zone
,
host
.
Name
))
}
glog
.
Infof
(
"Creating targetpool %v with %d healthchecks"
,
name
,
len
(
hcLinks
))
pool
:=
&
compute
.
TargetPool
{
...
...
@@ -542,7 +542,7 @@ func (gce *GCECloud) updateTargetPool(loadBalancerName string, existing sets.Str
}
func
(
gce
*
GCECloud
)
targetPoolURL
(
name
,
region
string
)
string
{
return
fmt
.
Sprintf
(
"https://www.googleapis.com/compute/v1/projects/%s/regions/%s/targetPools/%s"
,
gce
.
projectID
,
region
,
name
)
return
gce
.
service
.
BasePath
+
strings
.
Join
([]
string
{
"projects"
,
gce
.
projectID
,
"regions"
,
region
,
"targetPools"
,
name
},
"/"
)
}
func
makeHttpHealthCheck
(
name
,
path
string
,
port
int32
)
*
compute
.
HttpHealthCheck
{
...
...
@@ -671,10 +671,9 @@ func nodeNames(nodes []*v1.Node) []string {
return
ret
}
func
makeHostURL
(
projectID
,
zone
,
host
string
)
string
{
func
makeHostURL
(
apiEndpoint
,
projectID
,
zone
,
host
string
)
string
{
host
=
canonicalizeInstanceName
(
host
)
return
fmt
.
Sprintf
(
"https://www.googleapis.com/compute/v1/projects/%s/zones/%s/instances/%s"
,
projectID
,
zone
,
host
)
return
apiEndpoint
+
strings
.
Join
([]
string
{
"projects"
,
projectID
,
"zones"
,
zone
,
"instances"
,
host
},
"/"
)
}
func
hostURLToComparablePath
(
hostURL
string
)
string
{
...
...
pkg/cloudprovider/providers/gce/gce_loadbalancer_internal.go
View file @
3e8b4a27
...
...
@@ -624,7 +624,7 @@ func getPortsAndProtocol(svcPorts []v1.ServicePort) (ports []string, protocol v1
}
func
(
gce
*
GCECloud
)
getBackendServiceLink
(
name
string
)
string
{
return
fmt
.
Sprintf
(
"https://www.googleapis.com/compute/v1/projects/%s/regions/%s/backendServices/%s"
,
gce
.
projectID
,
gce
.
region
,
name
)
return
gce
.
service
.
BasePath
+
strings
.
Join
([]
string
{
"projects"
,
gce
.
projectID
,
"regions"
,
gce
.
region
,
"backendServices"
,
name
},
"/"
)
}
func
getNameFromLink
(
link
string
)
string
{
...
...
pkg/cloudprovider/providers/gce/gce_zones.go
View file @
3e8b4a27
...
...
@@ -23,6 +23,7 @@ import (
compute
"google.golang.org/api/compute/v1"
"k8s.io/kubernetes/pkg/cloudprovider"
"strings"
)
func
newZonesMetricContext
(
request
,
region
string
)
*
metricContext
{
...
...
@@ -52,5 +53,5 @@ func (gce *GCECloud) ListZonesInRegion(region string) ([]*compute.Zone, error) {
}
func
(
gce
*
GCECloud
)
getRegionLink
(
region
string
)
string
{
return
fmt
.
Sprintf
(
"https://www.googleapis.com/compute/v1/projects/%v/regions/%v"
,
gce
.
networkProjectID
,
region
)
return
gce
.
service
.
BasePath
+
strings
.
Join
([]
string
{
"projects"
,
gce
.
networkProjectID
,
"regions"
,
region
},
"/"
)
}
vendor/BUILD
View file @
3e8b4a27
...
...
@@ -352,6 +352,7 @@ filegroup(
"//vendor/golang.org/x/tools/container/intsets:all-srcs",
"//vendor/google.golang.org/api/cloudkms/v1:all-srcs",
"//vendor/google.golang.org/api/cloudmonitoring/v2beta2:all-srcs",
"//vendor/google.golang.org/api/compute/v0.alpha:all-srcs",
"//vendor/google.golang.org/api/compute/v0.beta:all-srcs",
"//vendor/google.golang.org/api/compute/v1:all-srcs",
"//vendor/google.golang.org/api/container/v1:all-srcs",
...
...
vendor/google.golang.org/api/compute/v0.alpha/BUILD
0 → 100644
View file @
3e8b4a27
package(default_visibility = ["//visibility:public"])
licenses(["notice"])
load(
"@io_bazel_rules_go//go:def.bzl",
"go_library",
)
go_library(
name = "go_default_library",
srcs = ["compute-gen.go"],
tags = ["automanaged"],
deps = [
"//vendor/golang.org/x/net/context:go_default_library",
"//vendor/golang.org/x/net/context/ctxhttp:go_default_library",
"//vendor/google.golang.org/api/gensupport:go_default_library",
"//vendor/google.golang.org/api/googleapi:go_default_library",
],
)
filegroup(
name = "package-srcs",
srcs = glob(["**"]),
tags = ["automanaged"],
visibility = ["//visibility:private"],
)
filegroup(
name = "all-srcs",
srcs = [":package-srcs"],
tags = ["automanaged"],
)
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