utils

package
v0.34.3 Latest Latest
Warning

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

Go to latest
Published: Feb 19, 2024 License: Apache-2.0 Imports: 62 Imported by: 0

Documentation

Index

Constants

View Source
const (
	AnnotationProvenanceFile = "kubecfg.github.com/provenance-file"
	AnnotationProvenancePath = "kubecfg.github.com/provenance-path"
)
View Source
const (
	OCIBundleBodyMediaType   = "application/vnd.kubecfg.bundle.tar+gzip"
	OCIBundleDocsMediaType   = "application/vnd.kubecfg.bundle.docs.tar+gzip"
	OCIBundleConfigMediaType = "application/vnd.kubecfg.bundle.config.v1+json"
)

Variables

View Source
var (
	ErrCacheNotFound = errors.New("not found")
)

Error Constants

Functions

func ClientForResource added in v0.5.0

func ClientForResource(client dynamic.Interface, mapper meta.RESTMapper, obj runtime.Object, defNs string) (dynamic.ResourceInterface, error)

ClientForResource returns the ResourceClient for a given object

func CompactDecodeObject added in v0.23.0

func CompactDecodeObject(data string, into runtime.Object) error

CompactDecodeObject does the reverse of CompactEncodeObject.

func CompactEncodeObject added in v0.23.0

func CompactEncodeObject(o runtime.Object) (string, error)

CompactEncodeObject returns a compact string representation (json->gzip->base64) of an object, intended for use in last-applied-configuration annotation.

func DeleteMetaDataAnnotation added in v0.23.0

func DeleteMetaDataAnnotation(obj metav1.Object, key string)

DeleteMetaDataAnnotation removes an annotation value

func DeleteMetaDataLabel added in v0.23.0

func DeleteMetaDataLabel(obj metav1.Object, key string)

DeleteMetaDataLabel removes a label value

func DependencyOrder added in v0.2.0

func DependencyOrder(disco discovery.OpenAPISchemaInterface, mapper meta.RESTMapper, list []*unstructured.Unstructured) (sort.Interface, error)

DependencyOrder is a `sort.Interface` that *best-effort* sorts the objects so that known dependencies appear earlier in the list. The idea is to prevent *some* of the "crash-restart" loops when creating inter-dependent resources.

func FlattenToV1

func FlattenToV1(objs []runtime.Object) []*unstructured.Unstructured

FlattenToV1 expands any List-type objects into their members, and cooerces everything to v1.Unstructured. Panics if coercion encounters an unexpected object type.

func FqName added in v0.5.0

func FqName(o metav1.Object) string

FqName returns "namespace.name"

func MakeUniversalImporter added in v0.8.0

func MakeUniversalImporter(searchURLs []*url.URL, alpha bool) jsonnet.Importer

MakeUniversalImporter creates an importer that handles resolving imports from the filesystem and HTTP/S.

In addition to the standard importer, supports:

  • URLs in import statements
  • URLs in library search paths
  • importing binary files (for local files and URLs)

A real-world example:

func MaybeMarkStale added in v0.23.0

func MaybeMarkStale(d discovery.DiscoveryInterface)

MaybeMarkStale calls MarkStale on the discovery client, if the client is a memcachedClient.

func NewMemcachedDiscoveryClient

func NewMemcachedDiscoveryClient(delegate discovery.DiscoveryInterface) discovery.CachedDiscoveryInterface

NewmemcachedDiscoveryClient creates a new CachedDiscoveryInterface which caches discovery information in memory and will stay up-to-date if Invalidate is called with regularity.

NOTE: The client will NOT resort to live lookups on cache misses.

func NewUnstructuredObject added in v0.34.3

func NewUnstructuredObject(o map[string]interface{}) (*unstructured.Unstructured, error)

NewUnstructuredObject returns a new unstructured.Unstructured object from a raw json object expressed as an untyped tree It returns an error if the object doesn't appear to be a valid k8s object. If the object is a k8s List object, the validation is performed opn the list items recursively.

func PathToURL added in v0.29.0

func PathToURL(path string) (string, error)

func Read

func Read(vm *jsonnet.VM, path string, opts ...ReadOption) ([]runtime.Object, error)

Read fetches and decodes K8s objects by path. TODO: Replace this with something supporting more sophisticated content negotiation.

func RegisterNativeFuncs added in v0.3.0

func RegisterNativeFuncs(vm *jsonnet.VM, resolver Resolver)

RegisterNativeFuncs adds kubecfg's native jsonnet functions to provided VM

func RemoveDuplicates added in v0.29.2

func RemoveDuplicates(objs []*unstructured.Unstructured) ([]*unstructured.Unstructured, error)

RemoveDuplicates returns error if the provided object slice contains multiple objects sharing the same version/kind/namespace/name combination that are not literal matches.

func ResourceNameFor added in v0.5.0

func ResourceNameFor(mapper meta.RESTMapper, o runtime.Object) string

ResourceNameFor returns a lowercase plural form of a type, for human messages. Returns lowercased kind if discovery lookup fails.

func SearchUp added in v0.30.0

func SearchUp(fileName string, relativeTo string) (string, bool, error)

SearchUp finds fileName somewhere in directory of relativeTo or in any of its parent directories.

func SetMetaDataAnnotation added in v0.5.0

func SetMetaDataAnnotation(obj metav1.Object, key, value string)

SetMetaDataAnnotation sets an annotation value

func SetMetaDataLabel added in v0.9.0

func SetMetaDataLabel(obj metav1.Object, key, value string)

SetMetaDataLabel sets an annotation value

func ToDataURL added in v0.29.2

func ToDataURL(code string) string

Types

type AlphabeticalOrder added in v0.2.0

type AlphabeticalOrder []*unstructured.Unstructured

AlphabeticalOrder is a `sort.Interface` that sorts the objects by namespace/name/kind alphabetical order

func (AlphabeticalOrder) Len added in v0.2.0

func (l AlphabeticalOrder) Len() int

func (AlphabeticalOrder) Less added in v0.2.0

func (l AlphabeticalOrder) Less(i, j int) bool

func (AlphabeticalOrder) Swap added in v0.2.0

func (l AlphabeticalOrder) Swap(i, j int)

type ArrayReader added in v0.27.0

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

func (*ArrayReader) Read added in v0.27.0

func (r *ArrayReader) Read(p []byte) (int, error)

type ImageName added in v0.3.0

type ImageName struct {
	// eg: "myregistryhost:5000/fedora/httpd:version1.0"
	Registry   string // "myregistryhost:5000"
	Repository string // "fedora"
	Name       string // "httpd"
	Tag        string // "version1.0"
	Digest     string
}

ImageName represents the parts of a docker image name

func ParseImageName added in v0.3.0

func ParseImageName(image string) (ImageName, error)

ParseImageName parses a docker image into an ImageName struct.

func (ImageName) RegistryRepoName added in v0.3.0

func (n ImageName) RegistryRepoName() string

RegistryRepoName returns the "repository" as used in the registry URL

func (ImageName) RegistryURL added in v0.3.0

func (n ImageName) RegistryURL() string

RegistryURL returns the deduced base URL of the registry for this image

func (ImageName) String added in v0.3.0

func (n ImageName) String() string

String implements the Stringer interface

type OCIBundle added in v0.29.0

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

func NewOCIBundle added in v0.29.0

func NewOCIBundle(manifest ocispec.Manifest, config OCIBundleConfig, r io.ReadCloser) (*OCIBundle, error)

func (*OCIBundle) Open added in v0.29.0

func (o *OCIBundle) Open(path string) (io.ReadCloser, error)

type OCIBundleConfig added in v0.29.0

type OCIBundleConfig struct {
	Entrypoint string          `json:"entrypoint"`
	Metadata   json.RawMessage `json:"metadata,omitempty"`
}

type OpenAPISchema added in v0.9.0

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

OpenAPISchema represents an OpenAPI schema for a given GroupVersionKind.

func NewOpenAPISchemaFor added in v0.9.0

func NewOpenAPISchemaFor(delegate discovery.OpenAPISchemaInterface, gvk schema.GroupVersionKind) (*OpenAPISchema, error)

NewOpenAPISchemaFor returns the OpenAPISchema object ready to validate objects of given GroupVersion

func (*OpenAPISchema) Validate added in v0.9.0

func (s *OpenAPISchema) Validate(obj *unstructured.Unstructured) []error

Validate is the primary entrypoint into this class

type ReadOption added in v0.26.0

type ReadOption = acquire.ReadOption

breaks import cycle

func WithExpr added in v0.29.0

func WithExpr(expr string) ReadOption

func WithOverlayCode added in v0.29.2

func WithOverlayCode(overlayCode string) ReadOption

func WithOverlayURL added in v0.29.2

func WithOverlayURL(overlayURL string) ReadOption

func WithProvenance added in v0.26.0

func WithProvenance(show bool) ReadOption

func WithReadTwice added in v0.27.0

func WithReadTwice(twice bool) ReadOption

type Resolver added in v0.3.0

type Resolver interface {
	Resolve(image *ImageName) error
}

Resolver is able to resolve docker image names into more specific forms

func NewIdentityResolver added in v0.3.0

func NewIdentityResolver() Resolver

NewIdentityResolver returns a resolver that does only trivial :latest canonicalisation

func NewRegistryResolver added in v0.3.0

func NewRegistryResolver(opt registry.Opt) Resolver

NewRegistryResolver returns a resolver that looks up a docker registry to resolve digests

type ServerVersion added in v0.4.0

type ServerVersion struct {
	Major int
	Minor int
}

ServerVersion captures k8s major.minor version in a parsed form

func FetchVersion added in v0.4.0

func FetchVersion(v discovery.ServerVersionInterface) (ret ServerVersion, err error)

FetchVersion fetches version information from discovery client, and parses

func GetDefaultVersion added in v0.9.0

func GetDefaultVersion() ServerVersion

GetDefaultVersion returns a default server version. This value will be updated periodically to match a current/popular version corresponding to the age of this code Current default version: 1.8

func ParseVersion added in v0.4.0

func ParseVersion(v *version.Info) (ServerVersion, error)

ParseVersion parses version.Info into a ServerVersion struct

func (ServerVersion) Compare added in v0.4.0

func (v ServerVersion) Compare(major, minor int) int

Compare returns -1/0/+1 iff v is less than / equal / greater than major.minor

func (ServerVersion) String added in v0.4.0

func (v ServerVersion) String() string

Jump to

Keyboard shortcuts

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