memorize

package
v0.0.0-...-432d548 Latest Latest
Warning

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

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

README

This package is used to migrate kubernetes resources to mem-kube resources, and vice-versa.

Documentation

Index

Constants

View Source
const (
	// KubeType read/write from/to kubenetes.
	KubeType = "kube"
	// MemType read/write from/to memory.
	MemType = "mem"
	// NopType no operation
	NopType = "nop"
)
View Source
const (
	// OwnerLabelKey the label key in ListMetas
	OwnerLabelKey = "owner-label"
	// OwnerHashLabelKey get the owner hash
	OwnerHashLabelKey = "owner-hash-label"
)

Variables

View Source
var (
	// ErrWrongTypeObject the object is not unstructured object
	ErrWrongTypeObject = errors.New("runtime.Object is not unstructured object")
)

Functions

func WrapKube

func WrapKube(parent runtime.Object, parentGvk schema.GroupVersionKind, obj runtime.Object) (runtime.Object, error)

WrapKube wraps an object into kubernetes object.

func WrapMem

func WrapMem(parent runtime.Object, parentGvk schema.GroupVersionKind, obj runtime.Object) (runtime.Object, error)

WrapMem wraps an object into an memorized object.

Types

type Descriptor

type Descriptor struct {
	Resource     string    `json:"resource"`
	Kind         string    `json:"kind"`
	Source       string    `json:"source"`
	Destination  string    `json:"destination"`
	Metas        ListMetas `json:"metas"`
	GroupVersion string    `json:"groupVersion,omitempty"` // if empty, use default
}

Descriptor the resource/object descrptor.

type FuncReaderWriter

type FuncReaderWriter struct {
	WriteFunc func(runtime.Object) error
	WrapFunc  func(parent runtime.Object, parentGvk schema.GroupVersionKind, obj runtime.Object) (runtime.Object, error)
	ListFunc  func(runtime.Object, ListMetas) ([]runtime.Object, error)
	Name      string
}

FuncReaderWriter wraps functions as a ReaderWriter.

func (FuncReaderWriter) List

func (f FuncReaderWriter) List(parent runtime.Object, metas ListMetas) ([]runtime.Object, error)

List lists objects.

func (FuncReaderWriter) Wrap

Wrap wraps an objects.

func (FuncReaderWriter) Write

func (f FuncReaderWriter) Write(obj runtime.Object) error

Write writes an object.

type ListMetas

type ListMetas struct {
	Selectors map[string]string `json:"selectors,omitempty"`
	Config    map[string]string `json:"config,omitempty"`
}

ListMetas payload arguments to List.

type Node

type Node struct {
	Reader Reader
	Writer Writer
	Gvk    schema.GroupVersionKind
	Metas  ListMetas
}

Node represents a type of object in the transition chain.

type NodeProcessor

type NodeProcessor struct {
	Node
	// contains filtered or unexported fields
}

NodeProcessor process one node.

func CreateNodeProcessors

func CreateNodeProcessors(gv schema.GroupVersion, descriptors []*Descriptor, creator ReaderWriterCreator) (*NodeProcessor, error)

CreateNodeProcessors create node processors. gv is the default GroupVersion, use descriptor GroupVersion if it's configed.

func Root

func Root(n Node) *NodeProcessor

Root create a root node processor.

func (*NodeProcessor) Child

func (p *NodeProcessor) Child(n Node) *NodeProcessor

Child creates a child node from this node.

func (*NodeProcessor) Process

func (p *NodeProcessor) Process(opts *ProcessOptions) error

Process starts to process the transition.

type NopReaderWriter

type NopReaderWriter struct {
}

NopReaderWriter nop

func (*NopReaderWriter) List

List list objects

func (*NopReaderWriter) Wrap

func (rw *NopReaderWriter) Wrap(parent runtime.Object, parentGvk schema.GroupVersionKind, obj runtime.Object) (runtime.Object, error)

Wrap wrap an object

func (*NopReaderWriter) Write

func (rw *NopReaderWriter) Write(runtime.Object) error

Write writes an object

type ProcessOptions

type ProcessOptions struct {
	Dry        bool
	NumWorkers int
}

ProcessOptions options for Process.

type Reader

type Reader interface {
	List(parent runtime.Object, metas ListMetas) ([]runtime.Object, error)
}

Reader reads/lists objects.

type ReaderWriter

type ReaderWriter interface {
	Writer
	Reader
}

ReaderWriter read and write objects.

type ReaderWriterCreator

type ReaderWriterCreator func(gvr schema.GroupVersionResource) ReaderWriterPair

ReaderWriterCreator used to create ReaderWriters

func NewDynamicReaderWriterCreator

func NewDynamicReaderWriterCreator(ns string, kubeapis dynamic.Interface, memclient *client.DynamicClient) ReaderWriterCreator

NewDynamicReaderWriterCreator setup a creator

type ReaderWriterPair

type ReaderWriterPair struct {
	KubeReaderWriter ReaderWriter
	MemReaderWriter  ReaderWriter
}

ReaderWriterPair holds ReaderWriters

type SelectorProvider

type SelectorProvider interface {
	Selector(ListMetas, runtime.Object) (string, error)
}

SelectorProvider provides selector in ListOptions

type Writer

type Writer interface {
	Write(runtime.Object) error
	Wrap(parent runtime.Object, parentGvk schema.GroupVersionKind, obj runtime.Object) (runtime.Object, error)
}

Writer writes object.

Jump to

Keyboard shortcuts

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