gce

package
v5.5.0+incompatible Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 14, 2019 License: Apache-2.0, Apache-2.0 Imports: 30 Imported by: 0

Documentation

Overview

Package gce is an implementation of Interface, LoadBalancer and Instances for Google Compute Engine.

Index

Constants

View Source
const (
	// DiskTypeSSD is the disk type for SSD PD
	DiskTypeSSD = "pd-ssd"
	// DiskTypeStandard is the disk type for standard PD
	DiskTypeStandard = "pd-standard"
)
View Source
const (
	// ProviderName is the cloud provider name
	ProviderName = "gce"
)

Variables

This section is empty.

Functions

func GetGCERegion

func GetGCERegion(zone string) (string, error)

GetGCERegion returns region of the gce zone. Zone names are of the form: ${region-name}-${ix}. For example, "us-central1-b" has a region of "us-central1". So we look for the last '-' and trim to just before that.

func NewAltTokenSource

func NewAltTokenSource(tokenURL, tokenBody string) oauth2.TokenSource

NewAltTokenSource creates a TokenSource

Types

type AltTokenSource

type AltTokenSource struct {
	// contains filtered or unexported fields
}

AltTokenSource defines a token source

func (*AltTokenSource) Token

func (a *AltTokenSource) Token() (*oauth2.Token, error)

Token returns a token

type Cloud

type Cloud struct {
	// contains filtered or unexported fields
}

Cloud is an implementation of Interface, LoadBalancer and Instances for Google Compute Engine.

func CreateGCECloud

func CreateGCECloud(projectID, region, zone string, managedZones []string, networkURL string, nodeTags []string, nodeInstancePrefix string, tokenSource oauth2.TokenSource, useMetadataServer bool) (*Cloud, error)

CreateGCECloud creates a GCE Cloud object using the specified parameters. If no networkUrl is specified, loads networkName via rest call. If no tokenSource is specified, uses oauth2.DefaultTokenSource. If managedZones is nil / empty all zones in the region will be managed.

func (*Cloud) AddInstancesToInstanceGroup

func (gce *Cloud) AddInstancesToInstanceGroup(name string, zone string, instanceNames []string) error

AddInstancesToInstanceGroup adds the given instances to the given instance group.

func (*Cloud) AddPortToInstanceGroup

func (gce *Cloud) AddPortToInstanceGroup(ig *compute.InstanceGroup, port int64) (*compute.NamedPort, error)

AddPortToInstanceGroup adds a port to the given instance group.

func (*Cloud) AddSSHKeyToAllInstances

func (gce *Cloud) AddSSHKeyToAllInstances(user string, keyData []byte) error

AddSSHKeyToAllInstances adds SSH key to all instances

func (*Cloud) AttachDisk

func (gce *Cloud) AttachDisk(diskName string, nodeName types.NodeName, readOnly bool) error

AttachDisk attaches a disk

func (*Cloud) Clusters

func (gce *Cloud) Clusters() (cloudprovider.Clusters, bool)

Clusters returns GCE clusters

func (*Cloud) CreateBackendService

func (gce *Cloud) CreateBackendService(bg *compute.BackendService) error

CreateBackendService creates the given BackendService.

func (*Cloud) CreateDisk

func (gce *Cloud) CreateDisk(name string, diskType string, zone string, sizeGb int64, tags map[string]string) error

CreateDisk creates a new Persistent Disk, with the specified name & size, in the specified zone. It stores specified tags encoded in JSON in Description field.

func (*Cloud) CreateDiskFromSnapshot

func (gce *Cloud) CreateDiskFromSnapshot(snapshot string,
	name string, diskType string, zone string, sizeGb int64, tags map[string]string) error

CreateDiskFromSnapshot create a disk from snapshot

func (*Cloud) CreateFirewall

func (gce *Cloud) CreateFirewall(name, desc string, sourceRanges netsets.IPNet, ports []int64, hostNames []string) error

CreateFirewall creates the given firewall rule.

func (*Cloud) CreateGlobalForwardingRule

func (gce *Cloud) CreateGlobalForwardingRule(targetProxyLink, ip, name, portRange string) (*compute.ForwardingRule, error)

CreateGlobalForwardingRule creates and returns a GlobalForwardingRule that points to the given TargetHttp(s)Proxy. targetProxyLink is the SelfLink of a TargetHttp(s)Proxy.

func (*Cloud) CreateHTTPHealthCheck

func (gce *Cloud) CreateHTTPHealthCheck(hc *compute.HttpHealthCheck) error

CreateHTTPHealthCheck creates the given HTTPHealthCheck.

func (*Cloud) CreateInstanceGroup

func (gce *Cloud) CreateInstanceGroup(name string, zone string) (*compute.InstanceGroup, error)

CreateInstanceGroup creates an instance group with the given instances. It is the callers responsibility to add named ports.

func (*Cloud) CreateRoute

func (gce *Cloud) CreateRoute(clusterName string, nameHint string, route *cloudprovider.Route) error

CreateRoute creates a route

func (*Cloud) CreateSnapshot

func (gce *Cloud) CreateSnapshot(diskName string, zone string, snapshotName string, tags map[string]string) error

CreateSnapshot creates a snapshot

func (*Cloud) CreateSslCertificate

func (gce *Cloud) CreateSslCertificate(sslCerts *compute.SslCertificate) (*compute.SslCertificate, error)

CreateSslCertificate creates and returns a SslCertificate.

func (*Cloud) CreateTargetHTTPProxy

func (gce *Cloud) CreateTargetHTTPProxy(urlMap *compute.UrlMap, name string) (*compute.TargetHttpProxy, error)

CreateTargetHTTPProxy creates and returns a TargetHTTPProxy with the given UrlMap.

func (*Cloud) CreateTargetHTTPSProxy

func (gce *Cloud) CreateTargetHTTPSProxy(urlMap *compute.UrlMap, sslCert *compute.SslCertificate, name string) (*compute.TargetHttpsProxy, error)

CreateTargetHTTPSProxy creates and returns a TargetHTTPSProxy with the given URLMap and SslCertificate.

func (*Cloud) CreateURLMap

func (gce *Cloud) CreateURLMap(backend *compute.BackendService, name string) (*compute.UrlMap, error)

CreateURLMap creates an url map, using the given backend service as the default service.

func (*Cloud) CurrentNodeName

func (gce *Cloud) CurrentNodeName(hostname string) (types.NodeName, error)

CurrentNodeName is an implementation of Instances.CurrentNodeName

func (*Cloud) DeleteBackendService

func (gce *Cloud) DeleteBackendService(name string) error

DeleteBackendService deletes the given BackendService by name.

func (*Cloud) DeleteDisk

func (gce *Cloud) DeleteDisk(diskToDelete string) error

DeleteDisk deletes a disk

func (*Cloud) DeleteFirewall

func (gce *Cloud) DeleteFirewall(name string) error

DeleteFirewall deletes the given firewall rule.

func (*Cloud) DeleteForwardingRule

func (gce *Cloud) DeleteForwardingRule(name string) error

DeleteForwardingRule deletes the forwarding rule

func (*Cloud) DeleteGlobalForwardingRule

func (gce *Cloud) DeleteGlobalForwardingRule(name string) error

DeleteGlobalForwardingRule deletes the GlobalForwardingRule by name.

func (*Cloud) DeleteGlobalStaticIP

func (gce *Cloud) DeleteGlobalStaticIP(name string) error

DeleteGlobalStaticIP deletes a global static IP by name.

func (*Cloud) DeleteHTTPHealthCheck

func (gce *Cloud) DeleteHTTPHealthCheck(name string) error

DeleteHTTPHealthCheck deletes the given HTTPHealthCheck by name.

func (*Cloud) DeleteInstanceGroup

func (gce *Cloud) DeleteInstanceGroup(name string, zone string) error

DeleteInstanceGroup deletes an instance group.

func (*Cloud) DeleteRoute

func (gce *Cloud) DeleteRoute(clusterName string, route *cloudprovider.Route) error

DeleteRoute deletes a route

func (*Cloud) DeleteSnapshot

func (gce *Cloud) DeleteSnapshot(snapshotToDelete string) error

DeleteSnapshot deletes a snapshot

func (*Cloud) DeleteSslCertificate

func (gce *Cloud) DeleteSslCertificate(name string) error

DeleteSslCertificate deletes the SslCertificate by name.

func (*Cloud) DeleteTargetHTTPProxy

func (gce *Cloud) DeleteTargetHTTPProxy(name string) error

DeleteTargetHTTPProxy deletes the TargetHTTPProxy by name.

func (*Cloud) DeleteTargetHTTPSProxy

func (gce *Cloud) DeleteTargetHTTPSProxy(name string) error

DeleteTargetHTTPSProxy deletes the TargetHTTPSProxy by name.

func (*Cloud) DeleteTargetPool

func (gce *Cloud) DeleteTargetPool(name string, hc *compute.HttpHealthCheck) error

DeleteTargetPool deletes the given target pool.

func (*Cloud) DeleteURLMap

func (gce *Cloud) DeleteURLMap(name string) error

DeleteURLMap deletes a url map by name.

func (*Cloud) DescribeSnapshot

func (gce *Cloud) DescribeSnapshot(snapshotToGet string) (status string, isCompleted bool, err error)

DescribeSnapshot checks the status of a snapshot

func (*Cloud) DetachDisk

func (gce *Cloud) DetachDisk(devicePath string, nodeName types.NodeName) error

DetachDisk detaches a disk

func (*Cloud) DiskIsAttached

func (gce *Cloud) DiskIsAttached(diskName string, nodeName types.NodeName) (bool, error)

DiskIsAttached checks if disk is attached

func (*Cloud) DisksAreAttached

func (gce *Cloud) DisksAreAttached(diskNames []string, nodeName types.NodeName) (map[string]bool, error)

DisksAreAttached checks if disks are attached

func (*Cloud) EnsureLoadBalancer

func (gce *Cloud) EnsureLoadBalancer(clusterName string, apiService *v1.Service, nodes []*v1.Node) (*v1.LoadBalancerStatus, error)

EnsureLoadBalancer is an implementation of LoadBalancer.EnsureLoadBalancer. Our load balancers in GCE consist of four separate GCE resources - a static IP address, a firewall rule, a target pool, and a forwarding rule. This function has to manage all of them. Due to an interesting series of design decisions, this handles both creating new load balancers and updating existing load balancers, recognizing when each is needed.

func (*Cloud) EnsureLoadBalancerDeleted

func (gce *Cloud) EnsureLoadBalancerDeleted(clusterName string, service *v1.Service) error

EnsureLoadBalancerDeleted is an implementation of LoadBalancer.EnsureLoadBalancerDeleted.

func (*Cloud) ExternalID

func (gce *Cloud) ExternalID(nodeName types.NodeName) (string, error)

ExternalID returns the cloud provider ID of the node with the specified NodeName (deprecated).

func (*Cloud) FindSnapshot

func (gce *Cloud) FindSnapshot(tags map[string]string) ([]string, []string, error)

FindSnapshot returns the found snapshots

func (*Cloud) GetAllZones

func (gce *Cloud) GetAllZones() (sets.String, error)

GetAllZones returns all the zones in which nodes are running

func (*Cloud) GetAutoLabelsForPD

func (gce *Cloud) GetAutoLabelsForPD(name string, zone string) (map[string]string, error)

GetAutoLabelsForPD builds the labels that should be automatically added to a PersistentVolume backed by a GCE PD Specifically, this builds FailureDomain (zone) and Region labels. The PersistentVolumeLabel admission controller calls this and adds the labels when a PV is created. If zone is specified, the volume will only be found in the specified zone, otherwise all managed zones will be searched.

func (*Cloud) GetBackendService

func (gce *Cloud) GetBackendService(name string) (*compute.BackendService, error)

GetBackendService retrieves a backend by name.

func (*Cloud) GetComputeService

func (gce *Cloud) GetComputeService() *compute.Service

GetComputeService gets the compute service Raw access to the underlying GCE service, probably should only be used for e2e tests

func (*Cloud) GetFirewall

func (gce *Cloud) GetFirewall(name string) (*compute.Firewall, error)

GetFirewall returns the Firewall by name.

func (*Cloud) GetGlobalForwardingRule

func (gce *Cloud) GetGlobalForwardingRule(name string) (*compute.ForwardingRule, error)

GetGlobalForwardingRule returns the GlobalForwardingRule by name.

func (*Cloud) GetGlobalStaticIP

func (gce *Cloud) GetGlobalStaticIP(name string) (address *compute.Address, err error)

GetGlobalStaticIP returns the global static IP by name.

func (*Cloud) GetHTTPHealthCheck

func (gce *Cloud) GetHTTPHealthCheck(name string) (*compute.HttpHealthCheck, error)

GetHTTPHealthCheck returns the given HTTPHealthCheck by name.

func (*Cloud) GetHealth

func (gce *Cloud) GetHealth(name string, instanceGroupLink string) (*compute.BackendServiceGroupHealth, error)

GetHealth returns the health of the BackendService identified by the given name, in the given instanceGroup. The instanceGroupLink is the fully qualified self link of an instance group.

func (*Cloud) GetInstanceGroup

func (gce *Cloud) GetInstanceGroup(name string, zone string) (*compute.InstanceGroup, error)

GetInstanceGroup returns an instance group by name.

func (*Cloud) GetLoadBalancer

func (gce *Cloud) GetLoadBalancer(clusterName string, service *v1.Service) (*v1.LoadBalancerStatus, bool, error)

GetLoadBalancer is an implementation of LoadBalancer.GetLoadBalancer

func (*Cloud) GetSslCertificate

func (gce *Cloud) GetSslCertificate(name string) (*compute.SslCertificate, error)

GetSslCertificate returns the SslCertificate by name.

func (*Cloud) GetTargetHTTPProxy

func (gce *Cloud) GetTargetHTTPProxy(name string) (*compute.TargetHttpProxy, error)

GetTargetHTTPProxy returns the UrlMap by name.

func (*Cloud) GetTargetHTTPSProxy

func (gce *Cloud) GetTargetHTTPSProxy(name string) (*compute.TargetHttpsProxy, error)

GetTargetHTTPSProxy returns the URLMap by name.

func (*Cloud) GetURLMap

func (gce *Cloud) GetURLMap(name string) (*compute.UrlMap, error)

GetURLMap returns the URLMap by name.

func (*Cloud) GetZone

func (gce *Cloud) GetZone() (cloudprovider.Zone, error)

GetZone gets a zone

func (*Cloud) InstanceID

func (gce *Cloud) InstanceID(nodeName types.NodeName) (string, error)

InstanceID returns the cloud provider ID of the node with the specified NodeName.

func (*Cloud) InstanceType

func (gce *Cloud) InstanceType(nodeName types.NodeName) (string, error)

InstanceType returns the type of the specified node with the specified NodeName.

func (*Cloud) Instances

func (gce *Cloud) Instances() (cloudprovider.Instances, bool)

Instances returns an implementation of Instances for Google Compute Engine.

func (*Cloud) ListBackendServices

func (gce *Cloud) ListBackendServices() (*compute.BackendServiceList, error)

ListBackendServices lists all backend services in the project.

func (*Cloud) ListClusters

func (gce *Cloud) ListClusters() ([]string, error)

ListClusters lists clusters

func (*Cloud) ListGlobalForwardingRules

func (gce *Cloud) ListGlobalForwardingRules() (*compute.ForwardingRuleList, error)

ListGlobalForwardingRules lists all GlobalForwardingRules in the project.

func (*Cloud) ListHTTPHealthChecks

func (gce *Cloud) ListHTTPHealthChecks() (*compute.HttpHealthCheckList, error)

ListHTTPHealthChecks lists all HTTPHealthChecks in the project.

func (*Cloud) ListInstanceGroups

func (gce *Cloud) ListInstanceGroups(zone string) (*compute.InstanceGroupList, error)

ListInstanceGroups lists all InstanceGroups in the project and zone.

func (*Cloud) ListInstancesInInstanceGroup

func (gce *Cloud) ListInstancesInInstanceGroup(name string, zone string, state string) (*compute.InstanceGroupsListInstances, error)

ListInstancesInInstanceGroup lists all the instances in a given instance group and state.

func (*Cloud) ListRoutes

func (gce *Cloud) ListRoutes(clusterName string) ([]*cloudprovider.Route, error)

ListRoutes lists routes

func (*Cloud) ListSslCertificates

func (gce *Cloud) ListSslCertificates() (*compute.SslCertificateList, error)

ListSslCertificates lists all SslCertificates in the project.

func (*Cloud) ListTargetHTTPProxies

func (gce *Cloud) ListTargetHTTPProxies() (*compute.TargetHttpProxyList, error)

ListTargetHTTPProxies lists all TargetHTTPProxies in the project.

func (*Cloud) ListTargetHTTPSProxies

func (gce *Cloud) ListTargetHTTPSProxies() (*compute.TargetHttpsProxyList, error)

ListTargetHTTPSProxies lists all TargetHTTPSProxies in the project.

func (*Cloud) ListURLMaps

func (gce *Cloud) ListURLMaps() (*compute.UrlMapList, error)

ListURLMaps lists all URLMaps in the project.

func (*Cloud) LoadBalancer

func (gce *Cloud) LoadBalancer() (cloudprovider.LoadBalancer, bool)

LoadBalancer returns an implementation of LoadBalancer for Google Compute Engine.

func (*Cloud) Master

func (gce *Cloud) Master(clusterName string) (string, error)

Master returns k8s-<cluster name>-master.internal

func (*Cloud) NodeAddresses

func (gce *Cloud) NodeAddresses(_ types.NodeName) ([]v1.NodeAddress, error)

NodeAddresses is an implementation of Instances.NodeAddresses.

func (*Cloud) ProviderName

func (gce *Cloud) ProviderName() string

ProviderName returns the cloud provider ID.

func (*Cloud) RemoveInstancesFromInstanceGroup

func (gce *Cloud) RemoveInstancesFromInstanceGroup(name string, zone string, instanceNames []string) error

RemoveInstancesFromInstanceGroup removes the given instances from the instance group.

func (*Cloud) ReserveGlobalStaticIP

func (gce *Cloud) ReserveGlobalStaticIP(name, ipAddress string) (address *compute.Address, err error)

ReserveGlobalStaticIP creates a global static IP. Caller is allocated a random IP if they do not specify an ipAddress. If an ipAddress is specified, it must belong to the current project, eg: an ephemeral IP associated with a global forwarding rule.

func (*Cloud) Routes

func (gce *Cloud) Routes() (cloudprovider.Routes, bool)

Routes returns an implementation of Routes for Google Compute Engine.

func (*Cloud) ScrubDNS

func (gce *Cloud) ScrubDNS(nameservers, searches []string) (nsOut, srchOut []string)

ScrubDNS filters DNS settings for pods.

func (*Cloud) SetProxyForGlobalForwardingRule

func (gce *Cloud) SetProxyForGlobalForwardingRule(fw *compute.ForwardingRule, targetProxyLink string) error

SetProxyForGlobalForwardingRule links the given TargetHttp(s)Proxy with the given GlobalForwardingRule. targetProxyLink is the SelfLink of a TargetHttp(s)Proxy.

func (*Cloud) SetSslCertificateForTargetHTTPSProxy

func (gce *Cloud) SetSslCertificateForTargetHTTPSProxy(proxy *compute.TargetHttpsProxy, sslCert *compute.SslCertificate) error

SetSslCertificateForTargetHTTPSProxy sets the given SslCertificate for the given TargetHTTPSProxy.

func (*Cloud) SetURLMapForTargetHTTPProxy

func (gce *Cloud) SetURLMapForTargetHTTPProxy(proxy *compute.TargetHttpProxy, urlMap *compute.UrlMap) error

SetURLMapForTargetHTTPProxy sets the given URLMap for the given TargetHTTPProxy.

func (*Cloud) SetURLMapForTargetHTTPSProxy

func (gce *Cloud) SetURLMapForTargetHTTPSProxy(proxy *compute.TargetHttpsProxy, urlMap *compute.UrlMap) error

SetURLMapForTargetHTTPSProxy sets the given URLMap for the given TargetHTTPSProxy.

func (*Cloud) UpdateBackendService

func (gce *Cloud) UpdateBackendService(bg *compute.BackendService) error

UpdateBackendService applies the given BackendService as an update to an existing service.

func (*Cloud) UpdateFirewall

func (gce *Cloud) UpdateFirewall(name, desc string, sourceRanges netsets.IPNet, ports []int64, hostNames []string) error

UpdateFirewall applies the given firewall rule as an update to an existing firewall rule with the same name.

func (*Cloud) UpdateHTTPHealthCheck

func (gce *Cloud) UpdateHTTPHealthCheck(hc *compute.HttpHealthCheck) error

UpdateHTTPHealthCheck applies the given HTTPHealthCheck as an update.

func (*Cloud) UpdateLoadBalancer

func (gce *Cloud) UpdateLoadBalancer(clusterName string, service *v1.Service, nodes []*v1.Node) error

UpdateLoadBalancer is an implementation of LoadBalancer.UpdateLoadBalancer.

func (*Cloud) UpdateURLMap

func (gce *Cloud) UpdateURLMap(urlMap *compute.UrlMap) (*compute.UrlMap, error)

UpdateURLMap applies the given UrlMap as an update, and returns the new UrlMap.

func (*Cloud) Zones

func (gce *Cloud) Zones() (cloudprovider.Zones, bool)

Zones returns an implementation of Zones for Google Compute Engine.

type Config

type Config struct {
	Global struct {
		TokenURL           string   `gcfg:"token-url"`
		TokenBody          string   `gcfg:"token-body"`
		ProjectID          string   `gcfg:"project-id"`
		NetworkName        string   `gcfg:"network-name"`
		NodeTags           []string `gcfg:"node-tags"`
		NodeInstancePrefix string   `gcfg:"node-instance-prefix"`
		Multizone          bool     `gcfg:"multizone"`
	}
}

Config contains config options for the GCE Cloud

type DiskType

type DiskType string

DiskType defines disk types

type Disks

type Disks interface {
	// AttachDisk attaches given disk to the node with the specified NodeName.
	// Current instance is used when instanceID is empty string.
	AttachDisk(diskName string, nodeName types.NodeName, readOnly bool) error

	// DetachDisk detaches given disk to the node with the specified NodeName.
	// Current instance is used when nodeName is empty string.
	DetachDisk(devicePath string, nodeName types.NodeName) error

	// DiskIsAttached checks if a disk is attached to the node with the specified NodeName.
	DiskIsAttached(diskName string, nodeName types.NodeName) (bool, error)

	// DisksAreAttached is a batch function to check if a list of disks are attached
	// to the node with the specified NodeName.
	DisksAreAttached(diskNames []string, nodeName types.NodeName) (map[string]bool, error)

	// CreateDisk creates a new PD with given properties. Tags are serialized
	// as JSON into Description field.
	CreateDisk(name string, diskType string, zone string, sizeGb int64, tags map[string]string) error

	// DeleteDisk deletes PD.
	DeleteDisk(diskToDelete string) error

	// Create an GCE PD volume snapshot
	CreateSnapshot(diskName string, zone string, snapshotName string, tags map[string]string) error
	// Delete an GCE PD volume snapshot
	DeleteSnapshot(snapshotToDelete string) error

	// Describe a GCE PD volume snapshot status for create or delete.
	// return status (completed or pending or error), and error
	DescribeSnapshot(snapshotToGet string) (status string, isCompleted bool, err error)

	// Find snapshot by tags
	FindSnapshot(tags map[string]string) ([]string, []string, error)

	// GetAutoLabelsForPD returns labels to apply to PersistentVolume
	// representing this PD, namely failure domain and zone.
	// zone can be provided to specify the zone for the PD,
	// if empty all managed zones will be searched.
	GetAutoLabelsForPD(name string, zone string) (map[string]string, error)
}

Disks is interface for manipulation with GCE PDs.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL