k8s

package
v0.0.10 Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2026 License: MIT Imports: 28 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DEFAULT_NAMESPACE_NAME = "default"
)

Variables

This section is empty.

Functions

func NewIntStr

func NewIntStr(v int) *intstr.IntOrString

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

func NewClient

func NewClient(kubeConfigYaml string) (*Client, error)

func NewClientFromFile

func NewClientFromFile(kubeConfPath string) (*Client, error)

func NewClientFromRestConfig

func NewClientFromRestConfig(restConf *rest.Config) (*Client, error)

func (*Client) Admin

func (c *Client) Admin() *admin.Client

集群管理

func (*Client) Config

func (c *Client) Config() *config.Client

应用配置

func (*Client) CurrentCluster

func (c *Client) CurrentCluster() *clientcmdapi.Cluster

func (*Client) CurrentContext

func (c *Client) CurrentContext() *clientcmdapi.Context

func (*Client) DeploymentWatcher

func (c *Client) DeploymentWatcher(namespaces ...string) *K8sWatcher[*appsv1.Deployment]

func (*Client) Event

func (c *Client) Event() *event.Client

应用事件

func (*Client) Gateway

func (c *Client) Gateway() (*gateway.Client, error)

func (*Client) GetContexts

func (c *Client) GetContexts() map[string]*clientcmdapi.Context

func (*Client) K8sClientSet

func (c *Client) K8sClientSet() *kubernetes.Clientset

func (*Client) Network

func (c *Client) Network() *network.Client

应用网络

func (*Client) PodWatcher

func (c *Client) PodWatcher(namespaces ...string) *K8sWatcher[*corev1.Pod]

func (*Client) ServerResources

func (c *Client) ServerResources() (*meta.ApiResourceList, error)

func (*Client) ServerVersion

func (c *Client) ServerVersion() (string, error)

func (*Client) ServiceWatcher

func (c *Client) ServiceWatcher(namespaces ...string) *K8sWatcher[*corev1.Service]

func (*Client) Storage

func (c *Client) Storage() *storage.Client

应用存储

func (*Client) WorkLoad

func (c *Client) WorkLoad() *workload.Client

应用负载

type K8sWatcher

type K8sWatcher[T runtime.Object] struct {
	// contains filtered or unexported fields
}

K8sWatcher 泛型Watcher,监听指定类型的资源

func NewK8sWatcher

func NewK8sWatcher[T runtime.Object](
	clientset kubernetes.Interface,
	namespaces []string,
	listFunc func(kubernetes.Interface, string, metav1.ListOptions) (runtime.Object, error),
	watchFunc func(kubernetes.Interface, string, metav1.ListOptions) (watch.Interface, error),
) *K8sWatcher[T]

NewK8sWatcher 创建泛型Watcher

func (*K8sWatcher[T]) GetName

func (w *K8sWatcher[T]) GetName() string

func (*K8sWatcher[T]) GetNamespaces

func (w *K8sWatcher[T]) GetNamespaces() []string

func (*K8sWatcher[T]) IsConfigUpdate

func (w *K8sWatcher[T]) IsConfigUpdate(configHash string) bool

func (*K8sWatcher[T]) OnError

func (w *K8sWatcher[T]) OnError(fn func(error))

func (*K8sWatcher[T]) RegisterHandler

func (w *K8sWatcher[T]) RegisterHandler(handler ResourceHandler[T])

RegisterHandler 注册泛型事件处理器

func (*K8sWatcher[T]) Run

func (w *K8sWatcher[T]) Run() error

Run 启动Watcher

func (*K8sWatcher[T]) SetConfigHash

func (w *K8sWatcher[T]) SetConfigHash(configHash string) *K8sWatcher[T]

func (*K8sWatcher[T]) SetName

func (w *K8sWatcher[T]) SetName(name string) *K8sWatcher[T]

func (*K8sWatcher[T]) Stop

func (w *K8sWatcher[T]) Stop()

Stop 停止Watcher

func (*K8sWatcher[T]) WithAnnotations

func (w *K8sWatcher[T]) WithAnnotations(key, value string) *K8sWatcher[T]

动态为对象补充集群信息, 方便后续处理

type RESOURCE

type RESOURCE string
const (
	RESOURCE_DEPLOYMENT RESOURCE = "deployments"
	RESOURCE_POD        RESOURCE = "pods"
	RESOURCE_SERVICE    RESOURCE = "services"
)

type ResourceHandler

type ResourceHandler[T runtime.Object] interface {
	OnAdd(obj T)
	OnUpdate(oldObj, newObj T)
	OnDelete(obj T)
}

ResourceHandler 定义泛型资源事件处理接口

type ResourceHandlerFunc

type ResourceHandlerFunc[T runtime.Object] struct {
	OnAddFunc    func(obj T)
	OnUpdateFunc func(oldObj, newObj T)
	OnDeleteFunc func(obj T)
}

ResourceHandlerFunc 是一个函数类型,直接实现 ResourceHandler 接口

func NewResourceHandlerFunc

func NewResourceHandlerFunc[T runtime.Object](
	onAddFunc func(obj T),
	onUpdateFunc func(oldObj, newObj T),
	onDeleteFunc func(obj T),
) *ResourceHandlerFunc[T]

func (*ResourceHandlerFunc[T]) OnAdd

func (f *ResourceHandlerFunc[T]) OnAdd(obj T)

func (*ResourceHandlerFunc[T]) OnDelete

func (f *ResourceHandlerFunc[T]) OnDelete(obj T)

func (*ResourceHandlerFunc[T]) OnUpdate

func (f *ResourceHandlerFunc[T]) OnUpdate(oldObj, newObj T)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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