managed

package
v0.5.22 Latest Latest
Warning

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

Go to latest
Published: Jul 25, 2022 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ControllerName

func ControllerName(kind string) string

ControllerName returns the recommended name for controllers that use this package to reconcile a particular kind of managed resource.

Types

type ConnectionDetails

type ConnectionDetails map[string][]byte

ConnectionDetails created or updated during an operation on an external resource, for example usernames, passwords, endpoints, ports, etc.

type CrActualDiffObservation added in v0.4.6

type CrActualDiffObservation struct {
	// ResourceHasData can be true when a managed resource is created, but the
	// device had already data in that resource. The data needs to get aligned
	// with the intended resource data
	HasData bool
	// ResourceUpToDate should be true if the corresponding external resource
	// appears to be up-to-date with the resourceSpec
	IsUpToDate bool
	// when the resource is not up to date these 2 parameter determine what to do to realign the resource to the spec
	Deletes []*gnmi.Path
	Updates []*gnmi.Update
}

type CrObservation added in v0.4.6

type CrObservation struct {
	// indicates if the device is exhausted or not, this can happen when too many api calls
	// occured towards the device
	Exhausted bool
	// indicates if the device in the proxy-cache is ready or not,
	// during proxy-cache initialization it can occur that the cache is not ready
	Ready bool
	// indicates if the MR is not yet reconciled, the reconciler should wait for further actions
	Pending bool
	// indicates if a MR exists in the proxy-cache
	Exists bool
	// indicates if the MR was not successfully applied to the device
	// unless the resourceSpec changes the transaction would not be successfull
	// we dont try to reconcile unless the spec changed
	Failed bool
	// Provides additional information why a MR is in failed status
	Message string
}

type CrSpecDiffObservation added in v0.4.6

type CrSpecDiffObservation struct {
	// indicates if the spec was changed and subsequent actionsare required
	Deletes []*gnmi.Path
	Updates []*gnmi.Update
}

type CrSpecObservation added in v0.4.6

type CrSpecObservation struct {
	// validation was successfull
	Success bool
	// Provides additional information why a validation failured occured
	Message string
}

type ExternalClient

type ExternalClient interface {

	// Create an external resource per the specifications of the supplied
	// Managed resource. Called when thr diff reports that the associated
	// external resource does not exist.
	Create(ctx context.Context, mg resource.Managed, obs ExternalObservation) error

	// Update the external resource represented by the supplied Managed
	// resource, if necessary. Called when the diff reports that the
	// associated external resource is up to date.
	Update(ctx context.Context, mg resource.Managed, obs ExternalObservation) error

	// Delete the external resource upon deletion of its associated Managed
	// resource. Called when the managed resource has been deleted.
	Delete(ctx context.Context, mg resource.Managed, obs ExternalObservation) error

	// GetSystemConfig returns the system config for a particular device from
	// the system proxy cache
	GetSystemConfig(ctx context.Context, mg resource.Managed) (*ygotnddp.Device, error)

	// GetResourceName returns the running config for a particular device from
	// the running device proxy cache
	GetRunningConfig(ctx context.Context, mg resource.Managed) ([]byte, error)

	// Close the gnmi connection to the system proxy cache
	Close()
}

An ExternalClient manages the lifecycle of an external resource. None of the calls here should be blocking. All of the calls should be idempotent. For example, Create call should not return AlreadyExists error if it's called again with the same parameters or Delete call should not return error if there is an ongoing deletion or resource does not exist.

type ExternalClientFns

type ExternalClientFns struct {
	//ObserveFn          func(ctx context.Context, mg resource.Managed, runningCfg []byte) (ExternalObservation, error)
	CreateFn           func(ctx context.Context, mg resource.Managed, obs ExternalObservation) error
	UpdateFn           func(ctx context.Context, mg resource.Managed, obs ExternalObservation) error
	DeleteFn           func(ctx context.Context, mg resource.Managed, obs ExternalObservation) error
	GetSystemConfigFn  func(ctx context.Context, mg resource.Managed) (*ygotnddp.Device, error)
	GetRunningConfigFn func(ctx context.Context, mg resource.Managed) ([]byte, error)
	CloseFn            func()
}

ExternalClientFns are a series of functions that satisfy the ExternalClient interface.

func (ExternalClientFns) Close added in v0.2.14

func (e ExternalClientFns) Close()

GetResourceName returns the resource matching the path

func (ExternalClientFns) Create

Create an external resource per the specifications of the supplied Managed resource.

func (ExternalClientFns) Delete

Delete the external resource upon deletion of its associated Managed resource.

func (ExternalClientFns) GetRunningConfig added in v0.4.0

func (e ExternalClientFns) GetRunningConfig(ctx context.Context, mg resource.Managed) ([]byte, error)

GetResourceName returns the running config for a particular device from the running device proxy cache

func (ExternalClientFns) GetSystemConfig added in v0.4.0

func (e ExternalClientFns) GetSystemConfig(ctx context.Context, mg resource.Managed) (*ygotnddp.Device, error)

GetSystemConfig returns the system config for a particular device from the system proxy cache

func (ExternalClientFns) Update

Update the external resource represented by the supplied Managed resource, if necessary.

type ExternalConnecter

type ExternalConnecter interface {
	// Connect to the provider specified by the supplied managed resource and
	// produce an ExternalClient.
	Connect(ctx context.Context, mg resource.Managed) (ExternalClient, error)
}

An ExternalConnecter produces a new ExternalClient given the supplied Managed resource.

type ExternalConnectorFn

type ExternalConnectorFn func(ctx context.Context, mg resource.Managed) (ExternalClient, error)

An ExternalConnectorFn is a function that satisfies the ExternalConnecter interface.

func (ExternalConnectorFn) Connect

Connect to the provider specified by the supplied managed resource and produce an ExternalClient.

type ExternalObservation

type ExternalObservation struct {
	// HasData can be true when a managed resource is created, but the
	// device had already data in that resource. The data needs to get aligned
	// with the intended MR data
	HasData bool
	// IsUpToDate should be true if the corresponding MR
	// appears to be up-to-date with the cr spec
	IsUpToDate bool
	// when the resource is not up to date these 2 parameter determine what to do to realign
	// the external resource on the device to the cr spec
	Deletes []*gnmi.Path
	Updates []*gnmi.Update
}

An ExternalObservation is the result of an observation of an external resource.

type NopClient

type NopClient struct{}

A NopClient does nothing.

func (*NopClient) Close added in v0.2.14

func (c *NopClient) Close()

func (*NopClient) Create

Create does nothing. It returns an empty ExternalCreation and no error.

func (*NopClient) Delete

Delete does nothing. It never returns an error.

func (*NopClient) GetRunningConfig added in v0.4.0

func (c *NopClient) GetRunningConfig(ctx context.Context, mg resource.Managed) ([]byte, error)

GetResourceName returns the running config for a particular device from the running device proxy cache

func (*NopClient) GetSystemConfig added in v0.4.0

func (c *NopClient) GetSystemConfig(ctx context.Context, mg resource.Managed) (*ygotnddp.Device, error)

GetSystemConfig returns the system config for a particular device from the system proxy cache

func (*NopClient) Update

Update does nothing. It returns an empty ExternalUpdate and no error.

type NopConnecter

type NopConnecter struct{}

A NopConnecter does nothing.

func (*NopConnecter) Connect

Connect returns a NopClient. It never returns an error.

type NopValidator

type NopValidator struct{}

func (*NopValidator) GetCrActualDiff added in v0.4.6

func (e *NopValidator) GetCrActualDiff(ctx context.Context, mg resource.Managed, runningCfg []byte) (CrActualDiffObservation, error)

func (*NopValidator) GetCrSpecDiff added in v0.4.6

func (e *NopValidator) GetCrSpecDiff(ctx context.Context, mg resource.Managed, systemCfg *ygotnddp.Device) (CrSpecDiffObservation, error)

func (*NopValidator) GetCrStatus added in v0.4.6

func (e *NopValidator) GetCrStatus(ctx context.Context, mg resource.Managed, systemCfg *ygotnddp.Device) (CrObservation, error)

func (*NopValidator) GetRootPaths added in v0.4.6

func (e *NopValidator) GetRootPaths(ctx context.Context, mg resource.Managed) ([]string, error)

func (*NopValidator) ValidateCrSpecDelete added in v0.4.6

func (e *NopValidator) ValidateCrSpecDelete(ctx context.Context, mg resource.Managed, runningCfg []byte) (CrSpecObservation, error)

func (*NopValidator) ValidateCrSpecUpdate added in v0.4.6

func (e *NopValidator) ValidateCrSpecUpdate(ctx context.Context, mg resource.Managed, runningCfg []byte) (CrSpecObservation, error)

type Reconciler

type Reconciler struct {
	// contains filtered or unexported fields
}

A Reconciler reconciles managed resources by creating and managing the lifecycle of an external resource, i.e. a resource in an external network device through an API. Each controller must watch the managed resource kind for which it is responsible.

func NewReconciler

func NewReconciler(m manager.Manager, of resource.ManagedKind, o ...ReconcilerOption) *Reconciler

NewReconciler returns a Reconciler that reconciles managed resources of the supplied ManagedKind with resources in an external network device. It panics if asked to reconcile a managed resource kind that is not registered with the supplied manager's runtime.Scheme. The returned Reconciler reconciles with a dummy, no-op 'external system' by default; callers should supply an ExternalConnector that returns an ExternalClient capable of managing resources in a real system.

func (*Reconciler) Reconcile

func (r *Reconciler) Reconcile(_ context.Context, req reconcile.Request) (reconcile.Result, error)

Reconcile a managed resource with an external resource.

type ReconcilerOption

type ReconcilerOption func(*Reconciler)

A ReconcilerOption configures a Reconciler.

func WithExternalConnecter

func WithExternalConnecter(c ExternalConnecter) ReconcilerOption

WithExternalConnecter specifies how the Reconciler should connect to the API used to sync and delete external resources.

func WithFinalizer

func WithFinalizer(f resource.Finalizer) ReconcilerOption

WithFinalizer specifies how the Reconciler should add and remove finalizers to and from the managed resource.

func WithLogger

func WithLogger(l logging.Logger) ReconcilerOption

WithLogger specifies how the Reconciler should log messages.

func WithPollInterval

func WithPollInterval(after time.Duration) ReconcilerOption

WithPollInterval specifies how long the Reconciler should wait before queueing a new reconciliation after a successful reconcile. The Reconciler requeues after a specified duration when it is not actively waiting for an external operation, but wishes to check whether an existing external resource needs to be synced to its ndd Managed resource.

func WithRecorder

func WithRecorder(er event.Recorder) ReconcilerOption

WithRecorder specifies how the Reconciler should record events.

func WithTimeout

func WithTimeout(duration time.Duration) ReconcilerOption

WithTimeout specifies the timeout duration cumulatively for all the calls happen in the reconciliation function. In case the deadline exceeds, reconciler will still have some time to make the necessary calls to report the error such as status update.

func WithValidator

func WithValidator(v Validator) ReconcilerOption

type Validator

type Validator interface {
	// GetCrStatus gets the status of the cr like pending, failed, not ready and also of the device is exhausted or not
	// this is used to trigger subsequent actions in the reconciler
	GetCrStatus(ctx context.Context, mg resource.Managed, systemCfg *ygotnddp.Device) (CrObservation, error)

	// ValidateCrSpecUpdate merges the running config and the new spec and validates the result.
	// If the result was not successfull the error message is returned to provide ctx of the error
	ValidateCrSpecUpdate(ctx context.Context, mg resource.Managed, runningCfg []byte) (CrSpecObservation, error)

	// ValidateCrSpecDelete deletes the rootPaths from the running config and validates the result.
	// If the result was not successfull the error message is returned to provide ctx of the error
	ValidateCrSpecDelete(ctx context.Context, mg resource.Managed, runningCfg []byte) (CrSpecObservation, error)

	// GetCrSpecDiff checks if the current cr spec differs from the original cr spec and triggers the necessary updates
	// to align the current cr spec with original spec. The method returns gnmi deletes and updates
	GetCrSpecDiff(ctx context.Context, mg resource.Managed, systemCfg *ygotnddp.Device) (CrSpecDiffObservation, error)

	// GetCrActualDiff checks if the current cr spec differs from the running config and triggers the necessary updates
	// to align the running config with the cr spec. The method returns gnmi deletes and updates
	GetCrActualDiff(ctx context.Context, mg resource.Managed, runningCfg []byte) (CrActualDiffObservation, error)

	// GetRootPaths returns the rootPaths of the current Spec
	GetRootPaths(ctx context.Context, mg resource.Managed) ([]string, error)
}

type ValidatorFn

type ValidatorFn struct {
	GetCrStatusFn          func(ctx context.Context, mg resource.Managed, systemCfg *ygotnddp.Device) (CrObservation, error)
	ValidateCrSpecUpdateFn func(ctx context.Context, mg resource.Managed, runningCfg []byte) (CrSpecObservation, error)
	ValidateCrSpecDeleteFn func(ctx context.Context, mg resource.Managed, runningCfg []byte) (CrSpecObservation, error)
	GetCrSpecDiffFn        func(ctx context.Context, mg resource.Managed, systemCfg *ygotnddp.Device) (CrSpecDiffObservation, error)
	GetCrActualDiffFn      func(ctx context.Context, mg resource.Managed, runningCfg []byte) (CrActualDiffObservation, error)
	GetRootPathsFn         func(ctx context.Context, mg resource.Managed) ([]string, error)
}

func (ValidatorFn) GetCrActualDiff added in v0.4.6

func (e ValidatorFn) GetCrActualDiff(ctx context.Context, mg resource.Managed, runningCfg []byte) (CrActualDiffObservation, error)

func (ValidatorFn) GetCrSpecDiff added in v0.4.6

func (e ValidatorFn) GetCrSpecDiff(ctx context.Context, mg resource.Managed, systemCfg *ygotnddp.Device) (CrSpecDiffObservation, error)

func (ValidatorFn) GetCrStatus added in v0.4.6

func (e ValidatorFn) GetCrStatus(ctx context.Context, mg resource.Managed, systemCfg *ygotnddp.Device) (CrObservation, error)

func (ValidatorFn) GetRootPaths added in v0.4.6

func (e ValidatorFn) GetRootPaths(ctx context.Context, mg resource.Managed) ([]string, error)

func (ValidatorFn) ValidateCrSpecDelete added in v0.4.6

func (e ValidatorFn) ValidateCrSpecDelete(ctx context.Context, mg resource.Managed, runningCfg []byte) (CrSpecObservation, error)

func (ValidatorFn) ValidateCrSpecUpdate added in v0.4.6

func (e ValidatorFn) ValidateCrSpecUpdate(ctx context.Context, mg resource.Managed, runningCfg []byte) (CrSpecObservation, error)

Jump to

Keyboard shortcuts

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