utils

package
v0.15.0 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const (
	// NICSuffix is the suffix for NIC names.
	NICSuffix = "-nic"
	// OSDiskSuffix is the suffix for OSDisk names.
	OSDiskSuffix = "-os-disk"
	//DataDiskSuffix is the suffix for Data disk names.
	DataDiskSuffix = "-data-disk"
	// AzureCSIDriverName is the name of the CSI driver name for Azure provider
	AzureCSIDriverName = "disk.csi.azure.com"
)
View Source
const (
	// ClusterTagPrefix is a prefix for a mandatory cluster tag on resources
	ClusterTagPrefix = "kubernetes.io-cluster-"
	// RoleTagPrefix is a prefix for a mandatory role tag on resources
	RoleTagPrefix = "kubernetes.io-role-"
)
View Source
const (
	// ProvisioningStateFailed is the provisioning state of the VM set by the provider indicating that the VM is in terminal state.
	ProvisioningStateFailed = "Failed"
)

Variables

View Source
var ErrorEncapsulatingPanic = errors.New("panic has occurred")

ErrorEncapsulatingPanic is a sentinel error indicating that there has been a panic which has been captured as an error and returned as value.

Functions

func CreateDataDiskName

func CreateDataDiskName(vmName, diskName string, lun int32) string

CreateDataDiskName creates a name for a DataDisk using VM name and data disk name specified in the provider Spec

func CreateNICName

func CreateNICName(vmName string) string

CreateNICName creates a NIC name given a VM name

func CreateOSDiskName

func CreateOSDiskName(vmName string) string

CreateOSDiskName creates OSDisk name from VM name

func CreateResourceTags

func CreateResourceTags(tags map[string]string) map[string]*string

CreateResourceTags changes the tag value to be a pointer to string. Azure APIs require tags to be represented as map[string]*string

func DataDisksMarkedForDetachment

func DataDisksMarkedForDetachment(vm *armcompute.VirtualMachine) bool

DataDisksMarkedForDetachment checks if there is at least DataDisk that is marked for detachment. If there are no DataDisk(s) configured then it will return false.

func ExtractVMNameFromNICName

func ExtractVMNameFromNICName(nicName string) string

ExtractVMNameFromNICName extracts VM Name from NIC name

func ExtractVMNameFromOSDiskName

func ExtractVMNameFromOSDiskName(osDiskName string) string

ExtractVMNameFromOSDiskName extracts VM name from OSDisk name

func GetDataDiskNameSuffix

func GetDataDiskNameSuffix(diskName string, lun int32) string

GetDataDiskNameSuffix creates the suffix based on an optional data disk name and required lun fields.

func IsEmptyString

func IsEmptyString(s string) bool

IsEmptyString trims the spaces around the string and checks its length. If it is 0 then it will return true else it will return false

func IsNilOrEmptyStringPtr

func IsNilOrEmptyStringPtr(s *string) bool

IsNilOrEmptyStringPtr returns true if the string pointer is nil or the return value of IsEmptyString(s).

func IsSliceNilOrEmpty

func IsSliceNilOrEmpty[T any](s []T) bool

IsSliceNilOrEmpty returns true of the slice is nil or has 0 length (empty).

func RunConcurrently

func RunConcurrently(ctx context.Context, tasks []Task, bound int) []error

RunConcurrently runs tasks concurrently with number of goroutines bounded by bound. If there is a panic executing a single Task then it will capture the panic and capture it as an error which will then subsequently be returned from this function. It will not propagate the panic causing the app to exit.

func ToImageReference added in v0.14.0

func ToImageReference(urn string) armcompute.ImageReference

ToImageReference transforms an image urn string (publisher:offer:sku:version) into an ImageReference

Types

type ResourceType

type ResourceType string

ResourceType is an enum type representing type different resource types supported by Azure.

const (
	// VirtualMachinesResourceType is a type used by Azure to represent virtual machine resources.
	VirtualMachinesResourceType ResourceType = "microsoft.compute/virtualmachines"
	// NetworkInterfacesResourceType is a type used by Azure to represent network interfaces resources.
	NetworkInterfacesResourceType ResourceType = "microsoft.network/networkinterfaces" //as defined in azure
	// DiskResourceType is a type used by Azure to represent disks (both OS and Data disks)
	DiskResourceType ResourceType = "microsoft.compute/disks"
	// VMImageResourceType is a type used by Azure to represent VM Image resources.
	// This is not defined in azure, however we have created this to allow defining API behavior for VM Images.
	VMImageResourceType ResourceType = "microsoft.compute/vmimage"
	// MarketPlaceOrderingOfferType is a type used by Azure to represent marketplace ordering offer types.
	MarketPlaceOrderingOfferType ResourceType = "microsoft.marketplaceordering/offertypes"
	// SubnetResourceType is a type used by Azure to represent subnet resources.
	SubnetResourceType ResourceType = "microsoft.network/virtualnetworks/subnets"
)

type RunGroup

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

RunGroup is a runner for concurrently spawning multiple asynchronous tasks. If any task errors or panics then these are captured as errors.

func NewRunGroup

func NewRunGroup(numTasks, bound int) *RunGroup

NewRunGroup creates a new RunGroup.

func (*RunGroup) Close

func (g *RunGroup) Close()

Close closes the RunGroup

func (*RunGroup) WaitAndCollectErrors

func (g *RunGroup) WaitAndCollectErrors() []error

WaitAndCollectErrors waits for all tasks to finish, collects and returns any errors.

type Task

type Task struct {
	// Name is the name of the task
	Name string
	// Fn is the function which accepts a context and returns an error if there is one.
	// Implementations of Fn should handle context cancellation properly.
	Fn func(ctx context.Context) error
}

Task is a holder for a named function.

Jump to

Keyboard shortcuts

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