ovhcloud

package
v0.0.0-...-da31dff Latest Latest
Warning

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

Go to latest
Published: Dec 17, 2024 License: Apache-2.0 Imports: 22 Imported by: 0

README

Cluster Autoscaler for OVHcloud

The cluster autoscaler for OVHclud scales worker nodes within any OVHcloud Kubernetes cluster's node pool. This autoscaler should only watch and offer scaling options on node pools with the autoscaling optional parameter enabled.

Configuration

The cluster-autoscaler with OVHcloud needs a configuration file to work by using --cloud-config parameter.

Here is an sample:

{
  "project_id": "<my_project_id>",
  "cluster_id": "<my_cluster_id>",

  "authentication_type": "consumer",

  "application_endpoint": "ovh-eu",
  "application_key": "key",
  "application_secret": "secret",
  "application_consumer_key": "consumer_key"
}

cluster_id and project_id can be found on your OVHcloud manager.

For application tokens, you should visit: https://api.ovh.com/createToken/

Host specification

At OVHcloud, we offer the cluster-autoscaler to run on the Kubernetes cluster control-plane.

The cluster-autoscaler is free to use, and we recommend not to use this project unless you want to try out specific configurations.

Environment

You should be able to find the custom resource definition with:

kubectl get crd nodepools.kube.cloud.ovh.com -o json

{
    "apiVersion": "apiextensions.k8s.io/v1",
    "kind": "CustomResourceDefinition",
    "metadata": {
        "name": "nodepools.kube.cloud.ovh.com",
        "selfLink": "/apis/apiextensions.k8s.io/v1/customresourcedefinitions/nodepools.kube.cloud.ovh.com",
        ...
    },
    ...
}

To know if your node pools auto-scaling is enabled, you can simply output the resources:

kubectl get nodepools

NAME             FLAVOR   AUTO-SCALING     MONTHLY BILLED   ANTI AFFINITY   AGE
nodepool-b2-7    b2-7     true             false            false           140d
...

You should be able to edit the auto-scaling parameters using kubectl edit or by requesting the OVHcloud API.

Development

Make sure you're inside the root path of the autoscaler repository

1.) Build the cluster-autoscaler binary:

make build-in-docker

2.) Build the docker image:

docker build -t ovhcloud/cluster-autoscaler:dev .

3.) Push the docker image to Docker hub:

docker push ovhcloud/cluster-autoscaler:dev

Documentation

Index

Constants

View Source
const (
	// OpenStackAuthenticationType to request a keystone token credentials.
	OpenStackAuthenticationType = "openstack"

	// ApplicationConsumerAuthenticationType to consume an application key credentials.
	ApplicationConsumerAuthenticationType = "consumer"
)

Authentication methods defines the way to interact with API.

View Source
const (
	// GPULabel is the label added to nodes with GPU resource.
	GPULabel = "node.kubernetes.ovhcloud.com/gpu"

	// NodePoolLabel is the label added to nodes grouped by node group.
	// Should be soon prepend with `node.kubernetes.ovhcloud.com/`
	NodePoolLabel = "nodepool"

	// MachineAvailableState defines the state for available flavors for node resources.
	MachineAvailableState = "available"

	// GPUMachineCategory defines the default instance category for GPU resources.
	GPUMachineCategory = "t"
)

Variables

This section is empty.

Functions

func BuildOVHcloud

BuildOVHcloud builds the OVHcloud provider.

Types

type ClientInterface

type ClientInterface interface {
	// ListNodePools lists all the node pools found in a Kubernetes cluster.
	ListNodePools(ctx context.Context, projectID string, clusterID string) ([]sdk.NodePool, error)

	// ListNodePoolNodes lists all the nodes contained in a node pool.
	ListNodePoolNodes(ctx context.Context, projectID string, clusterID string, poolID string) ([]sdk.Node, error)

	// CreateNodePool fills and installs a new pool in a Kubernetes cluster.
	CreateNodePool(ctx context.Context, projectID string, clusterID string, opts *sdk.CreateNodePoolOpts) (*sdk.NodePool, error)

	// UpdateNodePool updates the details of an existing node pool.
	UpdateNodePool(ctx context.Context, projectID string, clusterID string, poolID string, opts *sdk.UpdateNodePoolOpts) (*sdk.NodePool, error)

	// DeleteNodePool deletes a specific pool.
	DeleteNodePool(ctx context.Context, projectID string, clusterID string, poolID string) (*sdk.NodePool, error)

	// ListClusterFlavors list all available flavors usable in a Kubernetes cluster.
	ListClusterFlavors(ctx context.Context, projectID string, clusterID string) ([]sdk.Flavor, error)
}

ClientInterface defines all mandatory methods to be exposed as a client (mock or API)

type Config

type Config struct {
	// ProjectID is the id associated with the cluster project tenant.
	ProjectID string `json:"project_id"`

	// ClusterID is the id associated with the cluster where CA is running.
	ClusterID string `json:"cluster_id"`

	// AuthenticationType is the authentication method used to call the API (should be openstack or consumer)
	AuthenticationType string `json:"authentication_type"`

	// OpenStack keystone credentials if CA is run without API consumer.
	// By default, this is used as it on cluster control plane.
	OpenStackAuthUrl  string `json:"openstack_auth_url"`
	OpenStackUsername string `json:"openstack_username"`
	OpenStackPassword string `json:"openstack_password"`
	OpenStackDomain   string `json:"openstack_domain"`

	// Application credentials if CA is run as API consumer without using OpenStack keystone.
	// Tokens can be created here: https://api.ovh.com/createToken/
	ApplicationEndpoint    string `json:"application_endpoint"`
	ApplicationKey         string `json:"application_key"`
	ApplicationSecret      string `json:"application_secret"`
	ApplicationConsumerKey string `json:"application_consumer_key"`
}

Config is the configuration file content of OVHcloud provider

type NodeGroup

type NodeGroup struct {
	sdk.NodePool

	Manager     *OvhCloudManager
	CurrentSize int
	// contains filtered or unexported fields
}

NodeGroup implements cloudprovider.NodeGroup interface.

func (*NodeGroup) AtomicIncreaseSize

func (ng *NodeGroup) AtomicIncreaseSize(delta int) error

AtomicIncreaseSize is not implemented.

func (*NodeGroup) Autoprovisioned

func (ng *NodeGroup) Autoprovisioned() bool

Autoprovisioned returns true if the node group is autoprovisioned.

func (*NodeGroup) Create

func (ng *NodeGroup) Create() (cloudprovider.NodeGroup, error)

Create creates the node group on the cloud provider side.

func (*NodeGroup) Debug

func (ng *NodeGroup) Debug() string

Debug returns a debug string for the NodeGroup.

func (*NodeGroup) DecreaseTargetSize

func (ng *NodeGroup) DecreaseTargetSize(delta int) error

DecreaseTargetSize decreases the target size of the node group. This function doesn't permit to delete any existing node and can be used only to reduce the request for new nodes that have not been yet fulfilled. Delta should be negative. It is assumed that cloud provider will not delete the existing nodes if the size when there is an option to just decrease the target.

func (*NodeGroup) Delete

func (ng *NodeGroup) Delete() error

Delete deletes the node group on the cloud provider side. This will be executed only for autoprovisioned node groups, once their size drops to 0.

func (*NodeGroup) DeleteNodes

func (ng *NodeGroup) DeleteNodes(nodes []*apiv1.Node) error

DeleteNodes deletes the nodes from the group.

func (*NodeGroup) Exist

func (ng *NodeGroup) Exist() bool

Exist checks if the node group really exists on the cloud provider side. Allows to tell the theoretical node group from the real one.

func (*NodeGroup) ForceDeleteNodes

func (ng *NodeGroup) ForceDeleteNodes(nodes []*apiv1.Node) error

ForceDeleteNodes deletes nodes from the group regardless of constraints.

func (*NodeGroup) GetOptions

GetOptions returns NodeGroupAutoscalingOptions that should be used for this particular NodeGroup. Returning a nil will result in using default options.

func (*NodeGroup) Id

func (ng *NodeGroup) Id() string

Id returns node pool id.

func (*NodeGroup) IncreaseSize

func (ng *NodeGroup) IncreaseSize(delta int) error

IncreaseSize increases node pool size.

func (*NodeGroup) MaxSize

func (ng *NodeGroup) MaxSize() int

MaxSize returns maximum size of the node pool.

func (*NodeGroup) MinSize

func (ng *NodeGroup) MinSize() int

MinSize returns minimum size of the node pool.

func (*NodeGroup) Nodes

func (ng *NodeGroup) Nodes() ([]cloudprovider.Instance, error)

Nodes returns a list of all nodes that belong to this node group.

func (*NodeGroup) TargetSize

func (ng *NodeGroup) TargetSize() (int, error)

TargetSize returns the current TARGET size of the node pool. It is possible that the number is different from the number of nodes registered in Kubernetes.

func (*NodeGroup) TemplateNodeInfo

func (ng *NodeGroup) TemplateNodeInfo() (*framework.NodeInfo, error)

TemplateNodeInfo returns a node template for this node group.

type OVHCloudProvider

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

OVHCloudProvider implements CloudProvider interface.

func (*OVHCloudProvider) Cleanup

func (provider *OVHCloudProvider) Cleanup() error

Cleanup cleans up open resources before the cloud provider is destroyed, i.e. go routines etc.

func (*OVHCloudProvider) GPULabel

func (provider *OVHCloudProvider) GPULabel() string

GPULabel returns the label added to nodes with GPU resource.

func (*OVHCloudProvider) GetAvailableGPUTypes

func (provider *OVHCloudProvider) GetAvailableGPUTypes() map[string]struct{}

GetAvailableGPUTypes return all available GPU types cloud provider supports.

func (*OVHCloudProvider) GetAvailableMachineTypes

func (provider *OVHCloudProvider) GetAvailableMachineTypes() ([]string, error)

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

func (*OVHCloudProvider) GetNodeGpuConfig

func (provider *OVHCloudProvider) 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 (*OVHCloudProvider) GetResourceLimiter

func (provider *OVHCloudProvider) GetResourceLimiter() (*cloudprovider.ResourceLimiter, error)

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

func (*OVHCloudProvider) HasInstance

func (provider *OVHCloudProvider) HasInstance(node *apiv1.Node) (bool, error)

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

func (*OVHCloudProvider) Name

func (provider *OVHCloudProvider) Name() string

Name returns name of the cloud provider.

func (*OVHCloudProvider) NewNodeGroup

func (provider *OVHCloudProvider) 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. Implementation optional.

func (*OVHCloudProvider) NodeGroupForNode

func (provider *OVHCloudProvider) NodeGroupForNode(node *apiv1.Node) (cloudprovider.NodeGroup, error)

NodeGroupForNode returns the node group for the given node, nil if the node should not be processed by cluster autoscaler, or non-nil error if such occurred. Must be implemented.

func (*OVHCloudProvider) NodeGroups

func (provider *OVHCloudProvider) NodeGroups() []cloudprovider.NodeGroup

NodeGroups returns all node groups configured for this cloud provider.

func (*OVHCloudProvider) Pricing

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

func (*OVHCloudProvider) Refresh

func (provider *OVHCloudProvider) 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 OvhCloudManager

type OvhCloudManager struct {
	Client            ClientInterface
	OpenStackProvider *sdk.OpenStackProvider

	ClusterID string
	ProjectID string

	NodePools                  []sdk.NodePool
	NodeGroupPerProviderID     map[string]*NodeGroup
	NodeGroupPerProviderIDLock sync.RWMutex

	FlavorsCache               map[string]sdk.Flavor
	FlavorsCacheExpirationTime time.Time
}

OvhCloudManager defines current application context manager to interact with resources and API (or mock)

func NewManager

func NewManager(configFile io.Reader) (*OvhCloudManager, error)

NewManager initializes an API client given a cloud provider configuration file

func (*OvhCloudManager) ReAuthenticate

func (m *OvhCloudManager) ReAuthenticate() error

ReAuthenticate allows OpenStack keystone token to be revoked and re-created to call API

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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