Documentation ¶
Overview ¶
Package conversion contains the methods that convert k8s resources to specified version
Index ¶
- func ConvertURL(url string, gvr *schema.GroupVersionResource) (convertedUrl string, err error)
- func Gvk2Gvr(mapper meta.RESTMapper, gvk *schema.GroupVersionKind) (*schema.GroupVersionResource, error)
- func Gvr2Gvk(mapper meta.RESTMapper, gvr *schema.GroupVersionResource) (*schema.GroupVersionKind, error)
- func IsStableVersion(gv schema.GroupVersion) bool
- func MarshalJSON(u *unstructured.Unstructured) ([]byte, error)
- func ParseURL(url string) (bool, bool, *schema.GroupVersionResource, error)
- func ParseVersion(version string) (currentMajor, currentMinor int, err error)
- func UnmarshalJSON(b []byte) (*unstructured.Unstructured, error)
- func Version(info *version.Info) string
- func VersionCompare(v1, v2 string) (int, error)
- func WrapClient(cli client.Client, c SingleVersionConverter, convertBack bool) client.Client
- type GreetBackType
- type InstallFunc
- type MultiVersionConverter
- type ReaderWithConverter
- type SingleVersionConverter
- type StatusWriterWithConverter
- type VersionConverter
- func (c *VersionConverter) Convert(in runtime.Object, out runtime.Object, target runtime.GroupVersioner) (runtime.Object, error)
- func (c *VersionConverter) Decode(data []byte, defaults *schema.GroupVersionKind, into runtime.Object, ...) (runtime.Object, *schema.GroupVersionKind, error)
- func (c *VersionConverter) DirectConvert(in runtime.Object, out runtime.Object, target runtime.GroupVersioner) (runtime.Object, error)
- func (c *VersionConverter) Encode(obj runtime.Object, gv runtime.GroupVersioner) ([]byte, error)
- func (c *VersionConverter) GvkGreeting(gvk *schema.GroupVersionKind) (greetBack GreetBackType, rawGvk *schema.GroupVersionKind, ...)
- func (c *VersionConverter) GvrGreeting(gvr *schema.GroupVersionResource) (greetBack GreetBackType, rawGvk *schema.GroupVersionKind, ...)
- func (c *VersionConverter) ObjectGreeting(obj runtime.Object) (greetBack GreetBackType, rawGvk *schema.GroupVersionKind, ...)
- type WriterWithConverter
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 ¶
func Gvk2Gvr(mapper meta.RESTMapper, gvk *schema.GroupVersionKind) (*schema.GroupVersionResource, error)
Gvk2Gvr convert gvk to gvr by specified cluster
func Gvr2Gvk ¶
func Gvr2Gvk(mapper meta.RESTMapper, gvr *schema.GroupVersionResource) (*schema.GroupVersionKind, error)
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 ParseVersion ¶
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 VersionCompare ¶
VersionCompare compare the both versions return 1 means v1 > v2 return 0 means v1 = v2 return -1 means v1 < v2
func WrapClient ¶ added in v1.2.1
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 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
func WrapReader ¶
func WrapReader(r client.Reader, c SingleVersionConverter) ReaderWithConverter
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
func WrapStatusWriter ¶
func WrapStatusWriter(r client.StatusWriter, c SingleVersionConverter, convertBack bool) StatusWriterWithConverter
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 ¶
func (c *VersionConverter) Convert(in runtime.Object, out runtime.Object, target runtime.GroupVersioner) (runtime.Object, error)
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 ¶
func (c *VersionConverter) Decode(data []byte, defaults *schema.GroupVersionKind, into runtime.Object, versions ...schema.GroupVersion) (runtime.Object, *schema.GroupVersionKind, error)
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 ¶
func (c *VersionConverter) Encode(obj runtime.Object, gv runtime.GroupVersioner) ([]byte, error)
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