2014-06-17 17:50:42 +00:00
|
|
|
/*
|
2016-06-03 00:25:58 +00:00
|
|
|
Copyright 2014 The Kubernetes Authors.
|
2014-06-17 17:50:42 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
|
2014-06-18 04:58:41 +00:00
|
|
|
import (
|
2015-05-20 21:21:03 +00:00
|
|
|
"errors"
|
2015-05-05 14:52:20 +00:00
|
|
|
"fmt"
|
2015-05-03 06:32:21 +00:00
|
|
|
"strings"
|
2014-09-26 23:28:30 +00:00
|
|
|
|
2015-08-05 22:03:47 +00:00
|
|
|
"k8s.io/kubernetes/pkg/api"
|
2014-06-18 04:58:41 +00:00
|
|
|
)
|
|
|
|
|
2014-09-02 10:00:28 +00:00
|
|
|
// Interface is an abstract, pluggable interface for cloud providers.
|
2014-06-17 17:50:42 +00:00
|
|
|
type Interface interface {
|
2015-09-28 20:57:58 +00:00
|
|
|
// LoadBalancer returns a balancer interface. Also returns true if the interface is supported, false otherwise.
|
|
|
|
LoadBalancer() (LoadBalancer, bool)
|
2014-06-18 05:28:44 +00:00
|
|
|
// Instances returns an instances interface. Also returns true if the interface is supported, false otherwise.
|
|
|
|
Instances() (Instances, bool)
|
2014-07-28 22:42:08 +00:00
|
|
|
// Zones returns a zones interface. Also returns true if the interface is supported, false otherwise.
|
|
|
|
Zones() (Zones, bool)
|
2014-11-13 20:35:03 +00:00
|
|
|
// Clusters returns a clusters interface. Also returns true if the interface is supported, false otherwise.
|
|
|
|
Clusters() (Clusters, bool)
|
2015-05-15 21:49:26 +00:00
|
|
|
// Routes returns a routes interface along with whether the interface is supported.
|
|
|
|
Routes() (Routes, bool)
|
2015-05-05 14:10:24 +00:00
|
|
|
// ProviderName returns the cloud provider ID.
|
|
|
|
ProviderName() string
|
2015-10-24 00:01:49 +00:00
|
|
|
// ScrubDNS provides an opportunity for cloud-provider-specific code to process DNS settings for pods.
|
|
|
|
ScrubDNS(nameservers, searches []string) (nsOut, srchOut []string)
|
2014-11-13 20:35:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Clusters is an abstract, pluggable interface for clusters of containers.
|
|
|
|
type Clusters interface {
|
2015-10-03 14:43:10 +00:00
|
|
|
// ListClusters lists the names of the available clusters.
|
2014-11-13 20:35:03 +00:00
|
|
|
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)
|
2014-06-17 17:50:42 +00:00
|
|
|
}
|
|
|
|
|
2015-05-03 06:32:21 +00:00
|
|
|
// TODO(#6812): Use a shorter name that's less likely to be longer than cloud
|
|
|
|
// providers' name length limits.
|
|
|
|
func GetLoadBalancerName(service *api.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
|
2015-04-01 12:52:28 +00:00
|
|
|
}
|
|
|
|
|
2015-05-05 14:52:20 +00:00
|
|
|
func GetInstanceProviderID(cloud Interface, nodeName string) (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
|
|
|
|
}
|
|
|
|
|
2015-09-28 20:57:58 +00:00
|
|
|
// LoadBalancer is an abstract, pluggable interface for load balancers.
|
|
|
|
type LoadBalancer interface {
|
2014-06-17 17:50:42 +00:00
|
|
|
// TODO: Break this up into different interfaces (LB, etc) when we have more than one type of service
|
2015-09-28 20:57:58 +00:00
|
|
|
// GetLoadBalancer returns whether the specified load balancer exists, and
|
2015-05-22 21:33:29 +00:00
|
|
|
// if so, what its status is.
|
Change LoadBalancer methods to take api.Service
This is a better abstraction than passing in specific pieces of the
Service that each of the cloudproviders may or may not need. For
instance, many of the providers don't need a region, yet this is passed
in. Similarly many of the providers want a string IP for the load
balancer, but it passes in a converted net ip. Affinity is unused by
AWS. A provider change may also require adding a new parameter which has
an effect on all other cloud provider implementations.
Further, this will simplify adding provider specific load balancer
options, such as with labels or some other metadata. For example, we
could add labels for configuring the details of an AWS elastic load
balancer, such as idle timeout on connections, whether it is
internal or external, cross-zone load balancing, and so on.
Authors: @chbatey, @jsravn
2016-02-17 11:36:50 +00:00
|
|
|
// Implementations must treat the *api.Service parameter as read-only and not modify it.
|
2016-05-29 03:54:07 +00:00
|
|
|
GetLoadBalancer(clusterName string, service *api.Service) (status *api.LoadBalancerStatus, exists bool, err error)
|
2016-02-07 19:35:06 +00:00
|
|
|
// EnsureLoadBalancer creates a new load balancer 'name', or updates the existing one. Returns the status of the balancer
|
Change LoadBalancer methods to take api.Service
This is a better abstraction than passing in specific pieces of the
Service that each of the cloudproviders may or may not need. For
instance, many of the providers don't need a region, yet this is passed
in. Similarly many of the providers want a string IP for the load
balancer, but it passes in a converted net ip. Affinity is unused by
AWS. A provider change may also require adding a new parameter which has
an effect on all other cloud provider implementations.
Further, this will simplify adding provider specific load balancer
options, such as with labels or some other metadata. For example, we
could add labels for configuring the details of an AWS elastic load
balancer, such as idle timeout on connections, whether it is
internal or external, cross-zone load balancing, and so on.
Authors: @chbatey, @jsravn
2016-02-17 11:36:50 +00:00
|
|
|
// Implementations must treat the *api.Service parameter as read-only and not modify it.
|
2016-05-29 03:54:07 +00:00
|
|
|
EnsureLoadBalancer(clusterName string, service *api.Service, hosts []string) (*api.LoadBalancerStatus, error)
|
2015-09-28 20:57:58 +00:00
|
|
|
// UpdateLoadBalancer updates hosts under the specified load balancer.
|
Change LoadBalancer methods to take api.Service
This is a better abstraction than passing in specific pieces of the
Service that each of the cloudproviders may or may not need. For
instance, many of the providers don't need a region, yet this is passed
in. Similarly many of the providers want a string IP for the load
balancer, but it passes in a converted net ip. Affinity is unused by
AWS. A provider change may also require adding a new parameter which has
an effect on all other cloud provider implementations.
Further, this will simplify adding provider specific load balancer
options, such as with labels or some other metadata. For example, we
could add labels for configuring the details of an AWS elastic load
balancer, such as idle timeout on connections, whether it is
internal or external, cross-zone load balancing, and so on.
Authors: @chbatey, @jsravn
2016-02-17 11:36:50 +00:00
|
|
|
// Implementations must treat the *api.Service parameter as read-only and not modify it.
|
2016-05-29 03:54:07 +00:00
|
|
|
UpdateLoadBalancer(clusterName string, service *api.Service, hosts []string) error
|
2015-09-28 20:57:58 +00:00
|
|
|
// EnsureLoadBalancerDeleted deletes the specified load balancer if it
|
2015-05-06 18:57:13 +00:00
|
|
|
// 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.
|
Change LoadBalancer methods to take api.Service
This is a better abstraction than passing in specific pieces of the
Service that each of the cloudproviders may or may not need. For
instance, many of the providers don't need a region, yet this is passed
in. Similarly many of the providers want a string IP for the load
balancer, but it passes in a converted net ip. Affinity is unused by
AWS. A provider change may also require adding a new parameter which has
an effect on all other cloud provider implementations.
Further, this will simplify adding provider specific load balancer
options, such as with labels or some other metadata. For example, we
could add labels for configuring the details of an AWS elastic load
balancer, such as idle timeout on connections, whether it is
internal or external, cross-zone load balancing, and so on.
Authors: @chbatey, @jsravn
2016-02-17 11:36:50 +00:00
|
|
|
// Implementations must treat the *api.Service parameter as read-only and not modify it.
|
2016-05-29 03:54:07 +00:00
|
|
|
EnsureLoadBalancerDeleted(clusterName string, service *api.Service) error
|
2014-06-17 17:50:42 +00:00
|
|
|
}
|
2014-06-18 04:58:41 +00:00
|
|
|
|
2014-07-10 11:46:56 +00:00
|
|
|
// Instances is an abstract, pluggable interface for sets of instances.
|
2014-06-18 04:58:41 +00:00
|
|
|
type Instances interface {
|
2015-03-13 22:07:08 +00:00
|
|
|
// NodeAddresses returns the addresses of the specified instance.
|
2015-05-27 23:46:50 +00:00
|
|
|
// 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.
|
2015-03-11 23:37:11 +00:00
|
|
|
NodeAddresses(name string) ([]api.NodeAddress, error)
|
2015-05-08 15:19:17 +00:00
|
|
|
// ExternalID returns the cloud provider ID of the specified instance (deprecated).
|
2016-07-23 01:57:03 +00:00
|
|
|
// Note that if the instance does not exist or is no longer running, we must return ("", cloudprovider.InstanceNotFound)
|
2015-02-11 22:37:27 +00:00
|
|
|
ExternalID(name string) (string, error)
|
2015-05-08 15:19:17 +00:00
|
|
|
// InstanceID returns the cloud provider ID of the specified instance.
|
|
|
|
InstanceID(name string) (string, error)
|
2016-02-09 16:34:42 +00:00
|
|
|
// InstanceType returns the type of the specified instance.
|
|
|
|
InstanceType(name string) (string, error)
|
2014-07-10 11:46:56 +00:00
|
|
|
// List lists instances that match 'filter' which is a regular expression which must match the entire instance name (fqdn)
|
2014-06-25 05:27:33 +00:00
|
|
|
List(filter string) ([]string, error)
|
2015-05-28 18:45:08 +00:00
|
|
|
// 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
|
2015-10-03 14:43:10 +00:00
|
|
|
// CurrentNodeName returns the name of the node we are currently running on
|
2015-06-12 15:42:38 +00:00
|
|
|
// On most clouds (e.g. GCE) this is the hostname, so we provide the hostname
|
|
|
|
CurrentNodeName(hostname string) (string, error)
|
2014-06-18 04:58:41 +00:00
|
|
|
}
|
2014-07-28 22:42:08 +00:00
|
|
|
|
2015-05-15 21:49:26 +00:00
|
|
|
// Route is a representation of an advanced routing rule.
|
|
|
|
type Route struct {
|
2015-05-21 00:24:30 +00:00
|
|
|
// Name is the name of the routing rule in the cloud-provider.
|
2015-06-12 16:27:10 +00:00
|
|
|
// It will be ignored in a Create (although nameHint may influence it)
|
2015-05-21 00:24:30 +00:00
|
|
|
Name string
|
|
|
|
// TargetInstance is the name of the instance as specified in routing rules
|
|
|
|
// for the cloud-provider (in gce: the Instance Name).
|
|
|
|
TargetInstance string
|
2015-10-03 14:43:10 +00:00
|
|
|
// DestinationCIDR is the CIDR format IP range that this routing rule
|
2015-05-21 00:24:30 +00:00
|
|
|
// applies to.
|
2015-05-15 21:49:26 +00:00
|
|
|
DestinationCIDR string
|
|
|
|
}
|
|
|
|
|
|
|
|
// Routes is an abstract, pluggable interface for advanced routing rules.
|
|
|
|
type Routes interface {
|
2015-10-03 14:43:10 +00:00
|
|
|
// ListRoutes lists all managed routes that belong to the specified clusterName
|
2015-06-12 16:27:10 +00:00
|
|
|
ListRoutes(clusterName string) ([]*Route, error)
|
2015-10-03 14:43:10 +00:00
|
|
|
// CreateRoute creates the described managed route
|
2015-06-12 16:27:10 +00:00
|
|
|
// 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
|
2015-10-03 14:43:10 +00:00
|
|
|
// DeleteRoute deletes the specified managed route
|
2015-06-12 16:27:10 +00:00
|
|
|
// Route should be as returned by ListRoutes
|
|
|
|
DeleteRoute(clusterName string, route *Route) error
|
2014-06-18 04:58:41 +00:00
|
|
|
}
|
2014-07-28 22:42:08 +00:00
|
|
|
|
2015-05-20 21:21:03 +00:00
|
|
|
var InstanceNotFound = errors.New("instance not found")
|
|
|
|
|
2014-09-02 10:00:28 +00:00
|
|
|
// Zone represents the location of a particular machine.
|
2014-08-04 16:58:10 +00:00
|
|
|
type Zone struct {
|
|
|
|
FailureDomain string
|
|
|
|
Region string
|
|
|
|
}
|
|
|
|
|
2014-07-28 22:42:08 +00:00
|
|
|
// Zones is an abstract, pluggable interface for zone enumeration.
|
|
|
|
type Zones interface {
|
2014-08-04 16:58:10 +00:00
|
|
|
// GetZone returns the Zone containing the current failure zone and locality region that the program is running in
|
|
|
|
GetZone() (Zone, error)
|
2014-07-28 22:42:08 +00:00
|
|
|
}
|