kool

package module
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Dec 13, 2023 License: MIT Imports: 20 Imported by: 0

README

Kool

Kool is a helper library for creating k8s operators.

What's new

We use generics! No more FooInformer, BarInformer or BazInformer, just use kool.Informer!

So as Lister and Client.

// Using code-generator or kubebuilder:

var fooInformer FooInformer
var barInformer BarInformer
var bazInformer BazInformer

// Using kool:

import "github.com/FlyingOnion/kool"

var fooInformer kool.Informer[Foo]
var barInformer kool.Informer[Bar]
var bazInformer kool.Informer[Baz]

How to use

We provide koolbuilder to generate operator boilerplate online. You don't need to install any code generator binaries.

Choose one of the following links:

Cloudflare Pages (China-mainland-friendly)

https://koolbuilder.pages.dev

GitHub Pages

https://flyingonion.github.io/koolbuilder/index.html

Or use command line (for updating your operator):

go get github.com/FlyingOnion/koolbuilder

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DeepCopy

func DeepCopy[T any](in, out *T)

func MultiplyDuration

func MultiplyDuration[N Number](d time.Duration, n N) time.Duration

func NewRESTClient added in v0.1.1

func NewRESTClient(config *rest.Config, httpClient *http.Client, gv *schema.GroupVersion) (*rest.RESTClient, error)

NewRESTClient creates a new RESTClient for the given config. This client can only be used to interact with the given group version.

Types

type Client

type Client[T any] interface {
	Create(ctx context.Context, item *T, opts metav1.CreateOptions) (*T, error)
	Update(ctx context.Context, name string, item *T, opts metav1.UpdateOptions) (*T, error)
	UpdateStatus(ctx context.Context, name string, item *T, opts metav1.UpdateOptions) (*T, error)
	Delete(ctx context.Context, name string, opts metav1.DeleteOptions) error
	DeleteCollection(ctx context.Context, opts metav1.DeleteOptions, listOpts metav1.ListOptions) error
	Get(ctx context.Context, name string, opts metav1.GetOptions) (*T, error)
	List(ctx context.Context, opts metav1.ListOptions) (*List[T], error)
	Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error)
	Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts metav1.PatchOptions, subresources ...string) (result *T, err error)
}

func NewTypedClient

func NewTypedClient[T any](client *rest.RESTClient, ns, resource string) Client[T]

type ClientWithApply

type ClientWithApply[T, ApplyConfiguration any] interface {
	Client[T]
	Apply(ctx context.Context, ac *ApplyConfiguration, opts metav1.ApplyOptions) (result *T, err error)
	ApplyStatus(ctx context.Context, ac *ApplyConfiguration, opts metav1.ApplyOptions) (result *T, err error)
}

type DeepCopyGen

type DeepCopyGen[T any] interface {
	DeepCopyInto(*T)
}

type Informer

type Informer[T any] interface {
	Informer() cache.SharedIndexInformer
	Lister() Lister[T]
}

func NewInformer

func NewInformer[T any](client *rest.RESTClient, resyncPeriod time.Duration) Informer[T]

type List

type List[T any] struct {
	metav1.TypeMeta `json:",inline"`
	metav1.ListMeta `json:"metadata,omitempty"`
	Items           []T `json:"items"`
}

func (*List[T]) DeepCopy

func (in *List[T]) DeepCopy() *List[T]

func (*List[T]) DeepCopyInto

func (listA *List[T]) DeepCopyInto(listB *List[T])

func (*List[T]) DeepCopyObject

func (in *List[T]) DeepCopyObject() runtime.Object

type Lister

type Lister[T any] interface {
	List(selector labels.Selector) ([]*T, error)
	Namespaced(ns string) NamespacedLister[T]
}

func NewLister

func NewLister[T any](indexer cache.Indexer) Lister[T]

type NamespacedInformer

type NamespacedInformer[T any] interface {
	Informer() cache.SharedIndexInformer
	Lister() NamespacedLister[T]
}

func NewNamespacedInformer

func NewNamespacedInformer[T any](client *rest.RESTClient, ns string, resyncPeriod time.Duration) NamespacedInformer[T]

type NamespacedLister

type NamespacedLister[T any] interface {
	List(selector labels.Selector) ([]*T, error)
	Get(name string) (*T, error)
}

type Number

type Number interface {
	~int | ~int8 | ~int16 | ~int32 | ~int64 | ~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64
}

Jump to

Keyboard shortcuts

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