Documentation ¶
Index ¶
- Constants
- func BuildGenericLabels(ref GceRef, machineType string, nodeName string) (map[string]string, error)
- 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)
- 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) GetMigForInstance(instance *GceRef) (Mig, error)
- func (gc *GceCache) GetMigs() []*MigInformation
- func (gc *GceCache) GetResourceLimiter() (*cloudprovider.ResourceLimiter, error)
- func (gc *GceCache) RegenerateInstancesCache() error
- func (gc *GceCache) RegisterMig(mig Mig) bool
- func (gc *GceCache) SetMachinesCache(machinesCache map[MachineTypeKey]*gce.MachineType)
- func (gc *GceCache) SetResourceLimiter(resourceLimiter *cloudprovider.ResourceLimiter)
- func (gc *GceCache) UnregisterMig(toBeRemoved Mig) bool
- type GceCloudProvider
- func (gce *GceCloudProvider) Cleanup() error
- 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) BuildAllocatableFromCapacity(capacity apiv1.ResourceList) apiv1.ResourceList
- func (t *GceTemplateBuilder) BuildAllocatableFromKubeEnv(capacity apiv1.ResourceList, kubeEnv string) (apiv1.ResourceList, error)
- func (t *GceTemplateBuilder) BuildCapacity(machineType string, accelerators []*gce.AcceleratorConfig, zone string, ...) (apiv1.ResourceList, error)
- func (t *GceTemplateBuilder) BuildNodeFromTemplate(mig Mig, template *gce.InstanceTemplate, cpu int64, mem int64) (*apiv1.Node, error)
- type MachineTypeKey
- type Mig
- type MigInformation
Constants ¶
const (
// ProviderNameGCE is the name of GCE cloud provider.
ProviderNameGCE = "gce"
)
Variables ¶
This section is empty.
Functions ¶
func BuildGenericLabels ¶
BuildGenericLabels builds basic labels that should be present on every GCE node, including hostname, zone etc.
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) FetchMigTargetSize(GceRef) (int64, error) FetchMigBasename(GceRef) (string, error) FetchMigInstances(GceRef) ([]GceRef, 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. - instancesCache (2) is based on registered migs (1). For each mig, its instances are fetched from GCE API using gceService. - instancesCache (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) 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) GetMigs ¶
func (gc *GceCache) GetMigs() []*MigInformation
GetMigs returns a copy of migs list.
func (*GceCache) GetResourceLimiter ¶
func (gc *GceCache) GetResourceLimiter() (*cloudprovider.ResourceLimiter, error)
GetResourceLimiter returns resource limiter.
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) 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 alredy 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) 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() []*MigInformation // GetMigNodes returns mig nodes. GetMigNodes(mig Mig) ([]string, 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.
type GceTemplateBuilder ¶
type GceTemplateBuilder struct{}
GceTemplateBuilder builds templates for GCE nodes.
func (*GceTemplateBuilder) BuildAllocatableFromCapacity ¶
func (t *GceTemplateBuilder) BuildAllocatableFromCapacity(capacity apiv1.ResourceList) apiv1.ResourceList
BuildAllocatableFromCapacity builds node allocatable based only on node capacity. Calculates reserved as a ratio of capacity. See calculateReserved for more details
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(machineType string, accelerators []*gce.AcceleratorConfig, zone string, cpu int64, mem int64) (apiv1.ResourceList, error)
BuildCapacity builds a list of resource capacities for a node.
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.
type MachineTypeKey ¶
MachineTypeKey is used to identify MachineType.
type Mig ¶
type Mig interface { cloudprovider.NodeGroup GceRef() GceRef }
Mig implements NodeGroup interface.
type MigInformation ¶
MigInformation is a wrapper for Mig.