utils

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Jan 24, 2024 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SlowStartInitialBatchSize = 1
)

Variables

View Source
var ClientManagerSingleton = NewClientManager()

Functions

func Abbreviate

func Abbreviate(str string, maxLength uint32) string

Abbreviate abbreviates a string using ellipses

func AddAndUpdateFinalizer

func AddAndUpdateFinalizer(client client.Client, obj client.Object, finalizer string) error

func Any

func Any[T any](items []T, predicate func(*T) bool) bool

Any detect if item exist in the items

func DeleteAnnotation

func DeleteAnnotation(patchType types.PatchType, key string) client.Patch

func Escape

func Escape(key string) string

func Filter

func Filter[T any](items []T, predicate func(*T) bool) []T

Filter filter items which meet the predicate

func Find

func Find[T any](items []T, predicate func(*T) bool) (*T, bool)

Find find first item which meet the predicate

func GetMapValue

func GetMapValue(m map[string]string, key string) (string, bool)

func GetMapValueByDefault

func GetMapValueByDefault(m map[string]string, key, def string) string

func ObjectKeyString

func ObjectKeyString(obj client.Object) string

func RemoveAndUpdateFinalizer

func RemoveAndUpdateFinalizer(client client.Client, obj client.Object, finalizer string) error

func SlowStartBatch

func SlowStartBatch(count int, initialBatchSize int, shortCircuit bool, fn func(int, error) error) (int, error)

SlowStartBatch tries to call the provided function a total of 'count' times, starting slow to check for errors, then speeding up if calls succeed.

It groups the calls into batches, starting with a group of initialBatchSize. Within each batch, it may call the function multiple times concurrently.

If a whole batch succeeds, the next batch may get exponentially larger. If there are any failures in a batch, all remaining batches are skipped after waiting for the current batch to complete.

It returns the number of successful calls to the function.

func UpdateOnConflict

func UpdateOnConflict(ctx context.Context, reader client.Reader, writer UpdateWriter, obj client.Object, mutateFn controllerutil.MutateFn) (controllerutil.OperationResult, error)

reader is used to get freshest object writer can be client.Writer or client.StatusWriter

Types

type ClientConfig

type ClientConfig struct {
	CABundle []byte
}

type ClientManager

type ClientManager struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func NewClientManager

func NewClientManager() *ClientManager

NewClientManager construct ClientManager

func (*ClientManager) Client

func (cm *ClientManager) Client(cc *ClientConfig) (c *http.Client, err error)

Client get HttpClient from cache if present or new instance if not present

type UpdateWriter

type UpdateWriter interface {
	// Update updates the fields corresponding to the status subresource for the
	// given obj. obj must be a struct pointer so that obj can be updated
	// with the content returned by the Server.
	Update(ctx context.Context, obj client.Object, opts ...client.UpdateOption) error

	// Patch patches the given object's subresource. obj must be a struct
	// pointer so that obj can be updated with the content returned by the
	// Server.
	Patch(ctx context.Context, obj client.Object, patch client.Patch, opts ...client.PatchOption) error
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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