Documentation ¶
Overview ¶
Package ast declares the types used for loading Kubernetes resources from the filesystem into something like an Abstract Syntax Tree (AST) that allows for writing reusable visitors. The visitor package defines some base visitors to use for iterating over the tree and performing transforms.
Each node in the AST implements the "Node" interface which has only one method, "Accept". For a visitor to visit a node, it should pass itself to the node's Accept method, and then the node will call the appropriate "Visit[Type]" method on the visitor. Iteration is started by having the root of the tree Accept() the visitor.
Note that this isn't quite exactly a "true" AST as the subtypes are all fully typed, and it is feasible to iterate over the entire contents in a fully typed manner. The visitor itself is here for convenience to make processing and transforming the tree relatively concise.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var CompareFileObject = cmp.AllowUnexported(FileObject{})
CompareFileObject is a cmp.Option which allows tests to compare FileObjects.
Functions ¶
This section is empty.
Types ¶
type FileObject ¶
type FileObject struct { // The unstructured representation of the object. *unstructured.Unstructured // Relative is the path of this object in the repo prefixed by the Nomos Root. cmpath.Relative }
FileObject extends client.Object to include the path to the file in the repo.
func NewFileObject ¶
func NewFileObject(object *unstructured.Unstructured, source cmpath.Relative) FileObject
NewFileObject returns an ast.FileObject with the specified underlying client.Object and the designated source file. TODO: This function should accept an unstructured.Unstructured if possible. Also we should see if we can make FileObject *not* implement client.Object and instead make callers explicitly interact with one format or the other.
func (*FileObject) DeepCopy ¶
func (o *FileObject) DeepCopy() FileObject
DeepCopy returns a deep copy of the FileObject.
func (*FileObject) Structured ¶
func (o *FileObject) Structured() (runtime.Object, status.Error)
Structured returns the structured representation of the object. This can be cast to a golang struct (eg v1.CustomResourceDefinition) for validation and hydration logic. Note that the structured object should only be read. No mutations to the structured object (eg in hydration) will be persisted. Unmarshalling and re-marshalling an object can result in spurious JSON fields depending on what directives are specified for those fields. To be safe, we keep all resources in their raw unstructured format. If hydration or validation code requires the structured format, we can convert it here separate from the raw unstructured representation.
type Root ¶
type Root struct { // ClusterObjects represents resources that are cluster scoped. ClusterObjects []FileObject // ClusterRegistryObjects represents resources that are related to multi-cluster. ClusterRegistryObjects []FileObject // SystemObjects represents resources regarding nomos configuration. SystemObjects []FileObject // Tree represents the directory hierarchy containing namespace scoped resources. Tree *TreeNode }
Root represents a hierarchy of declared configs, settings for how those configs will be interpreted, and information regarding where those configs came from.
type TreeNode ¶
type TreeNode struct { // Path is the path this node has relative to a nomos Root. cmpath.Relative // The type of the HierarchyNode Type node.Type // Objects from the directory Objects []FileObject // children of the directory Children []*TreeNode }
TreeNode is analogous to a directory in the config hierarchy.
func (*TreeNode) Flatten ¶
func (n *TreeNode) Flatten() []FileObject
Flatten returns the list of materialized FileObjects contained in this TreeNode. Specifically, it returns either 1) the list of Objects if this is a Namespace node, or 2) the concatenated list of all objects returned by calling Flatten on all of its children.
func (*TreeNode) PartialCopy ¶
PartialCopy makes an almost shallow copy of n. An "almost shallow" copy of TreeNode make shallow copies of Children and members that are likely immutable. A deep copy is made of mutable members like Labels and Annotations.