watch_graph

package
v18.3.0 Latest Latest
Warning

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

Go to latest
Published: Aug 20, 2025 License: MIT Imports: 49 Imported by: 0

Documentation

Index

Constants

View Source
const (
	InfSyncFailedWarnType          = "INFORMER_SYNC_FAILED"
	DiscoFailedWarnType            = "DISCOVERY_FAILED"
	NamespaceListFailedWarnType    = "NAMESPACE_LIST_FAILED"
	ObjectProcessingFailedWarnType = "OBJECT_PROCESSING_FAILED"
	InternalErrorWarnType          = "INTERNAL_ERROR"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type ArcAttrs added in v18.2.0

type ArcAttrs struct {
	Controller              bool `json:"c,omitempty"`
	BlockOwnerDeletion      bool `json:"b,omitempty"`
	DestinationDoesNotExist bool `json:"e,omitempty"`
}

func (ArcAttrs) IsZero added in v18.2.0

func (a ArcAttrs) IsZero() bool

type ArcSet added in v18.2.0

type ArcSet[VID, AT comparable] map[ArcToID[VID, AT]]struct{}

ArcSet is a set of arcs.

type ArcSetWithData added in v18.2.0

type ArcSetWithData[VID, AT comparable, AD any] map[ArcToID[VID, AT]]AD

ArcSetWithData is a set of arcs with data.

type ArcToID

type ArcToID[VID, AT comparable] struct {
	To      VID
	ArcType AT
}

type ArcType

type ArcType byte // enough bits to represent each arc type as an individual bit.
const (
	UnknownArcType        ArcType = 0 // must be zero
	OwnerReferenceArcType ArcType = 1 << (iota - 1)
	ReferenceArcType
	TransitiveReferenceArcType
)

func ParseArcTypeStr added in v18.3.0

func ParseArcTypeStr(at string) ArcType

func (ArcType) String

func (at ArcType) String() string

type ArcTypeSet added in v18.3.0

type ArcTypeSet ArcType

ArcTypeSet is a set of arc types.

func (*ArcTypeSet) Add added in v18.3.0

func (s *ArcTypeSet) Add(v ArcType)

func (*ArcTypeSet) Contains added in v18.3.0

func (s *ArcTypeSet) Contains(v ArcType) bool

func (*ArcTypeSet) IsEmpty added in v18.3.0

func (s *ArcTypeSet) IsEmpty() bool

func (*ArcTypeSet) Remove added in v18.3.0

func (s *ArcTypeSet) Remove(v ArcType)

type Error

type Error struct {
	Message string
	Code    ErrorCode
}

func (*Error) String added in v18.2.0

func (e *Error) String() string

type ErrorCode

type ErrorCode byte
const (
	InvalidArgument ErrorCode
	Unavailable
	InternalError
)

func (ErrorCode) String added in v18.2.0

func (c ErrorCode) String() string

type GraphInspector added in v18.2.0

type GraphInspector[VID, AT comparable, VD, AD any] interface {
	InboundArcsFor(VID) ArcSet[VID, AT]
	OutboundArcsFor(VID) ArcSetWithData[VID, AT, AD]
	VertexData(VID) (VD, bool)
}

type Namespaces

type Namespaces struct {
	Names                    sets.Set[string]
	LabelSelector            string
	FieldSelector            string
	ObjectSelectorExpression cel.Program // can be nil
}

func (*Namespaces) All

func (n *Namespaces) All() bool

All checks if all namespaces should be watched.

type ObjectGraph

type ObjectGraph[VID, AT comparable, VD, AD any] struct {
	// contains filtered or unexported fields
}

func NewObjectGraph

func NewObjectGraph[VID, AT comparable, VD, AD any](opts ObjectGraphOpts[VID, AT, VD, AD]) *ObjectGraph[VID, AT, VD, AD]

func (*ObjectGraph[VID, AT, VD, AD]) DeleteVertex

func (g *ObjectGraph[VID, AT, VD, AD]) DeleteVertex(ctx context.Context, vid VID) bool

DeleteVertex deletes the vertex with the specified VID. All outbound arcs are also deleted.

func (*ObjectGraph[VID, AT, VD, AD]) InboundArcsFor added in v18.2.0

func (g *ObjectGraph[VID, AT, VD, AD]) InboundArcsFor(vid VID) ArcSet[VID, AT]

InboundArcsFor returns the set of arcs that have vid as their destination.

func (*ObjectGraph[VID, AT, VD, AD]) OutboundArcsFor added in v18.2.0

func (g *ObjectGraph[VID, AT, VD, AD]) OutboundArcsFor(vid VID) ArcSetWithData[VID, AT, AD]

func (*ObjectGraph[VID, AT, VD, AD]) SetVertex

func (g *ObjectGraph[VID, AT, VD, AD]) SetVertex(ctx context.Context, vid VID, vd VD, arcs ArcSetWithData[VID, AT, AD]) SetVertexResult

SetVertex sets a vertex in the graph declaratively: - replaces the existing vertex or adds a new one with the specified VID. - replaces all outbound arcs of that vertex with the provided arcs. arcs may be nil. NOTE: this function takes ownership of the arcs object. Do not use it after passing to this function.

func (*ObjectGraph[VID, AT, VD, AD]) VertexData added in v18.2.0

func (g *ObjectGraph[VID, AT, VD, AD]) VertexData(vid VID) (VD, bool)

type ObjectGraphObserver added in v18.2.0

type ObjectGraphObserver[VID, AT comparable, VD, AD any] interface {
	OnSetVertex(context.Context, GraphInspector[VID, AT, VD, AD], VID, VD)
	OnDeleteVertex(context.Context, GraphInspector[VID, AT, VD, AD], VID)
	OnSetArc(ctx context.Context, insp GraphInspector[VID, AT, VD, AD], from VID, to ArcToID[VID, AT], data AD)
	OnDeleteArc(ctx context.Context, insp GraphInspector[VID, AT, VD, AD], from VID, to ArcToID[VID, AT])
}

type ObjectGraphOpts

type ObjectGraphOpts[VID, AT comparable, VD, AD any] struct {
	IsVertexDataEqual func(a, b VD) bool
	IsArcDataEqual    func(a, b AD) bool
	Observer          ObjectGraphObserver[VID, AT, VD, AD]
}

type Opts

type Opts struct {
	Log              *slog.Logger
	Queries          []any // Elements are QueryInclude or QueryExclude
	Namespaces       Namespaces
	DiscoClient      discovery.AggregatedDiscoveryInterface
	Client           dynamic.Interface
	OnWarning        func(Warning)
	ObjectToEvalVars func(*unstructured.Unstructured, schema.GroupVersionResource) map[string]any
	Graph            *ObjectGraph[VertexID, ArcType, VertexData, ArcAttrs]
}

type QueryExclude

type QueryExclude struct {
	ResourceSelectorExpression cel.Program // never nil
}

type QueryInclude

type QueryInclude struct {
	ResourceSelectorExpression cel.Program // never nil

	Object QueryIncludeObject
}

type QueryIncludeObject

type QueryIncludeObject struct {
	LabelSelector            string
	FieldSelector            string
	ObjectSelectorExpression cel.Program        // can be nil
	JSONPath                 *jsonpath.JSONPath // can be nil
}

QueryIncludeObject holds config for object filtering.

type SetVertexResult added in v18.2.0

type SetVertexResult byte
const (
	// VertexNoop - no action was taken. Vertex exists and the data is the same.
	VertexNoop SetVertexResult = iota
	// VertexAdded - a new vertex was added.
	VertexAdded
	// VertexUpdated - vertex exists but data was updated.
	VertexUpdated
)

type VertexData

type VertexData struct {
	Object   map[string]any
	JSONPath *jsonpath.JSONPath // nil if no JSON Path processing is necessary
}

type VertexID

type VertexID struct {
	GVR       unique.Handle[schema.GroupVersionResource]
	Namespace string
	Name      string
}

type Warning

type Warning struct {
	Type       string
	Message    string
	Attributes WarningAttrs
}

func NewNamespaceListFailedWarning added in v18.2.0

func NewNamespaceListFailedWarning(namespace string, err error) Warning

func NewObjectProcessingWarning

func NewObjectProcessingWarning(gvr schema.GroupVersionResource, namespace, name, message string) Warning

type WarningAttrs added in v18.2.0

type WarningAttrs struct {
	Group     string `json:"g,omitempty"`
	Version   string `json:"v,omitempty"`
	Resource  string `json:"r,omitempty"`
	Namespace string `json:"ns,omitempty"`
	Name      string `json:"n,omitempty"`
}

WarningAttrs holds attributes for all warning types. All fields must be marked omitempty because different warnings have different fields set.

func (WarningAttrs) IsZero added in v18.2.0

func (a WarningAttrs) IsZero() bool

type WatchGraph

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

func New

func New(opts Opts) *WatchGraph

func (*WatchGraph) Run

func (g *WatchGraph) Run(ctx context.Context) *Error

Jump to

Keyboard shortcuts

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