mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-04 18:00:08 +00:00
Add cloud
for the generated GCE interfaces, support structs
Note: this does not wire the generated code.
This commit is contained in:
parent
bc56a90e0b
commit
ac48b1b075
@ -41,12 +41,15 @@ go_library(
|
|||||||
"gce_util.go",
|
"gce_util.go",
|
||||||
"gce_zones.go",
|
"gce_zones.go",
|
||||||
"metrics.go",
|
"metrics.go",
|
||||||
|
"support.go",
|
||||||
"token_source.go",
|
"token_source.go",
|
||||||
],
|
],
|
||||||
importpath = "k8s.io/kubernetes/pkg/cloudprovider/providers/gce",
|
importpath = "k8s.io/kubernetes/pkg/cloudprovider/providers/gce",
|
||||||
deps = [
|
deps = [
|
||||||
"//pkg/api/v1/service:go_default_library",
|
"//pkg/api/v1/service:go_default_library",
|
||||||
"//pkg/cloudprovider:go_default_library",
|
"//pkg/cloudprovider:go_default_library",
|
||||||
|
"//pkg/cloudprovider/providers/gce/cloud:go_default_library",
|
||||||
|
"//pkg/cloudprovider/providers/gce/cloud/meta:go_default_library",
|
||||||
"//pkg/controller:go_default_library",
|
"//pkg/controller:go_default_library",
|
||||||
"//pkg/kubelet/apis:go_default_library",
|
"//pkg/kubelet/apis:go_default_library",
|
||||||
"//pkg/master/ports:go_default_library",
|
"//pkg/master/ports:go_default_library",
|
||||||
|
@ -30,6 +30,13 @@ import (
|
|||||||
gcfg "gopkg.in/gcfg.v1"
|
gcfg "gopkg.in/gcfg.v1"
|
||||||
|
|
||||||
"cloud.google.com/go/compute/metadata"
|
"cloud.google.com/go/compute/metadata"
|
||||||
|
"github.com/golang/glog"
|
||||||
|
"golang.org/x/oauth2"
|
||||||
|
"golang.org/x/oauth2/google"
|
||||||
|
computealpha "google.golang.org/api/compute/v0.alpha"
|
||||||
|
computebeta "google.golang.org/api/compute/v0.beta"
|
||||||
|
compute "google.golang.org/api/compute/v1"
|
||||||
|
container "google.golang.org/api/container/v1"
|
||||||
|
|
||||||
"k8s.io/api/core/v1"
|
"k8s.io/api/core/v1"
|
||||||
"k8s.io/apimachinery/pkg/util/sets"
|
"k8s.io/apimachinery/pkg/util/sets"
|
||||||
@ -41,18 +48,12 @@ import (
|
|||||||
"k8s.io/client-go/tools/cache"
|
"k8s.io/client-go/tools/cache"
|
||||||
"k8s.io/client-go/tools/record"
|
"k8s.io/client-go/tools/record"
|
||||||
"k8s.io/client-go/util/flowcontrol"
|
"k8s.io/client-go/util/flowcontrol"
|
||||||
|
|
||||||
"k8s.io/kubernetes/pkg/cloudprovider"
|
"k8s.io/kubernetes/pkg/cloudprovider"
|
||||||
|
"k8s.io/kubernetes/pkg/cloudprovider/providers/gce/cloud"
|
||||||
"k8s.io/kubernetes/pkg/controller"
|
"k8s.io/kubernetes/pkg/controller"
|
||||||
kubeletapis "k8s.io/kubernetes/pkg/kubelet/apis"
|
kubeletapis "k8s.io/kubernetes/pkg/kubelet/apis"
|
||||||
"k8s.io/kubernetes/pkg/version"
|
"k8s.io/kubernetes/pkg/version"
|
||||||
|
|
||||||
"github.com/golang/glog"
|
|
||||||
"golang.org/x/oauth2"
|
|
||||||
"golang.org/x/oauth2/google"
|
|
||||||
computealpha "google.golang.org/api/compute/v0.alpha"
|
|
||||||
computebeta "google.golang.org/api/compute/v0.beta"
|
|
||||||
compute "google.golang.org/api/compute/v1"
|
|
||||||
container "google.golang.org/api/container/v1"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -147,6 +148,9 @@ type GCECloud struct {
|
|||||||
// the corresponding api is enabled.
|
// the corresponding api is enabled.
|
||||||
// If not enabled, it should return error.
|
// If not enabled, it should return error.
|
||||||
AlphaFeatureGate *AlphaFeatureGate
|
AlphaFeatureGate *AlphaFeatureGate
|
||||||
|
|
||||||
|
// New code generated interface to the GCE compute library.
|
||||||
|
c cloud.Cloud
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: replace gcfg with json
|
// TODO: replace gcfg with json
|
||||||
@ -243,7 +247,6 @@ func newGCECloud(config io.Reader) (gceCloud *GCECloud, err error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return CreateGCECloud(cloudConfig)
|
return CreateGCECloud(cloudConfig)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func readConfig(reader io.Reader) (*ConfigFile, error) {
|
func readConfig(reader io.Reader) (*ConfigFile, error) {
|
||||||
@ -363,11 +366,12 @@ func generateCloudConfig(configFile *ConfigFile) (cloudConfig *CloudConfig, err
|
|||||||
// 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(config *CloudConfig) (*GCECloud, error) {
|
func CreateGCECloud(config *CloudConfig) (*GCECloud, error) {
|
||||||
// Remove any pre-release version and build metadata from the semver, leaving only the MAJOR.MINOR.PATCH portion.
|
// Remove any pre-release version and build metadata from the semver,
|
||||||
// See http://semver.org/.
|
// leaving only the MAJOR.MINOR.PATCH portion. See http://semver.org/.
|
||||||
version := strings.TrimLeft(strings.Split(strings.Split(version.Get().GitVersion, "-")[0], "+")[0], "v")
|
version := strings.TrimLeft(strings.Split(strings.Split(version.Get().GitVersion, "-")[0], "+")[0], "v")
|
||||||
|
|
||||||
// Create a user-agent header append string to supply to the Google API clients, to identify Kubernetes as the origin of the GCP API calls.
|
// Create a user-agent header append string to supply to the Google API
|
||||||
|
// clients, to identify Kubernetes as the origin of the GCP API calls.
|
||||||
userAgent := fmt.Sprintf("Kubernetes/%s (%s %s)", version, runtime.GOOS, runtime.GOARCH)
|
userAgent := fmt.Sprintf("Kubernetes/%s (%s %s)", version, runtime.GOOS, runtime.GOARCH)
|
||||||
|
|
||||||
// Use ProjectID for NetworkProjectID, if it wasn't explicitly set.
|
// Use ProjectID for NetworkProjectID, if it wasn't explicitly set.
|
||||||
@ -506,6 +510,13 @@ func CreateGCECloud(config *CloudConfig) (*GCECloud, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
gce.manager = &gceServiceManager{gce}
|
gce.manager = &gceServiceManager{gce}
|
||||||
|
gce.c = cloud.NewGCE(&cloud.Service{
|
||||||
|
GA: service,
|
||||||
|
Alpha: serviceAlpha,
|
||||||
|
Beta: serviceBeta,
|
||||||
|
ProjectRouter: &gceProjectRouter{gce},
|
||||||
|
RateLimiter: &gceRateLimiter{gce},
|
||||||
|
})
|
||||||
|
|
||||||
return gce, nil
|
return gce, nil
|
||||||
}
|
}
|
||||||
|
66
pkg/cloudprovider/providers/gce/support.go
Normal file
66
pkg/cloudprovider/providers/gce/support.go
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
/*
|
||||||
|
Copyright 2017 The Kubernetes Authors.
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package gce
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
|
"k8s.io/kubernetes/pkg/cloudprovider/providers/gce/cloud"
|
||||||
|
"k8s.io/kubernetes/pkg/cloudprovider/providers/gce/cloud/meta"
|
||||||
|
)
|
||||||
|
|
||||||
|
// gceProjectRouter sends requests to the appropriate project ID.
|
||||||
|
type gceProjectRouter struct {
|
||||||
|
gce *GCECloud
|
||||||
|
}
|
||||||
|
|
||||||
|
// ProjectID returns the project ID to be used for the given operation.
|
||||||
|
func (r *gceProjectRouter) ProjectID(ctx context.Context, version meta.Version, service string) string {
|
||||||
|
switch service {
|
||||||
|
case "Firewalls", "Routes":
|
||||||
|
return r.gce.NetworkProjectID()
|
||||||
|
default:
|
||||||
|
return r.gce.projectID
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// gceRateLimiter implements cloud.RateLimiter.
|
||||||
|
type gceRateLimiter struct {
|
||||||
|
gce *GCECloud
|
||||||
|
}
|
||||||
|
|
||||||
|
// Accept blocks until the operation can be performed.
|
||||||
|
//
|
||||||
|
// TODO: the current cloud provider policy doesn't seem to be correct as it
|
||||||
|
// only rate limits the polling operations, but not the /submission/ of
|
||||||
|
// operations.
|
||||||
|
func (l *gceRateLimiter) Accept(ctx context.Context, key *cloud.RateLimitKey) error {
|
||||||
|
if key.Operation == "Get" && key.Service == "Operations" {
|
||||||
|
ch := make(chan struct{})
|
||||||
|
go func() {
|
||||||
|
l.gce.operationPollRateLimiter.Accept()
|
||||||
|
close(ch)
|
||||||
|
}()
|
||||||
|
select {
|
||||||
|
case <-ch:
|
||||||
|
break
|
||||||
|
case <-ctx.Done():
|
||||||
|
return ctx.Err()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user