...

Package retryclient

import "edge-infra.dev/pkg/sds/lib/k8s/retryclient"
Overview
Index
Subdirectories

Overview ▾

Package retryclient provides a Kubernetes client wrapper that implements retries for Kubernetes methods. This is primarily to handle issues related to quorum instability.

func New

func New(client ctrlclient.Client, reader ctrlclient.Reader, config Config) types.Retrier

New creates a new instance of RetryClient as a Retrier interface. If not provided via the config then the RetryClient will have the default args:

RequestTimeout: 5 Seconds

InitialBackoff: 0.5 Seconds

BackoffFactor: 1.5

MaxRetries: 3

You can keep all of the defaults or overwrite individual values by only including the values you wish to overwrite in the provided config. You can not set any of these fields to their nil values because these will not overwrite the defaults.

type Config

Config is a data structure used to configure the RetryClient. The fields can be used in the following ways:

RequestTimeout: The timeout used for client requests

InitialBackoff: The initial backoff period to wait between failed requests

BackoffFactor: The factor by which to increase the backoff period after each failed attempt

MaxRetries: The maximum number of retries to attempt before returning an error

type Config struct {
    RequestTimeout time.Duration
    InitialBackoff time.Duration
    BackoffFactor  float64
    MaxRetries     int
}

type RetryClient

RetryClient is a Kubernetes client that incorporates retries in its operations

type RetryClient struct {
    Config
    // contains filtered or unexported fields
}

func (*RetryClient) Client

func (r *RetryClient) Client() ctrlclient.Client

Client will return the controller runtime client used by the retry client

func (RetryClient) IgnoreCache

func (r RetryClient) IgnoreCache() types.Retrier

IgnoreCache returns a retryclient object that can be chained to make direct API server requests without using the client cache. This should be used sparingly as it will increase direct requests to the API server. The original retryclient will not be altered and will continue to use cache. This is done to make sure cache is only ignored where it is absolutely necessary.

func (*RetryClient) Reader

func (r *RetryClient) Reader() ctrlclient.Reader

Reader will return the controller runtime API reader used by the retry client

func (*RetryClient) SafeCreate

func (r *RetryClient) SafeCreate(ctx context.Context, obj ctrlclient.Object, opts ...ctrlclient.CreateOption) error

SafeCreate attempts to create a Kubernetes object, with retries.

func (*RetryClient) SafeDelete

func (r *RetryClient) SafeDelete(ctx context.Context, obj ctrlclient.Object, opts ...ctrlclient.DeleteOption) error

SafeDelete attempts to delete a Kubernetes object, with retries.

func (*RetryClient) SafeGet

func (r *RetryClient) SafeGet(ctx context.Context, objKey ctrlclient.ObjectKey, obj ctrlclient.Object, opts ...ctrlclient.GetOption) error

SafeGet attempts to retrieve a Kubernetes object, with retries.

func (*RetryClient) SafeList

func (r *RetryClient) SafeList(ctx context.Context, list ctrlclient.ObjectList, opts ...ctrlclient.ListOption) error

SafeList attempts to list Kubernetes objects, with retries.

func (*RetryClient) SafeUpdate

func (r *RetryClient) SafeUpdate(ctx context.Context, objKey ctrlclient.ObjectKey, obj ctrlclient.Object, fn func(context.Context, ctrlclient.Object) error, updateOpts ...ctrlclient.UpdateOption) error

SafeUpdate attempts to update a Kubernetes object using the provided function, with retries.

Subdirectories

Name Synopsis
..
mocks Package mocks is a generated GoMock package.
types