gce

package
v0.0.0-...-30e57c9 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2024 License: Apache-2.0 Imports: 45 Imported by: 24

Documentation

Index

Constants

View Source
const (

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

	// ErrorCodeResourcePoolExhausted is an error code used in InstanceErrorInfo if requested resources
	// cannot be provisioned by cloud provider.
	ErrorCodeResourcePoolExhausted = "RESOURCE_POOL_EXHAUSTED"

	// ErrorIPSpaceExhausted is an error code used in InstanceErrorInfo if the IP space has been
	// exhausted.
	ErrorIPSpaceExhausted = "IP_SPACE_EXHAUSTED"

	// ErrorCodePermissions is an error code used in InstanceErrorInfo if the user is facing
	// permissions error
	ErrorCodePermissions = "PERMISSIONS_ERROR"

	// ErrorCodeVmExternalIpAccessPolicyConstraint is an error code in InstanceErrorInfo if the user
	// is facing errors caused by vmExternalIpAccess policy constraint misconfiguration.
	ErrorCodeVmExternalIpAccessPolicyConstraint = "VM_EXTERNAL_IP_ACCESS_POLICY_CONSTRAINT"

	// ErrorInvalidReservation is an error code for InstanceErrorInfo if the node group couldn't
	// be scaled up because the reservation associated with the MIG was invalid.
	ErrorInvalidReservation = "INVALID_RESERVATION"

	// ErrorReservationNotFound is an error code for InstanceErrorInfo if the node group couldn't
	// be scaled up because no reservation was found, or the reservation was in different location,
	// or the reservation was incorrectly shared.
	ErrorReservationNotFound = "RESERVATION_NOT_FOUND"

	// ErrorReservationNotReady is an error code for InstanceErrorInfo if the node group couldn't
	// be scaled up because the associated reservation was not ready.
	ErrorReservationNotReady = "RESERVATION_NOT_READY"

	// ErrorReservationCapacityExceeded is an error code for InstanceErrorInfo if the node group couldn't
	// be scaled up because the associated reservation's capacity has been exceeded.
	ErrorReservationCapacityExceeded = "RESERVATION_CAPACITY_EXCEEDED"

	// ErrorReservationIncompatible is an error code for InstanceErrorInfo if the node group couldn't
	// be scaled up because the associated reservation is not compatible with the node group.
	ErrorReservationIncompatible = "RESERVATION_INCOMPATIBLE"

	// ErrorUnsupportedTpuConfiguration is an error code for InstanceErrorInfo if the
	// node group couldn't be scaled up because of invalid TPU configuration.
	ErrorUnsupportedTpuConfiguration = "UNSUPPORTED_TPU_CONFIGURATION"

	// ErrorCodeOther is an error code used in InstanceErrorInfo if other error occurs.
	ErrorCodeOther = "OTHER"

	// MaxInstancesLogged is the maximum number of instances for which we will
	// log detailed information for each Instance.List API call
	MaxInstancesLogged = 20
)
View Source
const (
	// KiB - KibiByte size (2^10)
	KiB = 1024
	// MiB - MebiByte size (2^20)
	MiB = 1024 * 1024
	// GiB - GibiByte size (2^30)
	GiB = 1024 * 1024 * 1024

	// MemoryEvictionHardTag tag passed by kubelet used to determine evictionHard values
	MemoryEvictionHardTag = "memory.available"
	// EphemeralStorageEvictionHardTag tag passed by kubelet used to determine evictionHard values
	EphemeralStorageEvictionHardTag = "nodefs.available"
)
View Source
const (
	// LocalSsdCountAnnotation is the annotation for number of attached local SSDs to the node.
	LocalSsdCountAnnotation = "cluster-autoscaler/gce/local-ssd-count"
	// BootDiskTypeAnnotation is the annotation for boot disk type of the node.
	BootDiskTypeAnnotation = "cluster-autoscaler/gce/boot-disk-type"
	// BootDiskSizeAnnotation is the annotation for boot disk sise of the node/
	BootDiskSizeAnnotation = "cluster-autoscaler/gce/boot-disk-size"
	// EphemeralStorageLocalSsdAnnotation is the annotation for nodes where ephemeral storage is backed up by local SSDs.
	EphemeralStorageLocalSsdAnnotation = "cluster-autoscaler/gce/ephemeral-storage-local-ssd"
)

These annotations are used internally only to store information in node temlate and use it later in CA, the actuall nodes won't have these annotations.

View Source
const DefaultBootDiskSizeGB = 100

DefaultBootDiskSizeGB is 100 GB.

View Source
const (
	// GPULabel is the label added to nodes with GPU resource.
	GPULabel = "cloud.google.com/gke-accelerator"
)

Variables

View Source
var (

	// DefaultBootDiskType is pd-balanced disk type.
	// ref: https://cloud.google.com/kubernetes-engine/docs/how-to/custom-boot-disks#specify
	DefaultBootDiskType = "pd-balanced"
)

Functions

func BuildGCE

BuildGCE builds GCE cloud provider, manager etc.

func BuildGenericLabels

func BuildGenericLabels(ref GceRef, machineType string, nodeName string, os OperatingSystem, arch SystemArchitecture) (map[string]string, error)

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

func EphemeralStorageOnLocalSSDFilesystemOverheadInBytes

func EphemeralStorageOnLocalSSDFilesystemOverheadInBytes(diskCount int64, osDistribution OperatingSystemDistribution) int64

EphemeralStorageOnLocalSSDFilesystemOverheadInBytes estimates the difference between the total physical capacity of the local SSDs and the ephemeral storage filesystem capacity. It uses experimental values measured for all possible disk counts in GKE. Custom Kubernetes on GCE may allow intermediate counts, attaching the measured count, but not using it all for ephemeral storage. In that case, the difference in overhead between GKE and custom node images may be higher than the difference in overhead between two disk counts, so interpolating wouldn't make much sense. Instead, we use the next count for which we measured a filesystem overhead, which is a safer approximation (better to reserve more and not scale up than not enough and not schedule).

func GenerateInstanceUrl

func GenerateInstanceUrl(domainUrl string, ref GceRef) string

GenerateInstanceUrl generates url for instance.

func GenerateMigUrl

func GenerateMigUrl(domainUrl string, ref GceRef) string

GenerateMigUrl generates url for instance.

func GetErrorInfo

func GetErrorInfo(errorCode, errorMessage, instanceStatus string, previousErrorInfo *cloudprovider.InstanceErrorInfo) *cloudprovider.InstanceErrorInfo

GetErrorInfo maps the error code, error message and instance status to CA instance error info

func GetKubeletEvictionHardForEphemeralStorage

func GetKubeletEvictionHardForEphemeralStorage(diskSize int64, evictionHard *EvictionHard) float64

GetKubeletEvictionHardForEphemeralStorage calculates the evictionHard value for Ephemeral Storage.

func GetKubeletEvictionHardForMemory

func GetKubeletEvictionHardForMemory(evictionHard *EvictionHard) int64

GetKubeletEvictionHardForMemory calculates the evictionHard value for Memory.

func GetLabelsFromKubeEnv

func GetLabelsFromKubeEnv(kubeEnv KubeEnv) (map[string]string, error)

GetLabelsFromKubeEnv returns labels from kube-env

func GetMachineFamily

func GetMachineFamily(machineType string) (string, error)

GetMachineFamily gets the machine family from the machine type. Machine family is determined as everything before the first dash character, unless this first part is "custom", which actually means "n1": https://cloud.google.com/compute/docs/instances/creating-instance-with-custom-machine-type#gcloud.

func GetTaintsFromKubeEnv

func GetTaintsFromKubeEnv(kubeEnv KubeEnv) ([]apiv1.Taint, error)

GetTaintsFromKubeEnv returns labels from kube-env

func IsCustomMachine

func IsCustomMachine(machineType string) bool

IsCustomMachine checks if a machine type is custom or predefined.

func IsInstanceTemplateRegional

func IsInstanceTemplateRegional(templateUrl string) (bool, error)

IsInstanceTemplateRegional determines whether or not an instance template is regional based on the url

func NewAutoscalingGceClientV1

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

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

func NewAutoscalingGceClientV1WithTimeout

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

NewAutoscalingGceClientV1WithTimeout creates a new client with custom timeouts for communicating with GCE v1 API

func NewCustomAutoscalingGceClientV1

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

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

func NewMigLister

func NewMigLister(cache *GceCache) *migLister

NewMigLister returns an instance of migLister

func ParseIgmUrl

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

ParseIgmUrl expects url in format: https://.*/<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://.*/<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://.*/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)
	FetchAllInstances(project, zone string, filter string) ([]GceInstance, error)
	FetchMigTargetSize(GceRef) (int64, error)
	FetchMigBasename(GceRef) (string, error)
	FetchMigInstances(GceRef) ([]GceInstance, error)
	FetchMigTemplateName(migRef GceRef) (InstanceTemplateName, error)
	FetchMigTemplate(migRef GceRef, templateName string, regional bool) (*gce.InstanceTemplate, error)
	FetchMigsWithName(zone string, filter *regexp.Regexp) ([]string, error)
	FetchZones(region string) ([]string, error)
	FetchAvailableCpuPlatforms() (map[string][]string, error)
	FetchAvailableDiskTypes() (map[string][]string, error)
	FetchReservations() ([]*gce.Reservation, error)
	FetchReservationsInProject(projectId string) ([]*gce.Reservation, error)
	FetchListManagedInstancesResults(migRef GceRef) (string, error)

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

	// WaitForOperation can be used to poll GCE operations until completion/timeout using WAIT calls.
	// Calling this is normally not needed when interacting with the client, other methods should call it internally.
	// Can be used to extend the interface with more methods outside of this package.
	WaitForOperation(operationName, operationType, project, zone string) error
}

AutoscalingGceClient is used for communicating with GCE API.

type EvictionHard

type EvictionHard struct {
	MemoryEvictionQuantity        int64
	EphemeralStorageEvictionRatio float64
}

EvictionHard is the struct used to keep parsed values for eviction

func ParseEvictionHardOrGetDefault

func ParseEvictionHardOrGetDefault(evictionHard map[string]string) *EvictionHard

ParseEvictionHardOrGetDefault tries to parse evictionHard map, else fills defaults to be used.

type GceCache

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

GceCache is used for caching cluster resources state.

It is needed to: - keep track of MIGs in the cluster, - keep track of instances in the cluster, - keep track of MIGs to instances mapping, - keep track of MIGs configuration such as target size and basename, - keep track of resource limiters and machine types, - limit repetitive GCE API calls.

Cache keeps these values and gives access to getters, setters and invalidators all guarded with mutex. Cache does not refresh the data by itself - it just provides an interface enabling access to this data.

The caches maintained here differ in terms of expected lifetime. Mig instance, basename, target size and instance template name caches need to be refreshed each loop to guarantee their freshness. Other values like Migs and instance templates are cached for longer periods of time and are refreshed either periodically or in response to detecting cluster state changes.

func NewGceCache

func NewGceCache() *GceCache

NewGceCache creates empty GceCache.

func (*GceCache) AddMachine

func (gc *GceCache) AddMachine(machineType MachineType, zone string)

AddMachine adds machine to cache under lock.

func (*GceCache) GetAutoscalingOptions

func (gc *GceCache) GetAutoscalingOptions(ref GceRef) map[string]string

GetAutoscalingOptions return autoscaling options strings obtained from IT.

func (*GceCache) GetListManagedInstancesResults

func (gc *GceCache) GetListManagedInstancesResults(migRef GceRef) (string, bool)

GetListManagedInstancesResults gets listManagedInstancesResults for a given mig from cache.

func (*GceCache) GetMachine

func (gc *GceCache) GetMachine(machineTypeName string, zone string) (MachineType, bool)

GetMachine retrieves machine type from cache under lock.

func (*GceCache) GetMig

func (gc *GceCache) GetMig(migRef GceRef) (Mig, bool)

GetMig returns a MIG for a given GceRef.

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) (GceRef, bool)

GetMigForInstance returns the cached MIG for instance GceRef

func (*GceCache) GetMigInstanceTemplate

func (gc *GceCache) GetMigInstanceTemplate(ref GceRef) (*gce.InstanceTemplate, bool)

GetMigInstanceTemplate returns the cached gce.InstanceTemplate for a mig GceRef

func (*GceCache) GetMigInstanceTemplateName

func (gc *GceCache) GetMigInstanceTemplateName(ref GceRef) (InstanceTemplateName, bool)

GetMigInstanceTemplateName returns the cached instance template ref for a mig GceRef

func (*GceCache) GetMigInstances

func (gc *GceCache) GetMigInstances(migRef GceRef) ([]GceInstance, bool)

GetMigInstances returns the cached instances for a given MIG GceRef

func (*GceCache) GetMigInstancesStateCount

func (gc *GceCache) GetMigInstancesStateCount(migRef GceRef) (instanceState map[cloudprovider.InstanceState]int64, found bool)

GetMigInstancesStateCount returns counts of instances in different states for the given mig from cache.

func (*GceCache) GetMigInstancesUpdateTime

func (gc *GceCache) GetMigInstancesUpdateTime(migRef GceRef) (time.Time, bool)

GetMigInstancesUpdateTime returns the timestamp when the cached instances were updated for a given MIG GceRef

func (*GceCache) GetMigKubeEnv

func (gc *GceCache) GetMigKubeEnv(ref GceRef) (KubeEnv, bool)

GetMigKubeEnv returns the cached KubeEnv for a mig GceRef

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) InvalidateAllInstancesToMig

func (gc *GceCache) InvalidateAllInstancesToMig()

InvalidateAllInstancesToMig clears the instance to mig cache

func (*GceCache) InvalidateAllListManagedInstancesResults

func (gc *GceCache) InvalidateAllListManagedInstancesResults()

InvalidateAllListManagedInstancesResults invalidates all listManagedInstancesResults entries.

func (*GceCache) InvalidateAllMachines

func (gc *GceCache) InvalidateAllMachines()

InvalidateAllMachines invalidates the machines cache under lock.

func (*GceCache) InvalidateAllMigBasenames

func (gc *GceCache) InvalidateAllMigBasenames()

InvalidateAllMigBasenames invalidates all basename entries.

func (*GceCache) InvalidateAllMigInstanceTemplateNames

func (gc *GceCache) InvalidateAllMigInstanceTemplateNames()

InvalidateAllMigInstanceTemplateNames clears the instance template ref cache

func (*GceCache) InvalidateAllMigInstanceTemplates

func (gc *GceCache) InvalidateAllMigInstanceTemplates()

InvalidateAllMigInstanceTemplates clears the instance template cache

func (*GceCache) InvalidateAllMigInstances

func (gc *GceCache) InvalidateAllMigInstances()

InvalidateAllMigInstances clears the mig instances cache

func (*GceCache) InvalidateAllMigKubeEnvs

func (gc *GceCache) InvalidateAllMigKubeEnvs()

InvalidateAllMigKubeEnvs clears the kube-env cache

func (*GceCache) InvalidateAllMigTargetSizes

func (gc *GceCache) InvalidateAllMigTargetSizes()

InvalidateAllMigTargetSizes clears the target size cache

func (*GceCache) InvalidateInstancesToMig

func (gc *GceCache) InvalidateInstancesToMig(migRef GceRef)

InvalidateInstancesToMig clears the instance to mig mapping for a GceRef

func (*GceCache) InvalidateMigBasename

func (gc *GceCache) InvalidateMigBasename(migRef GceRef)

InvalidateMigBasename invalidates basename entry for given mig.

func (*GceCache) InvalidateMigInstanceTemplate

func (gc *GceCache) InvalidateMigInstanceTemplate(ref GceRef)

InvalidateMigInstanceTemplate clears the instance template cache for a mig GceRef

func (*GceCache) InvalidateMigInstanceTemplateName

func (gc *GceCache) InvalidateMigInstanceTemplateName(ref GceRef)

InvalidateMigInstanceTemplateName clears the instance template ref cache for a mig GceRef

func (*GceCache) InvalidateMigInstances

func (gc *GceCache) InvalidateMigInstances(migRef GceRef)

InvalidateMigInstances clears the mig instances cache for a given Mig

func (*GceCache) InvalidateMigInstancesStateCount

func (gc *GceCache) InvalidateMigInstancesStateCount()

InvalidateMigInstancesStateCount invalidates all migInstancesStateCountCache entries.

func (*GceCache) InvalidateMigKubeEnv

func (gc *GceCache) InvalidateMigKubeEnv(ref GceRef)

InvalidateMigKubeEnv clears the kube-env cache for a mig GceRef

func (*GceCache) InvalidateMigTargetSize

func (gc *GceCache) InvalidateMigTargetSize(ref GceRef)

InvalidateMigTargetSize clears the target size cache

func (*GceCache) IsMigUnknownForInstance

func (gc *GceCache) IsMigUnknownForInstance(instanceRef GceRef) bool

IsMigUnknownForInstance checks if MIG was marked as unknown for instance, meaning that a Mig to which this instance should belong does not list it as one of its instances.

func (*GceCache) MarkInstanceMigUnknown

func (gc *GceCache) MarkInstanceMigUnknown(instanceRef GceRef)

MarkInstanceMigUnknown sets instance MIG to unknown, meaning that a Mig to which this instance should belong does not list it as one of its instances.

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) SetAutoscalingOptions

func (gc *GceCache) SetAutoscalingOptions(ref GceRef, options map[string]string)

SetAutoscalingOptions stores autoscaling options strings obtained from IT.

func (*GceCache) SetListManagedInstancesResults

func (gc *GceCache) SetListManagedInstancesResults(migRef GceRef, listManagedInstancesResults string)

SetListManagedInstancesResults sets listManagedInstancesResults for a given mig in cache

func (*GceCache) SetMachines

func (gc *GceCache) SetMachines(machinesCache map[MachineTypeKey]MachineType)

SetMachines 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) SetMigInstanceTemplate

func (gc *GceCache) SetMigInstanceTemplate(ref GceRef, instanceTemplate *gce.InstanceTemplate)

SetMigInstanceTemplate sets gce.InstanceTemplate for a mig GceRef

func (*GceCache) SetMigInstanceTemplateName

func (gc *GceCache) SetMigInstanceTemplateName(ref GceRef, instanceTemplateName InstanceTemplateName)

SetMigInstanceTemplateName sets instance template ref for a mig GceRef

func (*GceCache) SetMigInstances

func (gc *GceCache) SetMigInstances(migRef GceRef, instances []GceInstance, timeNow time.Time) error

SetMigInstances sets instances for a given Mig ref

func (*GceCache) SetMigInstancesStateCount

func (gc *GceCache) SetMigInstancesStateCount(migRef GceRef, instanceState map[cloudprovider.InstanceState]int64)

SetMigInstancesStateCount sets the counts of instances in different states for a given mig in cache.

func (*GceCache) SetMigKubeEnv

func (gc *GceCache) SetMigKubeEnv(ref GceRef, kubeEnv KubeEnv)

SetMigKubeEnv sets KubeEnv for a mig GceRef

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, pricingModel cloudprovider.PricingModel) (*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) GetNodeGpuConfig

func (gce *GceCloudProvider) GetNodeGpuConfig(node *apiv1.Node) *cloudprovider.GpuConfig

GetNodeGpuConfig returns the label, type and resource name for the GPU added to node. If node doesn't have any GPUs, it returns nil.

func (*GceCloudProvider) GetResourceLimiter

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

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

func (*GceCloudProvider) HasInstance

func (gce *GceCloudProvider) HasInstance(node *apiv1.Node) (bool, error)

HasInstance returns whether a given node has a corresponding instance in this cloud provider

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 GceInstance

type GceInstance struct {
	cloudprovider.Instance
	NumericId            uint64
	Igm                  GceRef
	InstanceTemplateName string
}

GceInstance extends cloudprovider.Instance with GCE specific numeric id.

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) ([]GceInstance, 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)
	// GetMigOptions returns MIG's NodeGroupAutoscalingOptions
	GetMigOptions(mig Mig, defaults config.NodeGroupAutoscalingOptions) *config.NodeGroupAutoscalingOptions

	// 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
	// CreateInstances creates delta new instances in a given mig.
	CreateInstances(mig Mig, delta int64) error
}

GceManager handles GCE communication and data caching.

func CreateGceManager

func CreateGceManager(configReader io.Reader, discoveryOpts cloudprovider.NodeGroupDiscoveryOptions,
	localSSDDiskSizeProvider localssdsize.LocalSSDSizeProvider,
	regional, bulkGceMigInstancesListingEnabled bool, concurrentGceRefreshes int, userAgent, domainUrl string, migInstancesMinRefreshWaitTime time.Duration) (GceManager, error)

CreateGceManager constructs GceManager object.

type GceMigOsInfo

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

GceMigOsInfo contains os details of nodes in gce mig.

func (*GceMigOsInfo) Arch

func (m *GceMigOsInfo) Arch() SystemArchitecture

Arch return system architecture.

func (*GceMigOsInfo) Os

func (m *GceMigOsInfo) Os() OperatingSystem

Os return operating system.

func (*GceMigOsInfo) OsDistribution

func (m *GceMigOsInfo) OsDistribution() OperatingSystemDistribution

OsDistribution return operating system distribution.

type GcePriceInfo

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

GcePriceInfo is the GCE specific implementation of the PricingInfo.

func NewGcePriceInfo

func NewGcePriceInfo() *GcePriceInfo

NewGcePriceInfo returns a new instance of the GcePriceInfo.

func (*GcePriceInfo) BaseCpuPricePerHour

func (g *GcePriceInfo) BaseCpuPricePerHour() float64

BaseCpuPricePerHour gets the base cpu price per hour

func (*GcePriceInfo) BaseGpuPricePerHour

func (g *GcePriceInfo) BaseGpuPricePerHour() float64

BaseGpuPricePerHour gets the base gpu price per hour

func (*GcePriceInfo) BaseMemoryPricePerHourPerGb

func (g *GcePriceInfo) BaseMemoryPricePerHourPerGb() float64

BaseMemoryPricePerHourPerGb gets the base memory price per hour per Gb

func (*GcePriceInfo) BasePreemptibleDiscount

func (g *GcePriceInfo) BasePreemptibleDiscount() float64

BasePreemptibleDiscount gets the base preemptible discount applicable

func (*GcePriceInfo) BootDiskPricePerHour

func (g *GcePriceInfo) BootDiskPricePerHour() map[string]float64

BootDiskPricePerHour gets the price of boot disk.

func (*GcePriceInfo) CustomCpuPricePerHour

func (g *GcePriceInfo) CustomCpuPricePerHour() map[string]float64

CustomCpuPricePerHour gets the cpu price per hour for custom machine of a machine family

func (*GcePriceInfo) CustomMemoryPricePerHourPerGb

func (g *GcePriceInfo) CustomMemoryPricePerHourPerGb() map[string]float64

CustomMemoryPricePerHourPerGb gets the memory price per hour per Gb for custom machine of a machine family

func (*GcePriceInfo) CustomPreemptibleDiscount

func (g *GcePriceInfo) CustomPreemptibleDiscount() map[string]float64

CustomPreemptibleDiscount gets the preemptible discount of a machine family

func (*GcePriceInfo) GpuPrices

func (g *GcePriceInfo) GpuPrices() map[string]float64

GpuPrices gets the price of GPUs

func (*GcePriceInfo) InstancePrices

func (g *GcePriceInfo) InstancePrices() map[string]float64

InstancePrices gets the prices for standard machine types

func (*GcePriceInfo) LocalSsdPricePerHour

func (g *GcePriceInfo) LocalSsdPricePerHour() float64

LocalSsdPricePerHour gets the price of boot disk.

func (*GcePriceInfo) PredefinedCpuPricePerHour

func (g *GcePriceInfo) PredefinedCpuPricePerHour() map[string]float64

PredefinedCpuPricePerHour gets the predefined cpu price per hour for machine family

func (*GcePriceInfo) PredefinedMemoryPricePerHourPerGb

func (g *GcePriceInfo) PredefinedMemoryPricePerHourPerGb() map[string]float64

PredefinedMemoryPricePerHourPerGb gets the predefined memory price per hour per Gb for machine family

func (*GcePriceInfo) PredefinedPreemptibleDiscount

func (g *GcePriceInfo) PredefinedPreemptibleDiscount() map[string]float64

PredefinedPreemptibleDiscount gets the predefined preemptible discount for machine family

func (*GcePriceInfo) PreemptibleGpuPrices

func (g *GcePriceInfo) PreemptibleGpuPrices() map[string]float64

PreemptibleGpuPrices gets the price of preemptible GPUs

func (*GcePriceInfo) PreemptibleInstancePrices

func (g *GcePriceInfo) PreemptibleInstancePrices() map[string]float64

PreemptibleInstancePrices gets the preemptible prices for standard machine types

func (*GcePriceInfo) SpotLocalSsdPricePerHour

func (g *GcePriceInfo) SpotLocalSsdPricePerHour() float64

SpotLocalSsdPricePerHour gets the price of boot disk.

type GcePriceModel

type GcePriceModel struct {
	PriceInfo PriceInfo
	// contains filtered or unexported fields
}

GcePriceModel implements PriceModel interface for GCE.

func NewGcePriceModel

func NewGcePriceModel(info PriceInfo, localSSDSizeProvider localssdsize.LocalSSDSizeProvider) *GcePriceModel

NewGcePriceModel gets a new instance of GcePriceModel

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 ParseIgmUrlRef

func ParseIgmUrlRef(url string) (GceRef, error)

ParseIgmUrlRef expects url in format: projects/<project-id>/zones/<zone>/instanceGroupManagers/<name> and returns a GceRef struct for it.

func ParseInstanceUrlRef

func ParseInstanceUrlRef(url string) (GceRef, error)

ParseInstanceUrlRef expects url in format: https://.*/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 GceReserved

type GceReserved struct{}

GceReserved implement Reserved interface

func (*GceReserved) CalculateKernelReserved

func (r *GceReserved) CalculateKernelReserved(m MigOsInfo, physicalMemory int64) int64

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

func (*GceReserved) CalculateOSReservedEphemeralStorage

func (r *GceReserved) CalculateOSReservedEphemeralStorage(m MigOsInfo, diskSize int64) int64

CalculateOSReservedEphemeralStorage estimates how much ephemeral storage OS will reserve and eviction threshold

type GceTemplateBuilder

type GceTemplateBuilder struct{}

GceTemplateBuilder builds templates for GCE nodes.

func (*GceTemplateBuilder) BuildAllocatableFromKubeEnv

func (t *GceTemplateBuilder) BuildAllocatableFromKubeEnv(capacity apiv1.ResourceList, kubeEnv KubeEnv, evictionHard *EvictionHard) (apiv1.ResourceList, error)

BuildAllocatableFromKubeEnv builds node allocatable based on capacity of the node and value of kubeEnv.

func (*GceTemplateBuilder) BuildCapacity

func (t *GceTemplateBuilder) BuildCapacity(m MigOsInfo, cpu int64, mem int64, accelerators []*gce.AcceleratorConfig,
	ephemeralStorage int64, ephemeralStorageLocalSSDCount int64, pods *int64, r OsReservedCalculator, extendedResources apiv1.ResourceList) (apiv1.ResourceList, error)

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

func (*GceTemplateBuilder) BuildNodeFromTemplate

func (t *GceTemplateBuilder) BuildNodeFromTemplate(mig Mig, migOsInfo MigOsInfo, template *gce.InstanceTemplate, kubeEnv KubeEnv, cpu int64, mem int64, pods *int64, reserved OsReservedCalculator, localSSDSizeProvider localssdsize.LocalSSDSizeProvider) (*apiv1.Node, error)

BuildNodeFromTemplate builds node from provided GCE template.

func (*GceTemplateBuilder) CalculateAllocatable

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

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

func (*GceTemplateBuilder) MigOsInfo

func (t *GceTemplateBuilder) MigOsInfo(migId string, kubeEnv KubeEnv) (MigOsInfo, error)

MigOsInfo return os detailes information that stored in template.

type InstanceTemplateName

type InstanceTemplateName struct {
	Name     string
	Regional bool
}

InstanceTemplateName is used to store the name, and whether or not the instance template is regional

func InstanceTemplateNameFromUrl

func InstanceTemplateNameFromUrl(instanceTemplateLink string) (InstanceTemplateName, error)

InstanceTemplateNameFromUrl retrieves name of the Instance Template from the url.

type KubeEnv

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

KubeEnv stores kube-env information from InstanceTemplate

func ExtractKubeEnv

func ExtractKubeEnv(template *gce.InstanceTemplate) (KubeEnv, error)

ExtractKubeEnv extracts kube-env from InstanceTemplate

func ParseKubeEnv

func ParseKubeEnv(templateName, kubeEnvValue string) (KubeEnv, error)

ParseKubeEnv parses kube-env from its string representation

func (KubeEnv) Var

func (ke KubeEnv) Var(name string) (string, bool)

Var extracts variable from KubeEnv

type MachineType

type MachineType struct {
	// Name is the name of the particular MachineType (ex. e2-standard-4)
	Name string
	// CPU is the number of cores the machine has.
	CPU int64
	// Memory is the memory capacity of the machine in bytes.
	Memory int64
	// MaxDisk is the maximum total persistent disks size (GB) allowed.
	MaxDiskSizeGb int64
}

MachineType represents information about underlying GCE machine used by one or more MIGs.

func NewCustomMachineType

func NewCustomMachineType(name string) (MachineType, error)

NewCustomMachineType creates a MachineType object describing a custom GCE machine. CPU and Memory are based on parsing custom machine name.

func NewMachineTypeFromAPI

func NewMachineTypeFromAPI(name string, mt *gce_api.MachineType) (MachineType, error)

NewMachineTypeFromAPI creates a MachineType object based on machine type representation from GCE API client.

type MachineTypeKey

type MachineTypeKey struct {
	Zone            string
	MachineTypeName string
}

MachineTypeKey is used to identify MachineType.

type Mig

type Mig interface {
	cloudprovider.NodeGroup

	GceRef() GceRef
}

Mig implements NodeGroup interface.

type MigInfoProvider

type MigInfoProvider interface {
	// GetMigInstances returns instances for a given MIG ref
	GetMigInstances(migRef GceRef) ([]GceInstance, error)
	// GetMigForInstance returns MIG ref for a given instance
	GetMigForInstance(instanceRef GceRef) (Mig, error)
	// RegenerateMigInstancesCache regenerates MIGs to instances mapping cache
	RegenerateMigInstancesCache() error
	// GetMigTargetSize returns target size for given MIG ref
	GetMigTargetSize(migRef GceRef) (int64, error)
	// GetMigBasename returns basename for given MIG ref
	GetMigBasename(migRef GceRef) (string, error)
	// GetMigInstanceTemplateName returns instance template name for given MIG ref
	GetMigInstanceTemplateName(migRef GceRef) (InstanceTemplateName, error)
	// GetMigInstanceTemplate returns instance template for given MIG ref
	GetMigInstanceTemplate(migRef GceRef) (*gce.InstanceTemplate, error)
	// GetMigKubeEnv returns kube-env for given MIG ref
	GetMigKubeEnv(migRef GceRef) (KubeEnv, error)
	// GetMigMachineType returns machine type used by a MIG.
	// For custom machines cpu and memory information is based on parsing
	// machine name. For standard types it's retrieved from GCE API.
	GetMigMachineType(migRef GceRef) (MachineType, error)
	// Returns the pagination behavior of the listManagedInstances API method for a given MIG ref
	GetListManagedInstancesResults(migRef GceRef) (string, error)
}

MigInfoProvider allows obtaining information about MIGs

func NewCachingMigInfoProvider

func NewCachingMigInfoProvider(cache *GceCache, migLister MigLister, gceClient AutoscalingGceClient, projectId string, concurrentGceRefreshes int, migInstancesMinRefreshWaitTime time.Duration, bulkGceMigInstancesListingEnabled bool) MigInfoProvider

NewCachingMigInfoProvider creates an instance of caching MigInfoProvider

type MigLister

type MigLister interface {
	// GetMigs returns the list of migs
	GetMigs() []Mig
	// HandleMigIssue handles an issue with a given mig
	HandleMigIssue(migRef GceRef, err error)
}

MigLister is a mig listing interface

type MigOsInfo

type MigOsInfo interface {
	// Os return operating system.
	Os() OperatingSystem
	// OsDistribution return operating system distribution.
	OsDistribution() OperatingSystemDistribution
	// Arch return system architecture.
	Arch() SystemArchitecture
}

MigOsInfo store os parameters.

func NewMigOsInfo

func NewMigOsInfo(os OperatingSystem, osDistribution OperatingSystemDistribution, arch SystemArchitecture) MigOsInfo

NewMigOsInfo return gce implementation of MigOsInfo interface.

type OperatingSystem

type OperatingSystem string

OperatingSystem denotes operating system used by nodes coming from node group

const (
	// OperatingSystemUnknown is used if operating system is unknown
	OperatingSystemUnknown OperatingSystem = ""
	// OperatingSystemLinux is used if operating system is Linux
	OperatingSystemLinux OperatingSystem = "linux"
	// OperatingSystemWindows is used if operating system is Windows
	OperatingSystemWindows OperatingSystem = "windows"

	// OperatingSystemDefault defines which operating system will be assumed if not explicitly passed via AUTOSCALER_ENV_VARS
	OperatingSystemDefault = OperatingSystemLinux
)

type OperatingSystemDistribution

type OperatingSystemDistribution string

OperatingSystemDistribution denotes distribution of the operating system used by nodes coming from node group

const (
	// OperatingSystemDistributionUnknown is used if operating distribution system is unknown
	OperatingSystemDistributionUnknown OperatingSystemDistribution = ""
	// OperatingSystemDistributionUbuntu is used if operating distribution system is Ubuntu
	OperatingSystemDistributionUbuntu OperatingSystemDistribution = "ubuntu"
	// OperatingSystemDistributionWindowsLTSC is used if operating distribution system is Windows LTSC
	OperatingSystemDistributionWindowsLTSC OperatingSystemDistribution = "windows_ltsc"
	// OperatingSystemDistributionWindowsSAC is used if operating distribution system is Windows SAC
	OperatingSystemDistributionWindowsSAC OperatingSystemDistribution = "windows_sac"
	// OperatingSystemDistributionCOS is used if operating distribution system is COS
	OperatingSystemDistributionCOS OperatingSystemDistribution = "cos"

	// OperatingSystemDistributionDefault defines which operating system will be assumed if not explicitly passed via AUTOSCALER_ENV_VARS
	OperatingSystemDistributionDefault = OperatingSystemDistributionCOS
)

type OperatingSystemImage

type OperatingSystemImage string

OperatingSystemImage denotes image of the operating system used by nodes coming from node group

const (
	// OperatingSystemImageUnknown is used if operating distribution system is unknown
	OperatingSystemImageUnknown OperatingSystemImage = ""
	// OperatingSystemImageUbuntu is used if operating distribution system is Ubuntu
	OperatingSystemImageUbuntu OperatingSystemImage = "ubuntu"
	// OperatingSystemImageWindowsLTSC is used if operating distribution system is Windows LTSC
	OperatingSystemImageWindowsLTSC OperatingSystemImage = "windows_ltsc"
	// OperatingSystemImageWindowsSAC is used if operating distribution system is Windows SAC
	OperatingSystemImageWindowsSAC OperatingSystemImage = "windows_sac"
	// OperatingSystemImageCOS is used if operating distribution system is COS
	OperatingSystemImageCOS OperatingSystemImage = "cos"
	// OperatingSystemImageCOSContainerd is used if operating distribution system is COS Containerd
	OperatingSystemImageCOSContainerd OperatingSystemImage = "cos_containerd"
	// OperatingSystemImageUbuntuContainerd is used if operating distribution system is Ubuntu Containerd
	OperatingSystemImageUbuntuContainerd OperatingSystemImage = "ubuntu_containerd"
	// OperatingSystemImageWindowsLTSCContainerd is used if operating distribution system is Windows LTSC Containerd
	OperatingSystemImageWindowsLTSCContainerd OperatingSystemImage = "windows_ltsc_containerd"
	// OperatingSystemImageWindowsSACContainerd is used if operating distribution system is Windows SAC Containerd
	OperatingSystemImageWindowsSACContainerd OperatingSystemImage = "windows_sac_containerd"

	// OperatingSystemImageDefault defines which operating system will be assumed as default.
	OperatingSystemImageDefault = OperatingSystemImageCOSContainerd
)

type OsReservedCalculator

type OsReservedCalculator interface {
	// CalculateKernelReserved computes how much memory OS kernel will reserve.
	// NodeVersion parameter is optional. If empty string is passed a result calculated using default node version will be returned.
	CalculateKernelReserved(m MigOsInfo, physicalMemory int64) int64

	// CalculateOSReservedEphemeralStorage estimates how much ephemeral storage OS will reserve and eviction threshold.
	// NodeVersion parameter is optional. If empty string is passed a result calculated using default node version will be returned.
	CalculateOSReservedEphemeralStorage(m MigOsInfo, diskSize int64) int64
}

OsReservedCalculator calculates the OS reserved values.

type PriceInfo

type PriceInfo interface {
	// BaseCpuPricePerHour gets the base cpu price per hour.
	BaseCpuPricePerHour() float64
	// BaseMemoryPricePerHourPerGb gets the base memory price per hour per Gb.
	BaseMemoryPricePerHourPerGb() float64
	// BasePreemptibleDiscount gets the base preemptible discount applicable.
	BasePreemptibleDiscount() float64
	// BaseGpuPricePerHour gets the base gpu price per hour.
	BaseGpuPricePerHour() float64

	// PredefinedCpuPricePerHour gets the predefined cpu price per hour for machine family.
	PredefinedCpuPricePerHour() map[string]float64
	// PredefinedMemoryPricePerHourPerGb gets the predefined memory price per hour per Gb for machine family.
	PredefinedMemoryPricePerHourPerGb() map[string]float64
	// PredefinedPreemptibleDiscount gets the predefined preemptible discount for machine family.
	PredefinedPreemptibleDiscount() map[string]float64

	// CustomCpuPricePerHour gets the cpu price per hour for custom machine of a machine family.
	CustomCpuPricePerHour() map[string]float64
	// CustomMemoryPricePerHourPerGb gets the memory price per hour per Gb for custom machine of a machine family.
	CustomMemoryPricePerHourPerGb() map[string]float64
	CustomPreemptibleDiscount() map[string]float64

	InstancePrices() map[string]float64
	PreemptibleInstancePrices() map[string]float64

	GpuPrices() map[string]float64
	// PreemptibleGpuPrices gets the price of preemptible GPUs.
	PreemptibleGpuPrices() map[string]float64

	// BootDiskPricePerHour returns the map of the prices per Gb of boot disk per hour.
	BootDiskPricePerHour() map[string]float64
	// LocalSsdPricePerHour returns the price per Gb of local SSD per hour.
	LocalSsdPricePerHour() float64
	// LocalSsdPricePerHour returns the price per Gb of local SSD per hour for Spot VMs.
	SpotLocalSsdPricePerHour() float64
}

PriceInfo is the interface to fetch the pricing information needed for gce pricing.

type SystemArchitecture

type SystemArchitecture string

SystemArchitecture denotes distribution of the System Architecture used by nodes coming from node group

const (
	// UnknownArch is used if the Architecture is Unknown
	UnknownArch SystemArchitecture = ""
	// Amd64 is used if the Architecture is x86_64
	Amd64 SystemArchitecture = "amd64"
	// Arm64 is used if the Architecture is ARM
	Arm64 SystemArchitecture = "arm64"
	// DefaultArch is used if the Architecture is used as a fallback if not passed by AUTOSCALER_ENV_VARS
	DefaultArch SystemArchitecture = Amd64
)

func ToSystemArchitecture

func ToSystemArchitecture(arch string) SystemArchitecture

ToSystemArchitecture parses a string to SystemArchitecture. Returns UnknownArch if the string doesn't represent a valid architecture.

func (SystemArchitecture) Name

func (s SystemArchitecture) Name() string

Name returns the string value for SystemArchitecture

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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