util

package
v0.25.2 Latest Latest
Warning

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

Go to latest
Published: Apr 5, 2024 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package util contains misc utils

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrInvalidNamespacedNameFormat namespaced name format error
	ErrInvalidNamespacedNameFormat = errors.New("invalid format, expect name or namespace/name")
	// ErrNamespaceExpected indicates that a namespace must be provided
	ErrNamespaceExpected = errors.New("missing namespace for resource")
	// ErrEmptyName indicates the resource must be non-empty
	ErrEmptyName = errors.New("resource name cannot be blank")
)

Functions

func Add added in v0.20.0

func Add[T any](ctx context.Context, entries ...T)

Add attaches an entry to the collector

func Get added in v0.20.0

func Get[T any](ctx context.Context) []T

Get returns all entries attached to the collector

func GetNamespacedName

func GetNamespacedName(obj metav1.Object) types.NamespacedName

GetNamespacedName a convenience method to return types.NamespacedName for an object

func MergeMaps

func MergeMaps(first map[string]string, second map[string][]byte) (map[string]string, error)

MergeMaps is used to merge configmap and secret values

func NewBootstrapSecrets

func NewBootstrapSecrets(name types.NamespacedName) (*corev1.Secret, error)

NewBootstrapSecrets generate secrets for pomerium bootstrap

func ParseNamespacedName

func ParseNamespacedName(name string, options ...NamespacedNameOption) (*types.NamespacedName, error)

ParseNamespacedName parses "namespace/name" or "name" format

func WithBin added in v0.20.0

func WithBin[T any](ctx context.Context) context.Context

WithBin enables collector of objects that's stored in context that may be used to collect i.e. some warnings that do not cause errors or maybe document some defaults that were applied

Types

type Config

type Config[T any] interface {
	Clone() T
}

Config is a configuration abstraction

type NamespacedNameOption

type NamespacedNameOption func(name *types.NamespacedName) error

NamespacedNameOption customizes namespaced name parsing

func WithClusterScope

func WithClusterScope() NamespacedNameOption

WithClusterScope ensures the name is not namespaced

func WithDefaultNamespace

func WithDefaultNamespace(namespace string) NamespacedNameOption

WithDefaultNamespace will set namespace to provided default, if missing

func WithMustNamespace

func WithMustNamespace(namespace string) NamespacedNameOption

WithMustNamespace enforces the namespace to match provided one

func WithNamespaceExpected

func WithNamespaceExpected() NamespacedNameOption

WithNamespaceExpected will set namespace to provided default, if missing

type RestartOnConfigChange

type RestartOnConfigChange[T Config[T]] interface {
	// OnConfigUpdated may be called to provide updated configuration versions
	OnConfigUpdated(context.Context, T)
	// Run runs the task, restarting it when equal() returns false, by canceling task's execution context
	// if the task cannot complete within the given timeout threshold, Run would return an error
	// ensuring there are no unaccounted tasks left
	Run(ctx context.Context,
		equal func(prev, next T) bool,
		fn func(context.Context, T) error,
		shutdownTimeout time.Duration,
	) error
}

RestartOnConfigChange allows to run a task that should be restarted when config changes.

func NewRestartOnChange

func NewRestartOnChange[T Config[T]]() RestartOnConfigChange[T]

NewRestartOnChange create a new instance

Jump to

Keyboard shortcuts

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