forest

package
v0.0.0-...-9966945 Latest Latest
Warning

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

Go to latest
Published: Apr 16, 2020 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package forest defines the Forest type.

Index

Constants

This section is empty.

Variables

View Source
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 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) 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.

func (*Forest) Lock

func (f *Forest) Lock()

func (*Forest) Unlock

func (f *Forest) Unlock()

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

func (ns *Namespace) AllowsCascadingDelete() bool

AllowsCascadingDelete returns if the namespace's or any of the owner ancestors' allowCascadingDelete field is set to true.

func (*Namespace) AncestryNames

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

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

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) ClearCondition

func (ns *Namespace) ClearCondition(obj api.AffectedObject, code api.Code) bool

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

func (ns *Namespace) ClearConditionsByCode(log logr.Logger, code api.Code) bool

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

func (ns *Namespace) ClearConditionsByNamespace(log logr.Logger, nses map[string]bool) bool

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

func (ns *Namespace) ClearLocalCondition(code api.Code) bool

ClearLocalCondition clears the condition(s) on this namespace.

func (*Namespace) Conditions

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

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

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

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) Exists

func (ns *Namespace) Exists() bool

Exists returns true if the namespace exists.

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

GetSource returns the original copy in the ancestors if it exists. Otherwise, return nil.

func (*Namespace) HasCondition

func (ns *Namespace) HasCondition(obj api.AffectedObject, code api.Code) bool

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

func (ns *Namespace) HasCritCondition() bool

HasCritCondition returns if the namespace or any of its ancestors has any critical condition.

func (*Namespace) HasLocalCritCondition

func (ns *Namespace) HasLocalCritCondition() bool

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 (ns *Namespace) IsAncestor(other *Namespace) bool

func (*Namespace) Name

func (ns *Namespace) Name() string

func (*Namespace) Parent

func (ns *Namespace) Parent() *Namespace

func (*Namespace) RelativesNames

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

RelativesNames returns the children and parent.

func (*Namespace) SetCondition

func (ns *Namespace) SetCondition(obj api.AffectedObject, code api.Code, msg string) bool

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

func (ns *Namespace) SetExists() bool

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

func (*Namespace) SetHNSes

func (ns *Namespace) SetHNSes(hnsnms []string) (diff []string)

SetHNSes updates the HNSes and returns a difference between the new/old list.

func (*Namespace) SetLocalCondition

func (ns *Namespace) SetLocalCondition(code api.Code, msg string) bool

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

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

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

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) UpdateAllowCascadingDelete

func (ns *Namespace) UpdateAllowCascadingDelete(acd bool)

UpdateAllowCascadingDelete updates if this namespace allows cascading deletion.

type NumObjectsSyncer

type NumObjectsSyncer interface {
	SyncNumObjects(logr.Logger)
}

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.

Jump to

Keyboard shortcuts

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