conversion

package
v1.7.2 Latest Latest
Warning

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

Go to latest
Published: Dec 29, 2022 License: Apache-2.0 Imports: 39 Imported by: 1

Documentation

Overview

Package conversion contains the methods that convert k8s resources to specified version

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConvertURL

func ConvertURL(url string, gvr *schema.GroupVersionResource) (convertedUrl string, err error)

ConvertURL convert url by given gvr

func Gvk2Gvr

Gvk2Gvr convert gvk to gvr by specified cluster

func Gvr2Gvk

Gvr2Gvk convert gvr to gvk by specified cluster

func IsStableVersion

func IsStableVersion(gv schema.GroupVersion) bool

IsStableVersion tells if given gv is stable

func MarshalJSON

func MarshalJSON(u *unstructured.Unstructured) ([]byte, error)

MarshalJSON marshal Unstructured into bytes

func ParseURL

func ParseURL(url string) (bool, bool, *schema.GroupVersionResource, error)

ParseURL parse k8s api url into gvr

func ParseVersion

func ParseVersion(version string) (currentMajor, currentMinor int, err error)

ParseVersion parse version to currentMajor and currentMinor

only two format is valid, example: 1. v1.19 2. 1.19

func UnmarshalJSON

func UnmarshalJSON(b []byte) (*unstructured.Unstructured, error)

UnmarshalJSON unmarshal bytes into Unstructured

func Version

func Version(info *version.Info) string

Version print cluster version info

func VersionCompare

func VersionCompare(v1, v2 string) (int, error)

VersionCompare compare the both versions return 1 means v1 > v2 return 0 means v1 = v2 return -1 means v1 < v2

func WrapCache added in v1.4.0

func WrapCache(cac cache.Cache, c SingleVersionConverter) cache.Cache

func WrapClient added in v1.2.1

func WrapClient(cli client.Client, c SingleVersionConverter, convertBack bool) client.Client

Types

type GreetBackType

type GreetBackType int

GreetBackType will tell what the way that obj can access cluster

const (
	IsPassThrough GreetBackType = iota
	IsNotSupport
	IsNeedConvert
	IsUnknown
)

func (GreetBackType) String added in v1.2.1

func (g GreetBackType) String() string

type InstallFunc

type InstallFunc func(scheme *runtime.Scheme)

type MultiVersionConverter

type MultiVersionConverter interface {
	GetVersionConvert(cluster string) (*VersionConverter, error)
}

MultiVersionConverter holds multi VersionConverters by different cluster name

type ReaderWithConverter

type ReaderWithConverter interface {
	SingleVersionConverter
	client.Reader
}

ReaderWithConverter wrap a Reader with given VersionConverter

type SingleVersionConverter

type SingleVersionConverter interface {
	// Convert converts an Object to another, generally the conversion is internalVersion <-> versioned.
	// if out was set, the converted result would be set into.
	Convert(in runtime.Object, out runtime.Object, target runtime.GroupVersioner) (runtime.Object, error)
	// DirectConvert converts a versioned Object to another version with given target gv.
	// if out was set, the converted result would be set into.
	DirectConvert(in runtime.Object, out runtime.Object, target runtime.GroupVersioner) (runtime.Object, error)

	// Encode encodes given obj, generally the gv should match Object
	Encode(obj runtime.Object, gv runtime.GroupVersioner) ([]byte, error)
	// Decode decodes data to object, if defaults was not set, the internalVersion would be used.
	Decode(data []byte, defaults *schema.GroupVersionKind, into runtime.Object, versions ...schema.GroupVersion) (runtime.Object, *schema.GroupVersionKind, error)

	// ObjectGreeting describes if given object is available in target cluster.
	// a recommend group version kind will return if it cloud not pass through.
	ObjectGreeting(obj runtime.Object) (isPassThrough GreetBackType, rawGvk *schema.GroupVersionKind, recommendGvk *schema.GroupVersionKind, err error)
	// GvrGreeting describes if given gvr is available in target cluster.
	// a recommend group version kind will return if it cloud not pass through.
	GvrGreeting(gvr *schema.GroupVersionResource) (isPassThrough GreetBackType, rawGvk *schema.GroupVersionKind, recommendGvk *schema.GroupVersionKind, err error)
	// GvkGreeting describes if given gvk is available in target cluster.
	// a recommend group version kind will return if it cloud not pass through.
	GvkGreeting(gvk *schema.GroupVersionKind) (isPassThrough GreetBackType, rawGvk *schema.GroupVersionKind, recommendGvk *schema.GroupVersionKind, err error)
}

type StatusWriterWithConverter

type StatusWriterWithConverter interface {
	SingleVersionConverter
	client.StatusWriter
}

StatusWriterWithConverter wrap a StatusWriter with given VersionConverter

type VersionConverter

type VersionConverter struct {

	// RestMapper is response to map gvk and gvr
	RestMapper meta.RESTMapper
	// contains filtered or unexported fields
}

VersionConverter knows how to convert object to specified version

func NewVersionConvertor

func NewVersionConvertor(discovery discovery.DiscoveryInterface, restMapper meta.RESTMapper, installFuncs ...InstallFunc) (*VersionConverter, error)

NewVersionConvertor create a version convert for a target cluster

func (*VersionConverter) Convert

Convert converts an Object to another, generally the conversion is internalVersion <-> versioned. if out was set, the converted result would be set into.

func (*VersionConverter) Decode

Decode decodes data to object, if defaults was not set, the internalVersion would be used.

func (*VersionConverter) DirectConvert

func (c *VersionConverter) DirectConvert(in runtime.Object, out runtime.Object, target runtime.GroupVersioner) (runtime.Object, error)

DirectConvert converts a versioned Object to another version with given target gv. if out was set, the converted result would be set into.

func (*VersionConverter) Encode

Encode encodes given obj, generally the gv should match Object

func (*VersionConverter) GvkGreeting

func (c *VersionConverter) GvkGreeting(gvk *schema.GroupVersionKind) (greetBack GreetBackType, rawGvk *schema.GroupVersionKind, recommendGvk *schema.GroupVersionKind, err error)

GvkGreeting describes if given gvk is available in target cluster. a recommend group version kind will return if it cloud not pass through.

func (*VersionConverter) GvrGreeting

func (c *VersionConverter) GvrGreeting(gvr *schema.GroupVersionResource) (greetBack GreetBackType, rawGvk *schema.GroupVersionKind, recommendGvk *schema.GroupVersionKind, err error)

GvrGreeting describes if given gvr is available in target cluster. a recommend group version kind will return if it cloud not pass through.

func (*VersionConverter) ObjectGreeting

func (c *VersionConverter) ObjectGreeting(obj runtime.Object) (greetBack GreetBackType, rawGvk *schema.GroupVersionKind, recommendGvk *schema.GroupVersionKind, err error)

ObjectGreeting describes if given object is available in target cluster. a recommend group version kind will return if it cloud not pass through.

type WriterWithConverter

type WriterWithConverter interface {
	SingleVersionConverter
	client.Writer
}

WriterWithConverter wrap a Writer with given VersionConverter

func WrapWriter

func WrapWriter(w client.Writer, c SingleVersionConverter, convertBack bool) WriterWithConverter

Jump to

Keyboard shortcuts

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