document

package
v0.0.0-...-b8e83fa Latest Latest
Warning

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

Go to latest
Published: Jun 17, 2022 License: Apache-2.0 Imports: 20 Imported by: 1

Documentation

Index

Constants

View Source
const (
	BaseAirshipSelector       = "airshipit.org"
	EphemeralHostSelector     = BaseAirshipSelector + "/ephemeral-node in (True, true)"
	EphemeralUserDataSelector = BaseAirshipSelector + "/ephemeral-user-data in (True, true)"

	// Please note that by default every document in the manifest is to be deployed to kubernetes cluster.
	// so this selector simply checks that deploy-k8s label is not equal to false or False (string)
	DeployToK8sSelector = "airshipit.org/deploy-k8s notin (False, false)"
)

Label Selectors

View Source
const (
	SecretKind        = "Secret"
	BareMetalHostKind = "BareMetalHost"

	ConfigMapKind    = "ConfigMap"
	ConfigMapVersion = "v1"

	ClusterctlMetadataKind    = "Metadata"
	ClusterctlMetadataVersion = "v1alpha3"
	ClusterctlMetadataGroup   = "clusterctl.cluster.x-k8s.io"

	// ValidatorGroup defines Group for document-validation container
	ValidatorGroup = "airshipit.org"
	// ValidatorVersion defines Version for document-validation container
	ValidatorVersion = "v1alpha1"
	// ValidatorKind defines Kind for document-validation container
	ValidatorKind = "GenericContainer"
	// ValidatorName defines Name for document-validation container
	ValidatorName = "document-validation"

	// CRDKind is a kind for custom resource definition documents
	CRDKind = "CustomResourceDefinition"

	// ClusterctlContainerGroup defines Group for clustertctl container
	ClusterctlContainerGroup = "airshipit.org"
	// ClusterctlContainerVersion defines Version for clustertctl container
	ClusterctlContainerVersion = "v1alpha1"
	// ClusterctlContainerKind defines Kind for clustertctl container
	ClusterctlContainerKind = "GenericContainer"
	// ClusterctlContainerName defines Name for clustertctl container
	ClusterctlContainerName = "clusterctl"

	// ApplierContainerGroup defines Group for applier container
	ApplierContainerGroup = "airshipit.org"
	// ApplierContainerVersion defines Version for applier container
	ApplierContainerVersion = "v1alpha1"
	// ApplierContainerKind defines Kind for applier container
	ApplierContainerKind = "GenericContainer"
	// ApplierContainerName defines Name for applier container
	ApplierContainerName = "applier"
)

GVKs

View Source
const KustomizationFile = "kustomization.yaml"

KustomizationFile is used for kustomization file

Variables

This section is empty.

Functions

func GetBMHBMCAddress

func GetBMHBMCAddress(bmh Document) (string, error)

GetBMHBMCAddress returns the bmc address for a particular the document supplied

func GetBMHBMCCredentials

func GetBMHBMCCredentials(bmh Document, bundle Bundle) (username string, password string, err error)

GetBMHBMCCredentials returns the BMC credentials for the bmh document supplied from the supplied bundle

func GetBMHNetworkData

func GetBMHNetworkData(bmh Document, bundle Bundle) (string, error)

GetBMHNetworkData retrieves the associated network data string for the bmh document supplied from the bundle supplied

func GetSecretDataKey

func GetSecretDataKey(cfg Document, key string) (string, error)

GetSecretDataKey understands how to retrieve a specific top level key from a secret that may have the data stored under a data or stringData field in which case the key may be base64 encoded or it may be plain text

it is meant to be used by other high level dochelpers

func MakeResMap

func MakeResMap(fs fs.FileSystem, kfile string) (map[string][]string, error)

MakeResMap creates resmap based of kustomize types

Types

type Bundle

type Bundle interface {
	Write(out io.Writer) error
	SetFileSystem(fs.FileSystem) error
	GetFileSystem() fs.FileSystem
	Select(selector Selector) ([]Document, error)
	SelectOne(selector Selector) (Document, error)
	SelectBundle(selector Selector) (Bundle, error)
	SelectByFieldValue(string, func(interface{}) bool) (Bundle, error)
	GetByGvk(string, string, string) ([]Document, error)
	GetByName(string) (Document, error)
	GetByAnnotation(annotationSelector string) ([]Document, error)
	GetByLabel(labelSelector string) ([]Document, error)
	GetAllDocuments() ([]Document, error)
	Append(Document) error
}

Bundle interface provides the specification for a bundle implementation

func NewBundle

func NewBundle(fSys fs.FileSystem, kustomizePath string) (Bundle, error)

NewBundle is a convenience function to create a new bundle Over time, it will evolve to support allowing more control for kustomize plugins

func NewBundleByPath

func NewBundleByPath(rootPath string) (Bundle, error)

NewBundleByPath is a function which builds new document.Bundle from kustomize rootPath using default FS object example: document.NewBundleByPath("path/to/phase-root")

func NewBundleFromBytes

func NewBundleFromBytes(data []byte) (Bundle, error)

NewBundleFromBytes is a function which builds new document.Bundle from raw []bytes

type BundleFactory

type BundleFactory struct {
	KustomizeBuildOptions
	resmap.ResMap
	fs.FileSystem
}

BundleFactory contains the objects within a bundle

func (*BundleFactory) Append

func (b *BundleFactory) Append(doc Document) error

Append bundle with the document, this only works with document interface implementation that is provided by this package

func (*BundleFactory) GetAllDocuments

func (b *BundleFactory) GetAllDocuments() ([]Document, error)

GetAllDocuments returns all documents in this bundle

func (*BundleFactory) GetByAnnotation

func (b *BundleFactory) GetByAnnotation(annotationSelector string) ([]Document, error)

GetByAnnotation is a convenience method to get documents for a particular annotation

func (*BundleFactory) GetByGvk

func (b *BundleFactory) GetByGvk(group, version, kind string) ([]Document, error)

GetByGvk is a convenience method to get documents for a particular Gvk tuple

func (*BundleFactory) GetByLabel

func (b *BundleFactory) GetByLabel(labelSelector string) ([]Document, error)

GetByLabel is a convenience method to get documents for a particular label

func (*BundleFactory) GetByName

func (b *BundleFactory) GetByName(name string) (Document, error)

GetByName finds a document by name

func (*BundleFactory) GetFileSystem

func (b *BundleFactory) GetFileSystem() fs.FileSystem

GetFileSystem gets the filesystem that will be used by this bundle

func (*BundleFactory) GetKustomizeBuildOptions

func (b *BundleFactory) GetKustomizeBuildOptions() KustomizeBuildOptions

GetKustomizeBuildOptions returns the build options object used to generate the resource map for this bundle

func (*BundleFactory) GetKustomizeResourceMap

func (b *BundleFactory) GetKustomizeResourceMap() resmap.ResMap

GetKustomizeResourceMap returns a Kustomize Resource Map for this bundle

func (*BundleFactory) Select

func (b *BundleFactory) Select(selector Selector) ([]Document, error)

Select offers an interface to pass a Selector, built on top of kustomize Selector to the bundle returning Documents that match the criteria

func (*BundleFactory) SelectBundle

func (b *BundleFactory) SelectBundle(selector Selector) (Bundle, error)

SelectBundle offers an interface to pass a Selector, built on top of kustomize Selector to the bundle returning a new Bundle that matches the criteria. This is useful where you want to actually prune the underlying bundle you are working with rather then getting back the matching documents for scenarios like test cases where you want to pass in custom "filtered" bundles specific to the test case

func (*BundleFactory) SelectByFieldValue

func (b *BundleFactory) SelectByFieldValue(path string, condition func(interface{}) bool) (Bundle, error)

SelectByFieldValue returns new Bundle with filtered resource documents. Method iterates over all resources in the bundle. If resource has field (i.e. key) specified in JSON path, and the comparison function returns 'true' for value referenced by JSON path, then resource is added to resulting bundle. Example: The bundle contains 3 documents

---
apiVersion: v1
kind: DocKind1
metadata:
  name: doc1
spec:
  somekey:
    somefield: "someValue"
---
apiVersion: v1
kind: DocKind2
metadata:
  name: doc2
spec:
  somekey:
    somefield: "someValue"
---
apiVersion: v1
kind: DocKind1
metadata:
  name: doc3
spec:
  somekey:
    somefield: "someOtherValue"

Execution of bundleInstance.SelectByFieldValue(

"spec.somekey.somefield",
func(v interface{}) { return v == "someValue" })

will return a new Bundle instance containing 2 documents:

---
apiVersion: v1
kind: DocKind1
metadata:
  name: doc1
spec:
  somekey:
    somefield: "someValue"
---
apiVersion: v1
kind: DocKind2
metadata:
  name: doc2
spec:
  somekey:
    somefield: "someValue"

func (*BundleFactory) SelectOne

func (b *BundleFactory) SelectOne(selector Selector) (Document, error)

SelectOne serves the common use case where you expect one match and only one match to your selector -- in other words, you want to error if you didn't find any documents, and error if you found more than one. This reduces code repetition that would otherwise be scattered around that evaluates the length of the doc set returned for this common case

func (*BundleFactory) SetFileSystem

func (b *BundleFactory) SetFileSystem(fSys fs.FileSystem) error

SetFileSystem sets the filesystem that will be used by this bundle

func (*BundleFactory) SetKustomizeBuildOptions

func (b *BundleFactory) SetKustomizeBuildOptions(k KustomizeBuildOptions) error

SetKustomizeBuildOptions sets the build options to be used for this bundle. In the future, it may perform some basic validations.

func (*BundleFactory) SetKustomizeResourceMap

func (b *BundleFactory) SetKustomizeResourceMap(r resmap.ResMap) error

SetKustomizeResourceMap allows us to set the populated resource map for this bundle. In the future, it may modify it before saving it.

func (*BundleFactory) Write

func (b *BundleFactory) Write(out io.Writer) error

Write will write out the entire bundle resource map

type BundleFactoryFunc

type BundleFactoryFunc func() (Bundle, error)

BundleFactoryFunc is a function that returns bundle, can be used to build bundle on demand instead of inplace, useful, when you don't know if bundle will be needed or not, see phase for detail

func BundleFactoryFromBytes

func BundleFactoryFromBytes(data []byte) BundleFactoryFunc

BundleFactoryFromBytes is a function which returns BundleFactoryFunc based on new bundle from bytes

func BundleFactoryFromDocRoot

func BundleFactoryFromDocRoot(docRootFunc func() (string, error)) BundleFactoryFunc

BundleFactoryFromDocRoot is a function which returns BundleFactoryFunc based on new bundle from DocumentRoot path

type DocFactoryFunc

type DocFactoryFunc func() (Document, error)

DocFactoryFunc is a type of function which returns (Document, error) and can be used on demand

type Document

type Document interface {
	Annotate(map[string]string)
	AsYAML() ([]byte, error)
	GetAnnotations() map[string]string
	GetBool(path string) (bool, error)
	GetFloat64(path string) (float64, error)
	GetFieldValue(path string) (interface{}, error)
	GetGroup() string
	GetInt64(path string) (int64, error)
	GetKind() string
	GetLabels() map[string]string
	GetMap(path string) (map[string]interface{}, error)
	GetName() string
	GetNamespace() string
	GetSlice(path string) ([]interface{}, error)
	GetString(path string) (string, error)
	GetStringMap(path string) (map[string]string, error)
	GetStringSlice(path string) ([]string, error)
	GetVersion() string
	Label(map[string]string)
	MarshalJSON() ([]byte, error)
	ToObject(interface{}) error
	ToAPIObject(runtime.Object, *runtime.Scheme) error
}

Document interface

func NewDocument

func NewDocument(r *resource.Resource) (Document, error)

NewDocument is a convenience method to construct a new Document. Although an error is unlikely at this time, this provides some future proofing for when we want more strict airship specific validation of documents getting created as this would be the front door for all Kustomize->Airship documents - e.g. in the future all documents require an airship annotation X

func NewDocumentFromBytes

func NewDocumentFromBytes(b []byte) (Document, error)

NewDocumentFromBytes constructs document from bytes

type ErrBadValueFormat

type ErrBadValueFormat struct {
	Value    string
	Expected string
	Actual   string
}

ErrBadValueFormat returned if wrong field type requested

func (ErrBadValueFormat) Error

func (e ErrBadValueFormat) Error() string

type ErrDocNotFound

type ErrDocNotFound struct {
	Selector Selector
}

ErrDocNotFound returned if desired document not found by selector

func (ErrDocNotFound) Error

func (e ErrDocNotFound) Error() string

type ErrDocumentDataKeyNotFound

type ErrDocumentDataKeyNotFound struct {
	DocName string
	Key     string
}

ErrDocumentDataKeyNotFound returned if desired key within a document not found

func (ErrDocumentDataKeyNotFound) Error

type ErrDocumentMalformed

type ErrDocumentMalformed struct {
	DocName string
	Message string
}

ErrDocumentMalformed returned if the document is structurally malformed (e.g. missing required low level keys)

func (ErrDocumentMalformed) Error

func (e ErrDocumentMalformed) Error() string

type ErrMultiDocsFound

type ErrMultiDocsFound struct {
	Selector Selector
}

ErrMultiDocsFound returned if multiple documents were found by selector

func (ErrMultiDocsFound) Error

func (e ErrMultiDocsFound) Error() string

type ErrRuntimeObjectKind

type ErrRuntimeObjectKind struct {
	Obj runtime.Object
}

ErrRuntimeObjectKind returned if runtime object contains either none or more than one Kinds defined in schema

func (ErrRuntimeObjectKind) Error

func (e ErrRuntimeObjectKind) Error() string

type Factory

type Factory struct {
	resource.Resource
}

Factory holds document data

func (*Factory) Annotate

func (d *Factory) Annotate(newAnnotations map[string]string)

Annotate document by applying annotations as map

func (*Factory) AsYAML

func (d *Factory) AsYAML() ([]byte, error)

AsYAML returns the document as a YAML byte stream.

func (*Factory) GetBool

func (d *Factory) GetBool(path string) (bool, error)

GetBool returns a bool at path.

func (*Factory) GetFieldValue

func (d *Factory) GetFieldValue(path string) (interface{}, error)

GetFieldValue get object at path

func (*Factory) GetFloat64

func (d *Factory) GetFloat64(path string) (float64, error)

GetFloat64 returns a float64 at path.

func (*Factory) GetGroup

func (d *Factory) GetGroup() string

GetGroup returns api group from apiVersion field

func (*Factory) GetInt64

func (d *Factory) GetInt64(path string) (int64, error)

GetInt64 returns an int64 at path.

func (*Factory) GetKind

func (d *Factory) GetKind() string

GetKind returns the Kind: field from the document.

func (*Factory) GetKustomizeResource

func (d *Factory) GetKustomizeResource() resource.Resource

GetKustomizeResource returns a Kustomize Resource object for this document.

func (*Factory) GetMap

func (d *Factory) GetMap(path string) (map[string]interface{}, error)

GetMap returns a map at path.

func (*Factory) GetName

func (d *Factory) GetName() string

GetName returns the name: field from the document.

func (*Factory) GetNamespace

func (d *Factory) GetNamespace() string

GetNamespace returns the namespace the resource thinks it's in.

func (*Factory) GetSlice

func (d *Factory) GetSlice(path string) ([]interface{}, error)

GetSlice returns a slice at path.

func (*Factory) GetString

func (d *Factory) GetString(path string) (string, error)

GetString returns the string value at path.

func (*Factory) GetStringMap

func (d *Factory) GetStringMap(path string) (map[string]string, error)

GetStringMap returns a string map at path.

func (*Factory) GetStringSlice

func (d *Factory) GetStringSlice(path string) ([]string, error)

GetStringSlice returns a string slice at path.

func (*Factory) GetVersion

func (d *Factory) GetVersion() string

GetVersion returns api version from apiVersion field

func (*Factory) Label

func (d *Factory) Label(newLabels map[string]string)

Label document by applying labels as map

func (*Factory) MarshalJSON

func (d *Factory) MarshalJSON() ([]byte, error)

MarshalJSON returns the document as JSON.

func (*Factory) SetKustomizeResource

func (d *Factory) SetKustomizeResource(r *resource.Resource) error

SetKustomizeResource sets a Kustomize Resource object for this document.

func (*Factory) ToAPIObject

func (d *Factory) ToAPIObject(obj runtime.Object, scheme *runtime.Scheme) error

ToAPIObject de-serializes a document into a runtime.Object

func (*Factory) ToObject

func (d *Factory) ToObject(obj interface{}) error

ToObject serializes document to object passed as an argument

type KustomNode

type KustomNode struct {
	Name     string // name used for display purposes (cli)
	Data     string // this could be a Kustomization object, or a string containing a file path
	Children []KustomNode
	Writer   io.Writer
}

KustomNode is used to create name and data to display tree structure

func BuildKustomTree

func BuildKustomTree(entrypoint string, writer io.Writer, manifestsDir string) (KustomNode, error)

BuildKustomTree creates a tree based on entrypoint

func GetKustomChildren

func GetKustomChildren(k KustomNode) []KustomNode

GetKustomChildren returns children nodes of kustomnode

func (KustomNode) PrintTree

func (k KustomNode) PrintTree(prefix string)

PrintTree prints tree view of phase

type KustomizeBuildOptions

type KustomizeBuildOptions struct {
	KustomizationPath string
	LoadRestrictions  types.LoadRestrictions
}

KustomizeBuildOptions contain the options for running a Kustomize build on a bundle

type Selector

type Selector struct {
	types.Selector `json:"selector,omitempty"`
}

Selector provides abstraction layer in front of kustomize selector

func NewApplierContainerExecutorSelector

func NewApplierContainerExecutorSelector() Selector

NewApplierContainerExecutorSelector returns selector to get executor documents for applier container

func NewBMCCredentialsSelector

func NewBMCCredentialsSelector(name string) Selector

NewBMCCredentialsSelector returns selector to get BaremetalHost BMC credentials

func NewCRDSelector

func NewCRDSelector() Selector

NewCRDSelector returns selector to get custom resource definition documents

func NewClusterctlContainerExecutorSelector

func NewClusterctlContainerExecutorSelector() Selector

NewClusterctlContainerExecutorSelector returns selector to get executor documents for clusterctl container

func NewClusterctlMetadataSelector

func NewClusterctlMetadataSelector() Selector

NewClusterctlMetadataSelector returns selector to get clusterctl metadata documents

func NewDeployToK8sSelector

func NewDeployToK8sSelector() Selector

NewDeployToK8sSelector returns a selector to get documents that are to be deployed to kubernetes cluster.

func NewEphemeralBMHSelector

func NewEphemeralBMHSelector() Selector

NewEphemeralBMHSelector returns selector to get BaremetalHost for ephemeral node

func NewEphemeralCloudDataSelector

func NewEphemeralCloudDataSelector() Selector

NewEphemeralCloudDataSelector returns selector to get BaremetalHost for ephemeral node

func NewNetworkDataSelector

func NewNetworkDataSelector(bmhDoc Document) (Selector, error)

NewNetworkDataSelector returns selector that can be used to get secret with network data bmhDoc argument is a document interface, that should hold fields spec.networkData.name and spec.networkData.namespace where to find the secret, if either of these fields are not defined in Document error will be returned

func NewSelector

func NewSelector() Selector

NewSelector returns instance of Selector container

func NewSelectorFromV1Alpha1

func NewSelectorFromV1Alpha1(selector v1alpha1.Selector) Selector

NewSelectorFromV1Alpha1 generates selector object from v1alpha1 analog

func NewValidatorExecutorSelector

func NewValidatorExecutorSelector() Selector

NewValidatorExecutorSelector returns selector to get validator executor documents

func (Selector) ByAnnotation

func (s Selector) ByAnnotation(annotationSelector string) Selector

ByAnnotation select by annotation selector.

func (Selector) ByGvk

func (s Selector) ByGvk(group, version, kind string) Selector

ByGvk select by gvk

func (Selector) ByKind

func (s Selector) ByKind(kind string) Selector

ByKind select by Kind

func (Selector) ByLabel

func (s Selector) ByLabel(labelSelector string) Selector

ByLabel select by label selector

func (Selector) ByName

func (s Selector) ByName(name string) Selector

ByName select by name

func (Selector) ByNamespace

func (s Selector) ByNamespace(namespace string) Selector

ByNamespace select by namespace

func (Selector) ByObject

func (s Selector) ByObject(obj runtime.Object, scheme *runtime.Scheme) (Selector, error)

ByObject select by runtime object defined in API schema

func (Selector) ByObjectReference

func (s Selector) ByObjectReference(objRef *corev1.ObjectReference) Selector

ByObjectReference select by ObjectReference

func (Selector) String

func (s Selector) String() string

String is a convenience function which dumps all relevant information about a Selector in the following format: [Key1=Value1, Key2=Value2, ...]

Directories

Path Synopsis
plugin

Jump to

Keyboard shortcuts

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