gce

package
v0.0.0-...-386b7fa 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 Imports: 35 Imported by: 0

Documentation

Index

Constants

View Source
const (

	// ErrorCodeQuotaExceeded is error code used in InstanceErrorInfo if quota exceeded error occurs.
	ErrorCodeQuotaExceeded = "QUOTA_EXCEEDED"

	// ErrorCodeStockout is error code used in InstanceErrorInfo if stockout occurs.
	ErrorCodeStockout = "STOCKOUT"
)
View Source
const (
	// ProviderNameGCE is the name of GCE cloud provider.
	ProviderNameGCE = "gce"

	// GPULabel is the label added to nodes with GPU resource.
	GPULabel = "cloud.google.com/gke-accelerator"
)
View Source
const (
	// MiB - MebiByte size (2^20)
	MiB = 1024 * 1024
	// GiB - GibiByte size (2^30)
	GiB = 1024 * 1024 * 1024

	// KubeletEvictionHardMemory is subtracted from capacity
	// when calculating allocatable (on top of kube-reserved).
	// Equals kubelet "evictionHard: {memory.available}"
	// We don't have a good place to get it from, but it has been hard-coded
	// to 100Mi since at least k8s 1.4.
	KubeletEvictionHardMemory = 100 * MiB
)

Variables

This section is empty.

Functions

func BuildGCE

BuildGCE builds GCE cloud provider, manager etc.

func BuildGenericLabels

func BuildGenericLabels(ref GceRef, machineType string, nodeName string) (map[string]string, error)

BuildGenericLabels builds basic labels that should be present on every GCE node, including hostname, zone etc.

func CalculateKernelReserved

func CalculateKernelReserved(physicalMemory int64) int64

CalculateKernelReserved computes how much memory Linux kernel will reserve. TODO(jkaniuk): account for crashkernel reservation on RHEL / CentOS

func GenerateInstanceUrl

func GenerateInstanceUrl(ref GceRef) string

GenerateInstanceUrl generates url for instance.

func GenerateMigUrl

func GenerateMigUrl(ref GceRef) string

GenerateMigUrl generates url for instance.

func NewAutoscalingGceClientV1

func NewAutoscalingGceClientV1(client *http.Client, projectId string) (*autoscalingGceClientV1, error)

NewAutoscalingGceClientV1 creates a new client for communicating with GCE v1 API.

func NewCustomAutoscalingGceClientV1

func NewCustomAutoscalingGceClientV1(client *http.Client, projectId, serverUrl string,
	waitTimeout, pollInterval time.Duration) (*autoscalingGceClientV1, error)

NewCustomAutoscalingGceClientV1 creates a new client using custom server url and timeouts for communicating with GCE v1 API.

func ParseIgmUrl

func ParseIgmUrl(url string) (project string, zone string, name string, err error)

ParseIgmUrl expects url in format: https://content.googleapis.com/compute/v1/projects/<project-id>/zones/<zone>/instanceGroupManagers/<name>

func ParseInstanceUrl

func ParseInstanceUrl(url string) (project string, zone string, name string, err error)

ParseInstanceUrl expects url in format: https://content.googleapis.com/compute/v1/projects/<project-id>/zones/<zone>/instances/<name>

func ParseMigUrl

func ParseMigUrl(url string) (project string, zone string, name string, err error)

ParseMigUrl expects url in format: https://content.googleapis.com/compute/v1/projects/<project-id>/zones/<zone>/instanceGroups/<name>

func RegisterMetrics

func RegisterMetrics()

RegisterMetrics registers all GCE metrics.

Types

type AutoscalingGceClient

type AutoscalingGceClient interface {
	// reading resources
	FetchMachineType(zone, machineType string) (*gce.MachineType, error)
	FetchMachineTypes(zone string) ([]*gce.MachineType, error)
	FetchAllMigs(zone string) ([]*gce.InstanceGroupManager, error)
	FetchMigTargetSize(GceRef) (int64, error)
	FetchMigBasename(GceRef) (string, error)
	FetchMigInstances(GceRef) ([]cloudprovider.Instance, error)
	FetchMigTemplate(GceRef) (*gce.InstanceTemplate, error)
	FetchMigsWithName(zone string, filter *regexp.Regexp) ([]string, error)
	FetchZones(region string) ([]string, error)

	// modifying resources
	ResizeMig(GceRef, int64) error
	DeleteInstances(migRef GceRef, instances []GceRef) error
}

AutoscalingGceClient is used for communicating with GCE API.

type GceCache

type GceCache struct {

	// Service used to refresh cache.
	GceService AutoscalingGceClient
	// contains filtered or unexported fields
}

GceCache is used for caching cluster resources state.

It is needed to: - keep track of autoscaled MIGs in the cluster, - keep track of instances and which MIG they belong to, - limit repetitive GCE API calls.

Cached resources: 1) MIG configuration, 2) instance->MIG mapping, 3) resource limits (self-imposed quotas), 4) machine types.

How it works: - migs (1), resource limits (3) and machine types (4) are only stored in this cache, not updated by it. - instanceRefToMigRef (2) is based on registered migs (1). For each mig, its instances are fetched from GCE API using gceService. - instanceRefToMigRef (2) is NOT updated automatically when migs field (1) is updated. Calling RegenerateInstancesCache is required to sync it with registered migs.

func NewGceCache

func NewGceCache(gceService AutoscalingGceClient) *GceCache

NewGceCache creates empty GceCache.

func (*GceCache) AddMachineToCache

func (gc *GceCache) AddMachineToCache(machineType string, zone string, machine *gce.MachineType)

AddMachineToCache adds machine to cache under lock.

func (*GceCache) GetMachineFromCache

func (gc *GceCache) GetMachineFromCache(machineType string, zone string) *gce.MachineType

GetMachineFromCache retrieves machine type from cache under lock.

func (*GceCache) GetMigBasename

func (gc *GceCache) GetMigBasename(migRef GceRef) (basename string, found bool)

GetMigBasename get basename for given mig from cache.

func (*GceCache) GetMigForInstance

func (gc *GceCache) GetMigForInstance(instanceRef GceRef) (Mig, error)

GetMigForInstance returns Mig to which the given instance belongs. Attempts to regenerate cache if there is a Mig with matching prefix in migs list. TODO(aleksandra-malinowska): reconsider failing when there's a Mig with matching prefix, but instance doesn't belong to it.

func (*GceCache) GetMigTargetSize

func (gc *GceCache) GetMigTargetSize(ref GceRef) (int64, bool)

GetMigTargetSize returns the cached targetSize for a GceRef

func (*GceCache) GetMigs

func (gc *GceCache) GetMigs() []Mig

GetMigs returns a copy of migs list.

func (*GceCache) GetResourceLimiter

func (gc *GceCache) GetResourceLimiter() (*cloudprovider.ResourceLimiter, error)

GetResourceLimiter returns resource limiter.

func (*GceCache) InvalidateAllMigBasenames

func (gc *GceCache) InvalidateAllMigBasenames()

InvalidateAllMigBasenames invalidates all basename entries.

func (*GceCache) InvalidateAllMigTargetSizes

func (gc *GceCache) InvalidateAllMigTargetSizes()

InvalidateAllMigTargetSizes clears the target size cache

func (*GceCache) InvalidateMigBasename

func (gc *GceCache) InvalidateMigBasename(migRef GceRef)

InvalidateMigBasename invalidates basename entry for given mig.

func (*GceCache) InvalidateMigTargetSize

func (gc *GceCache) InvalidateMigTargetSize(ref GceRef)

InvalidateMigTargetSize clears the target size cache

func (*GceCache) RegenerateInstanceCacheForMig

func (gc *GceCache) RegenerateInstanceCacheForMig(migRef GceRef) error

RegenerateInstanceCacheForMig triggers instances cache regeneration for single MIG under lock.

func (*GceCache) RegenerateInstancesCache

func (gc *GceCache) RegenerateInstancesCache() error

RegenerateInstancesCache triggers instances cache regeneration under lock.

func (*GceCache) RegisterMig

func (gc *GceCache) RegisterMig(newMig Mig) bool

RegisterMig returns true if the node group wasn't in cache before, or its config was updated.

func (*GceCache) SetMachinesCache

func (gc *GceCache) SetMachinesCache(machinesCache map[MachineTypeKey]*gce.MachineType)

SetMachinesCache sets the machines cache under lock.

func (*GceCache) SetMigBasename

func (gc *GceCache) SetMigBasename(migRef GceRef, basename string)

SetMigBasename sets basename for given mig in cache

func (*GceCache) SetMigTargetSize

func (gc *GceCache) SetMigTargetSize(ref GceRef, size int64)

SetMigTargetSize sets targetSize for a GceRef

func (*GceCache) SetResourceLimiter

func (gc *GceCache) SetResourceLimiter(resourceLimiter *cloudprovider.ResourceLimiter)

SetResourceLimiter sets resource limiter.

func (*GceCache) UnregisterMig

func (gc *GceCache) UnregisterMig(toBeRemoved Mig) bool

UnregisterMig returns true if the node group has been removed, and false if it was already missing from cache.

type GceCloudProvider

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

GceCloudProvider implements CloudProvider interface.

func BuildGceCloudProvider

func BuildGceCloudProvider(gceManager GceManager, resourceLimiter *cloudprovider.ResourceLimiter) (*GceCloudProvider, error)

BuildGceCloudProvider builds CloudProvider implementation for GCE.

func (*GceCloudProvider) Cleanup

func (gce *GceCloudProvider) Cleanup() error

Cleanup cleans up all resources before the cloud provider is removed

func (*GceCloudProvider) GPULabel

func (gce *GceCloudProvider) GPULabel() string

GPULabel returns the label added to nodes with GPU resource.

func (*GceCloudProvider) GetAvailableGPUTypes

func (gce *GceCloudProvider) GetAvailableGPUTypes() map[string]struct{}

GetAvailableGPUTypes return all available GPU types cloud provider supports

func (*GceCloudProvider) GetAvailableMachineTypes

func (gce *GceCloudProvider) GetAvailableMachineTypes() ([]string, error)

GetAvailableMachineTypes get all machine types that can be requested from the cloud provider.

func (*GceCloudProvider) GetResourceLimiter

func (gce *GceCloudProvider) GetResourceLimiter() (*cloudprovider.ResourceLimiter, error)

GetResourceLimiter returns struct containing limits (max, min) for resources (cores, memory etc.).

func (*GceCloudProvider) Name

func (gce *GceCloudProvider) Name() string

Name returns name of the cloud provider.

func (*GceCloudProvider) NewNodeGroup

func (gce *GceCloudProvider) NewNodeGroup(machineType string, labels map[string]string, systemLabels map[string]string,
	taints []apiv1.Taint, extraResources map[string]resource.Quantity) (cloudprovider.NodeGroup, error)

NewNodeGroup builds a theoretical node group based on the node definition provided. The node group is not automatically created on the cloud provider side. The node group is not returned by NodeGroups() until it is created.

func (*GceCloudProvider) NodeGroupForNode

func (gce *GceCloudProvider) NodeGroupForNode(node *apiv1.Node) (cloudprovider.NodeGroup, error)

NodeGroupForNode returns the node group for the given node.

func (*GceCloudProvider) NodeGroups

func (gce *GceCloudProvider) NodeGroups() []cloudprovider.NodeGroup

NodeGroups returns all node groups configured for this cloud provider.

func (*GceCloudProvider) Pricing

Pricing returns pricing model for this cloud provider or error if not available.

func (*GceCloudProvider) Refresh

func (gce *GceCloudProvider) Refresh() error

Refresh is called before every main loop and can be used to dynamically update cloud provider state. In particular the list of node groups returned by NodeGroups can change as a result of CloudProvider.Refresh().

type GceManager

type GceManager interface {
	// Refresh triggers refresh of cached resources.
	Refresh() error
	// Cleanup cleans up open resources before the cloud provider is destroyed, i.e. go routines etc.
	Cleanup() error

	// GetMigs returns list of registered MIGs.
	GetMigs() []Mig
	// GetMigNodes returns mig nodes.
	GetMigNodes(mig Mig) ([]cloudprovider.Instance, error)
	// GetMigForInstance returns MIG to which the given instance belongs.
	GetMigForInstance(instance GceRef) (Mig, error)
	// GetMigTemplateNode returns a template node for MIG.
	GetMigTemplateNode(mig Mig) (*apiv1.Node, error)
	// GetResourceLimiter returns resource limiter.
	GetResourceLimiter() (*cloudprovider.ResourceLimiter, error)
	// GetMigSize gets MIG size.
	GetMigSize(mig Mig) (int64, error)

	// SetMigSize sets MIG size.
	SetMigSize(mig Mig, size int64) error
	// DeleteInstances deletes the given instances. All instances must be controlled by the same MIG.
	DeleteInstances(instances []GceRef) error
}

GceManager handles GCE communication and data caching.

func CreateGceManager

func CreateGceManager(configReader io.Reader, discoveryOpts cloudprovider.NodeGroupDiscoveryOptions, regional bool) (GceManager, error)

CreateGceManager constructs GceManager object.

type GcePriceModel

type GcePriceModel struct {
}

GcePriceModel implements PriceModel interface for GCE.

func (*GcePriceModel) NodePrice

func (model *GcePriceModel) NodePrice(node *apiv1.Node, startTime time.Time, endTime time.Time) (float64, error)

NodePrice returns a price of running the given node for a given period of time. All prices are in USD.

func (*GcePriceModel) PodPrice

func (model *GcePriceModel) PodPrice(pod *apiv1.Pod, startTime time.Time, endTime time.Time) (float64, error)

PodPrice returns a theoretical minimum price of running a pod for a given period of time on a perfectly matching machine.

type GceRef

type GceRef struct {
	Project string
	Zone    string
	Name    string
}

GceRef contains s reference to some entity in GCE world.

func GceRefFromProviderId

func GceRefFromProviderId(id string) (GceRef, error)

GceRefFromProviderId creates InstanceConfig object from provider id which must be in format: gce://<project-id>/<zone>/<name> TODO(piosz): add better check whether the id is correct

func ParseInstanceUrlRef

func ParseInstanceUrlRef(url string) (GceRef, error)

ParseInstanceUrlRef expects url in format: https://content.googleapis.com/compute/v1/projects/<project-id>/zones/<zone>/instances/<name> and returns a GceRef struct for it.

func (GceRef) String

func (ref GceRef) String() string

func (GceRef) ToProviderId

func (ref GceRef) ToProviderId() string

ToProviderId converts GceRef to string in format used as ProviderId in Node object.

type GceTemplateBuilder

type GceTemplateBuilder struct{}

GceTemplateBuilder builds templates for GCE nodes.

func (*GceTemplateBuilder) BuildAllocatableFromKubeEnv

func (t *GceTemplateBuilder) BuildAllocatableFromKubeEnv(capacity apiv1.ResourceList, kubeEnv string) (apiv1.ResourceList, error)

BuildAllocatableFromKubeEnv builds node allocatable based on capacity of the node and value of kubeEnv. KubeEnv is a multi-line string containing entries in the form of <RESOURCE_NAME>:<string>. One of the resources it contains is a list of kubelet arguments from which we can extract the resources reserved by the kubelet for its operation. Allocated resources are capacity minus reserved. If we fail to extract the reserved resources from kubeEnv (e.g it is in a wrong format or does not contain kubelet arguments), we return an error.

func (*GceTemplateBuilder) BuildCapacity

func (t *GceTemplateBuilder) BuildCapacity(cpu int64, mem int64, accelerators []*gce.AcceleratorConfig) (apiv1.ResourceList, error)

BuildCapacity builds a list of resource capacities given list of hardware.

func (*GceTemplateBuilder) BuildNodeFromTemplate

func (t *GceTemplateBuilder) BuildNodeFromTemplate(mig Mig, template *gce.InstanceTemplate, cpu int64, mem int64) (*apiv1.Node, error)

BuildNodeFromTemplate builds node from provided GCE template.

func (*GceTemplateBuilder) CalculateAllocatable

func (t *GceTemplateBuilder) CalculateAllocatable(capacity, kubeReserved apiv1.ResourceList) apiv1.ResourceList

CalculateAllocatable computes allocatable resources subtracting kube reserved values and kubelet eviction memory buffer from corresponding capacity.

type MachineTypeKey

type MachineTypeKey struct {
	Zone        string
	MachineType string
}

MachineTypeKey is used to identify MachineType.

type Mig

type Mig interface {
	cloudprovider.NodeGroup

	GceRef() GceRef
}

Mig implements NodeGroup interface.

type MigTargetSizesProvider

type MigTargetSizesProvider interface {
	// GetMigTargetSize returns targetSize for MIG with given ref
	GetMigTargetSize(migRef GceRef) (int64, error)
}

MigTargetSizesProvider allows obtaining target sizes of MIGs

func NewCachingMigTargetSizesProvider

func NewCachingMigTargetSizesProvider(cache *GceCache, gceClient AutoscalingGceClient, projectId string) MigTargetSizesProvider

NewCachingMigTargetSizesProvider creates an instance of caching MigTargetSizesProvider

Jump to

Keyboard shortcuts

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