Documentation
¶
Index ¶
- Variables
- type Builder
- func (b *Builder) ContinueOnError() *Builder
- func (b *Builder) Do() *Result
- func (b *Builder) FilenameParam(filenameOptions *FilenameOptions) *Builder
- func (r *Builder) Flatten() *Builder
- func (b *Builder) Mapper() *mapper
- func (b *Builder) Path(recursive bool, paths ...string) *Builder
- func (b *Builder) ResourceTypeOrNameArgs(args ...string) *Builder
- func (b *Builder) Stdin() *Builder
- func (b *Builder) Stream(r io.Reader, name string) *Builder
- func (b *Builder) URL(httpAttemptCount int, urls ...*url.URL) *Builder
- func (b *Builder) Unstructured() *Builder
- type ConcurrentVisitorList
- type DecoratedVisitor
- type EagerVisitorList
- type FileVisitor
- type FilenameOptions
- type FlattenListVisitor
- type Info
- type Result
- type StreamVisitor
- type URLVisitor
- type Visitor
- func ExpandPathsToFileVisitors(mapper *mapper, paths string, recursive bool, extensions []string) ([]Visitor, error)
- func FileVisitorForSTDIN(mapper *mapper) Visitor
- func NewDecoratedVisitor(v Visitor, fn ...VisitorFunc) Visitor
- func NewFlattenListVisitor(v Visitor, typer runtime.ObjectTyper, mapper *mapper) Visitor
- type VisitorFunc
- type VisitorList
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var FileExtensions = []string{".json", ".yaml", ".yml"}
var InputExtensions = append(FileExtensions, "stdin")
var StdinMultiUseError = errors.New("standard input cannot be used for multiple arguments")
Functions ¶
This section is empty.
Types ¶
type Builder ¶
type Builder struct {
// contains filtered or unexported fields
}
func NewBuilder ¶
func NewBuilder(resourceMapper resourcemapper.Mapper, proxy types.NamespacedName, branch string) *Builder
func NewLocalBuilder ¶
func NewLocalBuilder() *Builder
Example ¶
ExampleNewLocalBuilderLoad demonstrates using a local resource builder to read typed resources from a manifest
package main import ( "bytes" "fmt" ) var exampleManifest = ` apiVersion: admissionregistration.k8s.io/v1 kind: MutatingWebhookConfiguration metadata: name: mutating1 --- apiVersion: admissionregistration.k8s.io/v1 kind: MutatingWebhookConfigurationList items: - apiVersion: admissionregistration.k8s.io/v1 kind: MutatingWebhookConfiguration metadata: name: mutating2 - apiVersion: admissionregistration.k8s.io/v1 kind: MutatingWebhookConfiguration metadata: name: mutating3 --- apiVersion: admissionregistration.k8s.io/v1 kind: ValidatingWebhookConfiguration metadata: name: validating1 --- apiVersion: admissionregistration.k8s.io/v1 kind: ValidatingWebhookConfigurationList items: - apiVersion: admissionregistration.k8s.io/v1 kind: ValidatingWebhookConfiguration metadata: name: validating2 - apiVersion: admissionregistration.k8s.io/v1 kind: ValidatingWebhookConfiguration metadata: name: validating3 --- apiVersion: v1 kind: List items: - apiVersion: admissionregistration.k8s.io/v1 kind: MutatingWebhookConfiguration metadata: name: mutating4 - apiVersion: admissionregistration.k8s.io/v1 kind: ValidatingWebhookConfiguration metadata: name: validating4 --- ` // ExampleNewLocalBuilderLoad demonstrates using a local resource builder to read typed resources from a manifest func main() { // Create a local builder... builder := NewLocalBuilder(). Unstructured(). // Provide input via a Reader. // As an alternative, could call Path(false, "/path/to/file") to read from a file. Stream(bytes.NewBufferString(exampleManifest), "input"). // Flatten items contained in List objects Flatten(). // Accumulate as many items as possible ContinueOnError() // Run the builder result := builder.Do() if err := result.err; err != nil { fmt.Println("builder error:", err) return } items, err := result.Infos() if err != nil { fmt.Println("infos error:", err) return } for _, item := range items { fmt.Printf("%s (%T)\n", item.String(), item.Object) } }
Output: Name: "mutating1", Namespace: "" (*unstructured.Unstructured) Name: "mutating2", Namespace: "" (*unstructured.Unstructured) Name: "mutating3", Namespace: "" (*unstructured.Unstructured) Name: "validating1", Namespace: "" (*unstructured.Unstructured) Name: "validating2", Namespace: "" (*unstructured.Unstructured) Name: "validating3", Namespace: "" (*unstructured.Unstructured) Name: "mutating4", Namespace: "" (*unstructured.Unstructured) Name: "validating4", Namespace: "" (*unstructured.Unstructured)
func (*Builder) ContinueOnError ¶
ContinueOnError will attempt to load and visit as many objects as possible, even if some visits return errors or some objects cannot be loaded. The default behavior is to terminate after the first error is returned from a VisitorFunc.
func (*Builder) Do ¶
Do returns a Result object with a Visitor for the resources identified by the Builder. The visitor will respect the error behavior specified by ContinueOnError. Note that stream inputs are consumed by the first execution - use Infos() or Object() on the Result to capture a list for further iteration.
func (*Builder) FilenameParam ¶
func (b *Builder) FilenameParam(filenameOptions *FilenameOptions) *Builder
FilenameParam groups input in two categories: URLs and files (files, directories, STDIN) If enforceNamespace is false, namespaces in the specs will be allowed to override the default namespace. If it is true, namespaces that don't match will cause an error. If ContinueOnError() is set prior to this method, objects on the path that are not recognized will be ignored (but logged at V(2)).
func (*Builder) Flatten ¶
Flatten will convert any objects with a field named "Items" that is an array of runtime.Object compatible types into individual entries and give them their own items. The original object is not passed to any visitors.
func (*Builder) Mapper ¶
func (b *Builder) Mapper() *mapper
Mapper returns a copy of the current mapper.
func (*Builder) Path ¶
Path accepts a set of paths that may be files, directories (all can containing one or more resources). Creates a FileVisitor for each file and then each FileVisitor is streaming the content to a StreamVisitor. If ContinueOnError() is set prior to this method being called, objects on the path that are unrecognized will be ignored (but logged at V(2)).
func (*Builder) ResourceTypeOrNameArgs ¶
ResourceTypeOrNameArgs indicates that the builder should accept arguments of the form `(<type1>[,<type2>,...]|<type> <name1>[,<name2>,...])`. When one argument is received, the types provided will be retrieved from the server (and be comma delimited). When two or more arguments are received, they must be a single type and resource name(s). The allowEmptySelector permits to select all the resources (via Everything func).
func (*Builder) Stdin ¶
Stdin will read objects from the standard input. If ContinueOnError() is set prior to this method being called, objects in the stream that are unrecognized will be ignored (but logged at V(2)). If StdinInUse() is set prior to this method being called, an error will be recorded as there are multiple entities trying to use the single standard input stream.
func (*Builder) Stream ¶
Stream will read objects from the provided reader, and if an error occurs will include the name string in the error message. If ContinueOnError() is set prior to this method being called, objects in the stream that are unrecognized will be ignored (but logged at V(2)).
func (*Builder) Unstructured ¶
Unstructured updates the builder so that it will request and send unstructured objects. Unstructured objects preserve all fields sent by the server in a map format based on the object's JSON structure which means no data is lost when the client reads and then writes an object. Use this mode in preference to Internal unless you are working with Go types directly.
type ConcurrentVisitorList ¶
type ConcurrentVisitorList struct {
// contains filtered or unexported fields
}
func (ConcurrentVisitorList) Visit ¶
func (l ConcurrentVisitorList) Visit(fn VisitorFunc) error
type DecoratedVisitor ¶
type DecoratedVisitor struct {
// contains filtered or unexported fields
}
DecoratedVisitor will invoke the decorators in order prior to invoking the visitor function passed to Visit. An error will terminate the visit.
func (DecoratedVisitor) Visit ¶
func (v DecoratedVisitor) Visit(fn VisitorFunc) error
Visit implements Visitor
type EagerVisitorList ¶
type EagerVisitorList []Visitor
EagerVisitorList implements Visit for the sub visitors it contains. All errors will be captured and returned at the end of iteration.
func (EagerVisitorList) Visit ¶
func (r EagerVisitorList) Visit(fn VisitorFunc) error
Visit implements Visitor, and gathers errors that occur during processing until all sub visitors have been visited.
type FileVisitor ¶
type FileVisitor struct { Path string *StreamVisitor }
FileVisitor is wrapping around a StreamVisitor, to handle open/close files
func (*FileVisitor) Visit ¶
func (v *FileVisitor) Visit(fn VisitorFunc) error
Visit in a FileVisitor is just taking care of opening/closing files
type FilenameOptions ¶
type FlattenListVisitor ¶
type FlattenListVisitor struct {
// contains filtered or unexported fields
}
FlattenListVisitor flattens any objects that runtime.ExtractList recognizes as a list - has an "Items" public field that is a slice of runtime.Objects or objects satisfying that interface - into multiple Infos. Returns nil in the case of no errors. When an error is hit on sub items (for instance, if a List contains an object that does not have a registered client or resource), returns an aggregate error.
func (FlattenListVisitor) Visit ¶
func (v FlattenListVisitor) Visit(fn VisitorFunc) error
type Info ¶
type Info struct { // Namespace will be set if the object is namespaced and has a specified value. Namespace string Name string // Optional, Source is the filename or URL to template file (.json or .yaml), // or stdin to use to handle the resource Source string // Optional, this is the most recent value of the resource. Object runtime.Object }
type StreamVisitor ¶
StreamVisitor reads objects from an io.Reader and walks them. A stream visitor can only be visited once.
func NewStreamVisitor ¶
func NewStreamVisitor(r io.Reader, mapper *mapper, source string) *StreamVisitor
NewStreamVisitor is a helper function that is useful when we want to change the fields of the struct but keep calls the same.
func (*StreamVisitor) Visit ¶
func (v *StreamVisitor) Visit(fn VisitorFunc) error
Visit implements Visitor over a stream. StreamVisitor is able to distinct multiple resources in one stream.
type URLVisitor ¶
type URLVisitor struct { URL *url.URL *StreamVisitor HttpAttemptCount int }
URLVisitor downloads the contents of a URL, and if successful, returns an info object representing the downloaded object.
func (*URLVisitor) Visit ¶
func (v *URLVisitor) Visit(fn VisitorFunc) error
type Visitor ¶
type Visitor interface {
Visit(VisitorFunc) error
}
Visitor lets clients walk a list of resources.
func ExpandPathsToFileVisitors ¶
func ExpandPathsToFileVisitors(mapper *mapper, paths string, recursive bool, extensions []string) ([]Visitor, error)
ExpandPathsToFileVisitors will return a slice of FileVisitors that will handle files from the provided path. After FileVisitors open the files, they will pass an io.Reader to a StreamVisitor to do the reading. (stdin is also taken care of). Paths argument also accepts a single file, and will return a single visitor
func FileVisitorForSTDIN ¶
func FileVisitorForSTDIN(mapper *mapper) Visitor
FileVisitorForSTDIN return a special FileVisitor just for STDIN
func NewDecoratedVisitor ¶
func NewDecoratedVisitor(v Visitor, fn ...VisitorFunc) Visitor
the user supplied visitor function is invoked, giving them the opportunity to mutate the Info object or terminate early with an error.
func NewFlattenListVisitor ¶
func NewFlattenListVisitor(v Visitor, typer runtime.ObjectTyper, mapper *mapper) Visitor
NewFlattenListVisitor creates a visitor that will expand list style runtime.Objects into individual items and then visit them individually.
type VisitorFunc ¶
VisitorFunc implements the Visitor interface for a matching function. If there was a problem walking a list of resources, the incoming error will describe the problem and the function can decide how to handle that error. A nil returned indicates to accept an error to continue loops even when errors happen. This is useful for ignoring certain kinds of errors or aggregating errors in some way.
type VisitorList ¶
type VisitorList []Visitor
VisitorList implements Visit for the sub visitors it contains. The first error returned from a child Visitor will terminate iteration.
func (VisitorList) Visit ¶
func (l VisitorList) Visit(fn VisitorFunc) error
Visit implements Visitor