tfutils

package
v1.9.0 Latest Latest
Warning

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

Go to latest
Published: Jan 15, 2025 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultTimeout = 10 * time.Minute

Variables

This section is empty.

Functions

func CalculateDelayAndMinTimeOut

func CalculateDelayAndMinTimeOut(timeout time.Duration) (delay time.Duration, minTimeout time.Duration)

func GenerateCertificate added in v1.6.0

func GenerateCertificate() error

func IsRetriableErrorForEntitlement added in v1.9.0

func IsRetriableErrorForEntitlement(err error) bool

func IsRetriableErrorForEnvInstance added in v1.9.0

func IsRetriableErrorForEnvInstance(err error) bool

func ReadCertificate added in v1.6.0

func ReadCertificate() (string, error)

func SetDifference

func SetDifference[S ~[]E, E any](setA, setB S, isEqual equalityPredicate[E]) (result S)

TODO This is a utility function to compute to be removed and to be added substructures in resource configurations. TODO This is required since terraform only computes required CRUD operations on resource level. Changes in inner TODO configurations need to be computed based on the state and plan data by the update operation of a provider. TODO Should the terraform plugin framework support this functionality in the future, e.g. as a part of the Set TODO datatype, we can remove this code.

func ToBTPCLIParamsMap

func ToBTPCLIParamsMap(a any) (map[string]string, error)

Types

type NotFoundError

type NotFoundError struct {
	LastError    error
	LastRequest  interface{}
	LastResponse interface{}
	Message      string
	Retries      int
}

NotFoundError represents when a StateRefreshFunc returns a nil result during a StateChangeConf waiter method and that StateChangeConf is configured for specific targets.

func (*NotFoundError) Error

func (e *NotFoundError) Error() string

Error returns the Message string, if non-empty, or a string indicating the resource could not be found.

func (*NotFoundError) Unwrap

func (e *NotFoundError) Unwrap() error

Unwrap returns the LastError, compatible with errors.Unwrap.

type StateChangeConf

type StateChangeConf struct {
	Delay          time.Duration    // Wait this time before starting checks
	Pending        []string         // States that are "allowed" and will continue trying
	Refresh        StateRefreshFunc // Refreshes the current state
	Target         []string         // Target state
	Timeout        time.Duration    // The amount of time to wait before timeout
	MinTimeout     time.Duration    // Smallest time to wait before refreshes
	PollInterval   time.Duration    // Override MinTimeout/backoff and only poll this often
	NotFoundChecks int              // Number of times to allow not found (nil result from Refresh)

	// This is to work around inconsistent APIs
	ContinuousTargetOccurence int // Number of times the Target state has to occur continuously
}

StateChangeConf is the configuration struct used for `WaitForState`.

func (*StateChangeConf) WaitForState

func (conf *StateChangeConf) WaitForState() (interface{}, error)

WaitForState watches an object and waits for it to achieve the state specified in the configuration using the specified Refresh() func, waiting the number of seconds specified in the timeout configuration.

func (*StateChangeConf) WaitForStateContext

func (conf *StateChangeConf) WaitForStateContext(ctx context.Context) (interface{}, error)

WaitForStateContext watches an object and waits for it to achieve the state specified in the configuration using the specified Refresh() func, waiting the number of seconds specified in the timeout configuration.

If the Refresh function returns an error, exit immediately with that error.

If the Refresh function returns a state other than the Target state or one listed in Pending, return immediately with an error.

If the Timeout is exceeded before reaching the Target state, return an error.

Otherwise, the result is the result of the first call to the Refresh function to reach the target state.

Cancellation from the passed in context will cancel the refresh loop

type StateRefreshFunc

type StateRefreshFunc func() (result interface{}, state string, err error)

StateRefreshFunc is a function type used for StateChangeConf that is responsible for refreshing the item being watched for a state change.

It returns three results. `result` is any object that will be returned as the final object after waiting for state change. This allows you to return the final updated object, for example an EC2 instance after refreshing it. A nil result represents not found.

`state` is the latest state of that object. And `err` is any error that may have happened while refreshing the state.

type TimeoutError

type TimeoutError struct {
	LastError     error
	LastState     string
	Timeout       time.Duration
	ExpectedState []string
}

TimeoutError is returned when WaitForState times out

func (*TimeoutError) Error

func (e *TimeoutError) Error() string

Error returns a string with any information available.

func (*TimeoutError) Unwrap

func (e *TimeoutError) Unwrap() error

Unwrap returns the LastError, compatible with errors.Unwrap.

type UnexpectedStateError

type UnexpectedStateError struct {
	LastError     error
	State         string
	ExpectedState []string
}

UnexpectedStateError is returned when Refresh returns a state that's neither in Target nor Pending

func (*UnexpectedStateError) Error

func (e *UnexpectedStateError) Error() string

Error returns a string with the unexpected state value, the desired target, and any last error.

func (*UnexpectedStateError) Unwrap

func (e *UnexpectedStateError) Unwrap() error

Unwrap returns the LastError, compatible with errors.Unwrap.

Jump to

Keyboard shortcuts

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