util

package
v0.6.0 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const (
	// OpenEBSCasTypeKey present in label of PV
	OpenEBSCasTypeKey = "openebs.io/cas-type"
	// Unknown to be retuned when cas type is not known
	Unknown = "unknown"
	// OpenEBSCasTypeKeySc present in parameter of SC
	OpenEBSCasTypeKeySc = "cas-type"
	// ZFSCasType cas type name
	ZFSCasType = "localpv-zfs"
	// LVMCasType cas type name
	LVMCasType = "localpv-lvm"
	// LocalPvHostpathCasType cas type name
	LocalPvHostpathCasType = "localpv-hostpath"
	// LocalHostpathCasLabel cas-type label in dynamic-localpv-provisioner
	LocalHostpathCasLabel = "local-hostpath"
	// StorageKey key present in pvc status.capacity
	StorageKey = "storage"
	// NotAvailable shows something is missing, could be a component,
	// unknown version, or some other unknowns
	NotAvailable = "N/A"
)
View Source
const (
	// ZFSCSIDriver is the name of the ZFS localpv CSI driver
	ZFSCSIDriver = "zfs.csi.openebs.io"
	// LocalPVLVMCSIDriver is the name of the LVM LocalPV CSI driver
	// NOTE: This might also mean local-hostpath, local-device or zfs-localpv later.
	LocalPVLVMCSIDriver = "local.csi.openebs.io"
)
View Source
const (
	// LVMLocalPVcsiControllerLabelValue is the label value of CSI controller STS & pod
	LVMLocalPVcsiControllerLabelValue = "openebs-lvm-controller"
	// ZFSLocalPVcsiControllerLabelValue is the label value of CSI controller STS & pod
	ZFSLocalPVcsiControllerLabelValue = "openebs-zfs-controller"
)

Constant CSI component-name label values

View Source
const (
	// LVMComponentNames for the lvm control plane components
	LVMComponentNames = "openebs-lvm-controller,openebs-lvm-node"
	// ZFSComponentNames for the zfs control plane components
	ZFSComponentNames = "openebs-zfs-controller,openebs-zfs-node"
	// HostpathComponentNames for the hostpath control plane components
	HostpathComponentNames = "openebs-localpv-provisioner"
)
View Source
const (
	// List If we want the return type as a list
	List ReturnType = "list"
	// Map If we want the return type as a map
	Map ReturnType = "map"
	// Name key if we want the keys to be made on name
	Name Key = "name"
	// Label key if want to make the keys on labels
	Label Key = "label"
)

Variables

View Source
var (
	// CasTypeAndComponentNameMap stores the component name of the corresponding cas type
	CasTypeAndComponentNameMap = map[string]string{
		LVMCasType:             LVMLocalPVcsiControllerLabelValue,
		ZFSCasType:             ZFSLocalPVcsiControllerLabelValue,
		LocalPvHostpathCasType: HostpathComponentNames,
	}
	// ComponentNameToCasTypeMap is a reverse map of CasTypeAndComponentNameMap
	ComponentNameToCasTypeMap = map[string]string{
		LVMLocalPVcsiControllerLabelValue: LVMCasType,
		ZFSLocalPVcsiControllerLabelValue: ZFSCasType,
		HostpathComponentNames:            LocalPvHostpathCasType,
	}
	// ProvsionerAndCasTypeMap stores the cas type name of the corresponding provisioner
	ProvsionerAndCasTypeMap = map[string]string{
		LocalPVLVMCSIDriver: LVMCasType,
		ZFSCSIDriver:        ZFSCasType,
	}
	// CasTypeToCSIProvisionerMap stores the provisioner of corresponding cas-types
	CasTypeToCSIProvisionerMap = map[string]string{
		LVMCasType: LocalPVLVMCSIDriver,
		ZFSCasType: ZFSCSIDriver,
	}

	// CasTypeToComponentNamesMap stores the names of the control-plane components of each cas-types.
	// To show statuses of new CasTypes, please update this map.
	CasTypeToComponentNamesMap = map[string]string{
		LocalPvHostpathCasType: HostpathComponentNames,
		ZFSCasType:             ZFSComponentNames,
		LVMCasType:             LVMComponentNames,
	}
	// VolumeListColumnDefinations stores the Table headers for Volume Details
	VolumeListColumnDefinations = []metav1.TableColumnDefinition{
		{Name: "Namespace", Type: "string"},
		{Name: "Name", Type: "string"},
		{Name: "Status", Type: "string"},
		{Name: "Version", Type: "string"},
		{Name: "Capacity", Type: "string"},
		{Name: "Storage Class", Type: "string"},
		{Name: "Attached", Type: "string"},
		{Name: "Access Mode", Type: "string"},
		{Name: "Attached Node", Type: "string"},
	}
	// LVMvolgroupListColumnDefinitions stores the table headers for listing lvm vg-group when displayed as tree
	LVMvolgroupListColumnDefinitions = []metav1.TableColumnDefinition{
		{Name: "Name", Type: "string"},
		{Name: "FreeSize", Type: "string"},
		{Name: "TotalSize", Type: "string"},
	}
	// ZFSPoolListColumnDefinitions stores the table headers for listing zfs pools when displayed as tree
	ZFSPoolListColumnDefinitions = []metav1.TableColumnDefinition{
		{Name: "Name", Type: "string"},
		{Name: "FreeSize", Type: "string"},
	}

	VersionColumnDefinition = []metav1.TableColumnDefinition{
		{Name: "Component", Type: "string"},
		{Name: "Version", Type: "string"},
	}
	// ClusterInfoColumnDefinitions stores the Table headers for Cluster-Info details
	ClusterInfoColumnDefinitions = []metav1.TableColumnDefinition{
		{Name: "Cas-Type", Type: "string"},
		{Name: "Namespace", Type: "string"},
		{Name: "Version", Type: "string"},
		{Name: "Working", Type: "string"},
		{Name: "Status", Type: "string"},
	}
)
View Source
var Kubeconfig string

Functions

func AccessModeToString

func AccessModeToString(accessModeArray []corev1.PersistentVolumeAccessMode) string

AccessModeToString Flattens the arrat of AccessModes and returns a string fit to display in the output

func CheckErr

func CheckErr(err error, handleErr func(string))

CheckErr to handle command errors

func CheckError

func CheckError(err error)

CheckError prints err to stderr and exits with code 1 if err is not nil. Otherwise, it is a no-op.

func ColorStringOnStatus added in v0.3.0

func ColorStringOnStatus(stringToColor string) string

ColorStringOnStatus is used for coloring the strings based on statuses

func ColorText added in v0.3.0

func ColorText(s string, c Color) string

ColorText returns an ASCII colored string based on given color.

func ConvertToIBytes

func ConvertToIBytes(value string) string

ConvertToIBytes humanizes all the passed units to IBytes format

func Duration

func Duration(d time.Duration) string

Duration return the time.Duration in no.of days,hour, mins, seconds format. The number of terms to be shown can be increased or decreased using maxTerms constant.

func Fatal

func Fatal(msg string)

Fatal prints the message (if provided) and then exits. If V(2) or greater, klog.Fatal is invoked for extended information.

func GetAvailableCapacity added in v0.3.0

func GetAvailableCapacity(total string, used string) string

GetAvailableCapacity returns the available capacity irrespective of units

func GetCasType

func GetCasType(v1PV *corev1.PersistentVolume, v1SC *v1.StorageClass) string

GetCasType from the v1pv and v1sc, this is a fallback checker method, it checks both the resource only if the castype is not found.

func GetCasTypeFromPV

func GetCasTypeFromPV(v1PV *corev1.PersistentVolume) string

GetCasTypeFromPV from the passed PersistentVolume or the Stora

func GetCasTypeFromSC

func GetCasTypeFromSC(v1SC *v1.StorageClass) string

GetCasTypeFromSC by passing the storage class

func GetReadyContainers

func GetReadyContainers(containers []corev1.ContainerStatus) string

GetReadyContainers to show the number of ready vs total containers of pod i.e 2/3

func GetUsedPercentage added in v0.3.0

func GetUsedPercentage(total string, used string) float64

GetUsedPercentage returns the usage percentage irrespective of units

func HandleEmptyTableError added in v0.4.0

func HandleEmptyTableError(resource string, ns string, casType string) error

HandleEmptyTableError handles error when resources or set of resources are not found

func IsValidCasType added in v0.4.0

func IsValidCasType(casType string) bool

IsValidCasType to return true if the casType is supported

func PrintByTemplate

func PrintByTemplate(templateName string, resourceTemplate string, resource interface{}) error

PrintByTemplate of the provided template and resource

func PromptToStartAgain added in v0.5.0

func PromptToStartAgain(label string, defaultOption bool) bool

PromptToStartAgain opens prompt and waits for the user for response

func TablePrinter

func TablePrinter(columns []metav1.TableColumnDefinition, rows []metav1.TableRow, options printers.PrintOptions)

TablePrinter uses cli-runtime TablePrinter to create a similar UI for the ctl

func TemplatePrinter

func TemplatePrinter(template string, obj runtime.Object)

TemplatePrinter uses cli-runtime TemplatePrinter to print by template without extra type

Types

type Color added in v0.3.0

type Color int

Color describes a terminal color.

const (
	Red    Color = iota + 31 // 31
	Green                    // 32
	Orange                   // 33
	Blue                     // 34
)

Defines basic ANSI colors.

type ComponentData added in v0.4.0

type ComponentData struct {
	Namespace string
	Status    string
	Version   string
	CasType   string
}

ComponentData stores the data for each component of an engine

type Key

type Key string

Key defines what should be the key if we create a map, i.e. Label or Name

type LVMPVCInfo added in v0.4.0

type LVMPVCInfo struct {
	Name             string
	Namespace        string
	CasType          string
	BoundVolume      string
	StorageClassName string
	Size             string
	PVCStatus        corev1.PersistentVolumeClaimPhase
	MountPods        string
}

LVMPVCInfo struct will have all the details we want to give in the output for describe pvc details section for lvm pvc

type LVMVolDesc added in v0.3.0

type LVMVolDesc struct {
	Name            string
	Namespace       string
	AccessMode      string
	CSIDriver       string
	Capacity        string
	PVC             string
	VolumePhase     corev1.PersistentVolumePhase
	StorageClass    string
	Version         string
	Status          string
	VolumeGroup     string
	Shared          string
	ThinProvisioned string
	NodeID          string
}

LVMVolDesc is the output helper for LVMVolDesc

type LocalHostPathVolInfo added in v0.4.0

type LocalHostPathVolInfo struct {
	VolumeInfo
	Path          string
	ReclaimPolicy string
	CasType       string
}

type MapOptions

type MapOptions struct {
	Key      Key
	LabelKey string
}

MapOptions struct to get the resources as Map with the provided options Key defines what to use as a key, ex:- name, label, currently these two are supported, add more according to need. LabelKey defines which Label to use as key.

type PVCInfo

type PVCInfo struct {
	Name             string
	Namespace        string
	CasType          string
	BoundVolume      string
	StorageClassName string
	Size             string
	PVStatus         corev1.PersistentVolumePhase
	MountPods        string
}

PVCInfo struct will have all the details we want to give in the output for describe pvc details section for generic pvc

type ReturnType

type ReturnType string

ReturnType defines in which format the object needs to be returned i.e. List or Map

type Volume

type Volume struct {
	// AccessModes contains all ways the volume can be mounted
	AccessMode string
	// Attachment status of the PV and it's claim
	AttachementStatus string
	// Represents the actual capacity of the underlying volume.
	Capacity string
	Name     string
	//Namespace defines the space within each name must be unique.
	// An empty namespace is equivalent to the "default" namespace
	Namespace string
	Node      string
	// Name of the PVClaim of the underlying Persistent Volume
	PVC string
	// Name of StorageClass to which this persistent volume belongs.
	StorageClass string
	// version of the spec used to create the volumes
	Version string
}

Volume struct will have all the details we want to give in the output for openebsctl commands

func CheckForVol

func CheckForVol(name string, vols map[string]*Volume) *Volume

CheckForVol is used to check if the we can get the volume, if no volume attachment to SC for the corresponding volume is found display error

type VolumeInfo

type VolumeInfo struct {
	AccessMode string
	// Capacity of the underlying PV
	Capacity string
	// Name of the volume & Namespace on which it exists
	Name string
	PVC  string
	// Phase indicates if a volume is available, bound to a claim, or released
	// by a claim.
	VolumePhase corev1.PersistentVolumePhase
	// Name of StorageClass to which this persistent volume belongs.
	StorageClass string
	Size         string
}

VolumeInfo struct will have all the details we want to give in the output for openebsctl command volume describe

type ZFSPVCInfo added in v0.4.0

type ZFSPVCInfo struct {
	Name             string
	Namespace        string
	CasType          string
	BoundVolume      string
	StorageClassName string
	Size             string
	PVCStatus        corev1.PersistentVolumeClaimPhase
	MountPods        string
}

ZFSPVCInfo struct will have all the details we want to give in the output for describe pvc details section for zfs pvc

type ZFSVolDesc added in v0.3.0

type ZFSVolDesc struct {
	Name         string
	Namespace    string
	AccessMode   string
	CSIDriver    string
	Capacity     string
	PVC          string
	VolumePhase  corev1.PersistentVolumePhase
	StorageClass string
	Version      string
	Status       string
	VolumeType   string
	PoolName     string
	FileSystem   string
	Compression  string
	Dedup        string
	NodeID       string
	Recordsize   string
}

ZFSVolDesc is the output helper for ZfsVolDesc

Jump to

Keyboard shortcuts

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