Commit e2de110e authored by Kubernetes Submit Queue's avatar Kubernetes Submit Queue Committed by GitHub

Merge pull request #50467 from freehan/local-cloud-provider

Automatic merge from submit-queue (batch tested with PRs 51039, 50512, 50546, 50965, 50467) add alpha api gate at gce cloud provider **What this PR does / why we need it**: Add a flag in gce.conf to gate alpha api. Related wrapper function can choose to examine corresponding gate. Currently, there is no new alpha api wrapper funciton being introduced. So there is no supported alpha api. **Release note**: ```release-note None ``` cc: @yujuhong @saad-ali @MrHohn
parents 5f29fa4a c04ba4ea
...@@ -13,6 +13,7 @@ go_library( ...@@ -13,6 +13,7 @@ go_library(
"gce.go", "gce.go",
"gce_addresses.go", "gce_addresses.go",
"gce_addresses_fakes.go", "gce_addresses_fakes.go",
"gce_alpha.go",
"gce_annotations.go", "gce_annotations.go",
"gce_backendservice.go", "gce_backendservice.go",
"gce_cert.go", "gce_cert.go",
......
...@@ -118,6 +118,11 @@ type GCECloud struct { ...@@ -118,6 +118,11 @@ type GCECloud struct {
// lock to prevent shared resources from being prematurely deleted while the operation is // lock to prevent shared resources from being prematurely deleted while the operation is
// in progress. // in progress.
sharedResourceLock sync.Mutex sharedResourceLock sync.Mutex
// AlphaFeatureGate gates gce alpha features in GCECloud instance.
// Related wrapper functions that interacts with gce alpha api should examine whether
// the corresponding api is enabled.
// If not enabled, it should return error.
AlphaFeatureGate *AlphaFeatureGate
} }
type ServiceManager interface { type ServiceManager interface {
...@@ -151,6 +156,9 @@ type ConfigFile struct { ...@@ -151,6 +156,9 @@ type ConfigFile struct {
// Specifying ApiEndpoint will override the default GCE compute API endpoint. // Specifying ApiEndpoint will override the default GCE compute API endpoint.
ApiEndpoint string `gcfg:"api-endpoint"` ApiEndpoint string `gcfg:"api-endpoint"`
LocalZone string `gcfg:"local-zone"` LocalZone string `gcfg:"local-zone"`
// Possible values: List of api names separated by comma. Default to none.
// For example: MyFeatureFlag
AlphaFeatures []string `gcfg:"alpha-features"`
} }
} }
...@@ -167,6 +175,7 @@ type CloudConfig struct { ...@@ -167,6 +175,7 @@ type CloudConfig struct {
NodeInstancePrefix string NodeInstancePrefix string
TokenSource oauth2.TokenSource TokenSource oauth2.TokenSource
UseMetadataServer bool UseMetadataServer bool
AlphaFeatureGate *AlphaFeatureGate
} }
func init() { func init() {
...@@ -245,6 +254,12 @@ func generateCloudConfig(configFile *ConfigFile) (cloudConfig *CloudConfig, err ...@@ -245,6 +254,12 @@ func generateCloudConfig(configFile *ConfigFile) (cloudConfig *CloudConfig, err
cloudConfig.NodeTags = configFile.Global.NodeTags cloudConfig.NodeTags = configFile.Global.NodeTags
cloudConfig.NodeInstancePrefix = configFile.Global.NodeInstancePrefix cloudConfig.NodeInstancePrefix = configFile.Global.NodeInstancePrefix
alphaFeatureGate, err := NewAlphaFeatureGate(configFile.Global.AlphaFeatures)
if err != nil {
glog.Errorf("Encountered error for creating alpha feature gate: %v", err)
}
cloudConfig.AlphaFeatureGate = alphaFeatureGate
} }
// retrieve projectID and zone // retrieve projectID and zone
...@@ -398,6 +413,7 @@ func CreateGCECloud(config *CloudConfig) (*GCECloud, error) { ...@@ -398,6 +413,7 @@ func CreateGCECloud(config *CloudConfig) (*GCECloud, error) {
nodeInstancePrefix: config.NodeInstancePrefix, nodeInstancePrefix: config.NodeInstancePrefix,
useMetadataServer: config.UseMetadataServer, useMetadataServer: config.UseMetadataServer,
operationPollRateLimiter: operationPollRateLimiter, operationPollRateLimiter: operationPollRateLimiter,
AlphaFeatureGate: config.AlphaFeatureGate,
} }
gce.manager = &GCEServiceManager{gce} gce.manager = &GCEServiceManager{gce}
......
/*
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 (
"fmt"
utilerrors "k8s.io/apimachinery/pkg/util/errors"
)
// All known alpha features
var knownAlphaFeatures = map[string]bool{}
type AlphaFeatureGate struct {
features map[string]bool
}
func (af *AlphaFeatureGate) Enabled(key string) bool {
return af.features[key]
}
func NewAlphaFeatureGate(features []string) (*AlphaFeatureGate, error) {
errList := []error{}
featureMap := make(map[string]bool)
for _, name := range features {
if _, ok := knownAlphaFeatures[name]; !ok {
errList = append(errList, fmt.Errorf("alpha feature %q is not supported.", name))
} else {
featureMap[name] = true
}
}
return &AlphaFeatureGate{featureMap}, utilerrors.NewAggregate(errList)
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment