rnode

package
v1.30.0 Latest Latest
Warning

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

Go to latest
Published: Jun 11, 2024 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Resource does not have a .Fingerprint field. Note: this
	// means that the resource is technically not compliant with
	// API conventions but these exceptions occur throughout the
	// GCE APIs and we have to work around them.
	UpdateFuncsNoFingerprint = 1 << iota
)

Variables

This section is empty.

Functions

func CreateActions added in v1.26.0

func CreateActions[GA any, Alpha any, Beta any](
	ops GenericOps[GA, Alpha, Beta],
	node Node,
	resource api.Resource[GA, Alpha, Beta],
) ([]exec.Action, error)

func CreatePreconditions added in v1.26.0

func CreatePreconditions(want Node) (exec.EventList, error)

func DeleteActions added in v1.26.0

func DeleteActions[GA any, Alpha any, Beta any](
	ops GenericOps[GA, Alpha, Beta],
	got, want Node,
) ([]exec.Action, error)

func DeletePreconditions added in v1.26.0

func DeletePreconditions(got, want Node) exec.EventList

func GenericGet added in v1.26.0

func GenericGet[GA any, Alpha any, Beta any](
	ctx context.Context,
	gcp cloud.Cloud,
	resourceName string,
	ops GenericOps[GA, Alpha, Beta],
	typeTrait api.TypeTrait[GA, Alpha, Beta],
	b Builder,
) error

func NewGenericDeleteAction added in v1.26.0

func NewGenericDeleteAction[GA any, Alpha any, Beta any](
	want exec.EventList,
	ops GenericOps[GA, Alpha, Beta],
	got Node,
) *genericDeleteAction[GA, Alpha, Beta]

func RecreateActions added in v1.26.0

func RecreateActions[GA any, Alpha any, Beta any](
	ops GenericOps[GA, Alpha, Beta],
	got, want Node,
	resource api.Resource[GA, Alpha, Beta],
) ([]exec.Action, error)

func UpdateActions added in v1.26.0

func UpdateActions[GA any, Alpha any, Beta any](
	ops GenericOps[GA, Alpha, Beta],
	got, want Node,
	resource api.Resource[GA, Alpha, Beta],
	fingerprint string,
) ([]exec.Action, error)

Types

type Builder

type Builder interface {
	// ID uniquely identifying this resource.
	ID() *cloud.ResourceID

	// State of the node.
	State() NodeState
	// SetState of the node.
	SetState(state NodeState)

	// Ownership of this resource.
	Ownership() OwnershipStatus
	// SetOwnership of this resource.
	SetOwnership(os OwnershipStatus)

	// Resource (cloud type) for this Node.
	Resource() UntypedResource
	// SetResource to a new value.
	SetResource(UntypedResource) error

	// Version of the resource. This is used when fetching the
	// resource from the Cloud.
	Version() meta.Version

	// OutRefs parses the outgoing references of the Resource.
	OutRefs() ([]ResourceRef, error)
	// AddInRef to this node Builder.
	AddInRef(ref ResourceRef)

	// SyncFromCloud downloads the resource from the Cloud. This
	// may result in one or more blocking calls to the GCE APIs.
	SyncFromCloud(ctx context.Context, cl cloud.Cloud) error

	// Build the node, converting this to a Node in a Graph.
	Build() (Node, error)
	// contains filtered or unexported methods
}

Builder is a Node in the graph Builder.

type BuilderBase

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

BuilderBase implements the non-type specific fields.

func (*BuilderBase) AddInRef

func (b *BuilderBase) AddInRef(ref ResourceRef)

func (*BuilderBase) Defaults

func (b *BuilderBase) Defaults(id *cloud.ResourceID)

Defaults sets the default values for a empty Builder node.

func (*BuilderBase) ID

func (b *BuilderBase) ID() *cloud.ResourceID

func (*BuilderBase) Init

func (b *BuilderBase) Init(
	id *cloud.ResourceID,
	state NodeState,
	ownership OwnershipStatus,
	resource UntypedResource,
)

Init the values of the BuilderBase.

func (*BuilderBase) Ownership

func (b *BuilderBase) Ownership() OwnershipStatus

func (*BuilderBase) SetOwnership

func (b *BuilderBase) SetOwnership(os OwnershipStatus)

func (*BuilderBase) SetState

func (b *BuilderBase) SetState(state NodeState)

func (*BuilderBase) State

func (b *BuilderBase) State() NodeState

func (*BuilderBase) Version

func (b *BuilderBase) Version() meta.Version

type CreateFuncs added in v1.26.0

type CreateFuncs[GA any, Alpha any, Beta any] struct {
	GA    CreateFuncsByScope[GA]
	Alpha CreateFuncsByScope[Alpha]
	Beta  CreateFuncsByScope[Beta]
}

func (*CreateFuncs[GA, Alpha, Beta]) Do added in v1.26.0

func (f *CreateFuncs[GA, Alpha, Beta]) Do(
	ctx context.Context,
	id *cloud.ResourceID,
	r api.Resource[GA, Alpha, Beta],
) error

type CreateFuncsByScope added in v1.26.0

type CreateFuncsByScope[T any] struct {
	Global   func(context.Context, *meta.Key, *T, ...cloud.Option) error
	Regional func(context.Context, *meta.Key, *T, ...cloud.Option) error
	Zonal    func(context.Context, *meta.Key, *T, ...cloud.Option) error
}

func (*CreateFuncsByScope[T]) Do added in v1.26.0

func (s *CreateFuncsByScope[T]) Do(ctx context.Context, key *meta.Key, x *T, options ...cloud.Option) error

type DeleteFuncs added in v1.26.0

type DeleteFuncs[GA any, Alpha any, Beta any] struct {
	GA    DeleteFuncsByScope[GA]
	Alpha DeleteFuncsByScope[Alpha]
	Beta  DeleteFuncsByScope[Beta]
}

func (*DeleteFuncs[GA, Alpha, Beta]) Do added in v1.26.0

func (f *DeleteFuncs[GA, Alpha, Beta]) Do(ctx context.Context, id *cloud.ResourceID) error

type DeleteFuncsByScope added in v1.26.0

type DeleteFuncsByScope[T any] struct {
	Global   func(context.Context, *meta.Key, ...cloud.Option) error
	Regional func(context.Context, *meta.Key, ...cloud.Option) error
	Zonal    func(context.Context, *meta.Key, ...cloud.Option) error
}

func (*DeleteFuncsByScope[T]) Do added in v1.26.0

func (s *DeleteFuncsByScope[T]) Do(ctx context.Context, id *cloud.ResourceID, options ...cloud.Option) error

type GenericOps added in v1.26.0

type GenericOps[GA any, Alpha any, Beta any] interface {
	GetFuncs(gcp cloud.Cloud) *GetFuncs[GA, Alpha, Beta]
	CreateFuncs(gcp cloud.Cloud) *CreateFuncs[GA, Alpha, Beta]
	UpdateFuncs(gcp cloud.Cloud) *UpdateFuncs[GA, Alpha, Beta]
	DeleteFuncs(gcp cloud.Cloud) *DeleteFuncs[GA, Alpha, Beta]
}

GenericOps are a typed dispatch for (API version, scope) for CRUD verbs. Set the field to nil if the operation is not supported.

type GetFuncs added in v1.26.0

type GetFuncs[GA any, Alpha any, Beta any] struct {
	GA    GetFuncsByScope[GA]
	Alpha GetFuncsByScope[Alpha]
	Beta  GetFuncsByScope[Beta]
}

func (*GetFuncs[GA, Alpha, Beta]) Do added in v1.26.0

func (f *GetFuncs[GA, Alpha, Beta]) Do(
	ctx context.Context,
	ver meta.Version,
	id *cloud.ResourceID,
	tt api.TypeTrait[GA, Alpha, Beta],
) (api.Resource[GA, Alpha, Beta], error)

type GetFuncsByScope added in v1.26.0

type GetFuncsByScope[T any] struct {
	Global   func(context.Context, *meta.Key, ...cloud.Option) (*T, error)
	Regional func(context.Context, *meta.Key, ...cloud.Option) (*T, error)
	Zonal    func(context.Context, *meta.Key, ...cloud.Option) (*T, error)
}

GetFuncsByScope dispatches the operation by the appropriate scope. Set the field to nil if the scope is not supported.

func (*GetFuncsByScope[T]) Do added in v1.26.0

func (s *GetFuncsByScope[T]) Do(ctx context.Context, key *meta.Key, options ...cloud.Option) (*T, error)

Do the operation.

type Node

type Node interface {
	// ID uniquely identifying this resource.
	ID() *cloud.ResourceID
	// State of the node.
	State() NodeState
	// Ownership of this resource.
	Ownership() OwnershipStatus
	// OutRefs of this resource pointing to other resources.
	OutRefs() []ResourceRef
	// InRefs pointing to this resource.
	InRefs() []ResourceRef
	// Resource is the cloud resource (e.g. the Resource[compute.Address,...]).
	Resource() UntypedResource
	// Builder returns a node builder that has the same attributes and
	// underlying type but has no contents in the resource. This is used to
	// populate a graph for getting the current state from Cloud (i.e. the "got"
	// graph).
	Builder() Builder
	// Diff this node (want) with the state of the Node (got). This computes
	// whether the Sync operation will be an update or recreation.
	Diff(got Node) (*PlanDetails, error)
	// Plan returns the plan for updating this Node.
	Plan() *Plan
	// Actions needed to perform the plan. This will be empty for graphs that
	// have not been planned. "got" is the current state of the Node in the
	// "got" graph.
	Actions(got Node) ([]exec.Action, error)
}

Node in the resource graph.

type NodeBase

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

NodeBase are common non-typed fields for implementing a Node in the graph.

func (*NodeBase) ID

func (n *NodeBase) ID() *cloud.ResourceID

func (*NodeBase) InRefs

func (n *NodeBase) InRefs() []ResourceRef

func (*NodeBase) InitFromBuilder

func (n *NodeBase) InitFromBuilder(b Builder) error

InitFromBuilder is an rgraph library internal method for common initialization from a Builder.

func (*NodeBase) OutRefs

func (n *NodeBase) OutRefs() []ResourceRef

func (*NodeBase) Ownership

func (n *NodeBase) Ownership() OwnershipStatus

func (*NodeBase) Plan

func (n *NodeBase) Plan() *Plan

func (*NodeBase) State

func (n *NodeBase) State() NodeState

type NodeState

type NodeState string

NodeState is the state of the node in the Graph.

const (
	// NodeUnknown is the initial state of the Node.
	NodeUnknown NodeState = "Unknown"
	// NodeExists means the resource exists in the graph.
	NodeExists NodeState = "Exists"
	// NodeDoesNotExist is a tombstone for a Node. It means that
	// the given Node should not exist in the Graph.
	NodeDoesNotExist NodeState = "DoesNotExist"
	// NodeStateError means that the resource could not be fetched
	// from the Cloud.
	NodeStateError NodeState = "Error"
)

type Operation

type Operation string

Operation to perform on the Node.

var (
	// OpUnknown means no planning has been done.
	OpUnknown Operation = "Unknown"
	// OpNothing means nothing will happen.
	OpNothing Operation = "Nothing"
	// OpCreate will create the resource.
	OpCreate Operation = "Create"
	// OpRecreate will update the resource by first deleting, then creating the
	// resource. This is necessary as some resources cannot be updated directly
	// in place.
	OpRecreate Operation = "Recreate"
	// OpUpdate will call one or more updates ethods. The specific RPCs called
	// to do the update will be specific to the resource type itself.
	OpUpdate Operation = "Update"
	// OpDelete will delete the resource.
	OpDelete Operation = "Delete"
)

type OwnershipStatus

type OwnershipStatus string

OwnershipStatus of the node in the graph.

var (
	// OwnershipUnknown is the initial state of a Node.
	OwnershipUnknown OwnershipStatus = "Unknown"
	// OwnershipManaged means the Node's lifecycle and values are
	// to be planned and sync'd.
	OwnershipManaged OwnershipStatus = "Managed"
	// OwnershipExternal means the Node's lifecycle is not managed
	// by planning. The resource will not be mutated in any way
	// and is present in the graph for read-only purposes.
	OwnershipExternal OwnershipStatus = "External"
)

type Plan

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

Plan for what will be done to the Node.

func (*Plan) Details

func (p *Plan) Details() *PlanDetails

Details returns details on the current plan.

func (*Plan) Explain added in v1.26.0

func (p *Plan) Explain() string

Explain returns a human-readable string that is suitable for analysis. It will be rather verbose.

func (*Plan) GraphvizString

func (p *Plan) GraphvizString() string

GraphvizString returns a Graphviz-formatted summary of the plan.

func (*Plan) Op

func (p *Plan) Op() Operation

Op to perform.

func (*Plan) Set

func (p *Plan) Set(a PlanDetails)

Set the plan to the specified action.

func (*Plan) String

func (p *Plan) String() string

type PlanDetails

type PlanDetails struct {
	// Operation associated with this explanation.
	Operation Operation
	// Why is a human readable string describing why this operation was
	// selected.
	Why string
	// Diff is an optional description of the diff between the current and
	// wanted resources.
	Diff *api.DiffResult
}

PlanDetails is a human-readable reasons describing the Sync operation that has been planned.

type ResourceRef

type ResourceRef struct {
	// From is the object containing the reference.
	From *cloud.ResourceID
	// Path to the field with the value in From.
	Path api.Path
	// To is the resource that is referenced.
	To *cloud.ResourceID
}

ResourceRef identifies a reference from the resource From in the field Path to the resource To.

type UntypedResource

type UntypedResource interface {
	ResourceID() *cloud.ResourceID
	Version() meta.Version
}

UntypedResource is the type-erased version of Resource.

type UpdateFuncs added in v1.26.0

type UpdateFuncs[GA any, Alpha any, Beta any] struct {
	GA    UpdateFuncsByScope[GA]
	Alpha UpdateFuncsByScope[Alpha]
	Beta  UpdateFuncsByScope[Beta]

	Options int
}

func (*UpdateFuncs[GA, Alpha, Beta]) Do added in v1.26.0

func (f *UpdateFuncs[GA, Alpha, Beta]) Do(
	ctx context.Context,
	fingerprint string,
	id *cloud.ResourceID,
	desired api.Resource[GA, Alpha, Beta],
) error

type UpdateFuncsByScope added in v1.26.0

type UpdateFuncsByScope[T any] struct {
	Global   func(context.Context, *meta.Key, *T, ...cloud.Option) error
	Regional func(context.Context, *meta.Key, *T, ...cloud.Option) error
	Zonal    func(context.Context, *meta.Key, *T, ...cloud.Option) error
}

func (*UpdateFuncsByScope[T]) Do added in v1.26.0

func (s *UpdateFuncsByScope[T]) Do(ctx context.Context, key *meta.Key, x *T, options ...cloud.Option) error

Jump to

Keyboard shortcuts

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