Documentation ¶
Overview ¶
Package forest defines the Forest type.
Index ¶
- Variables
- type Forest
- func (f *Forest) AddTypeSyncer(nss TypeSyncer)
- func (f *Forest) Get(nm string) *Namespace
- func (f *Forest) GetNamespaceNames() []string
- func (f *Forest) GetTypeSyncer(gvk schema.GroupVersionKind) TypeSyncer
- func (f *Forest) GetTypeSyncers() []TypeSyncer
- func (f *Forest) Lock()
- func (f *Forest) Unlock()
- type Namespace
- func (ns *Namespace) AllowsCascadingDelete() bool
- func (ns *Namespace) AncestryNames(other *Namespace) []string
- func (ns *Namespace) CanSetParent(p *Namespace) string
- func (ns *Namespace) ChildNames() []string
- func (ns *Namespace) ClearCondition(obj api.AffectedObject, code api.Code) bool
- func (ns *Namespace) ClearConditionsByCode(log logr.Logger, code api.Code) bool
- func (ns *Namespace) ClearConditionsByNamespace(log logr.Logger, nses map[string]bool) bool
- func (ns *Namespace) ClearLocalCondition(code api.Code) bool
- func (ns *Namespace) Conditions() []api.Condition
- func (ns *Namespace) DeleteOriginalObject(gvk schema.GroupVersionKind, nm string)
- func (ns *Namespace) DescendantNames() []string
- func (ns *Namespace) Exists() bool
- func (ns *Namespace) GetNumOriginalObjects(gvk schema.GroupVersionKind) int
- func (ns *Namespace) GetOriginalObject(gvk schema.GroupVersionKind, nm string) *unstructured.Unstructured
- func (ns *Namespace) GetOriginalObjects(gvk schema.GroupVersionKind) []*unstructured.Unstructured
- func (ns *Namespace) GetPropagatedObjects(gvk schema.GroupVersionKind) []*unstructured.Unstructured
- func (ns *Namespace) GetSource(gvk schema.GroupVersionKind, name string) *unstructured.Unstructured
- func (ns *Namespace) HasCondition(obj api.AffectedObject, code api.Code) bool
- func (ns *Namespace) HasCritCondition() bool
- func (ns *Namespace) HasLocalCritCondition() bool
- func (ns *Namespace) HasOriginalObject(gvk schema.GroupVersionKind, oo string) bool
- func (ns *Namespace) IsAncestor(other *Namespace) bool
- func (ns *Namespace) Name() string
- func (ns *Namespace) Parent() *Namespace
- func (ns *Namespace) RelativesNames() []string
- func (ns *Namespace) SetCondition(obj api.AffectedObject, code api.Code, msg string) bool
- func (ns *Namespace) SetExists() bool
- func (ns *Namespace) SetHNSes(hnsnms []string) (diff []string)
- func (ns *Namespace) SetLocalCondition(code api.Code, msg string) bool
- func (ns *Namespace) SetOriginalObject(obj *unstructured.Unstructured)
- func (ns *Namespace) SetParent(p *Namespace) error
- func (ns *Namespace) UnsetExists() bool
- func (ns *Namespace) UpdateAllowCascadingDelete(acd bool)
- type NumObjectsSyncer
- type TypeSyncer
Constants ¶
This section is empty.
Variables ¶
var ( // OutOfSync is used to report a precondition failure. It's not (currently) returned from this // package but is used externally. OutOfSync = errors.New("The forest is out of sync with itself") )
Functions ¶
This section is empty.
Types ¶
type Forest ¶
type Forest struct { // ObjectsStatusSyncer is the ConfigReconciler that an object reconciler can call if the status of the HNCConfiguration // object needs to be updated. ObjectsStatusSyncer NumObjectsSyncer // contains filtered or unexported fields }
Forest defines a forest of namespaces - that is, a set of trees. It includes methods to mutate the forest legally (ie, prevent 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) 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) 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 { // IsOwned indicates that this namespace is being or was created solely to live as a // subnamespace of the specified parent. IsOwned bool // HNSes store a list of HNS instances in the namespace. HNSes []string // 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) AllowsCascadingDelete ¶
AllowsCascadingDelete returns if the namespace's or any of the owner ancestors' allowCascadingDelete field is set to true.
func (*Namespace) AncestryNames ¶
AncestryNames returns a slice of strings like ["grandparent", "parent", "child"] if there is a path from `other` to the current namespace (if `other` is nil, the first element of the slice will be the root of the tree, *not* the empty string).
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) ClearCondition ¶
ClearCondition clears conditions in the namespace for a single object. If `code` is non-empty, it only clears conditions with that code, otherwise it clears all conditions for that object. It should only be called by the code that also *sets* the conditions.
It returns true if it made any changes, false otherwise.
func (*Namespace) ClearConditionsByCode ¶
ClearConditionsByCode clears all conditions of a given code from this namespace across all objects. It should only be called by the code that also *sets* the condition.
It returns true if it made any changes, false otherwise.
func (*Namespace) ClearConditionsByNamespace ¶
ClearConditionsByNamespace accepts a set of namespace names, and clears any condition that matches those names. It's only used to flush obsolete object conditions.
This is a bit ugly but I'm not sure what the better answer is.
func (*Namespace) ClearLocalCondition ¶
ClearLocalCondition clears the condition(s) on this namespace.
func (*Namespace) Conditions ¶
Conditions returns a list of conditions in the namespace in the format expected by the API.
func (*Namespace) DeleteOriginalObject ¶
func (ns *Namespace) DeleteOriginalObject(gvk schema.GroupVersionKind, nm string)
DeleteOriginalObject deletes an original object by name.
func (*Namespace) DescendantNames ¶
DescendantNames returns a slice of strings like ["child" ... "grandchildren" ...] of names of all namespaces in its subtree. Nil is returned if the namespace has no descendant.
func (*Namespace) GetNumOriginalObjects ¶
func (ns *Namespace) GetNumOriginalObjects(gvk schema.GroupVersionKind) int
GetNumOriginalObjects returns the total number of original objects of a specific GVK in the namespace.
func (*Namespace) GetOriginalObject ¶
func (ns *Namespace) GetOriginalObject(gvk schema.GroupVersionKind, nm string) *unstructured.Unstructured
GetOriginalObject gets an original object by name. It returns nil, if the object doesn't exist.
func (*Namespace) GetOriginalObjects ¶
func (ns *Namespace) GetOriginalObjects(gvk schema.GroupVersionKind) []*unstructured.Unstructured
GetOriginalObjects returns all original objects in the namespace.
func (*Namespace) GetPropagatedObjects ¶
func (ns *Namespace) GetPropagatedObjects(gvk schema.GroupVersionKind) []*unstructured.Unstructured
GetPropagatedObjects returns all original copies in the ancestors.
func (*Namespace) GetSource ¶
func (ns *Namespace) GetSource(gvk schema.GroupVersionKind, name string) *unstructured.Unstructured
GetSource returns the original copy in the ancestors if it exists. Otherwise, return nil.
func (*Namespace) HasCondition ¶
HasCondition returns true if there's a condition with the given object and code. If code is the empty string, it returns true if there's _any_ condition for the given object.
func (*Namespace) HasCritCondition ¶
HasCritCondition returns if the namespace or any of its ancestors has any critical condition.
func (*Namespace) HasLocalCritCondition ¶
HasLocalCritCondition returns if the namespace itself has any local critical conditions, ignoring its ancestors. We assume that any condition set on the namespace itself is critical, which is true for now.
func (*Namespace) HasOriginalObject ¶
func (ns *Namespace) HasOriginalObject(gvk schema.GroupVersionKind, oo string) bool
HasOriginalObject returns if the namespace has an original object.
func (*Namespace) IsAncestor ¶
func (*Namespace) RelativesNames ¶
RelativesNames returns the children and parent.
func (*Namespace) SetCondition ¶
SetCondition sets a condition for the specified object and code, returning true if it does not exist previously or if the message has changed.
Returns true if the condition wasn't previously set
func (*Namespace) SetExists ¶
SetExists marks this namespace as existing, returning true if didn't previously exist.
func (*Namespace) SetHNSes ¶
SetHNSes updates the HNSes and returns a difference between the new/old list.
func (*Namespace) SetLocalCondition ¶
SetLocalCondition sets a condition that applies to the current namespace.
func (*Namespace) SetOriginalObject ¶
func (ns *Namespace) SetOriginalObject(obj *unstructured.Unstructured)
SetOriginalObject updates or creates the original object in the namespace in the forest.
func (*Namespace) SetParent ¶
SetParent attempts to set the namespace's parent. This includes removing it from the list of children of its own parent, if necessary. It may return an error if the parent is illegal, i.e. if it causes a cycle. It cannot cause an error if the parent is being set to nil.
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) UpdateAllowCascadingDelete ¶
UpdateAllowCascadingDelete updates if this namespace allows cascading deletion.
type NumObjectsSyncer ¶
NumObjectsSyncer syncs the number of propagated and source objects. ConfigReconciler implements the interface so that it can be called by an ObjectReconciler if the number of propagated or source objects is changed.
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, api.SynchronizationMode, logr.Logger) 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.