cloudops

package module
v0.0.0-...-1aa1ecb Latest Latest
Warning

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

Go to latest
Published: Aug 19, 2024 License: Apache-2.0 Imports: 8 Imported by: 23

README

cloudops

Go Report Card Build Status

Goal

  1. Define abstraction layerproviding a common interface to perform cloud operations that include:
  • Provisioning and managing Instances
  • Provisioning and managing Storage
  • Provisioning and managing network resources.
  1. Provide implementation for variety of clouds.

Cloudops will provide a set of binaries for debugging but its main purpose is to be used a library.

Building and running Cloudops

Cloudops expects GOLANG to be installed. To build cloudops, simply run make:

make
Vendoring

This repo uses go dep for vendoring. The following make rule will update the vendor directory.

make vendor

Documentation

Index

Constants

View Source
const (

	// AWS provider
	AWS ProviderType = "aws"
	// Azure provider
	Azure = "azure"
	// Vsphere provider
	Vsphere = "vsphere"
	// GCE provider
	GCE = "gce"
	// CSI provider
	CSI = "csi"
	// IBM provider
	IBM = "ibm"
	// Pure provider
	Pure = "pure"
	// Oracle provider
	Oracle = "oracle"

	// DryRunOption is the key to tell if dry run the request
	DryRunOption = "dry-run"
)
View Source
const (

	// ErrVolDetached is code for a volume is detached on the instance
	ErrVolDetached
	// ErrVolInval is the code for a invalid volume
	ErrVolInval
	// ErrVolAttachedOnRemoteNode is code when a volume is not attached locally
	// but attached on a remote node
	ErrVolAttachedOnRemoteNode
	// ErrVolNotFound is code when a volume is not found
	ErrVolNotFound
	// ErrInvalidDevicePath is code when a volume/disk has invalid device path
	ErrInvalidDevicePath
	// ErrExponentialTimeout is code when all the retries with exponential backoff have exhausted
	ErrExponentialTimeout
	// ErrDiskGreaterOrEqualToExpandSize is code when a volume/disk expansion call fails
	// as the given disk is already at a size greater than or equal to requested size
	ErrDiskGreaterOrEqualToExpandSize
	// ErrVolumeAttachedOnMultipleNodes is code when a volume is attached to multiple nodes
	ErrVolumeAttachedOnMultipleNodes
)

Custom storage operation error codes.

View Source
const ProviderOpsMaxRetries = 10

ProviderOpsMaxRetries is the number of retries to use for provider ops

View Source
const ProviderOpsRetryInterval = 3 * time.Second

ProviderOpsRetryInterval is the time to wait before each retry of provider ops

View Source
const ProviderOpsTimeout = time.Minute

ProviderOpsTimeout is the default timeout of storage provider ops

View Source
const (
	// SetIdentifierNone is a default identifier to group all disks from a
	// particular set
	SetIdentifierNone = "None"
)

Variables

View Source
var (
	// ErrNumOfZonesCannotBeZero is returned when the number of zones provided is zero
	ErrNumOfZonesCannotBeZero = errors.New("number of zones cannot be zero or less than zero")
	// ErrCurrentCapacitySameAsDesired is returned when total current capacity
	// of instance is already equal to requested capacity
	ErrCurrentCapacitySameAsDesired = errors.New("current capacity is already equal to new capacity")
)

Functions

func AddElementToMap

func AddElementToMap(
	sets map[string][]interface{},
	elem interface{},
	key string,
)

AddElementToMap adds to the given 'elem' to the 'sets' map with given 'key'

func GetEnvValueStrict

func GetEnvValueStrict(key string) (string, error)

GetEnvValueStrict fetches value for env variable "key". Returns error if not found or empty

func NewStorageError

func NewStorageError(code int, msg string, instance string) error

NewStorageError creates a new custom storage error instance

func RegisterStorageManager

func RegisterStorageManager(
	provider ProviderType,
	initFn InitStorageManagerFn,
) error

RegisterStorageManager registers cloud providers who support Storage Management

Types

type CloudResourceInfo

type CloudResourceInfo struct {
	// Name of the cloud resource.
	Name string
	// ID of the cloud resource.
	ID string
	// Labels on the cloud resource.
	Labels map[string]string
	// Zone where the resource exists.
	Zone string
	// Region where the resource exists.
	Region string
}

CloudResourceInfo provides metadata information on a cloud resource.

type Compute

type Compute interface {
	// DeleteInstance deletes the instance
	DeleteInstance(instanceID string, zone string, timeout time.Duration) error
	// InstanceID of instance where command is executed.
	InstanceID() string
	// InspectInstance inspects the node with the given instance ID
	// TODO: Add support for taking zone as input to inspect instance in any zone
	InspectInstance(instanceID string) (*InstanceInfo, error)
	// InspectInstanceGroupForInstance inspects the instance group to which the
	// cloud instance with given ID belongs
	InspectInstanceGroupForInstance(instanceID string) (*InstanceGroupInfo, error)
	// GetInstance returns cloud provider specific instance details
	GetInstance(displayName string) (interface{}, error)
	// SetInstanceGroupSize sets desired node count per availability zone
	// for given instance group
	SetInstanceGroupSize(instanceGroupID string,
		count int64,
		timeout time.Duration) error
	// GetInstanceGroupSize returns current node count of given instance group
	GetInstanceGroupSize(instanceGroupID string) (int64, error)
	// GetClusterSizeForInstance returns current node count in given cluster
	// This count is total node count across all availability zones
	GetClusterSizeForInstance(instanceID string) (int64, error)
	// SetClusterVersion sets desired version for the cluster
	SetClusterVersion(version string, timeout time.Duration) error
	// SetInstanceGroupVersion sets desired node group version
	SetInstanceGroupVersion(instanceGroupID string,
		version string,
		timeout time.Duration) error
	// SetInstanceUpgradeStrategy sets desired Upgrade strategy & respective parameters for the node group
	SetInstanceUpgradeStrategy(instanceGroupID string,
		upgradeStrategy string,
		timeout time.Duration,
		surgeSetting string) error
}

Compute interface to manage compute instances.

type ErrCloudProviderRequestFailure

type ErrCloudProviderRequestFailure struct {
	// Request is the API function name
	Request string
	// Message is the error message returned by the cloud provider
	Message string
}

ErrCloudProviderRequestFailure is returned when an unknown API request failure occurred.

func (*ErrCloudProviderRequestFailure) Error

type ErrCurrentCapacityHigherThanDesired

type ErrCurrentCapacityHigherThanDesired struct {
	// Current is the current capacity
	Current uint64
	// Desired is the desired new capacity
	Desired uint64
}

ErrCurrentCapacityHigherThanDesired is returned when the current capacity of the instance is already higher than the desired capacity

func (*ErrCurrentCapacityHigherThanDesired) Error

type ErrInvalidMaxDriveSizeRequest

type ErrInvalidMaxDriveSizeRequest struct {
	// Request is the request that caused the invalid error
	Request *MaxDriveSizeRequest
	// Reason is the reason why the request was invalid
	Reason string
}

ErrInvalidMaxDriveSizeRequest is returned when an unsupported or invalid request is sent to get the max drive size

func (*ErrInvalidMaxDriveSizeRequest) Error

type ErrInvalidStoragePoolUpdateRequest

type ErrInvalidStoragePoolUpdateRequest struct {
	// Request is the request that caused the invalid error
	Request *StoragePoolUpdateRequest
	// Reason is the reason why the request was invalid
	Reason string
}

ErrInvalidStoragePoolUpdateRequest is returned when an unsupported or invalid request is sent to get the updated storage config on an instance

func (*ErrInvalidStoragePoolUpdateRequest) Error

type ErrMaxDriveSizeCandidateNotFound

type ErrMaxDriveSizeCandidateNotFound struct {
	// Request is the request that caused the error
	Request *MaxDriveSizeRequest
	// Reason is the reason why the request caused an error
	Reason string
}

ErrMaxDriveSizeCandidateNotFound is returned when an unsupported or invalid request is sent to get the max drive size

func (*ErrMaxDriveSizeCandidateNotFound) Error

type ErrNoInstanceGroup

type ErrNoInstanceGroup struct {
	// Reason is an optional reason for not belong to an instance group
	Reason string
}

ErrNoInstanceGroup is returned when instance doesn't belong to an instance group

func (*ErrNoInstanceGroup) Error

func (e *ErrNoInstanceGroup) Error() string

type ErrNotFound

type ErrNotFound struct {
	// Type is the type of the object
	Type string
	// ID is the unique identifer of the object
	ID string
}

ErrNotFound is error type when an object of Type with ID is not found

func (*ErrNotFound) Error

func (e *ErrNotFound) Error() string

type ErrNotSupported

type ErrNotSupported struct {
	// Operation is the operation not being supported
	Operation string
	// Reason is an optional reason for not supporting the operation
	Reason string
}

ErrNotSupported is the error type for unsupported operations

func (*ErrNotSupported) Error

func (e *ErrNotSupported) Error() string

type ErrStorageDistributionCandidateNotFound

type ErrStorageDistributionCandidateNotFound struct {
	Reason string
}

ErrStorageDistributionCandidateNotFound is returned when the storage manager fails to determine the right storage distribution candidate

func (*ErrStorageDistributionCandidateNotFound) Error

type InitStorageManagerFn

type InitStorageManagerFn func(StorageDecisionMatrix) (StorageManager, error)

InitStorageManagerFn initializes the cloud provider for Storage Management

type InstanceGroupInfo

type InstanceGroupInfo struct {
	CloudResourceInfo
	// AutoscalingEnabled is true if auto scaling is turned on
	AutoscalingEnabled bool
	// Min number of nodes in the instance group
	Min *int64
	// Max number of nodes in the instance group
	Max *int64
	// Zones that the instance group is part of
	Zones []string
}

InstanceGroupInfo encapsulates info for a cloud instance group. In AWS this maps to ASG.

type InstanceInfo

type InstanceInfo struct {
	CloudResourceInfo
	// State is the current state of the instance
	State InstanceState
}

InstanceInfo encapsulates info for a cloud instance

type InstanceState

type InstanceState uint64

InstanceState is an enum for the current state of a compute instance

const (
	// InstanceStateUnknown unknown instance state
	InstanceStateUnknown InstanceState = iota
	// InstanceStateOnline instance is online
	InstanceStateOnline
	// InstanceStateOffline instance is offline
	InstanceStateOffline
	// InstanceStateTerminating instance is terminating
	InstanceStateTerminating
	// InstanceStateStarting instance is starting
	InstanceStateStarting
)

type MaxDriveSizeRequest

type MaxDriveSizeRequest struct {
	// DriveType is the type of drive specified in terms of cloud provided names.
	DriveType string `json:"drive_type" yaml:"drive_type"`
}

type MaxDriveSizeResponse

type MaxDriveSizeResponse struct {
	// MaxSize is the maximum size of the drive that can be provisioned
	// for input drive type.
	MaxSize uint64 `json:"max_size" yaml:"max_size"`
}

type Ops

type Ops interface {
	// Name returns name of the cloud operations driver
	Name() string
	// Storage operations in the cloud
	Storage
	// Compute operations in the cloud
	Compute
}

Ops interface to perform basic cloud operations.

type ProviderType

type ProviderType string

ProviderType is an enum indicating the different cloud provider supported by cloudops

type Storage

type Storage interface {
	// Create volume based on input template volume and also apply given labels.
	Create(template interface{}, labels map[string]string, options map[string]string) (interface{}, error)
	// GetDeviceID returns ID/Name of the given device/disk or snapshot
	GetDeviceID(template interface{}) (string, error)
	// Attach volumeID, accepts attachoOptions as opaque data
	// Return attach path.
	Attach(volumeID string, options map[string]string) (string, error)
	// IsVolumeReadyToExpand pre-checks if a pool of volumes are in a state that can
	// be modified. Should be called before sending an expand request to the cloud provider.
	AreVolumesReadyToExpand(volumeIDs []*string) (bool, error)
	// Expand expands the provided device from the existing size to the new size
	// It returns the new size of the device. It is a blocking API where it will
	// only return once the requested size is validated with the cloud provider or
	// the number of retries prescribed by the cloud provider are exhausted.
	Expand(volumeID string, newSizeInGiB uint64, options map[string]string) (uint64, error)
	// Detach volumeID.
	Detach(volumeID string, options map[string]string) error
	// DetachFrom detaches the disk/volume with given ID from the given instance ID
	DetachFrom(volumeID, instanceID string) error
	// Delete volumeID.
	Delete(volumeID string, options map[string]string) error
	// DeleteFrom deletes the given volume/disk from the given instanceID
	DeleteFrom(volumeID, instanceID string) error
	// Desribe an instance
	Describe() (interface{}, error)
	// FreeDevices returns free block devices on the instance.
	// blockDeviceMappings is a data structure that contains all block devices on
	// the instance and where they are mapped to
	FreeDevices() ([]string, error)
	// Inspect volumes specified by volumeID
	Inspect(volumeIds []*string, options map[string]string) ([]interface{}, error)
	// DeviceMappings returns map[local_attached_volume_path]->volume ID/NAME
	DeviceMappings() (map[string]string, error)
	// Enumerate volumes that match given filters. Organize them into
	// sets identified by setIdentifier.
	// labels can be nil, setIdentifier can be empty string.
	Enumerate(volumeIds []*string,
		labels map[string]string,
		setIdentifier string,
	) (map[string][]interface{}, error)
	// DevicePath for the given volume i.e path where it's attached
	DevicePath(volumeID string) (string, error)
	// Snapshot the volume with given volumeID
	Snapshot(volumeID string, readonly bool, options map[string]string) (interface{}, error)
	// SnapshotDelete deletes the snapshot with given ID
	SnapshotDelete(snapID string, options map[string]string) error
	// ApplyTags will apply given labels/tags on the given volume
	ApplyTags(volumeID string, labels map[string]string, options map[string]string) error
	// RemoveTags removes labels/tags from the given volume
	RemoveTags(volumeID string, labels map[string]string, options map[string]string) error
	// Tags will list the existing labels/tags on the given volume
	Tags(volumeID string) (map[string]string, error)
}

Storage interface to manage storage operations.

type StorageDecisionMatrix

type StorageDecisionMatrix struct {
	// Rows of the decision matrix
	Rows []StorageDecisionMatrixRow `json:"rows" yaml:"rows"`
}

StorageDecisionMatrix is used to determine the optimum cloud storage distribution for a cluster based on user's requirement specified through StorageSpec

func (*StorageDecisionMatrix) FilterByDriveCount

func (dm *StorageDecisionMatrix) FilterByDriveCount(currentDriveCount uint64) *StorageDecisionMatrix

FilterByDriveCount filters out the rows for which the current drive count does not fit within the row's min and max drive count.

func (*StorageDecisionMatrix) FilterByDriveSize

func (dm *StorageDecisionMatrix) FilterByDriveSize(currentDriveSize uint64) *StorageDecisionMatrix

FilterByDriveSize returns a list of rows for which the current drive size fits within the row's min and max size or if the row's min size is greater than the current drive size

func (*StorageDecisionMatrix) FilterByDriveSizeRange

func (dm *StorageDecisionMatrix) FilterByDriveSizeRange(currentDriveSize uint64) *StorageDecisionMatrix

FilterByDriveSizeRange filters out the rows for which the current drive size does not fit within the row's min and max size.

func (*StorageDecisionMatrix) FilterByDriveType

func (dm *StorageDecisionMatrix) FilterByDriveType(requestedDriveType string) *StorageDecisionMatrix

FilterByDriveType filters out the rows which do not match the requested drive type.

func (*StorageDecisionMatrix) FilterByIOPS

func (dm *StorageDecisionMatrix) FilterByIOPS(requestedIOPS uint64) *StorageDecisionMatrix

FilterByIOPS filters out the rows for which the requestedIOPS do not lie within the range of min and max IOPS or whose minIOPS are less than the requestedIOPS

func (*StorageDecisionMatrix) FilterByMinIOPS

func (dm *StorageDecisionMatrix) FilterByMinIOPS(requestedIOPS uint64) *StorageDecisionMatrix

FilterByMinIOPS filters out the rows whose minIOPS are less than the requested IOPS.

func (*StorageDecisionMatrix) SortByIOPS

func (dm *StorageDecisionMatrix) SortByIOPS() *StorageDecisionMatrix

SortByIOPS sorts the rows of the decision matrix in ascending order by MaxIOPS supported by that row.

func (*StorageDecisionMatrix) SortByMaxSize

func (dm *StorageDecisionMatrix) SortByMaxSize()

SortByMaxSize sorts the rows of the decision matrix in descending order by MaxSize supported by that row.

func (*StorageDecisionMatrix) SortByPriority

func (dm *StorageDecisionMatrix) SortByPriority()

SortByPriority sorts the rows of the decision matrix by Priority.

type StorageDecisionMatrixRow

type StorageDecisionMatrixRow struct {
	// MinIOPS is the minimum desired iops from the underlying cloud storage.
	MinIOPS uint64 `json:"min_iops" yaml:"min_iops"`
	// MaxIOPS is the maximum desired iops from the underlying cloud storage.
	MaxIOPS uint64 `json:"max_iops" yaml:"max_iops"`
	// InstanceType is the type of instance on which the cloud storage can
	// be attached.
	InstanceType string `json:"instance_type" yaml:"instance_type"`
	// InstanceMaxDrives is the maximum number of drives that can be attached
	// to an instance without a performance hit.
	InstanceMaxDrives uint64 `json:"instance_max_drives" yaml:"instance_max_drives"`
	// InstanceMinDrives is the minimum number of drives that need to be
	// attached to an instance to achieve maximum performance.
	InstanceMinDrives uint64 `json:"instance_min_drives" yaml:"instance_min_drives"`
	// Region of the instance.
	Region string `json:"region" yaml:"region"`
	// MinSize is the minimum size of the drive that needs to be provisioned
	// to achieve the desired IOPS on the provided instance types.
	MinSize uint64 `json:"min_size" yaml:"min_size"`
	// MaxSize is the maximum size of the drive that can be provisioned
	// without affecting performance on the provided instance type.
	MaxSize uint64 `json:"max_size" yaml:"max_size"`
	// Priority for this entry in the decision matrix.
	Priority int `json:"priority" yaml:"priority"`
	// ThinProvisioning if set will provision the backing device to be thinly provisioned if supported by cloud provider.
	ThinProvisioning bool `json:"thin_provisioning" yaml:"thin_provisioning"`
	// DriveType is the type of drive
	DriveType string `json:"drive_type" yaml:"drive_type"`
}

StorageDecisionMatrixRow defines an entry in the cloud storage decision matrix.

type StorageDistributionRequest

type StorageDistributionRequest struct {
	// UserStorageSpec is a list of user's storage requirements.
	UserStorageSpec []*StorageSpec `json:"user_storage_spec" yaml:"user_storage_spec"`
	// InstanceType is the type of instance where user needs to provision storage.
	InstanceType string `json:"instance_type" yaml:"instance_type"`
	// InstancesPerZone is the number of instances in each zone.
	InstancesPerZone uint64 `json:"instances_per_zone" yaml:"instances_per_zone"`
	// ZoneCount is the number of zones across which the instances are
	// distributed in the cluster.
	ZoneCount uint64 `json:"zone_count" yaml:"zone_count"`
}

StorageDistributionRequest is the input the cloud drive decision matrix. It provides the user's storage requirement as well as other cloud provider specific details.

type StorageDistributionResponse

type StorageDistributionResponse struct {
	// InstanceStorage defines a list of storage pool specs that need to be
	// provisioned on an instance.
	InstanceStorage []*StoragePoolSpec `json:"instance_storage" yaml:"instance_storage"`
}

StorageDistributionResponse is the result returned the CloudStorage Decision Matrix for the provided request.

type StorageError

type StorageError struct {
	// Code is one of storage operation driver error codes.
	Code int
	// Msg is human understandable error message.
	Msg string
	// Instance provides more information on the error.
	Instance string
}

StorageError error returned for storage operations

func (*StorageError) Error

func (e *StorageError) Error() string

type StorageManager

type StorageManager interface {
	// GetStorageDistribution returns the storage distribution for the provided request
	GetStorageDistribution(request *StorageDistributionRequest) (*StorageDistributionResponse, error)
	// RecommendStoragePoolUpdate returns the recommended storage configuration on
	// the instance based on the given request
	RecommendStoragePoolUpdate(request *StoragePoolUpdateRequest) (*StoragePoolUpdateResponse, error)
	// GetMaxDriveSize returns the maximum size a drive can expand to for given cloud drive type
	GetMaxDriveSize(request *MaxDriveSizeRequest) (*MaxDriveSizeResponse, error)
}

StorageManager interface provides a set of APIs to manage cloud storage drives across multiple nodes in the cluster.

func NewStorageManager

func NewStorageManager(
	decisionMatrix StorageDecisionMatrix,
	provider ProviderType,
) (StorageManager, error)

NewStorageManager returns a cloud provider specific implementation of StorageManager interface.

type StoragePoolSpec

type StoragePoolSpec struct {
	// DriveCapacityGiB is the capacity of the drive in GiB.
	DriveCapacityGiB uint64 `json:"drive_capacity_gb" yaml:"drive_capacity_gb"`
	// DriveType is the type of drive specified in terms of cloud provided names.
	DriveType string `json:"drive_type" yaml:"drive_type"`
	// DriveCount is the number of drives that need to be provisioned on the
	// instance
	DriveCount uint64 `json:"drive_count" yaml:"drive_count"`
	// InstancesPerZone is the number of instances per zone
	InstancesPerZone uint64 `json:"instances_per_zone" yaml:"instances_per_zone"`
	// IOPS is the IOPS of the drive
	IOPS uint64 `json:"iops" yaml:"iops"`
}

StoragePoolSpec defines the type, capacity and number of storage drive that needs to be provisioned. These set of drives should be grouped into a single storage pool.

type StoragePoolUpdateRequest

type StoragePoolUpdateRequest struct {
	// DesiredCapacity is the new required capacity on the storage pool
	DesiredCapacity uint64 `json:"new_capacity" yaml:"new_capacity"`
	// ResizeOperationType is the operation user wants for the storage resize on the node
	ResizeOperationType api.SdkStoragePool_ResizeOperationType
	// CurrentDriveCount is the current number of drives in the storage pool
	CurrentDriveCount uint64 `json:"current_drive_count" yaml:"current_drive_count"`
	// CurrentIOPS is the current IOPS for drives in the storage pool
	CurrentIOPS uint64 `json:"current_iops" yaml:"current_iops"`
	// CurrentDriveSize is the current size of drives in the storage pool
	CurrentDriveSize uint64 `json:"current_drive_size" yaml:"current_drive_size"`
	// CurrentDriveType is the current type of drives in the storage pool
	CurrentDriveType string `json:"current_drive_type" yaml:"current_drive_type"`
	// TotalDrivesOnNode is the total number of drives attached on the node
	TotalDrivesOnNode uint64 `json:"total_drives_on_node" yaml:"total_drives_on_node"`
}

StoragePoolUpdateRequest is the required changes for updating the storage on a given cloud instance

type StoragePoolUpdateResponse

type StoragePoolUpdateResponse struct {
	// InstanceStorage defines a list of storage pool specs that need to be
	// provisioned or updated on an instance.
	InstanceStorage []*StoragePoolSpec `json:"instance_storage" yaml:"instance_storage"`
	// ResizeOperationType is the operation caller should perform on the disks in
	// the above InstanceStorage for the storage update on the instance
	ResizeOperationType api.SdkStoragePool_ResizeOperationType
}

StoragePoolUpdateResponse is the result returned by the CloudStorage Decision Matrix for the storage update request

type StorageSpec

type StorageSpec struct {
	// MinCapacity is the minimum capacity of storage for the cluster.
	MinCapacity uint64 `json:"min_capacity" yaml:"min_capacity"`
	// MaxCapacity is the upper threshold on the total capacity of storage
	// that can be provisioned in this cluster.
	MaxCapacity uint64 `json:"max_capacity" yaml:"max_capacity"`
	// DriveType is the type of drive that's required (optional)
	DriveType string `json:"drive_type" yaml:"drive_type"`
	// IOPS is the desired IOPS from the underlying storage (optional)
	IOPS uint64 `json:"iops" yaml:"iops"`
}

StorageSpec is the user provided storage requirement for the cluster. This specifies desired capacity thresholds and desired IOPS If there is a requirement for two different drive types then multiple StorageSpecs need to be provided to the StorageManager

Directories

Path Synopsis
aws
csi
gce
ibm
Package mock is a generated GoMock package.
Package mock is a generated GoMock package.
pkg
specs
decisionmatrix
Package decisionmatrix includes cloud provider specific decision matrices in the form of yamls.
Package decisionmatrix includes cloud provider specific decision matrices in the form of yamls.

Jump to

Keyboard shortcuts

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