utils

package
v1.4.6 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const (
	// 127 or \u007f is the DEL character
	DEL rune = 127
)
View Source
const MaxThreadCount = 40

Variables

View Source
var (
	Bold = color.New(color.Bold).SprintFunc()
	Red  = color.New(color.FgRed).SprintFunc()
)
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)
)
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.

View Source
var Scheme = runtime.NewScheme()

Functions

func AddCondition added in v1.2.8

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

func AddFinalizer

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

func BoolToCondition

func BoolToCondition(val bool) metav1.ConditionStatus

func DefaultIfZero added in v1.4.0

func DefaultIfZero(left, right interface{}) interface{}

func DefaultIfZeroFloat added in v1.4.0

func DefaultIfZeroFloat(left, right float32) float32

func DefaultIfZeroFloat64 added in v1.4.0

func DefaultIfZeroFloat64(left, right float64) float64

func DefaultIfZeroInt added in v1.4.0

func DefaultIfZeroInt(left, right int) int

func DefaultIfZeroInt64 added in v1.4.0

func DefaultIfZeroInt64(left, right int64) int64

func DefaultIfZeroString added in v1.4.0

func DefaultIfZeroString(left, right string) string

func DirectCSIDriveTypeMeta added in v1.3.0

func DirectCSIDriveTypeMeta() metav1.TypeMeta

func DirectCSIVolumeTypeMeta added in v1.3.0

func DirectCSIVolumeTypeMeta() metav1.TypeMeta

func Eventf added in v1.4.2

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

func ExcludeFinalizer added in v1.4.2

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

func FakeInit added in v1.4.2

func FakeInit()

func FmapString added in v1.4.0

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

func FmapStringSlice added in v1.4.0

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

func GetAPIExtensionsClient added in v1.1.0

func GetAPIExtensionsClient() apiextensions.ApiextensionsV1Interface

func GetClientForNonCoreGroupKindVersions

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

func GetCondition added in v1.2.8

func GetCondition(statusConditions []metav1.Condition, condType string) metav1.Condition

func GetDirectCSIClient

func GetDirectCSIClient() directcsi.DirectV1beta2Interface

func GetDirectClientset

func GetDirectClientset() direct.Interface

func GetDiscoveryClient

func GetDiscoveryClient() discovery.DiscoveryInterface

func GetDriveList added in v1.4.2

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

func GetGroupKindVersions

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

func GetKubeClient

func GetKubeClient() kubernetes.Interface

func GetKubeConfig

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

func GetLabelV added in v1.4.0

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

func GetMetadataClient

func GetMetadataClient() metadata.Interface

func GetVolumeList added in v1.4.2

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

func Init

func Init()

func IsCondition added in v1.2.8

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

func IsConditionStatus added in v1.2.8

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

func ListDrives added in v1.4.2

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

func ListVolumes added in v1.4.2

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

func LogYAML added in v1.2.1

func LogYAML(obj interface{}) error

func MustJSON added in v1.4.0

func MustJSON(obj interface{}) string

func MustYAML added in v1.4.0

func MustYAML(obj interface{}) string

func NewDirectCSILabel added in v1.4.0

func NewDirectCSILabel(key string) string

func NewIdentityTopologySelector added in v1.4.0

func NewIdentityTopologySelector(identity string) corev1.TopologySelectorTerm

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

NewObjectMeta - 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)

func PrintYaml added in v1.2.1

func PrintYaml(data string)

func RemoveFinalizer

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

func SafeGetLabels added in v1.4.0

func SafeGetLabels(obj metav1.Object) map[string]string

func SanitizeDrivePath added in v1.4.0

func SanitizeDrivePath(in string) string

func SanitizeFinalizers added in v1.4.0

func SanitizeFinalizers(finalizers []string) []string

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 SanitizeLabelKV added in v1.4.0

func SanitizeLabelKV(key, value string) (string, string)

func SanitizeLabelMap added in v1.4.0

func SanitizeLabelMap(kvMap map[string]string) map[string]string

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)

func SetDirectCSIClient added in v1.4.1

func SetDirectCSIClient(fakeClient *directcsifake.FakeDirectV1beta2)

func SetLabelKV added in v1.4.0

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

func ToJSON added in v1.4.0

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

func ToYAML added in v1.4.0

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

func UpdateCondition added in v1.2.8

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

func UpdateLabels added in v1.4.0

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

func ValidateAccessTier added in v1.3.0

func ValidateAccessTier(at string) (directcsi.AccessTier, error)

Types

type ListDriveResult added in v1.4.2

type ListDriveResult struct {
	Drive directcsi.DirectCSIDrive
	Err   error
}

type ListVolumeResult added in v1.4.2

type ListVolumeResult struct {
	Volume directcsi.DirectCSIVolume
	Err    error
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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