util

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: May 11, 2023 License: Apache-2.0 Imports: 24 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Tick    = string(rune(0x2705))
	Err     = string(rune(0x1F6AB))
	Sad     = string(rune(0x1F613))
	Wait    = string(rune(0x23F3))
	Watch   = string(rune(0x1F440))
	Find    = string(rune(0x1F50D))
	Bin     = string(rune(0x1F5D1))
	Recycle = string(rune(0x267D))
	Party   = string(rune(0x1F389))
)
View Source
const (
	ComponentController = "controller"
	InstanceController  = "controller"
	ClusterController   = "controller"
)
View Source
const (
	NotApplicable = "NA"
)

Variables

View Source
var (
	LabelName       = "kubeslice-controller-resource-name"
	LabelValue      = "%s-%s"
	NamespacePrefix = "kubeslice-"
)
View Source
var (
	LabelsKubeSliceController = map[string]string{
		"kubeslice-resource-owner": "controller",
	}
)
View Source
var Loglevel zapcore.Level
View Source
var LoglevelString string

Functions

func AddFinalizer

func AddFinalizer(ctx context.Context, object client.Object, finalizerName string) (ctrl.Result, error)

AddFinalizer is a function to add specific conditions before deleting the resource

func AppendHyphenAndPercentageSToString

func AppendHyphenAndPercentageSToString(stringToAppend string) string

AppendHyphenAndPercentageSToString is a function to add hyphen and % at the end of string

func AppendHyphenToString

func AppendHyphenToString(stringToAppend string) string

AppendHyphenToString is a function add hyphen at the end of string

func ArrayToString added in v0.2.1

func ArrayToString(arr []string) string

func CheckDuplicateInArray

func CheckDuplicateInArray(data []string) (bool, []string)

CheckDuplicateInArray check duplicate data in array

func CheckForProjectNamespace added in v0.5.3

func CheckForProjectNamespace(namespace *corev1.Namespace) bool

CheckForProjectNamespace is a function to check namespace is in decided format

func CleanupDeleteResource added in v0.6.3

func CleanupDeleteResource(ctx context.Context, object client.Object) error

DeleteResource is a function to delete the resource of given kind

func CleanupUpdateResource added in v0.6.3

func CleanupUpdateResource(ctx context.Context, object client.Object) error

UpdateResource is a function to update resource

func CleanupUpdateStatus added in v0.6.3

func CleanupUpdateStatus(ctx context.Context, object client.Object) error

UpdateStatus is a function to update the status of given resource

func ContainsString

func ContainsString(strings []string, t string) bool

ContainsString is a function to check if the given string is in given array

func CreateResource

func CreateResource(ctx context.Context, object client.Object) error

CreateResource is a function to create the given kind of resource if not exist in namepscae

func CtxEventRecorder added in v0.8.4

func CtxEventRecorder(ctx context.Context) events.EventRecorder

CtxEventRecorder is a function to get the EventRecorder

func CtxLogger

func CtxLogger(ctx context.Context) *zap.SugaredLogger

CtxLogger is a function to get the logs

func CtxScheme added in v0.7.1

func CtxScheme(ctx context.Context) *runtime.Scheme

CtxScheme is a function to get the Scheme

func DeleteResource

func DeleteResource(ctx context.Context, object client.Object) error

DeleteResource is a function to delete the resource of given kind

func EncodeToBase64

func EncodeToBase64(v interface{}) (string, error)

EncodeToBase64 is a function to encode the string

func FindCIDRByMaxClusters added in v0.5.3

func FindCIDRByMaxClusters(maxCluster int) string

FindCIDRByMaxClusters is a function to find the CIDR by max clusters

func GetClusterPrefixPool added in v0.5.3

func GetClusterPrefixPool(sliceSubnet string, ipamInt int, subnetCidr string) string

func GetKubeSliceControllerRequestContext

func GetKubeSliceControllerRequestContext(ctx context.Context) *kubeSliceControllerRequestContext

GetKubeSliceControllerRequestContext is a function to get the request context

func GetObjectKind

func GetObjectKind(obj runtime.Object) string

GetObjectKindis a function which return the kind of existing resource

func GetOwnerLabel

func GetOwnerLabel(completeResourceName string) map[string]string

GetOwnerLabel is a function returns the label of object

func GetProjectName added in v0.7.1

func GetProjectName(namespace string) string

GetProjectName is function to get the project name from the namespace

func GetResourceIfExist

func GetResourceIfExist(ctx context.Context, namespacedName client.ObjectKey, object client.Object) (bool,
	error)

GetResourceIfExist is a function to get the given resource is in namespace

func GetZapLogLevel

func GetZapLogLevel(userLogLevel string) zapcore.Level

GetZapLogLevel is function to add the layer of debug, error, info in logging

func HasLastTwoOctetsZero

func HasLastTwoOctetsZero(subnet string) bool

HasLastTwoOctetsZero is a function to check if the subnet address's last octet is 0

func HasPrefix

func HasPrefix(subnet string, prefix string) bool

HasPrefix is function to check if the string has given prefix

func IsDNSCompliant

func IsDNSCompliant(name string) bool

IsDNSCompliant is a function to check if the given string/name is DNS compliant

func IsInSlice

func IsInSlice(slice []string, element string) bool

IsInSlice function for check if element is in array slice

func IsPrivateSubnet

func IsPrivateSubnet(subnet string) bool

IsPrivateSubnet function for check if prefix matches any item in a slice

func IsReconciled

func IsReconciled(object ctrl.Result, err error) (bool, ctrl.Result, error)

IsReconciled is a function to requeue the reconcilation process

func ListResources

func ListResources(ctx context.Context, list client.ObjectList, opts ...client.ListOption) error

ListResources is a function to list down the resources/objects of given kind

func NewLogger added in v0.6.0

func NewLogger() *uzap.SugaredLogger

NewLogger Creates a new SugaredLogger instance with predefined standard fields SugaredLogger makes it easy to use structured logging with logging levels and additional fields

func OverlapIP

func OverlapIP(ip1, ip2 string) bool

OverlapIP function to check whether two IP addresses overlap each other

func PrepareKubeSliceControllersRequestContext

func PrepareKubeSliceControllersRequestContext(ctx context.Context, client Client,
	scheme *runtime.Scheme, controllerName string, er *events.EventRecorder) context.Context

PrepareKubeSliceControllersRequestContext is a function to create the context for kube slice

func RecordEvent added in v0.7.1

func RecordEvent(ctx context.Context, recorder events.EventRecorder, object runtime.Object, relatedObject runtime.Object, name events.EventName)

RecordEvent is a function to record the event

func RemoveDuplicatesFromArray added in v0.2.1

func RemoveDuplicatesFromArray(duplicate []string) (nonDup []string)

func RemoveFinalizer

func RemoveFinalizer(ctx context.Context, object client.Object, finalizerName string) (ctrl.Result, error)

RemoveFinalizer is a function to discard the condition to delete the resource

func Resource

func Resource(resource string) schema.GroupResource

Resource is a function returns the resource for testing

func Retry added in v0.6.3

func Retry(ctx context.Context, backoffLimit int, sleep time.Duration, f func() error) (err error)

Retry tries to execute the funtion, If failed reattempts till backoffLimit

func UpdateResource

func UpdateResource(ctx context.Context, object client.Object) error

UpdateResource is a function to update resource

func UpdateStatus

func UpdateStatus(ctx context.Context, object client.Object) error

UpdateStatus is a function to update the status of given resource

func ValidateCoOrdinates added in v0.2.1

func ValidateCoOrdinates(latitude string, longitude string) bool

Types

type Client

type Client interface {
	Get(ctx context.Context, key client.ObjectKey, obj client.Object) error
	List(ctx context.Context, list client.ObjectList, opts ...client.ListOption) error
	Create(ctx context.Context, obj client.Object, opts ...client.CreateOption) error
	Delete(ctx context.Context, obj client.Object, opts ...client.DeleteOption) error
	Patch(ctx context.Context, obj client.Object, patch client.Patch, opts ...client.PatchOption) error
	Update(ctx context.Context, obj client.Object, opts ...client.UpdateOption) error
	Status() client.StatusWriter
	DeleteAllOf(ctx context.Context, obj client.Object, opts ...client.DeleteAllOfOption) error
}

Client is interface for k8s

func CtxClient added in v0.7.1

func CtxClient(ctx context.Context) Client

CtxClient is a function to get the Client

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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