graph

package
v0.7.0-beta.13 Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2023 License: AGPL-3.0 Imports: 8 Imported by: 1

Documentation

Overview

Package graph tries to model the controller reconciliation loop in a more structured way. It structures the reconciliation loop to 3 stage: Init, Build and Execute.

Initialization Stage

the Init stage is for meta loading, object query etc. Try loading infos that used in the following stages.

Building Stage

## Validation

The first part of Building is Validation, which Validates everything (object spec is legal, resources in K8s cluster are enough etc.) to make sure the following Build and Execute parts can go well.

## Building The Building part's target is to generate an execution plan. The plan is composed by a DAG which represents the actions that should be taken on all K8s native objects owned by the controller, a group of Transformers which transform the initial DAG to the final one, and a WalkFunc which does the real action when the final DAG is walked through.

Execution Stage

The plan is executed in this stage, all the object manipulations(create/update/delete) are committed.

Index

Constants

This section is empty.

Variables

View Source
var ErrPrematureStop = errors.New("Premature-Stop")

ErrPrematureStop is used to stop the Transformer chain for some purpose. Use it in Transformer.Transform when all jobs have done and no need to run following transformers

Functions

This section is empty.

Types

type DAG

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

func NewDAG

func NewDAG() *DAG

NewDAG news an empty DAG

func (*DAG) AddConnect

func (d *DAG) AddConnect(from, to Vertex) bool

AddConnect add 'to' to the DAG 'd' and connect 'from' to 'to'

func (*DAG) AddConnectRoot

func (d *DAG) AddConnectRoot(v Vertex) bool

AddConnectRoot add 'v' to the DAG 'd' and connect root to 'v'

func (*DAG) AddEdge

func (d *DAG) AddEdge(e Edge) bool

AddEdge puts edge 'e' into 'd'

func (*DAG) AddVertex

func (d *DAG) AddVertex(v Vertex) bool

AddVertex puts 'v' into 'd'

func (*DAG) Connect

func (d *DAG) Connect(from, to Vertex) bool

Connect vertex 'from' to 'to' by a new edge if not exist

func (*DAG) Equals

func (d *DAG) Equals(other *DAG, less func(v1, v2 Vertex) bool) bool

Equals tells whether two DAGs are equal `less` tells whether vertex 'v1' is less than vertex 'v2'. `less` should return false if 'v1' equals to 'v2'.

func (*DAG) Merge

func (d *DAG) Merge(subDag *DAG)

func (*DAG) RemoveEdge

func (d *DAG) RemoveEdge(e Edge) bool

RemoveEdge deletes edge 'e'

func (*DAG) RemoveVertex

func (d *DAG) RemoveVertex(v Vertex) bool

RemoveVertex deletes 'v' from 'd' the in&out edges are also deleted

func (*DAG) Root

func (d *DAG) Root() Vertex

Root returns root vertex that has no in adjacent. our DAG should have one and only one root vertex

func (*DAG) String

func (d *DAG) String() string

String returns a string representation of the DAG in topology order

func (*DAG) Vertices

func (d *DAG) Vertices() []Vertex

Vertices returns all vertices in 'd'

func (*DAG) WalkBFS

func (d *DAG) WalkBFS(walkFunc WalkFunc) error

WalkBFS walks the DAG 'd' in breadth-first order

func (*DAG) WalkReverseTopoOrder

func (d *DAG) WalkReverseTopoOrder(walkFunc WalkFunc, less func(v1, v2 Vertex) bool) error

WalkReverseTopoOrder walks the DAG 'd' in reverse topology order

func (*DAG) WalkTopoOrder

func (d *DAG) WalkTopoOrder(walkFunc WalkFunc, less func(v1, v2 Vertex) bool) error

WalkTopoOrder walks the DAG 'd' in topology order

type Edge

type Edge interface {
	From() Vertex
	To() Vertex
}

func RealEdge

func RealEdge(from, to Vertex) Edge

type Plan

type Plan interface {
	// Execute the plan
	Execute() error
}

Plan defines the final actions should be executed.

type PlanBuilder

type PlanBuilder interface {
	// Init loads the primary object to be reconciled, and does meta initialization
	Init() error

	// AddTransformer adds transformers to the builder in sequence order.
	// And the transformers will be executed in the add order.
	AddTransformer(transformer ...Transformer) PlanBuilder

	// AddParallelTransformer adds transformers to the builder.
	// And the transformers will be executed in parallel.
	AddParallelTransformer(transformer ...Transformer) PlanBuilder

	// Build runs all the transformers added by AddTransformer and/or AddParallelTransformer.
	Build() (Plan, error)
}

PlanBuilder builds a Plan by applying a group of Transformer to an empty DAG.

type TransformContext

type TransformContext interface {
	GetContext() context.Context
	GetClient() client.ReadonlyClient
	GetRecorder() record.EventRecorder
	GetLogger() logr.Logger
}

TransformContext is used by Transformer.Transform

type Transformer

type Transformer interface {
	Transform(ctx TransformContext, dag *DAG) error
}

Transformer transforms a DAG to a new version

type TransformerChain

type TransformerChain []Transformer

TransformerChain chains a group Transformer together

func (TransformerChain) ApplyTo

func (r TransformerChain) ApplyTo(ctx TransformContext, dag *DAG) error

ApplyTo applies TransformerChain t to dag

type Vertex

type Vertex interface{}

type WalkFunc

type WalkFunc func(v Vertex) error

WalkFunc defines the action should be taken when we walk through the DAG. the func is vertex basis

Jump to

Keyboard shortcuts

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