2014-06-17 17:50:42 +00:00
|
|
|
/*
|
2015-05-01 16:19:44 +00:00
|
|
|
Copyright 2014 The Kubernetes Authors All rights reserved.
|
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"
|
2014-06-18 04:58:41 +00:00
|
|
|
"net"
|
2015-05-03 06:32:21 +00:00
|
|
|
"strings"
|
2014-09-26 23:28:30 +00:00
|
|
|
|
|
|
|
"github.com/GoogleCloudPlatform/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 {
|
2014-06-18 05:28:44 +00:00
|
|
|
// TCPLoadBalancer returns a balancer interface. Also returns true if the interface is supported, false otherwise.
|
|
|
|
TCPLoadBalancer() (TCPLoadBalancer, bool)
|
|
|
|
// 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)
|
2014-11-13 20:35:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Clusters is an abstract, pluggable interface for clusters of containers.
|
|
|
|
type Clusters interface {
|
|
|
|
// List 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)
|
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
|
|
|
}
|
|
|
|
|
2014-07-10 11:46:56 +00:00
|
|
|
// TCPLoadBalancer is an abstract, pluggable interface for TCP load balancers.
|
2014-06-17 17:50:42 +00:00
|
|
|
type TCPLoadBalancer interface {
|
|
|
|
// TODO: Break this up into different interfaces (LB, etc) when we have more than one type of service
|
2015-05-01 17:37:48 +00:00
|
|
|
// GetTCPLoadBalancer returns whether the specified load balancer exists, and
|
2015-05-22 21:33:29 +00:00
|
|
|
// if so, what its status is.
|
|
|
|
GetTCPLoadBalancer(name, region string) (status *api.LoadBalancerStatus, exists bool, err error)
|
|
|
|
// CreateTCPLoadBalancer creates a new tcp load balancer. Returns the status of the balancer
|
|
|
|
CreateTCPLoadBalancer(name, region string, externalIP net.IP, ports []int, hosts []string, affinityType api.ServiceAffinity) (*api.LoadBalancerStatus, error)
|
2014-07-10 11:46:56 +00:00
|
|
|
// UpdateTCPLoadBalancer updates hosts under the specified load balancer.
|
2014-06-17 17:50:42 +00:00
|
|
|
UpdateTCPLoadBalancer(name, region string, hosts []string) error
|
2015-05-06 18:57:13 +00:00
|
|
|
// EnsureTCPLoadBalancerDeleted 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.
|
|
|
|
EnsureTCPLoadBalancerDeleted(name, region string) 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-03-11 23:37:11 +00:00
|
|
|
NodeAddresses(name string) ([]api.NodeAddress, error)
|
2015-02-11 22:37:27 +00:00
|
|
|
// ExternalID returns the cloud provider ID of the specified instance.
|
|
|
|
ExternalID(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)
|
2014-09-26 23:28:30 +00:00
|
|
|
// GetNodeResources gets the resources for a particular node
|
|
|
|
GetNodeResources(name string) (*api.NodeResources, 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.
|
|
|
|
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
|
|
|
|
// Destination CIDR is the CIDR format IP range that this routing rule
|
|
|
|
// applies to.
|
2015-05-15 21:49:26 +00:00
|
|
|
DestinationCIDR string
|
2015-05-21 00:24:30 +00:00
|
|
|
// Description is a free-form string. It can be useful for tagging Routes.
|
|
|
|
Description string
|
2015-05-15 21:49:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Routes is an abstract, pluggable interface for advanced routing rules.
|
|
|
|
type Routes interface {
|
2015-05-21 00:24:30 +00:00
|
|
|
// List all routes that match the filter
|
2015-05-15 21:49:26 +00:00
|
|
|
ListRoutes(filter string) ([]*Route, error)
|
|
|
|
// Create the described route
|
|
|
|
CreateRoute(route *Route) error
|
|
|
|
// Delete the specified route
|
|
|
|
DeleteRoute(name string) 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
|
|
|
}
|