forest

package
v0.0.0-...-44dad58 Latest Latest
Warning

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

Go to latest
Published: Dec 20, 2021 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package forest defines the Forest type.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Forest

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

Forest defines a forest of namespaces - that is, a set of trees. It includes methods to mutate the forest and track problems such as cycles.

The forest should always be locked/unlocked (via the `Lock` and `Unlock` methods) while it's being mutated to avoid different controllers from making inconsistent changes.

func NewForest

func NewForest() *Forest

func (*Forest) AddTypeSyncer

func (f *Forest) AddTypeSyncer(nss TypeSyncer)

AddTypeSyncer adds a reconciler to the types list.

func (*Forest) Get

func (f *Forest) Get(nm string) *Namespace

Get returns a `Namespace` object representing a namespace in K8s.

func (*Forest) GetNamespaceNames

func (f *Forest) GetNamespaceNames() []string

GetNamespaceNames returns names of all namespaces in the cluster.

func (*Forest) GetRoots

func (f *Forest) GetRoots() []*Namespace

GetRoots returns all the root namespaces in the cluster. Any possible cycles are omitted since we look for namespaces with no parent and cycles must always be at roots.

func (*Forest) GetTypeSyncer

func (f *Forest) GetTypeSyncer(gvk schema.GroupVersionKind) TypeSyncer

GetTypeSyncer returns the reconciler for the given GVK or nil if the reconciler does not exist.

func (*Forest) GetTypeSyncerFromGroupKind

func (f *Forest) GetTypeSyncerFromGroupKind(gk schema.GroupKind) TypeSyncer

GetTypeSyncerFromGroupKind returns the reconciler for the given GK or nil if the reconciler does not exist.

func (*Forest) GetTypeSyncers

func (f *Forest) GetTypeSyncers() []TypeSyncer

GetTypeSyncers returns the types list. Retuns a copy here so that the caller does not need to hold the mutex while accessing the returned value and can modify the returned value without fear of corrupting the original types list.

func (*Forest) Lock

func (f *Forest) Lock()

func (*Forest) Unlock

func (f *Forest) Unlock()

type Namespace

type Namespace struct {

	// IsSub indicates that this namespace is being or was created solely to live as a
	// subnamespace of the specified parent.
	IsSub bool

	// Anchors store a list of anchors in the namespace.
	Anchors []string

	// Manager stores the manager of the namespace. The default value
	// "hnc.x-k8s.io" means it's managed by HNC.
	Manager string

	// ExternalTreeLabels stores external tree labels if this namespace is an external namespace.
	// It will be empty if the namespace is not external. External namespace will at least have one
	// tree label of itself. The key is the tree label without ".tree.hnc.x-k8s.io/depth" suffix.
	// The value is the depth.
	ExternalTreeLabels map[string]int
	// contains filtered or unexported fields
}

Namespace represents a namespace in a forest. Other than its structure, it contains some properties useful to the reconcilers.

func (*Namespace) AllowsCascadingDeletion

func (ns *Namespace) AllowsCascadingDeletion() bool

AllowsCascadingDeletion returns true if the namespace's or any of the ancestors' allowCascadingDeletion field is set to true.

func (*Namespace) AncestryNames

func (ns *Namespace) AncestryNames() []string

AncestryNames returns all ancestors of this namespace. The namespace itself is the last element of the returned slice, with the root at the beginning of the list.

This method is cycle-safe, and can be used to detect and recover from cycles. If there's a cycle, the first ancestor that's a member of the cycle we encounter is repeated at the beginning of the list.

func (*Namespace) CanSetParent

func (ns *Namespace) CanSetParent(p *Namespace) string

CanSetParent returns the empty string if the assignment is currently legal, or a non-empty string indicating the reason if it cannot be done.

func (*Namespace) ChildNames

func (ns *Namespace) ChildNames() []string

ChildNames returns a sorted list of names or nil if there are no children.

func (*Namespace) ClearConditions

func (ns *Namespace) ClearConditions()

ClearConditions set conditions to nil.

func (*Namespace) Conditions

func (ns *Namespace) Conditions() []api.Condition

Conditions returns a full list of the conditions in the namespace.

func (*Namespace) CycleNames

func (ns *Namespace) CycleNames() []string

CycleNames returns nil if the namespace is not in a cycle, or a list of names in the cycle if it is. All namespaces in the cycle return the same list, which is the same as calling ns.AncestryNames() on the namespaces with the lexicographically smallest name.

func (*Namespace) DeleteSourceObject

func (ns *Namespace) DeleteSourceObject(gvk schema.GroupVersionKind, nm string)

DeleteSourceObject deletes a source object by name.

func (*Namespace) DescendantNames

func (ns *Namespace) DescendantNames() []string

DescendantNames returns a slice of strings like ["achild", "agrandchild", "bchild", ...] of names of all namespaces in its subtree, or nil if the namespace has no descendents. The names are returned in alphabetical order (as defined by `sort.Strings()`), *not* depth-first, breadth-first, etc.

This method is cycle-safe. If there are cycles, each namespace is only listed once.

func (*Namespace) Exists

func (ns *Namespace) Exists() bool

Exists returns true if the namespace exists.

func (*Namespace) FullDescendantNames

func (ns *Namespace) FullDescendantNames() []string

FullDescendantNames returns a sorted list of descendant namespaces that are full namespaces.

func (*Namespace) GetAncestorSourceObjects

func (ns *Namespace) GetAncestorSourceObjects(gvk schema.GroupVersionKind, name string) []*unstructured.Unstructured

GetAncestorSourceObjects returns all source objects with the specified name in the ancestors (including itself) from top down. If the name is not specified, all the source objects in the ancestors will be returned.

func (*Namespace) GetCritAncestor

func (ns *Namespace) GetCritAncestor() string

GetCritAncestor returns the name of the first ancestor with a critical condition, or the empty string if there are no such ancestors. It *can* return the name of the current namespace.

func (*Namespace) GetLabels

func (ns *Namespace) GetLabels() labels.Set

func (*Namespace) GetNumSourceObjects

func (ns *Namespace) GetNumSourceObjects(gvk schema.GroupVersionKind) int

GetNumSourceObjects returns the total number of source objects of a specific GVK in the namespace.

func (*Namespace) GetSourceObject

func (ns *Namespace) GetSourceObject(gvk schema.GroupVersionKind, nm string) *unstructured.Unstructured

GetSourceObject gets a source object by name. If it doesn't exist, return nil.

func (*Namespace) GetSourceObjects

func (ns *Namespace) GetSourceObjects(gvk schema.GroupVersionKind) []*unstructured.Unstructured

GetSourceObjects returns all source objects in the namespace.

func (*Namespace) HasAnchor

func (ns *Namespace) HasAnchor(n string) bool

HasAnchor returns true if the name exists in the anchor list.

func (*Namespace) HasLocalCritCondition

func (ns *Namespace) HasLocalCritCondition() bool

HasLocalCritCondition returns if the namespace itself has any local critical conditions, ignoring its ancestors. Any code with the "Crit" prefix is a critical condition.

func (*Namespace) HasSourceObject

func (ns *Namespace) HasSourceObject(gvk schema.GroupVersionKind, oo string) bool

HasSourceObject returns if the namespace has a source object.

func (*Namespace) IsAncestor

func (ns *Namespace) IsAncestor(other *Namespace) bool

IsAncestor is *not* cycle-safe, so should only be called from namespace trees that are known not to have cycles.

func (*Namespace) IsExternal

func (ns *Namespace) IsExternal() bool

IsExternal returns true if the namespace is not managed by HNC.

func (*Namespace) Name

func (ns *Namespace) Name() string

Name returns the name of the namespace, of "<none>" if the namespace is nil.

func (*Namespace) Parent

func (ns *Namespace) Parent() *Namespace

Parent returns a pointer to the parent namespace.

func (*Namespace) RelativesNames

func (ns *Namespace) RelativesNames() []string

RelativesNames returns the children and parent.

func (*Namespace) SetAnchors

func (ns *Namespace) SetAnchors(anchors []string) (diff []string)

SetAnchors updates the anchors and returns a difference between the new/old list.

func (*Namespace) SetCondition

func (ns *Namespace) SetCondition(tp, reason, msg string)

SetCondition adds a new condition to the current condition list.

func (*Namespace) SetExists

func (ns *Namespace) SetExists() bool

SetExists marks this namespace as existing, returning true if didn't previously exist.

func (*Namespace) SetLabels

func (ns *Namespace) SetLabels(labels map[string]string) bool

Deep copy the input labels so that it'll not be changed after. It returns true if the labels are updated; returns false if there's no change.

func (*Namespace) SetParent

func (ns *Namespace) SetParent(p *Namespace)

SetParent modifies the namespace's parent, including updating the list of children. It may result in a cycle being created; this can be prevented by calling CanSetParent before, or seeing if it happened by calling CycleNames afterwards.

func (*Namespace) SetSourceObject

func (ns *Namespace) SetSourceObject(obj *unstructured.Unstructured)

SetSourceObject updates or creates the source object in forest.namespace.

func (*Namespace) UnsetExists

func (ns *Namespace) UnsetExists() bool

UnsetExists marks this namespace as missing, returning true if it previously existed. It also removes it from its parent, if any, since a nonexistent namespace can't have a parent.

func (*Namespace) UpdateAllowCascadingDeletion

func (ns *Namespace) UpdateAllowCascadingDeletion(acd bool) bool

UpdateAllowCascadingDeletion updates if this namespace allows cascading deletion. It returns true if the value has changed, false otherwise.

type TypeSyncer

type TypeSyncer interface {
	// SyncNamespace syncs objects of a namespace for a specific type.
	SyncNamespace(context.Context, logr.Logger, string) error

	// Provides the GVK that is handled by the reconciler who implements the interface.
	GetGVK() schema.GroupVersionKind

	// SetMode sets the propagation mode of objects that are handled by the reconciler who implements
	// the interface.  The method also syncs objects in the cluster for the type handled by the
	// reconciler if necessary.
	SetMode(context.Context, logr.Logger, api.SynchronizationMode) error

	// GetMode gets the propagation mode of objects that are handled by the reconciler who implements the interface.
	GetMode() api.SynchronizationMode

	// GetNumPropagatedObjects returns the number of propagated objects on the apiserver.
	GetNumPropagatedObjects() int
}

TypeSyncer syncs objects of a specific type. Reconcilers implement the interface so that they can be called by the HierarchyReconciler if the hierarchy changes.

Jump to

Keyboard shortcuts

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