genericresource

package
v1.9.1 Latest Latest
Warning

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

Go to latest
Published: Apr 11, 2024 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Overview

Package genericresource is modified from "k8s.io/cli-runtime/pkg/resource". It can fetch any object (not only runtime.object) from file, http, and stdin.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Builder

type Builder struct {
	// contains filtered or unexported fields
}

Builder provides convenience functions for taking arguments and parameters from the command line and converting them to a list of resources to iterate over using the Visitor interface.

func NewBuilder

func NewBuilder() *Builder

NewBuilder returns a Builder.

func (*Builder) Constructor

func (b *Builder) Constructor(newFunc func() interface{}) *Builder

Constructor tells wanted type of object.

func (*Builder) Do

func (b *Builder) Do() *Result

Do returns a Result object with a Visitor for the resources identified by the Builder. Note that stream inputs are consumed by the first execution - use Infos() or Objects() on the Result to capture a list for further iteration.

func (*Builder) Filename

func (b *Builder) Filename(recursive bool, filenames ...string) *Builder

Filename groups input in two categories: URLs and files (files, directories, STDIN)

func (*Builder) Path

func (b *Builder) Path(recursive bool, paths ...string) *Builder

Path accepts a set of paths that may be files, directories (all can contain one or more resources). Creates a FileVisitor for each file and then each FileVisitor is streaming the content to a StreamVisitor.

func (*Builder) Schema

func (b *Builder) Schema(schema resource.ContentValidator) *Builder

Schema set the schema to validate data in files.

func (*Builder) Stdin

func (b *Builder) Stdin() *Builder

Stdin will read objects from the standard input.

func (*Builder) URL

func (b *Builder) URL(httpAttemptCount int, urls ...*url.URL) *Builder

URL accepts a number of URLs directly.

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 Info

type Info struct {
	// 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 returned by the server if available. It will
	// typically be in unstructured or internal forms, depending on how the Builder was
	// defined. If retrieved from the server, the Builder expects the mapping client to
	// decide the final form. Use the AsVersioned, AsUnstructured, and AsInternal helpers
	// to alter the object versions.
	// If Subresource is specified, this will be the object for the subresource.
	Data []byte

	Object interface{}
}

Info contains temporary info to execute a REST call, or show the results of an already completed REST call.

type Result

type Result struct {
	// contains filtered or unexported fields
}

Result contains helper methods for dealing with the outcome of a Builder.

func (*Result) Err

func (r *Result) Err() error

Err returns one or more errors (via a util.ErrorList) that occurred prior to visiting the elements in the visitor. To see all errors including those that occur during visitation, invoke Infos().

func (*Result) Infos

func (r *Result) Infos() ([]*Info, error)

Infos returns an array of all of the resource infos retrieved via traversal. Will attempt to traverse the entire set of visitors only once, and will return a cached list on subsequent calls.

func (*Result) Objects

func (r *Result) Objects() ([]interface{}, error)

Objects returns the list of objects of all found resources.

func (*Result) Visit

func (r *Result) Visit(fn VisitorFunc) error

Visit implements the Visitor interface on the items described in the Builder. Note that some visitor sources are not traversable more than once, or may return different results. If you wish to operate on the same set of resources multiple times, use the Infos() method.

type StreamVisitor

type StreamVisitor struct {
	io.Reader

	Source string
	Schema resource.ContentValidator
	// contains filtered or unexported fields
}

StreamVisitor reads objects from an io.Reader and walks them. A stream visitor can only be visited once. Unmarshal stream to object by json.

func NewStreamVisitor

func NewStreamVisitor(r io.Reader, mapper *mapper, source string, schema resource.ContentValidator) *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 NewURLVisitor

func NewURLVisitor(mapper *mapper, httpAttemptCount int, u *url.URL, schema resource.ContentValidator) *URLVisitor

NewURLVisitor returns a visitor to download from given url. It will max retry "httpAttemptCount" when failed.

func (*URLVisitor) Visit

func (v *URLVisitor) Visit(fn VisitorFunc) error

Visit down object from url.

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, schema resource.ContentValidator) ([]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, schema resource.ContentValidator) Visitor

FileVisitorForSTDIN return a special FileVisitor just for STDIN

type VisitorFunc

type VisitorFunc func(*Info, error) error

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

Jump to

Keyboard shortcuts

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