k8sclient

package
v0.0.0-...-344df76 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2024 License: MIT Imports: 25 Imported by: 0

Documentation

Overview

Package k8sclient get k8s client

Index

Constants

View Source
const (
	// Containers ...
	Containers = "Containers"
	// InitContainers ...
	InitContainers = "InitContainers"
)

Variables

View Source
var (
	// 最多返回 10W 条日志
	MAX_TAIL_LINES  = int64(100 * 1000)
	MAX_LIMIT_BYTES = 30 * 1024 * 1024 // 最多 30M 数据

	// 默认返回 100 条日志
	DEFAULT_TAIL_LINES = int64(100)
)

需要取指针, 不能用常量

Functions

func DeleteBcsLogConfig

func DeleteBcsLogConfig(ctx context.Context, clusterID, namespace, name string) error

DeleteBcsLogConfig delete bcslogconfigs

func GetBCSConf

func GetBCSConf() *config.BCSConf

GetBCSConf 返回BCS配置

func GetBcsLogConfig

func GetBcsLogConfig(ctx context.Context, clusterID, namespace, name string) (*logv1.BcsLogConfig, error)

GetBcsLogConfig get bcslogconfigs

func GetClusterNetClientByClusterId

func GetClusterNetClientByClusterId(clusterId string) (*clusternet.Clientset, error)

GetClusterNetClientByClusterId 通过集群 ID 获取 clusternet client 对象

func GetClusterNodeList

func GetClusterNodeList(ctx context.Context, clusterId string, excludeMasterRole bool) ([]v1.Node, error)

GetClusterNodeList 获取集群中节点列表

func GetDynamicClientByClusterId

func GetDynamicClientByClusterId(clusterId string) (dynamic.Interface, error)

GetDynamicClientByClusterId 通过集群 ID 获取 k8s dynamic client 对象

func GetK8SClientByClusterId

func GetK8SClientByClusterId(clusterId string) (*kubernetes.Clientset, error)

GetK8SClientByClusterId 通过集群 ID 获取 k8s client 对象

func GetK8SVersion

func GetK8SVersion(ctx context.Context, clusterId string) (*version.Version, error)

GetK8SVersion 获取 k8s 版本

func GetKubebkbcsClientByClusterID

func GetKubebkbcsClientByClusterID(clusterID string) (*bcsclientset.Clientset, error)

GetKubebkbcsClientByClusterID 通过集群 ID 获取 kube bcs 对象

func GetManagedClusterList

func GetManagedClusterList(ctx context.Context, clusterID string) ([]string, error)

GetManagedClusterList 获取联邦集群子集群列表

func GetMasterNodeList

func GetMasterNodeList(ctx context.Context, clusterID string) ([]string, []string, error)

GetMasterNodeList 获取集群节点列表

func GetNamespaces

func GetNamespaces(ctx context.Context, clusterID string) ([]string, error)

GetNamespaces 获取集群的namespace列表

func GetNodeByName

func GetNodeByName(ctx context.Context, clusterId, name string) ([]string, error)

GetNodeByName 获取集群节点信息

func GetNodeCRVersionByName

func GetNodeCRVersionByName(ctx context.Context, clusterId, name string) (string, error)

GetNodeCRVersionByName 通过节点名称获取容器运行时版本

func GetNodeInfo

func GetNodeInfo(ctx context.Context, clusterId, nodeName string) (*v1.Node, error)

GetNodeInfo 获取节点信息 返回相应的节点对象

func GetNodeList

func GetNodeList(ctx context.Context, clusterID string, excludeMasterRole, filter bool) ([]string, []string, error)

GetNodeList 获取集群节点列表

func GetPodEntryValue

func GetPodEntryValue(ctx context.Context, clusterID, namespace, podname, key string) (string, error)

GetPodEntryValue :

func GetPodLogByte

func GetPodLogByte(ctx context.Context, clusterId, namespace, podname string, opt *LogQuery) ([]byte, error)

GetPodLogByte 获取日志

func GetPodLogStream

func GetPodLogStream(ctx context.Context, clusterId, namespace, podname string, opt *LogQuery) (<-chan *Log, error)

GetPodLogStream 获取日志流

func K8SLessThan

func K8SLessThan(ctx context.Context, clusterId, ver string) bool

K8SLessThan 对比版本, 如果异常, 按向下兼容

func ListBcsLogConfig

func ListBcsLogConfig(ctx context.Context, clusterID string) ([]logv1.BcsLogConfig, error)

ListBcsLogConfig list bcslogconfigs

Types

type Container

type Container struct {
	Name          string `json:"name"`
	ContainerType string `json:"container_type"`
}

Container 格式化的容器, 精简后的 v1.Container

func GetPodContainers

func GetPodContainers(ctx context.Context, clusterId, namespace, podname string) ([]*Container, error)

GetPodContainers 获取 Pod 容器名称列表

type Item

type Item struct {
	Metadata *Metadata `json:"metadata"`
}

Item :

type Log

type Log struct {
	Log  string `json:"log"`
	Time string `json:"time"`
}

Log 格式化的日志

type LogQuery

type LogQuery struct {
	ContainerName string `form:"container_name" binding:"required"` // 必填参数
	Previous      bool   `form:"previous"`
	StartedAt     string `form:"started_at"`
	FinishedAt    string `form:"finished_at"`
	TailLines     int64  `form:"-"`
	LimitBytes    int64  `form:"-"`
	// contains filtered or unexported fields
}

LogQuery 日志查询参数, 精简后的 v1.PodLogOptions

type LogWithPreviousLink struct {
	Logs     []*Log `json:"logs"`
	Previous string `json:"previous"` // 向上翻页链接
}

LogWithPreviousLink :

func GetPodLog

func GetPodLog(ctx context.Context, clusterId, namespace, podname string, opt *LogQuery) (*LogWithPreviousLink, error)

GetPodLog 获取格式的日志列表

func (l *LogWithPreviousLink) MakePreviousLink(projectId, clusterId, namespace, podname string, opt *LogQuery) error

MakePreviousLink 计算向上翻页链接

type Metadata

type Metadata struct {
	Name        string `json:"name"`
	Labels      Set    `json:"labels"`
	Annotations Set    `json:"annotations"`
}

Metadata :

type Set

type Set map[string]string

Set is a map of label:value. It implements Labels. https://github.com/kubernetes/apimachinery/blob/master/pkg/labels/labels.go

type Workload

type Workload struct {
	Kind       string    `json:"kind"`
	ApiVersion string    `json:"apiVersion"`
	Metadata   *Metadata `json:"metadata"`
	Items      []*Item   `json:"items,omitempty"` // 类型是 NamespaceList 等有值
}

Workload 简化版 worload

func GetPod

func GetPod(ctx context.Context, clusterID, namespace, podname string) (*Workload, error)

GetPod 单个Pod, 查询缓存

Jump to

Keyboard shortcuts

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