kubernetesk8s.io/kubernetes/pkg/util/goroutinemap Index | Files | Directories

package goroutinemap

import "k8s.io/kubernetes/pkg/util/goroutinemap"

Package goroutinemap implements a data structure for managing go routines by name. It prevents the creation of new go routines if an existing go routine with the same name exists.

Index

Functions

func IsAlreadyExists

func IsAlreadyExists(err error) bool

IsAlreadyExists returns true if an error returned from GoRoutineMap indicates a new operation can not be started because an operation with the same operation name is already executing.

func NewAlreadyExistsError

func NewAlreadyExistsError(operationName string) error

NewAlreadyExistsError returns a new instance of AlreadyExists error.

Types

type GoRoutineMap

type GoRoutineMap interface {
	// Run adds operation name to the list of running operations and spawns a
	// new go routine to execute the operation.
	// If an operation with the same operation name already exists, an
	// AlreadyExists or ExponentialBackoff error is returned.
	// Once the operation is complete, the go routine is terminated and the
	// operation name is removed from the list of executing operations allowing
	// a new operation to be started with the same operation name without error.
	Run(operationName string, operationFunc func() error) error

	// Wait blocks until operations map is empty. This is typically
	// necessary during tests - the test should wait until all operations finish
	// and evaluate results after that.
	Wait()

	// WaitForCompletion blocks until either all operations have successfully completed
	// or have failed but are not pending. The test should wait until operations are either
	// complete or have failed.
	WaitForCompletion()

	// IsOperationPending returns true if the operation is pending (currently
	// running), otherwise returns false.
	IsOperationPending(operationName string) bool
}

GoRoutineMap defines a type that can run named goroutines and track their state. It prevents the creation of multiple goroutines with the same name and may prevent recreation of a goroutine until after the a backoff time has elapsed after the last goroutine with that name finished.

func NewGoRoutineMap

func NewGoRoutineMap(exponentialBackOffOnError bool) GoRoutineMap

NewGoRoutineMap returns a new instance of GoRoutineMap.

Source Files

goroutinemap.go

Directories

PathSynopsis
pkg/util/goroutinemap/exponentialbackoffPackage exponentialbackoff contains logic for implementing exponential backoff for GoRoutineMap and NestedPendingOperations.
Version
v1.33.0 (latest)
Published
Apr 23, 2025
Platform
linux/amd64
Imports
5 packages
Last checked
5 hours ago

Tools for package owners.