reconciler

package
v0.0.0-...-1eb86f4 Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2019 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Overview

Package reconciler reconciles resources in a graph.

Steps

The reconciliation process consists at a high level of 3 steps:

  1. Get existing resources

    Existing resources for the project in the current namespace are listed. Any previously created resources are returned.

  2. Create or Update resources

    The desired graph is walked in the order specified by the dependencies. Each resource encountered is compared to existing resources.

    - When an exact match is found, the walk continues to the next resource, with the output passed to it.

    - If an existing resource with the same type and name exists but the input values do not match, the resource is updated.

    - When no resource exists for the type-name combination, it is created.

  3. Delete resources

    Resources that were not matched in the create/update phase are cleaned up. Thus, resources are always created in the desired state, before anything gets removed.

Concurrency

When possible, changes are performed concurrently.

A and B execute concurrently.
When both have been executed (without error), C is executed.

    A --> C
    B -/

A is executed, then B & C concurrently, then D.

    A -> B -> D
      \- C -/

Retries

All operations are retried with exponential backoff. If a non-retryiable error occurs, the resource definition should wrap the returned error with backoff.PermanentError(err).

Index

Constants

This section is empty.

Variables

View Source
var DefaultConcurrency = 10

DefaultConcurrency is the default maximum concurrency to use.

In practice, the reconciler is likely bound by network i/o.

Functions

This section is empty.

Types

type Graph

type Graph interface {
	LeafResources() []*resource.Desired
	ParentResources(child string) []*resource.Desired
	DependenciesOf(child string) []*resource.Dependency
}

A Graph contains the desired graph to reconcile.

type IDGenerator

type IDGenerator interface {
	GenerateID() string
}

An IDGenerator generates unique identifiers for created resources.

type IDGeneratorFunc

type IDGeneratorFunc func() string

IDGeneratorFunc is a function type that implements the IDGenerator interface.

func (IDGeneratorFunc) GenerateID

func (fn IDGeneratorFunc) GenerateID() string

GenerateID calls the wrapped function.

type Reconciler

type Reconciler struct {
	Resources ResourceStorage
	Source    SourceStorage
	Registry  Registry
	IDGen     IDGenerator

	// Concurrency sets the maximum allowed concurrency to use.
	// If not set, DefaultConcurrency is used.
	Concurrency uint

	// Logger logs reconciliation updates. If not set, logs are discarded.
	Logger *zap.Logger

	// Backoff algorithm used for retries. If not set, exponential backoff is used.
	Backoff func() backoff.BackOff
}

A Reconciler reconciles changes to a graph.

See package doc for details.

func (*Reconciler) Reconcile

func (r *Reconciler) Reconcile(ctx context.Context, id, proj string, graph Graph) error

Reconcile reconciles changes to the graph.

type Registry

type Registry interface {
	Type(typename string) reflect.Type
}

A Registry is able to provide type information for resources.

type ResourceStorage

type ResourceStorage interface {
	PutResource(ctx context.Context, project string, resource *resource.Deployed) error
	DeleteResource(ctx context.Context, project string, resource *resource.Deployed) error
	ListResources(ctx context.Context, project string) ([]*resource.Deployed, error)
}

ResourceStorage persists resources.

type SourceStorage

type SourceStorage interface {
	Get(ctx context.Context, filename string) (io.ReadCloser, error)
}

SourceStorage provides resource source code.

Directories

Path Synopsis
internal
task
Package task provides mechanics for de-duplicating task execution.
Package task provides mechanics for de-duplicating task execution.

Jump to

Keyboard shortcuts

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