k8s

package
v0.0.0-...-6113c70 Latest Latest
Warning

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

Go to latest
Published: Jun 7, 2023 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Initing = iota
	Connected
	DisConnected
)

Cluster status

View Source
const (
	// GracefulStopWaitTimeout graceful stop cluster wait time
	GracefulStopWaitTimeout = time.Second * 30
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	KubeRestConfig *rest.Config
	KubeInterface  kubernetes.Interface

	CtrlRtManager manager.Manager
	CtrlRtCache   runtimecache.Cache
	// contains filtered or unexported fields
}

Client wrap controller-runtime client

func NewClient

func NewClient(clsName string, opts ...Option) (*Client, error)

NewClient build Client

func (*Client) AddEventHandler

func (cli *Client) AddEventHandler(obj client.Object, handler cache.ResourceEventHandler) error

AddEventHandler add event handler

func (*Client) CreateObj

func (cli *Client) CreateObj(obj client.Object, opts ...client.CreateOption) error

CreateObj create obj with requestTimeout

func (*Client) CreateObjWithTimeout

func (cli *Client) CreateObjWithTimeout(timeout time.Duration, obj client.Object, opts ...client.CreateOption) error

CreateObjWithTimeout create obj with timeout

func (*Client) DeleteObj

func (cli *Client) DeleteObj(obj client.Object, opts ...client.DeleteOption) error

DeleteObj create obj with timeout requestTimeout

func (*Client) DeleteObjWithTimeout

func (cli *Client) DeleteObjWithTimeout(timeout time.Duration, obj client.Object, opts ...client.DeleteOption) error

DeleteObjWithTimeout delete obj with timeout

func (*Client) GetInformerWithObj

func (cli *Client) GetInformerWithObj(obj client.Object) (runtimecache.Informer, error)

GetInformerWithObj get object informer with cache

func (*Client) GetName

func (cli *Client) GetName() string

GetName return cluster name

func (*Client) GetObj

func (cli *Client) GetObj(key types.NamespacedName, obj client.Object) error

GetObj get obj with requestTimeout

func (*Client) GetObjWithTimeout

func (cli *Client) GetObjWithTimeout(timeout time.Duration, key types.NamespacedName, obj client.Object) error

GetObjWithTimeout get obj with timeout

func (*Client) HasSynced

func (cli *Client) HasSynced() bool

HasSynced return all informer has synced

func (*Client) Start

func (cli *Client) Start(ctx context.Context) error

Start start client

func (*Client) Stop

func (cli *Client) Stop()

Stop stop client with timeout 30s

func (*Client) UpdateObj

func (cli *Client) UpdateObj(obj client.Object, opts ...client.UpdateOption) error

UpdateObj update obj with timeout requestTimeout

func (*Client) UpdateObjStatus

func (cli *Client) UpdateObjStatus(obj client.Object, opts ...client.UpdateOption) error

UpdateObjStatus update obj status with timeout requestTimeout

func (*Client) UpdateObjStatusWithTimeout

func (cli *Client) UpdateObjStatusWithTimeout(timeout time.Duration, obj client.Object, opts ...client.SubResourceUpdateOption) error

UpdateObjStatusWithTimeout update status obj with timeout

func (*Client) UpdateObjWithTimeout

func (cli *Client) UpdateObjWithTimeout(timeout time.Duration, obj client.Object, opts ...client.UpdateOption) error

UpdateObjWithTimeout update obj with timeout

type ClusterConfigInfo

type ClusterConfigInfo interface {
	GetName() string
	GetKubeConfig() string
	GetKubeContext() string
	GetKubeConfigType() KubeConfigType
}

ClusterConfigInfo cluster config info

func BuildClusterCfgInfo

func BuildClusterCfgInfo(name, kubeConfig, kubeContext string, kubeConfigType KubeConfigType) ClusterConfigInfo

BuildClusterCfgInfo build cluster info

type ClusterConfigurationManager

type ClusterConfigurationManager interface {
	GetAll() ([]ClusterConfigInfo, error)
	GetOptions() []Option
}

ClusterConfigurationManager cluster configuration manager

func NewClusterCfgManagerWithCM

func NewClusterCfgManagerWithCM(kubeInterface kubernetes.Interface, namespace string, label map[string]string, dataname string, options ...Option) ClusterConfigurationManager

NewClusterCfgManagerWithCM build clusterconfigmap

func NewClusterCfgManagerWithDir

func NewClusterCfgManagerWithDir(dir, suffix string, kubeConfigType KubeConfigType, options ...Option) (ClusterConfigurationManager, error)

NewClusterCfgManagerWithDir build clusterconfigdir

type InitHandler

type InitHandler func(*Client) error

InitHandler ...

type KubeConfigType

type KubeConfigType string
const (
	KubeConfigTypeRawString KubeConfigType = "RawString"
	KubeConfigTypeFile      KubeConfigType = "File"
)

Kubeconfig type

type MultiClient

type MultiClient struct {
	InitHandlerList []InitHandler
	// contains filtered or unexported fields
}

MultiClient multi cluster client obj

func NewMultiClient

func NewMultiClient(rebuildInterval time.Duration, clusterCfgMgr ClusterConfigurationManager) (*MultiClient, error)

NewMultiClient build MultiClient

func (*MultiClient) AddEventHandler

func (mc *MultiClient) AddEventHandler(obj client.Object, handler cache.ResourceEventHandler) error

AddEventHandler add event with multiclient

func (*MultiClient) GetAll

func (mc *MultiClient) GetAll() []*Client

GetAll get all cluster.

func (*MultiClient) GetAllConnected

func (mc *MultiClient) GetAllConnected() []*Client

GetAllConnected get all cluster when cluster is connected.

func (*MultiClient) GetAllReady

func (mc *MultiClient) GetAllReady() []*Client

GetAllReady get all cluster when cluster is connected and informer has synced

func (*MultiClient) GetConnectedWithName

func (mc *MultiClient) GetConnectedWithName(name string) (*Client, error)

GetConnectedWithName get cluster with name and cluster is healthy.

func (*MultiClient) GetReadyWithName

func (mc *MultiClient) GetReadyWithName(name string) (*Client, error)

GetReadyWithName get cluster with name and cluster is healthy and status ready.

func (*MultiClient) GetWithName

func (mc *MultiClient) GetWithName(name string) (*Client, error)

GetWithName get cluster with name.

func (*MultiClient) HasSynced

func (mc *MultiClient) HasSynced() bool

HasSynced return all cluster has synced

func (*MultiClient) Rebuild

func (mc *MultiClient) Rebuild() error

Rebuild rebuild with cluster info

func (*MultiClient) SetIndexField

func (mc *MultiClient) SetIndexField(obj client.Object, field string, extractValue client.IndexerFunc) error

SetIndexField set informer indexfield

func (*MultiClient) Start

func (mc *MultiClient) Start(ctx context.Context) error

Start start multiclient

func (*MultiClient) Stop

func (mc *MultiClient) Stop()

Stop multiclient

func (*MultiClient) TriggerSync

func (mc *MultiClient) TriggerSync(obj client.Object) error

TriggerSync only trigger informer sync obj

type Option

type Option func(*option)

func WithAutoHealthCheckInterval

func WithAutoHealthCheckInterval(interval time.Duration) Option

func WithKubeConfig

func WithKubeConfig(kubeConfig string) Option

func WithKubeConfigType

func WithKubeConfigType(typ KubeConfigType) Option

func WithKubeContext

func WithKubeContext(kubeContext string) Option

func WithKubeSetRsetConfigFn

func WithKubeSetRsetConfigFn(setKubeRestConfigFnList ...SetKubeRestConfigFn) Option

func WithRequestTimeout

func WithRequestTimeout(timeout time.Duration) Option

func WithRuntimeManagerOptions

func WithRuntimeManagerOptions(ctrlRtManagerOpts manager.Options) Option

type SetKubeRestConfigFn

type SetKubeRestConfigFn func(*rest.Config)

SetKubeRestConfigFn set kubernetes restconfig info

Jump to

Keyboard shortcuts

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