Documentation ¶
Overview ¶
Package forest defines the Forest type.
Index ¶
- type Forest
- func (f *Forest) AddTypeSyncer(nss TypeSyncer)
- func (f *Forest) Get(nm string) *Namespace
- func (f *Forest) GetNamespaceNames() []string
- func (f *Forest) GetRoots() []*Namespace
- func (f *Forest) GetTypeSyncer(gvk schema.GroupVersionKind) TypeSyncer
- func (f *Forest) GetTypeSyncerFromGroupKind(gk schema.GroupKind) TypeSyncer
- func (f *Forest) GetTypeSyncers() []TypeSyncer
- func (f *Forest) Lock()
- func (f *Forest) Unlock()
- type Namespace
- func (ns *Namespace) AllowsCascadingDeletion() bool
- func (ns *Namespace) AncestryNames() []string
- func (ns *Namespace) CanSetParent(p *Namespace) string
- func (ns *Namespace) ChildNames() []string
- func (ns *Namespace) ClearConditions()
- func (ns *Namespace) Conditions() []api.Condition
- func (ns *Namespace) CycleNames() []string
- func (ns *Namespace) DeleteSourceObject(gvk schema.GroupVersionKind, nm string)
- func (ns *Namespace) DescendantNames() []string
- func (ns *Namespace) Exists() bool
- func (ns *Namespace) FullDescendantNames() []string
- func (ns *Namespace) GetAncestorSourceObjects(gvk schema.GroupVersionKind, name string) []*unstructured.Unstructured
- func (ns *Namespace) GetCritAncestor() string
- func (ns *Namespace) GetLabels() labels.Set
- func (ns *Namespace) GetNumSourceObjects(gvk schema.GroupVersionKind) int
- func (ns *Namespace) GetSourceObject(gvk schema.GroupVersionKind, nm string) *unstructured.Unstructured
- func (ns *Namespace) GetSourceObjects(gvk schema.GroupVersionKind) []*unstructured.Unstructured
- func (ns *Namespace) HasAnchor(n string) bool
- func (ns *Namespace) HasLocalCritCondition() bool
- func (ns *Namespace) HasSourceObject(gvk schema.GroupVersionKind, oo string) bool
- func (ns *Namespace) IsAncestor(other *Namespace) bool
- func (ns *Namespace) IsExternal() bool
- func (ns *Namespace) Name() string
- func (ns *Namespace) Parent() *Namespace
- func (ns *Namespace) RelativesNames() []string
- func (ns *Namespace) SetAnchors(anchors []string) (diff []string)
- func (ns *Namespace) SetCondition(tp, reason, msg string)
- func (ns *Namespace) SetExists() bool
- func (ns *Namespace) SetLabels(labels map[string]string) bool
- func (ns *Namespace) SetParent(p *Namespace)
- func (ns *Namespace) SetSourceObject(obj *unstructured.Unstructured)
- func (ns *Namespace) UnsetExists() bool
- func (ns *Namespace) UpdateAllowCascadingDeletion(acd bool) bool
- type TypeSyncer
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 (*Forest) AddTypeSyncer ¶
func (f *Forest) AddTypeSyncer(nss TypeSyncer)
AddTypeSyncer adds a reconciler to the types list.
func (*Forest) GetNamespaceNames ¶
GetNamespaceNames returns names of all namespaces in the cluster.
func (*Forest) GetRoots ¶
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.
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 ¶
AllowsCascadingDeletion returns true if the namespace's or any of the ancestors' allowCascadingDeletion field is set to true.
func (*Namespace) AncestryNames ¶
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 ¶
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 ¶
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 ¶
Conditions returns a full list of the conditions in the namespace.
func (*Namespace) CycleNames ¶
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 ¶
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) FullDescendantNames ¶
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 ¶
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) 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) HasLocalCritCondition ¶
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 ¶
IsAncestor is *not* cycle-safe, so should only be called from namespace trees that are known not to have cycles.
func (*Namespace) IsExternal ¶
IsExternal returns true if the namespace is not managed by HNC.
func (*Namespace) Name ¶
Name returns the name of the namespace, of "<none>" if the namespace is nil.
func (*Namespace) RelativesNames ¶
RelativesNames returns the children and parent.
func (*Namespace) SetAnchors ¶
SetAnchors updates the anchors and returns a difference between the new/old list.
func (*Namespace) SetCondition ¶
SetCondition adds a new condition to the current condition list.
func (*Namespace) SetExists ¶
SetExists marks this namespace as existing, returning true if didn't previously exist.
func (*Namespace) SetLabels ¶
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 ¶
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 ¶
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 ¶
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.