util

package
v0.21.0-beta.5 Latest Latest
Warning

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

Go to latest
Published: Oct 18, 2024 License: Apache-2.0 Imports: 12 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

View Source
var EnsureCRD = func(ctx context.Context, config *rest.Config, manifest []byte, groupVersionKind schema.GroupVersionKind) error {
	exists, err := KindExists(config, groupVersionKind)
	if err != nil {
		return err
	} else if exists {
		return nil
	}

	err = wait.ExponentialBackoffWithContext(ctx, wait.Backoff{Duration: time.Second, Factor: 1.5, Cap: 5 * time.Minute, Steps: math.MaxInt32}, func(ctx context.Context) (bool, error) {
		err := applier.ApplyManifest(ctx, config, manifest)
		if err != nil {
			loghelper.Infof("Failed to apply CRD %s: %v", groupVersionKind.String(), err)
			return false, nil
		}
		return true, nil
	})
	if err != nil {
		return fmt.Errorf("failed to apply CRD %s: %w", groupVersionKind.String(), err)
	}

	var errKindExists error
	err = wait.ExponentialBackoffWithContext(ctx, wait.Backoff{Duration: time.Second, Factor: 1.5, Cap: time.Minute, Steps: math.MaxInt32}, func(_ context.Context) (bool, error) {
		var found bool
		found, errKindExists = KindExists(config, groupVersionKind)
		return found, nil
	})
	if err != nil {
		return fmt.Errorf("failed to find CRD %s: %w: %w", groupVersionKind.String(), err, errKindExists)
	}

	return nil
}

EnsureCRD should be replaceable by unit tests

Functions

func Contains

func Contains(needle string, haystack []string) bool

func GetCause added in v0.20.0

func GetCause(err error) string

func KindExists

func KindExists(config *rest.Config, groupVersionKind schema.GroupVersionKind) (bool, error)

KindExists checks if given CRDs exist in the given group. Returns foundKinds, notFoundKinds, error

Types

This section is empty.

Directories

Path Synopsis
Package locker provides a mechanism for creating finer-grained locking to help free up more global locks to handle other tasks.
Package locker provides a mechanism for creating finer-grained locking to help free up more global locks to handle other tasks.
Package fifomu provides a Mutex whose Lock method returns the lock to callers in FIFO call order.
Package fifomu provides a Mutex whose Lock method returns the lock to callers in FIFO call order.
Package websocketproxy is a reverse proxy for WebSocket connections.
Package websocketproxy is a reverse proxy for WebSocket connections.

Jump to

Keyboard shortcuts

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