utils

package
v1.4.5 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2021 License: AGPL-3.0 Imports: 44 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TopologyDriverIdentity = "direct.csi.min.io/identity"
	TopologyDriverNode     = "direct.csi.min.io/node"
	TopologyDriverRack     = "direct.csi.min.io/rack"
	TopologyDriverZone     = "direct.csi.min.io/zone"
	TopologyDriverRegion   = "direct.csi.min.io/region"
)

Topology keys.

View Source
const (
	// DEL character i.e. 127 or \u007f.
	DEL rune = 127
)
View Source
const MaxThreadCount = 200

MaxThreadCount is maximum thread count.

Variables

View Source
var (
	Bold = color.New(color.Bold).SprintFunc()
	Red  = color.New(color.FgRed).SprintFunc()
)

Color print functions.

View Source
var (
	PodNameLabel      = NewDirectCSILabel("pod.name")
	PodNamespaceLabel = NewDirectCSILabel("pod.namespace")

	NodeLabel       = NewDirectCSILabel("node")
	DriveLabel      = NewDirectCSILabel("drive")
	DrivePathLabel  = NewDirectCSILabel("path")
	AccessTierLabel = NewDirectCSILabel("access-tier")

	VersionLabel   = NewDirectCSILabel("version")
	CreatedByLabel = NewDirectCSILabel("created-by")

	ReservedDrivePathLabel = NewDirectCSILabel("drive-path")

	DirectCSIGroupVersion = SanitizeLabelK(directcsi.Group + "/" + directcsi.Version)
)

Various direct-csi labels.

View Source
var AddToScheme = localSchemeBuilder.AddToScheme

AddToScheme adds all types of this clientset into the given scheme. This allows composition of clientsets, like in:

import (
  "k8s.io/client-go/kubernetes"
  clientsetscheme "k8s.io/client-go/kubernetes/scheme"
  aggregatorclientsetscheme "k8s.io/kube-aggregator/pkg/client/clientset_generated/clientset/scheme"
)

kclientset, _ := kubernetes.NewForConfig(c)
_ = aggregatorclientsetscheme.AddToScheme(clientsetscheme.Scheme)

After this, RawExtensions in Kubernetes types will serialize kube-aggregator types correctly.

Codecs is new codec of new runtime scheme.

ParameterCodec is new parameter codec of new runtime scheme.

View Source
var Scheme = runtime.NewScheme()

Scheme is new runtime scheme.

Functions

func AddFinalizer

func AddFinalizer(objectMeta *metav1.ObjectMeta, finalizer string) []string

AddFinalizer adds finalizer in object meta.

func BoolToCondition

func BoolToCondition(val bool) metav1.ConditionStatus

BoolToCondition converts boolean value to condition status.

func CreateDrive added in v1.4.4

func CreateDrive(ctx context.Context, driveInterface clientset.DirectCSIDriveInterface, drive *directcsi.DirectCSIDrive) error

CreateDrive creates drive CRD.

func DefaultIfZeroString added in v1.4.0

func DefaultIfZeroString(left, right string) string

DefaultIfZeroString returns string which is non empty of left or right.

func DeleteDrive added in v1.4.4

func DeleteDrive(ctx context.Context, driveInterface clientset.DirectCSIDriveInterface, drive *directcsi.DirectCSIDrive, force bool) error

DeleteDrive deletes drive CRD.

func DirectCSIDriveTypeMeta added in v1.3.0

func DirectCSIDriveTypeMeta() metav1.TypeMeta

DirectCSIDriveTypeMeta gets new direct-csi drive meta.

func DirectCSIVolumeTypeMeta added in v1.3.0

func DirectCSIVolumeTypeMeta() metav1.TypeMeta

DirectCSIVolumeTypeMeta gets new direct-csi volume meta.

func Eventf added in v1.4.2

func Eventf(object runtime.Object, eventType, reason, messageFmt string, args ...interface{})

Eventf raises kubernetes events.

func ExcludeFinalizer added in v1.4.2

func ExcludeFinalizer(finalizers []string, finalizer string) (result []string, found bool)

ExcludeFinalizer returns finalizers excluding given finalizer.

func FakeInit added in v1.4.2

func FakeInit()

FakeInit initializes fake clients.

func FmapString added in v1.4.0

func FmapString(str string, f func(rune) rune) string

FmapString applies function on each rune in string.

func FmapStringSlice added in v1.4.0

func FmapStringSlice(vs []string, f func(string) string) []string

FmapStringSlice applies function on each value in slice.

func GetAPIExtensionsClient added in v1.1.0

func GetAPIExtensionsClient() apiextensions.ApiextensionsV1Interface

GetAPIExtensionsClient gets API extension client.

func GetCRDClient

GetCRDClient gets CRD client.

func GetClientForNonCoreGroupKindVersions

func GetClientForNonCoreGroupKindVersions(group, kind string, versions ...string) (rest.Interface, *schema.GroupVersionKind, error)

GetClientForNonCoreGroupKindVersions gets client for group/kind of given versions.

func GetDirectCSIClient

func GetDirectCSIClient() directcsi.DirectV1beta3Interface

GetDirectCSIClient gets direct-csi client.

func GetDirectClientset

func GetDirectClientset() direct.Interface

GetDirectClientset gets direct-csi clientset.

func GetDiscoveryClient

func GetDiscoveryClient() discovery.DiscoveryInterface

GetDiscoveryClient gets discovery client.

func GetDriveList added in v1.4.2

func GetDriveList(ctx context.Context, driveInterface clientset.DirectCSIDriveInterface, nodes, drives, accessTiers []LabelValue) ([]directcsi.DirectCSIDrive, error)

GetDriveList gets list of drives.

func GetDrivePath added in v1.4.4

func GetDrivePath(drive *directcsi.DirectCSIDrive) string

GetDrivePath gets sanitized drive path.

func GetGroupKindVersions

func GetGroupKindVersions(group, kind string, versions ...string) (*schema.GroupVersionKind, error)

GetGroupKindVersions gets group/version/kind of given versions.

func GetKubeClient

func GetKubeClient() kubernetes.Interface

GetKubeClient gets kube client.

func GetKubeConfig

func GetKubeConfig() (*rest.Config, error)

GetKubeConfig gets kubernetes configuration.

func GetLabelV added in v1.4.0

func GetLabelV(obj metav1.Object, key string) string

GetLabelV gets label value.

func GetMetadataClient

func GetMetadataClient() metadata.Interface

GetMetadataClient gets metadata client.

func GetVolumeList added in v1.4.2

func GetVolumeList(ctx context.Context, volumeInterface clientset.DirectCSIVolumeInterface, nodes, drives, podNames, podNss []LabelValue) ([]directcsi.DirectCSIVolume, error)

GetVolumeList gets list of volumes.

func Init

func Init()

Init initializes various clients.

func IsCondition added in v1.2.8

func IsCondition(statusConditions []metav1.Condition, condType string, condStatus metav1.ConditionStatus, reason, msg string) bool

IsCondition checks type/status/reason/message in conditions.

func IsConditionStatus added in v1.2.8

func IsConditionStatus(statusConditions []metav1.Condition, condType string, condStatus metav1.ConditionStatus) bool

IsConditionStatus checks type/status in conditions.

func ListDrives added in v1.4.2

func ListDrives(ctx context.Context, driveInterface clientset.DirectCSIDriveInterface, nodes, drives, accessTiers []LabelValue, maxObjects int64) (<-chan ListDriveResult, error)

ListDrives lists direct-csi drives.

func ListVolumes added in v1.4.2

func ListVolumes(ctx context.Context, volumeInterface clientset.DirectCSIVolumeInterface, nodes, drives, podNames, podNss []LabelValue, maxObjects int64) (<-chan ListVolumeResult, error)

ListVolumes lists direct-csi volumes.

func LogYAML added in v1.2.1

func LogYAML(obj interface{}) error

LogYAML prints value as YAML string to standard output.

func MustJSON added in v1.4.0

func MustJSON(obj interface{}) string

MustJSON converts given value to JSON string.

func MustYAML added in v1.4.0

func MustYAML(obj interface{}) string

MustYAML converts value to YAML string.

func NewDirectCSIDrive added in v1.4.4

func NewDirectCSIDrive(name string, status directcsi.DirectCSIDriveStatus) *directcsi.DirectCSIDrive

NewDirectCSIDrive creates new direct-csi drive.

func NewDirectCSIDriveStatus added in v1.4.4

func NewDirectCSIDriveStatus(device *sys.Device, nodeID string, topology map[string]string) directcsi.DirectCSIDriveStatus

NewDirectCSIDriveStatus creates direct CSI drive status.

func NewDirectCSILabel added in v1.4.0

func NewDirectCSILabel(key string) string

NewDirectCSILabel creates direct-csi label of a key.

func NewIdentityTopologySelector added in v1.4.0

func NewIdentityTopologySelector(identity string) corev1.TopologySelectorTerm

NewIdentityTopologySelector creates identity topology selector.

func NewObjectMeta added in v1.4.0

func NewObjectMeta(
	name string,
	namespace string,
	labels map[string]string,
	annotations map[string]string,
	finalizers []string,
	ownerRefs []metav1.OwnerReference,
) metav1.ObjectMeta

NewObjectMeta - creates a new ObjectMeta with sanitized fields

func NewTypeMeta added in v1.4.0

func NewTypeMeta(groupVersion, resource string) metav1.TypeMeta

NewTypeMeta - creates a new TypeMeta upcoming:

  • verify API group/version/kind
  • verify that kubernetes backend support group/version/kind (use discovery client)

func ParseSingleKubeNativeFromBytes added in v1.1.0

func ParseSingleKubeNativeFromBytes(data []byte) (runtime.Object, error)

ParseSingleKubeNativeFromBytes parses YAML byte data to runtime object.

func RemoveFinalizer

func RemoveFinalizer(objectMeta *metav1.ObjectMeta, finalizer string) []string

RemoveFinalizer removes finalizer in object meta.

func SanitizeDrivePath added in v1.4.0

func SanitizeDrivePath(in string) string

SanitizeDrivePath sanitizes drive path.

func SanitizeKubeResourceName added in v1.4.0

func SanitizeKubeResourceName(name string) string

SanitizeKubeResourceName - Sanitize given name to a valid kubernetes name format. RegEx for a kubernetes name is

([a-z0-9][-a-z0-9]*)?[a-z0-9]

with a max length of 253

WARNING: This function will truncate to 253 bytes if the input is longer

func SanitizeLabelK added in v1.4.0

func SanitizeLabelK(key string) string

SanitizeLabelK - Sanitize given label key to valid kubernetes label format. RegEx for label key is

([A-Za-z0-9][-A-Za-z0-9_.]*[/]?[-A-Za-z0-9_.]*)?[A-Za-z0-9]

with a max length of 63

WARNING: This function will truncate to 63 bytes if the input is longer

func SanitizeLabelV added in v1.4.0

func SanitizeLabelV(value string) string

SanitizeLabelV - Sanitize given label value to valid kubernetes label format. RegEx for label value is

([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9]

with a max length of 63

WARNING: This function will truncate to 63 bytes if the input is longer

func SetAccessTierLabel added in v1.4.0

func SetAccessTierLabel(obj metav1.Object, accessTier directcsi.AccessTier)

SetAccessTierLabel sets access tier label in object.

func SetDirectCSIClient added in v1.4.1

func SetDirectCSIClient(fakeClient *directcsifake.FakeDirectV1beta3)

SetDirectCSIClient sets fake direct-csi client.

func SetLabelKV added in v1.4.0

func SetLabelKV(obj metav1.Object, key, value string)

SetLabelKV sets label key/value in given object.

func ToJSON added in v1.4.0

func ToJSON(obj interface{}) (string, error)

ToJSON converts given value to JSON string.

func ToYAML added in v1.4.0

func ToYAML(obj interface{}) (string, error)

ToYAML converts value to YAML string.

func UpdateCondition added in v1.2.8

func UpdateCondition(statusConditions []metav1.Condition, condType string, condStatus metav1.ConditionStatus, reason, msg string)

UpdateCondition updates conditions of type/status/reason/message.

func UpdateLabels added in v1.4.0

func UpdateLabels(obj metav1.Object, labelKVs ...string)

UpdateLabels updates labels in object.

func WriteObject added in v1.4.4

func WriteObject(writer io.Writer, obj interface{}) error

Types

type LabelValue added in v1.4.4

type LabelValue string

func AccessTiersToLabelValues added in v1.4.4

func AccessTiersToLabelValues(accessTiers []directcsi.AccessTier) (labelValues []LabelValue)

func NewLabelValue added in v1.4.4

func NewLabelValue(value string) (LabelValue, error)

func ToLabelValues added in v1.4.4

func ToLabelValues(vs []string) (labelValues []LabelValue, err error)

type ListDriveResult added in v1.4.2

type ListDriveResult struct {
	Drive directcsi.DirectCSIDrive
	Err   error
}

ListDriveResult denotes list of drive result.

type ListVolumeResult added in v1.4.2

type ListVolumeResult struct {
	Volume directcsi.DirectCSIVolume
	Err    error
}

ListVolumeResult denotes list of volume result.

type SafeFile added in v1.4.4

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

func NewSafeFile added in v1.4.4

func NewSafeFile(fileName string) (*SafeFile, error)

func (*SafeFile) Close added in v1.4.4

func (safeFile *SafeFile) Close() error

func (*SafeFile) Write added in v1.4.4

func (safeFile *SafeFile) Write(p []byte) (int, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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