utils

package
v0.1.0 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const (
	SlowStartInitialBatchSize = 1
)

Variables

This section is empty.

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 AdmissionRequestObjectKeyString added in v0.1.0

func AdmissionRequestObjectKeyString(req admission.Request) string

func DeleteWithFinalizer added in v0.1.0

func DeleteWithFinalizer(ctx context.Context, client client.Client, obj client.Object, finalizer string) error

func Escape

func Escape(key string) string

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 MutateAnnotations added in v0.1.0

func MutateAnnotations(obj client.Object, mutateFn func(annotations map[string]string))

func MutateLabels added in v0.1.0

func MutateLabels(obj client.Object, mutateFn func(labels map[string]string))

func ObjectKeyString

func ObjectKeyString(obj client.Object) string

func RemoveAndUpdateFinalizer

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

func SliceTopologyInfoEqual added in v0.1.0

func SliceTopologyInfoEqual(a, b []v1alpha1.TopologyInfo) bool

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