summaryrefslogtreecommitdiff
path: root/vendor/k8s.io/kubernetes/pkg/cloudprovider
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/k8s.io/kubernetes/pkg/cloudprovider')
-rw-r--r--vendor/k8s.io/kubernetes/pkg/cloudprovider/README.md16
-rw-r--r--vendor/k8s.io/kubernetes/pkg/cloudprovider/cloud.go186
-rw-r--r--vendor/k8s.io/kubernetes/pkg/cloudprovider/doc.go18
-rw-r--r--vendor/k8s.io/kubernetes/pkg/cloudprovider/plugins.go134
4 files changed, 354 insertions, 0 deletions
diff --git a/vendor/k8s.io/kubernetes/pkg/cloudprovider/README.md b/vendor/k8s.io/kubernetes/pkg/cloudprovider/README.md
new file mode 100644
index 000000000..ada366620
--- /dev/null
+++ b/vendor/k8s.io/kubernetes/pkg/cloudprovider/README.md
@@ -0,0 +1,16 @@
+##### Deprecation Notice: This directory has entered maintenance mode and will not be accepting new providers. Cloud Providers in this directory will continue to be actively developed or maintained and supported at their current level of support as a longer-term solution evolves.
+
+## Overview:
+The mechanism for supporting cloud providers is currently in transition: the original method of implementing cloud provider-specific functionality within the main kubernetes tree (here) is no longer advised; however, the proposed solution is still in development.
+
+#### Guidance for potential cloud providers:
+* Support for cloud providers is currently in a state of flux. Background information on motivation and the proposal for improving is in the github [proposal](https://git.k8s.io/community/contributors/design-proposals/cloud-provider-refactoring.md).
+* In support of this plan, a new cloud-controller-manager binary was added in 1.6. This was the first of several steps (see the proposal for more information).
+* Attempts to contribute new cloud providers or (to a lesser extent) persistent volumes to the core repo will likely meet with some pushback from reviewers/approvers.
+* It is understood that this is an unfortunate situation in which 'the old way is no longer supported but the new way is not ready yet', but the initial path is unsustainable, and contributors are encouraged to participate in the implementation of the proposed long-term solution, as there is risk that PRs for new cloud providers here will not be approved.
+* Though the fully productized support envisioned in the proposal is still 2 - 3 releases out, the foundational work is underway, and a motivated cloud provider could accomplish the work in a forward-looking way. Contributors are encouraged to assist with the implementation of the design outlined in the proposal.
+
+#### Some additional context on status / direction:
+* 1.6 added a new cloud-controller-manager binary that may be used for testing the new out-of-core cloudprovider flow.
+* Setting cloud-provider=external allows for creation of a separate controller-manager binary
+* 1.7 adds [extensible admission control](https://git.k8s.io/community/contributors/design-proposals/admission_control_extension.md), further enabling topology customization.
diff --git a/vendor/k8s.io/kubernetes/pkg/cloudprovider/cloud.go b/vendor/k8s.io/kubernetes/pkg/cloudprovider/cloud.go
new file mode 100644
index 000000000..2fb837b71
--- /dev/null
+++ b/vendor/k8s.io/kubernetes/pkg/cloudprovider/cloud.go
@@ -0,0 +1,186 @@
+/*
+Copyright 2014 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 cloudprovider
+
+import (
+ "errors"
+ "fmt"
+ "strings"
+
+ "k8s.io/apimachinery/pkg/types"
+ "k8s.io/kubernetes/pkg/api/v1"
+ "k8s.io/kubernetes/pkg/controller"
+)
+
+// Interface is an abstract, pluggable interface for cloud providers.
+type Interface interface {
+ // Initialize provides the cloud with a kubernetes client builder and may spawn goroutines
+ // to perform housekeeping activities within the cloud provider.
+ Initialize(clientBuilder controller.ControllerClientBuilder)
+ // LoadBalancer returns a balancer interface. Also returns true if the interface is supported, false otherwise.
+ LoadBalancer() (LoadBalancer, bool)
+ // Instances returns an instances interface. Also returns true if the interface is supported, false otherwise.
+ Instances() (Instances, bool)
+ // Zones returns a zones interface. Also returns true if the interface is supported, false otherwise.
+ Zones() (Zones, bool)
+ // Clusters returns a clusters interface. Also returns true if the interface is supported, false otherwise.
+ Clusters() (Clusters, bool)
+ // Routes returns a routes interface along with whether the interface is supported.
+ Routes() (Routes, bool)
+ // ProviderName returns the cloud provider ID.
+ ProviderName() string
+ // ScrubDNS provides an opportunity for cloud-provider-specific code to process DNS settings for pods.
+ ScrubDNS(nameservers, searches []string) (nsOut, srchOut []string)
+}
+
+// Clusters is an abstract, pluggable interface for clusters of containers.
+type Clusters interface {
+ // ListClusters lists the names of the available clusters.
+ ListClusters() ([]string, error)
+ // Master gets back the address (either DNS name or IP address) of the master node for the cluster.
+ Master(clusterName string) (string, error)
+}
+
+// TODO(#6812): Use a shorter name that's less likely to be longer than cloud
+// providers' name length limits.
+func GetLoadBalancerName(service *v1.Service) string {
+ //GCE requires that the name of a load balancer starts with a lower case letter.
+ ret := "a" + string(service.UID)
+ ret = strings.Replace(ret, "-", "", -1)
+ //AWS requires that the name of a load balancer is shorter than 32 bytes.
+ if len(ret) > 32 {
+ ret = ret[:32]
+ }
+ return ret
+}
+
+// GetInstanceProviderID builds a ProviderID for a node in a cloud.
+func GetInstanceProviderID(cloud Interface, nodeName types.NodeName) (string, error) {
+ instances, ok := cloud.Instances()
+ if !ok {
+ return "", fmt.Errorf("failed to get instances from cloud provider")
+ }
+ instanceID, err := instances.InstanceID(nodeName)
+ if err != nil {
+ return "", fmt.Errorf("failed to get instance ID from cloud provider: %v", err)
+ }
+ return cloud.ProviderName() + "://" + instanceID, nil
+}
+
+// LoadBalancer is an abstract, pluggable interface for load balancers.
+type LoadBalancer interface {
+ // TODO: Break this up into different interfaces (LB, etc) when we have more than one type of service
+ // GetLoadBalancer returns whether the specified load balancer exists, and
+ // if so, what its status is.
+ // Implementations must treat the *v1.Service parameter as read-only and not modify it.
+ // Parameter 'clusterName' is the name of the cluster as presented to kube-controller-manager
+ GetLoadBalancer(clusterName string, service *v1.Service) (status *v1.LoadBalancerStatus, exists bool, err error)
+ // EnsureLoadBalancer creates a new load balancer 'name', or updates the existing one. Returns the status of the balancer
+ // Implementations must treat the *v1.Service and *v1.Node
+ // parameters as read-only and not modify them.
+ // Parameter 'clusterName' is the name of the cluster as presented to kube-controller-manager
+ EnsureLoadBalancer(clusterName string, service *v1.Service, nodes []*v1.Node) (*v1.LoadBalancerStatus, error)
+ // UpdateLoadBalancer updates hosts under the specified load balancer.
+ // Implementations must treat the *v1.Service and *v1.Node
+ // parameters as read-only and not modify them.
+ // Parameter 'clusterName' is the name of the cluster as presented to kube-controller-manager
+ UpdateLoadBalancer(clusterName string, service *v1.Service, nodes []*v1.Node) error
+ // EnsureLoadBalancerDeleted deletes the specified load balancer if it
+ // exists, returning nil if the load balancer specified either didn't exist or
+ // was successfully deleted.
+ // This construction is useful because many cloud providers' load balancers
+ // have multiple underlying components, meaning a Get could say that the LB
+ // doesn't exist even if some part of it is still laying around.
+ // Implementations must treat the *v1.Service parameter as read-only and not modify it.
+ // Parameter 'clusterName' is the name of the cluster as presented to kube-controller-manager
+ EnsureLoadBalancerDeleted(clusterName string, service *v1.Service) error
+}
+
+// Instances is an abstract, pluggable interface for sets of instances.
+type Instances interface {
+ // NodeAddresses returns the addresses of the specified instance.
+ // TODO(roberthbailey): This currently is only used in such a way that it
+ // returns the address of the calling instance. We should do a rename to
+ // make this clearer.
+ NodeAddresses(name types.NodeName) ([]v1.NodeAddress, error)
+ // NodeAddressesByProviderID returns the addresses of the specified instance.
+ // The instance is specified using the providerID of the node. The
+ // ProviderID is a unique identifier of the node. This will not be called
+ // from the node whose nodeaddresses are being queried. i.e. local metadata
+ // services cannot be used in this method to obtain nodeaddresses
+ NodeAddressesByProviderID(providerId string) ([]v1.NodeAddress, error)
+ // ExternalID returns the cloud provider ID of the node with the specified NodeName.
+ // Note that if the instance does not exist or is no longer running, we must return ("", cloudprovider.InstanceNotFound)
+ ExternalID(nodeName types.NodeName) (string, error)
+ // InstanceID returns the cloud provider ID of the node with the specified NodeName.
+ InstanceID(nodeName types.NodeName) (string, error)
+ // InstanceType returns the type of the specified instance.
+ InstanceType(name types.NodeName) (string, error)
+ // InstanceTypeByProviderID returns the type of the specified instance.
+ InstanceTypeByProviderID(providerID string) (string, error)
+ // AddSSHKeyToAllInstances adds an SSH public key as a legal identity for all instances
+ // expected format for the key is standard ssh-keygen format: <protocol> <blob>
+ AddSSHKeyToAllInstances(user string, keyData []byte) error
+ // CurrentNodeName returns the name of the node we are currently running on
+ // On most clouds (e.g. GCE) this is the hostname, so we provide the hostname
+ CurrentNodeName(hostname string) (types.NodeName, error)
+}
+
+// Route is a representation of an advanced routing rule.
+type Route struct {
+ // Name is the name of the routing rule in the cloud-provider.
+ // It will be ignored in a Create (although nameHint may influence it)
+ Name string
+ // TargetNode is the NodeName of the target instance.
+ TargetNode types.NodeName
+ // DestinationCIDR is the CIDR format IP range that this routing rule
+ // applies to.
+ DestinationCIDR string
+ // Blackhole is set to true if this is a blackhole route
+ // The node controller will delete the route if it is in the managed range.
+ Blackhole bool
+}
+
+// Routes is an abstract, pluggable interface for advanced routing rules.
+type Routes interface {
+ // ListRoutes lists all managed routes that belong to the specified clusterName
+ ListRoutes(clusterName string) ([]*Route, error)
+ // CreateRoute creates the described managed route
+ // route.Name will be ignored, although the cloud-provider may use nameHint
+ // to create a more user-meaningful name.
+ CreateRoute(clusterName string, nameHint string, route *Route) error
+ // DeleteRoute deletes the specified managed route
+ // Route should be as returned by ListRoutes
+ DeleteRoute(clusterName string, route *Route) error
+}
+
+var (
+ InstanceNotFound = errors.New("instance not found")
+ DiskNotFound = errors.New("disk is not found")
+)
+
+// Zone represents the location of a particular machine.
+type Zone struct {
+ FailureDomain string
+ Region string
+}
+
+// Zones is an abstract, pluggable interface for zone enumeration.
+type Zones interface {
+ // GetZone returns the Zone containing the current failure zone and locality region that the program is running in
+ GetZone() (Zone, error)
+}
diff --git a/vendor/k8s.io/kubernetes/pkg/cloudprovider/doc.go b/vendor/k8s.io/kubernetes/pkg/cloudprovider/doc.go
new file mode 100644
index 000000000..41f8ae860
--- /dev/null
+++ b/vendor/k8s.io/kubernetes/pkg/cloudprovider/doc.go
@@ -0,0 +1,18 @@
+/*
+Copyright 2014 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 cloudprovider supplies interfaces and implementations for cloud service providers.
+package cloudprovider // import "k8s.io/kubernetes/pkg/cloudprovider"
diff --git a/vendor/k8s.io/kubernetes/pkg/cloudprovider/plugins.go b/vendor/k8s.io/kubernetes/pkg/cloudprovider/plugins.go
new file mode 100644
index 000000000..0fc41f5ea
--- /dev/null
+++ b/vendor/k8s.io/kubernetes/pkg/cloudprovider/plugins.go
@@ -0,0 +1,134 @@
+/*
+Copyright 2014 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 cloudprovider
+
+import (
+ "fmt"
+ "io"
+ "os"
+ "sync"
+
+ "github.com/golang/glog"
+)
+
+// Factory is a function that returns a cloudprovider.Interface.
+// The config parameter provides an io.Reader handler to the factory in
+// order to load specific configurations. If no configuration is provided
+// the parameter is nil.
+type Factory func(config io.Reader) (Interface, error)
+
+// All registered cloud providers.
+var (
+ providersMutex sync.Mutex
+ providers = make(map[string]Factory)
+)
+
+const externalCloudProvider = "external"
+
+// RegisterCloudProvider registers a cloudprovider.Factory by name. This
+// is expected to happen during app startup.
+func RegisterCloudProvider(name string, cloud Factory) {
+ providersMutex.Lock()
+ defer providersMutex.Unlock()
+ if _, found := providers[name]; found {
+ glog.Fatalf("Cloud provider %q was registered twice", name)
+ }
+ glog.V(1).Infof("Registered cloud provider %q", name)
+ providers[name] = cloud
+}
+
+// IsCloudProvider returns true if name corresponds to an already registered
+// cloud provider.
+func IsCloudProvider(name string) bool {
+ providersMutex.Lock()
+ defer providersMutex.Unlock()
+ _, found := providers[name]
+ return found
+}
+
+// CloudProviders returns the name of all registered cloud providers in a
+// string slice
+func CloudProviders() []string {
+ names := []string{}
+ providersMutex.Lock()
+ defer providersMutex.Unlock()
+ for name := range providers {
+ names = append(names, name)
+ }
+ return names
+}
+
+// GetCloudProvider creates an instance of the named cloud provider, or nil if
+// the name is unknown. The error return is only used if the named provider
+// was known but failed to initialize. The config parameter specifies the
+// io.Reader handler of the configuration file for the cloud provider, or nil
+// for no configuation.
+func GetCloudProvider(name string, config io.Reader) (Interface, error) {
+ providersMutex.Lock()
+ defer providersMutex.Unlock()
+ f, found := providers[name]
+ if !found {
+ return nil, nil
+ }
+ return f(config)
+}
+
+// Detects if the string is an external cloud provider
+func IsExternal(name string) bool {
+ return name == externalCloudProvider
+}
+
+// InitCloudProvider creates an instance of the named cloud provider.
+func InitCloudProvider(name string, configFilePath string) (Interface, error) {
+ var cloud Interface
+ var err error
+
+ if name == "" {
+ glog.Info("No cloud provider specified.")
+ return nil, nil
+ }
+
+ if IsExternal(name) {
+ glog.Info("External cloud provider specified")
+ return nil, nil
+ }
+
+ if configFilePath != "" {
+ var config *os.File
+ config, err = os.Open(configFilePath)
+ if err != nil {
+ glog.Fatalf("Couldn't open cloud provider configuration %s: %#v",
+ configFilePath, err)
+ }
+
+ defer config.Close()
+ cloud, err = GetCloudProvider(name, config)
+ } else {
+ // Pass explicit nil so plugins can actually check for nil. See
+ // "Why is my nil error value not equal to nil?" in golang.org/doc/faq.
+ cloud, err = GetCloudProvider(name, nil)
+ }
+
+ if err != nil {
+ return nil, fmt.Errorf("could not init cloud provider %q: %v", name, err)
+ }
+ if cloud == nil {
+ return nil, fmt.Errorf("unknown cloud provider %q", name)
+ }
+
+ return cloud, nil
+}