Documentation ¶
Index ¶
- Constants
- func BuildGCE(opts config.AutoscalingOptions, do cloudprovider.NodeGroupDiscoveryOptions, ...) cloudprovider.CloudProvider
- func BuildGenericLabels(ref GceRef, machineType string, nodeName string) (map[string]string, error)
- func CalculateKernelReserved(physicalMemory int64) int64
- func GenerateInstanceUrl(ref GceRef) string
- func GenerateMigUrl(ref GceRef) string
- func NewAutoscalingGceClientV1(client *http.Client, projectId string) (*autoscalingGceClientV1, error)
- func NewCustomAutoscalingGceClientV1(client *http.Client, projectId, serverUrl string, ...) (*autoscalingGceClientV1, error)
- func ParseIgmUrl(url string) (project string, zone string, name string, err error)
- func ParseInstanceUrl(url string) (project string, zone string, name string, err error)
- func ParseMigUrl(url string) (project string, zone string, name string, err error)
- func RegisterMetrics()
- type AutoscalingGceClient
- type GceCache
- func (gc *GceCache) AddMachineToCache(machineType string, zone string, machine *gce.MachineType)
- func (gc *GceCache) GetMachineFromCache(machineType string, zone string) *gce.MachineType
- func (gc *GceCache) GetMigBasename(migRef GceRef) (basename string, found bool)
- func (gc *GceCache) GetMigForInstance(instanceRef GceRef) (Mig, error)
- func (gc *GceCache) GetMigTargetSize(ref GceRef) (int64, bool)
- func (gc *GceCache) GetMigs() []Mig
- func (gc *GceCache) GetResourceLimiter() (*cloudprovider.ResourceLimiter, error)
- func (gc *GceCache) InvalidateAllMigBasenames()
- func (gc *GceCache) InvalidateAllMigTargetSizes()
- func (gc *GceCache) InvalidateMigBasename(migRef GceRef)
- func (gc *GceCache) InvalidateMigTargetSize(ref GceRef)
- func (gc *GceCache) RegenerateInstanceCacheForMig(migRef GceRef) error
- func (gc *GceCache) RegenerateInstancesCache() error
- func (gc *GceCache) RegisterMig(newMig Mig) bool
- func (gc *GceCache) SetMachinesCache(machinesCache map[MachineTypeKey]*gce.MachineType)
- func (gc *GceCache) SetMigBasename(migRef GceRef, basename string)
- func (gc *GceCache) SetMigTargetSize(ref GceRef, size int64)
- func (gc *GceCache) SetResourceLimiter(resourceLimiter *cloudprovider.ResourceLimiter)
- func (gc *GceCache) UnregisterMig(toBeRemoved Mig) bool
- type GceCloudProvider
- func (gce *GceCloudProvider) Cleanup() error
- func (gce *GceCloudProvider) GPULabel() string
- func (gce *GceCloudProvider) GetAvailableGPUTypes() map[string]struct{}
- func (gce *GceCloudProvider) GetAvailableMachineTypes() ([]string, error)
- func (gce *GceCloudProvider) GetResourceLimiter() (*cloudprovider.ResourceLimiter, error)
- func (gce *GceCloudProvider) Name() string
- func (gce *GceCloudProvider) NewNodeGroup(machineType string, labels map[string]string, systemLabels map[string]string, ...) (cloudprovider.NodeGroup, error)
- func (gce *GceCloudProvider) NodeGroupForNode(node *apiv1.Node) (cloudprovider.NodeGroup, error)
- func (gce *GceCloudProvider) NodeGroups() []cloudprovider.NodeGroup
- func (gce *GceCloudProvider) Pricing() (cloudprovider.PricingModel, errors.AutoscalerError)
- func (gce *GceCloudProvider) Refresh() error
- type GceManager
- type GcePriceModel
- type GceRef
- type GceTemplateBuilder
- func (t *GceTemplateBuilder) BuildAllocatableFromKubeEnv(capacity apiv1.ResourceList, kubeEnv string) (apiv1.ResourceList, error)
- func (t *GceTemplateBuilder) BuildCapacity(cpu int64, mem int64, accelerators []*gce.AcceleratorConfig) (apiv1.ResourceList, error)
- func (t *GceTemplateBuilder) BuildNodeFromTemplate(mig Mig, template *gce.InstanceTemplate, cpu int64, mem int64) (*apiv1.Node, error)
- func (t *GceTemplateBuilder) CalculateAllocatable(capacity, kubeReserved apiv1.ResourceList) apiv1.ResourceList
- type MachineTypeKey
- type Mig
- type MigTargetSizesProvider
Constants ¶
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" )
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" )
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 ¶
func BuildGCE(opts config.AutoscalingOptions, do cloudprovider.NodeGroupDiscoveryOptions, rl *cloudprovider.ResourceLimiter) cloudprovider.CloudProvider
BuildGCE builds GCE cloud provider, manager etc.
func BuildGenericLabels ¶
BuildGenericLabels builds basic labels that should be present on every GCE node, including hostname, zone etc.
func CalculateKernelReserved ¶
CalculateKernelReserved computes how much memory Linux kernel will reserve. TODO(jkaniuk): account for crashkernel reservation on RHEL / CentOS
func GenerateInstanceUrl ¶
GenerateInstanceUrl generates url for instance.
func GenerateMigUrl ¶
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 ¶
ParseIgmUrl expects url in format: https://content.googleapis.com/compute/v1/projects/<project-id>/zones/<zone>/instanceGroupManagers/<name>
func ParseInstanceUrl ¶
ParseInstanceUrl expects url in format: https://content.googleapis.com/compute/v1/projects/<project-id>/zones/<zone>/instances/<name>
func ParseMigUrl ¶
ParseMigUrl expects url in format: https://content.googleapis.com/compute/v1/projects/<project-id>/zones/<zone>/instanceGroups/<name>
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 ¶
GetMigBasename get basename for given mig from cache.
func (*GceCache) GetMigForInstance ¶
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 ¶
GetMigTargetSize returns the cached targetSize for a GceRef
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 ¶
InvalidateMigBasename invalidates basename entry for given mig.
func (*GceCache) InvalidateMigTargetSize ¶
InvalidateMigTargetSize clears the target size cache
func (*GceCache) RegenerateInstanceCacheForMig ¶
RegenerateInstanceCacheForMig triggers instances cache regeneration for single MIG under lock.
func (*GceCache) RegenerateInstancesCache ¶
RegenerateInstancesCache triggers instances cache regeneration under lock.
func (*GceCache) RegisterMig ¶
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 ¶
SetMigBasename sets basename for given mig in cache
func (*GceCache) SetMigTargetSize ¶
SetMigTargetSize sets targetSize for a GceRef
func (*GceCache) SetResourceLimiter ¶
func (gc *GceCache) SetResourceLimiter(resourceLimiter *cloudprovider.ResourceLimiter)
SetResourceLimiter sets resource limiter.
func (*GceCache) UnregisterMig ¶
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 ¶
func (gce *GceCloudProvider) Pricing() (cloudprovider.PricingModel, errors.AutoscalerError)
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.
type GceRef ¶
GceRef contains s reference to some entity in GCE world.
func GceRefFromProviderId ¶
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 ¶
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) ToProviderId ¶
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 ¶
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