Documentation
¶
Index ¶
- Constants
- Variables
- func ApiData(c *gin.Context, code int, data interface{}, message string)
- func ApplyLimitRange(ctx context.Context, kubeClient *kubernetes.Clientset, namespace string, ...) error
- func ApplyResourceQuota(ctx context.Context, kubeClient *kubernetes.Clientset, namespace string, ...) error
- func AtomicWriteFile(filePath string, data []byte) error
- func BadRequest(c *gin.Context, code int, data interface{}, message string)
- func BadRequestError(c *gin.Context, message string)
- func BadRequestWithDetails(c *gin.Context, data interface{}, message string)
- func Base64Decrypt(encryptedPassword string) (string, error)
- func Base64DecryptWithMagic(encryptedPassword string) (string, error)
- func Base64Encrypt(password string) string
- func Base64EncryptWithMagic(password string) string
- func BatchDeleteK8sInstance(ctx context.Context, deploymentRequests []*model.K8sDeploymentRequest, ...) error
- func BatchRestartK8sInstance(ctx context.Context, deploymentRequests []model.K8sDeploymentRequest, ...) error
- func BuildCronJobConfig(req *model.K8sInstance) *batchv1.CronJob
- func BuildDaemonSetConfig(req *model.K8sInstance) *appsv1.DaemonSet
- func BuildDeploymentConfig(req *model.K8sInstance) *appsv1.Deployment
- func BuildJobConfig(req *model.K8sInstance) *batchv1.Job
- func BuildK8sContainers(containers []corev1.Container) []model.K8sPodContainer
- func BuildK8sContainersWithPointer(k8sContainers []model.K8sPodContainer) []*model.K8sPodContainer
- func BuildK8sNode(ctx context.Context, id int, node corev1.Node, ...) (*model.K8sNode, error)
- func BuildK8sPods(pods *corev1.PodList) []*model.K8sPod
- func BuildMatchers(alertEvent *model.MonitorAlertEvent, l *zap.Logger, useName int8) ([]*labels.Matcher, error)
- func BuildStatefulSetConfig(req *model.K8sInstance) *appsv1.StatefulSet
- func CalculateAlertHash(pool *model.MonitorAlertManagerPool) string
- func CalculatePromHash(pool *model.MonitorScrapePool) string
- func CheckAlertIpExists(req *model.MonitorAlertManagerPool, pools []*model.MonitorAlertManagerPool) error
- func CheckAlertsIpExists(req *model.MonitorAlertManagerPool, rules []*model.MonitorAlertManagerPool) bool
- func CheckPoolIpExists(pools []*model.MonitorScrapePool, req *model.MonitorScrapePool) error
- func CleanupFailedPool(localYamlDir string, pool *model.MonitorScrapePool, instances int)
- func CleanupOldIPs(tempConfigMap map[string]string, updatedPools map[string]struct{}, ...)
- func CloneMap(original map[string]string) map[string]string
- func CopyMap[K comparable, V any](src map[K]V) map[K]V
- func CreateDeployment(ctx context.Context, deploymentRequest *model.K8sDeploymentRequest, ...) error
- func CreateService(ctx context.Context, serviceRequest *model.K8sServiceRequest, ...) error
- func DecryptBatch(encryptedSecretKeys []string, encryptionKey []byte) ([]string, error)
- func DecryptSecretKey(encryptedSecretKey string, encryptionKey []byte) (string, error)
- func DeepCopyScrapeConfig(sc *pc.ScrapeConfig) *pc.ScrapeConfig
- func DeleteDeployment(ctx context.Context, deploymentRequest *model.K8sDeploymentRequest, ...) error
- func DeleteService(ctx context.Context, serviceRequest *model.K8sServiceRequest, ...) error
- func DeleteWithId(l *zap.Logger, funcName string, timeout int, url string, ...) ([]byte, error)
- func EncryptBatch(secretKeys []string, encryptionKey []byte) ([]string, error)
- func EncryptSecretKey(secretKey string, encryptionKey []byte) (string, error)
- func EnsureNamespace(ctx context.Context, kubeClient *kubernetes.Clientset, namespace string) error
- func Error(c *gin.Context)
- func ErrorWithDetails(c *gin.Context, data interface{}, message string)
- func ErrorWithMessage(c *gin.Context, message string)
- func ExtractUserNames(users []*model.User) []string
- func Forbidden(c *gin.Context, data interface{}, message string)
- func ForbiddenError(c *gin.Context, message string)
- func FormatMap(m map[string]string) string
- func FromSliceTuMap(kvs []string) map[string]string
- func GenPromDuration(seconds int) promModel.Duration
- func GenerateKeyFromPassword(password string, salt []byte) ([]byte, error)
- func GenerateRandomKey() ([]byte, error)
- func GenerateRandomSalt() ([]byte, error)
- func GetClientIP(r *http.Request) string
- func GetDaemonSetResources(ctx context.Context, kubeClient *kubernetes.Clientset, namespace string) ([]model.Resource, error)
- func GetDeploymentResources(ctx context.Context, kubeClient *kubernetes.Clientset, namespace string) ([]model.Resource, error)
- func GetDynamicClient(ctx context.Context, id int, clusterDao admin.ClusterDAO, ...) (*dynamic.DynamicClient, error)
- func GetInternalIP(node corev1.Node) string
- func GetKubeAndMetricsClient(id int, logger *zap.Logger, client client.K8sClient) (*kubernetes.Clientset, *metricsClient.Clientset, error)
- func GetKubeClient(clusterId int, client client.K8sClient, l *zap.Logger) (*kubernetes.Clientset, error)
- func GetLocalIPs() ([]string, error)
- func GetNodeAge(node corev1.Node) string
- func GetNodeEvents(ctx context.Context, client *kubernetes.Clientset, nodeName string) ([]model.OneEvent, error)
- func GetNodeLabels(node corev1.Node) []string
- func GetNodeResource(ctx context.Context, metricsCli *metricsClient.Clientset, nodeName string, ...) ([]string, error)
- func GetNodeRoles(node corev1.Node) []string
- func GetNodeStatus(node corev1.Node) string
- func GetNodesByName(ctx context.Context, client *kubernetes.Clientset, nodeName string) (*corev1.NodeList, error)
- func GetParamID(ctx *gin.Context) (int, error)
- func GetParamName(ctx *gin.Context) (string, error)
- func GetPodResources(ctx context.Context, kubeClient *kubernetes.Clientset, namespace string) ([]model.Resource, error)
- func GetPodsByNodeName(ctx context.Context, client *kubernetes.Clientset, nodeName string) (*corev1.PodList, error)
- func GetQueryParam[T any](ctx *gin.Context, key string) (T, error)
- func GetReplicaSetResources(ctx context.Context, kubeClient *kubernetes.Clientset, namespace string) ([]model.Resource, error)
- func GetResourceName(kind string) string
- func GetResourceString(node corev1.Node, resourceName string) string
- func GetServiceResources(ctx context.Context, kubeClient *kubernetes.Clientset, namespace string) ([]model.Resource, error)
- func GetStatefulSetResources(ctx context.Context, kubeClient *kubernetes.Clientset, namespace string) ([]model.Resource, error)
- func GetStringParam(ctx *gin.Context, key string) (string, error)
- func GetTaintsMapFromTaints(taints []corev1.Taint) map[string]corev1.Taint
- func HandleRequest(ctx *gin.Context, req interface{}, action func() (interface{}, error))
- func InitAadGetKubeClient(ctx context.Context, cluster *model.K8sCluster, logger *zap.Logger, ...) (*kubernetes.Clientset, error)
- func InternalServerError(c *gin.Context, code int, data interface{}, message string)
- func InternalServerErrorWithDetails(c *gin.Context, data interface{}, message string)
- func IsNodeSchedulable(node corev1.Node) bool
- func MapToStringSlice(inputMap map[string]string) ([]string, error)
- func MergeTaints(existingTaints []corev1.Taint, newTaints []corev1.Taint) []corev1.Taint
- func ParseExternalLabels(labelsList []string) []string
- func ParseTags(tags []string) (map[promModel.LabelName]promModel.LabelValue, error)
- func ParseURL(u string) (*pcc.URL, error)
- func Ping(ipAddr string) bool
- func PostWithJson(ctx context.Context, client *http.Client, l *zap.Logger, url string, ...) ([]byte, error)
- func PostWithJsonString(l *zap.Logger, funcName string, timeout int, url string, jsonStr string, ...) ([]byte, error)
- func PromqlExprCheck(expr string) (bool, error)
- func RemoveTaints(existingTaints []corev1.Taint, taintsToDelete []corev1.Taint) []corev1.Taint
- func RestartDeployment(ctx context.Context, deploymentRequest *model.K8sDeploymentRequest, ...) error
- func SecureZeroMemory(data []byte)
- func SendSilenceRequest(ctx context.Context, l *zap.Logger, url string, data []byte) (string, error)
- func SetUserInfoToContext(ctx context.Context, userInfo *UserInfo) context.Context
- func SetUserInfoToGinContext(c *gin.Context, userInfo *UserInfo)
- func StringSliceToMap(inputSlice []string) (map[string]string, error)
- func Success(c *gin.Context)
- func SuccessWithData(c *gin.Context, data interface{})
- func SuccessWithDetails(c *gin.Context, data interface{}, message string)
- func SuccessWithMessage(c *gin.Context, message string)
- func Unauthorized(c *gin.Context, code int, data interface{}, message string)
- func UnauthorizedErrorWithDetails(c *gin.Context, data interface{}, message string)
- func UpdateDeployment(ctx context.Context, deploymentRequest *model.K8sDeploymentRequest, ...) error
- func UpdateService(ctx context.Context, serviceRequest *model.K8sServiceRequest, ...) error
- func ValidateEncryptedData(encryptedData string) error
- func ValidateUniqueResource[T any](ctx context.Context, ...) error
- type ApiResponse
- type ContainerInfo
- type Handler
- type K8sBatchRequest
- type K8sInstanceReply
- type K8sObjectRequest
- type K8sRequestItem
- type KeyValuePair
- type LabelOption
- type OperationData
- type RefreshClaims
- type SelectOption
- type SelectOptionInt
- type SilenceResponse
- type UserClaims
- type UserInfo
Constants ¶
const ( StatusError = 1 // 操作失败 StatusSuccess = 0 // 操作成功 )
定义操作成功和失败的常量状态码
Variables ¶
var UpGrader = websocket.Upgrader{ CheckOrigin: func(r *http.Request) bool { return true }, }
UpGrader 升级HTTP连接为WebSocket连接
Functions ¶
func ApiData ¶
ApiData 通用的返回函数,用于标准化API响应格式 参数: - c: gin 上下文 - code: 状态码 - data: 返回的数据 - message: 返回的消息
func ApplyLimitRange ¶
func ApplyLimitRange(ctx context.Context, kubeClient *kubernetes.Clientset, namespace string, cluster *model.K8sCluster) error
ApplyLimitRange 应用 LimitRange 到指定命名空间
func ApplyResourceQuota ¶
func ApplyResourceQuota(ctx context.Context, kubeClient *kubernetes.Clientset, namespace string, cluster *model.K8sCluster) error
ApplyResourceQuota 应用 ResourceQuota 到指定命名空间
func BadRequest ¶
BadRequest 参数错误的返回,使用HTTP 400状态码
func BadRequestError ¶
BadRequestError 参数错误的失败返回
func BadRequestWithDetails ¶
BadRequestWithDetails 带详细数据和消息的参数错误返回
func Base64Decrypt ¶
Base64Decrypt 用于解密加密后的密码
func Base64DecryptWithMagic ¶
Base64DecryptWithMagic 解密 与加密过程相反的步骤还原原始密码
func Base64EncryptWithMagic ¶
Base64EncryptWithMagic 加密 通过先添加特定盐值、反转字符串再进行base64编码
func BatchDeleteK8sInstance ¶
func BatchDeleteK8sInstance(ctx context.Context, deploymentRequests []*model.K8sDeploymentRequest, serviceRequests []*model.K8sServiceRequest, client client.K8sClient, logger *zap.Logger) error
BatchDeleteK8sInstance 批量删除 Kubernetes 实例
func BatchRestartK8sInstance ¶
func BatchRestartK8sInstance(ctx context.Context, deploymentRequests []model.K8sDeploymentRequest, client client.K8sClient, logger *zap.Logger) error
BatchRestartK8sInstance 批量重启 Kubernetes 实例
func BuildCronJobConfig ¶
func BuildCronJobConfig(req *model.K8sInstance) *batchv1.CronJob
构建CronJob创建配置
func BuildDaemonSetConfig ¶
func BuildDaemonSetConfig(req *model.K8sInstance) *appsv1.DaemonSet
构建DaemonSet创建配置
func BuildDeploymentConfig ¶
func BuildDeploymentConfig(req *model.K8sInstance) *appsv1.Deployment
构建Deployment创建配置
func BuildK8sContainers ¶
func BuildK8sContainers(containers []corev1.Container) []model.K8sPodContainer
BuildK8sContainers 构建 K8sContainer 列表
func BuildK8sContainersWithPointer ¶
func BuildK8sContainersWithPointer(k8sContainers []model.K8sPodContainer) []*model.K8sPodContainer
BuildK8sContainersWithPointer 转换普通切片为指针切片
func BuildK8sNode ¶
func BuildK8sPods ¶
BuildK8sPods BuildK8sNodes 构建 K8sNode 列表
func BuildMatchers ¶
func BuildStatefulSetConfig ¶
func BuildStatefulSetConfig(req *model.K8sInstance) *appsv1.StatefulSet
构建StatefulSet创建配置
func CalculateAlertHash ¶
func CalculateAlertHash(pool *model.MonitorAlertManagerPool) string
func CalculatePromHash ¶
func CalculatePromHash(pool *model.MonitorScrapePool) string
CalculateHash 计算哈希值
func CheckAlertIpExists ¶
func CheckAlertIpExists(req *model.MonitorAlertManagerPool, pools []*model.MonitorAlertManagerPool) error
func CheckAlertsIpExists ¶
func CheckAlertsIpExists(req *model.MonitorAlertManagerPool, rules []*model.MonitorAlertManagerPool) bool
func CheckPoolIpExists ¶
func CheckPoolIpExists(pools []*model.MonitorScrapePool, req *model.MonitorScrapePool) error
func CleanupFailedPool ¶
func CleanupFailedPool(localYamlDir string, pool *model.MonitorScrapePool, instances int)
清理失败池子的临时文件
func CleanupOldIPs ¶
func CleanupOldIPs(tempConfigMap map[string]string, updatedPools map[string]struct{}, validIPs map[string]struct{})
清理已更新池子的旧IP
func CreateDeployment ¶
func CreateDeployment(ctx context.Context, deploymentRequest *model.K8sDeploymentRequest, client client.K8sClient, logger *zap.Logger) error
CreateDeployment 创建 Deployment
func CreateService ¶
func CreateService(ctx context.Context, serviceRequest *model.K8sServiceRequest, client client.K8sClient, logger *zap.Logger) error
CreateService 创建 Kubernetes Service
func DecryptBatch ¶
DecryptBatch 批量解密
func DecryptSecretKey ¶
DecryptSecretKey 使用指定密钥解密数据
func DeepCopyScrapeConfig ¶
func DeepCopyScrapeConfig(sc *pc.ScrapeConfig) *pc.ScrapeConfig
DeepCopyScrapeConfig 深度拷贝 ScrapeConfig
func DeleteDeployment ¶
func DeleteDeployment(ctx context.Context, deploymentRequest *model.K8sDeploymentRequest, client client.K8sClient, logger *zap.Logger) error
DeleteDeployment 删除 Deployment
func DeleteService ¶
func DeleteService(ctx context.Context, serviceRequest *model.K8sServiceRequest, client client.K8sClient, logger *zap.Logger) error
DeleteService 删除 Service
func DeleteWithId ¶
func EncryptBatch ¶
EncryptBatch 批量加密
func EncryptSecretKey ¶
EncryptSecretKey 使用指定密钥加密数据
func EnsureNamespace ¶
EnsureNamespace 确保指定的命名空间存在,如果不存在则创建
func ErrorWithDetails ¶
ErrorWithDetails 带详细数据和消息的操作失败返回
func ErrorWithMessage ¶
ErrorWithMessage 带消息的操作失败返回
func ExtractUserNames ¶
func FromSliceTuMap ¶
func GenPromDuration ¶
GenPromDuration 转换秒为Prometheus Duration
func GenerateKeyFromPassword ¶
GenerateKeyFromPassword 从密码生成密钥(使用PBKDF2)
func GetDaemonSetResources ¶
func GetDaemonSetResources(ctx context.Context, kubeClient *kubernetes.Clientset, namespace string) ([]model.Resource, error)
GetDaemonSetResources 获取 DaemonSet 资源
func GetDeploymentResources ¶
func GetDeploymentResources(ctx context.Context, kubeClient *kubernetes.Clientset, namespace string) ([]model.Resource, error)
GetDeploymentResources 获取 Deployment 资源
func GetDynamicClient ¶
func GetDynamicClient(ctx context.Context, id int, clusterDao admin.ClusterDAO, client client.K8sClient) (*dynamic.DynamicClient, error)
func GetKubeAndMetricsClient ¶
func GetKubeAndMetricsClient(id int, logger *zap.Logger, client client.K8sClient) (*kubernetes.Clientset, *metricsClient.Clientset, error)
func GetKubeClient ¶
func GetKubeClient(clusterId int, client client.K8sClient, l *zap.Logger) (*kubernetes.Clientset, error)
GetKubeClient 获取 Kubernetes 客户端
func GetLocalIPs ¶
func GetNodeEvents ¶
func GetNodeEvents(ctx context.Context, client *kubernetes.Clientset, nodeName string) ([]model.OneEvent, error)
GetNodeEvents 获取节点事件
func GetNodeResource ¶
func GetNodeResource(ctx context.Context, metricsCli *metricsClient.Clientset, nodeName string, pods *corev1.PodList, node *corev1.Node) ([]string, error)
GetNodeResource 获取节点资源信息
func GetNodesByName ¶
func GetNodesByName(ctx context.Context, client *kubernetes.Clientset, nodeName string) (*corev1.NodeList, error)
GetNodesByName 获取指定集群上的 Node 列表
func GetParamName ¶
GetParamName 从查询参数中解析 Name,并进行类型转换
func GetPodResources ¶
func GetPodResources(ctx context.Context, kubeClient *kubernetes.Clientset, namespace string) ([]model.Resource, error)
GetPodResources 获取 Pod 资源
func GetPodsByNodeName ¶
func GetPodsByNodeName(ctx context.Context, client *kubernetes.Clientset, nodeName string) (*corev1.PodList, error)
GetPodsByNodeName 获取指定节点上的 Pod 列表
func GetQueryParam ¶
GetQueryParam 从查询参数中解析指定类型的值
func GetReplicaSetResources ¶
func GetReplicaSetResources(ctx context.Context, kubeClient *kubernetes.Clientset, namespace string) ([]model.Resource, error)
GetReplicaSetResources 获取 ReplicaSet 资源
func GetResourceString ¶
GetResourceString 获取节点资源信息
func GetServiceResources ¶
func GetServiceResources(ctx context.Context, kubeClient *kubernetes.Clientset, namespace string) ([]model.Resource, error)
GetServiceResources 获取 Service 资源
func GetStatefulSetResources ¶
func GetStatefulSetResources(ctx context.Context, kubeClient *kubernetes.Clientset, namespace string) ([]model.Resource, error)
GetStatefulSetResources 获取 StatefulSet 资源
func GetTaintsMapFromTaints ¶
GetTaintsMapFromTaints 将 taints 转换为键为 "Key:Value:Effect" 的 map
func HandleRequest ¶
HandleRequest 用于统一处理请求绑定和响应
func InitAadGetKubeClient ¶
func InternalServerError ¶
InternalServerError 服务器内部错误的返回,使用HTTP 500状态码
func InternalServerErrorWithDetails ¶
InternalServerErrorWithDetails 带详细数据和消息的服务器内部错误返回
func MapToStringSlice ¶
MapToStringSlice 将 map 转换为 []string,要求偶数个元素,key和值依次排列
func MergeTaints ¶
MergeTaints 合并新的 taints,避免重复
func ParseExternalLabels ¶
ParseExternalLabels 解析外部标签
func PostWithJson ¶
func PostWithJson(ctx context.Context, client *http.Client, l *zap.Logger, url string, jsonStr string, params map[string]string, headers map[string]string) ([]byte, error)
PostWithJson 发送带有JSON字符串的POST请求
func PostWithJsonString ¶
func PostWithJsonString(l *zap.Logger, funcName string, timeout int, url string, jsonStr string, paramsMap map[string]string, headerMap map[string]string) ([]byte, error)
PostWithJsonString 发送带 JSON 数据的 POST 请求
func PromqlExprCheck ¶
func RemoveTaints ¶
RemoveTaints 从现有的 taints 中删除指定的 taints
func RestartDeployment ¶
func RestartDeployment(ctx context.Context, deploymentRequest *model.K8sDeploymentRequest, client client.K8sClient, logger *zap.Logger) error
RestartDeployment 触发 Deployment 重启
func SendSilenceRequest ¶
func SetUserInfoToContext ¶
SetUserInfoToContext 将用户信息设置到context中
func SetUserInfoToGinContext ¶
SetUserInfoToGinContext 将用户信息设置到gin.Context中
func StringSliceToMap ¶
StringSliceToMap 将 []string 转换为 map[string]string,要求输入长度为偶数,奇数索引为 key,偶数索引为 value
func SuccessWithData ¶
SuccessWithData 带数据的操作成功返回
func SuccessWithDetails ¶
SuccessWithDetails 带详细数据和消息的操作成功返回
func SuccessWithMessage ¶
SuccessWithMessage 带消息的操作成功返回
func Unauthorized ¶
Unauthorized 未认证的返回,使用HTTP 401状态码
func UnauthorizedErrorWithDetails ¶
UnauthorizedErrorWithDetails 带详细数据和消息的未认证返回
func UpdateDeployment ¶
func UpdateDeployment(ctx context.Context, deploymentRequest *model.K8sDeploymentRequest, client client.K8sClient, logger *zap.Logger) error
UpdateDeployment 更新或创建 Deployment
func UpdateService ¶
func UpdateService(ctx context.Context, serviceRequest *model.K8sServiceRequest, client client.K8sClient, logger *zap.Logger) error
UpdateService 更新或创建 Service
func ValidateEncryptedData ¶
ValidateEncryptedData 验证加密数据格式
Types ¶
type ApiResponse ¶
type ApiResponse struct { Code int `json:"code"` // 状态码,表示业务逻辑的状态,而非HTTP状态码 Data interface{} `json:"data"` // 响应数据 Message string `json:"message"` // 反馈信息 Type string `json:"type"` // 消息类型 }
ApiResponse 通用的API响应结构体
type ContainerInfo ¶
type ContainerInfo struct { Name string `json:"name"` Image string `json:"image"` Ports []int `json:"ports"` }
ContainerInfo 结构体,存储容器的信息
type Handler ¶
type Handler interface { SetLoginToken(ctx *gin.Context, uid int, username string, accountType int8) (string, string, error) SetJWTToken(ctx *gin.Context, uid int, username string, ssid string, accountType int8) (string, error) ExtractToken(ctx *gin.Context) string CheckSession(ctx *gin.Context, ssid string) error ClearToken(ctx *gin.Context) error // contains filtered or unexported methods }
func NewJWTHandler ¶
func NewJWTHandler(c redis.Cmdable) Handler
type K8sBatchRequest ¶
type K8sBatchRequest struct { Cluster string `json:"cluster"` Items []K8sRequestItem `json:"items"` }
type K8sInstanceReply ¶
type K8sInstanceReply struct { Name string `json:"name"` Status string `json:"status"` Replicas int32 `json:"replicas"` Containers []ContainerInfo `json:"containers"` }
K8sInstance 结构体,存储实例的信息,包括 Deployment 和相关容器
type K8sObjectRequest ¶
type K8sRequestItem ¶
type KeyValuePair ¶
type LabelOption ¶
type LabelOption struct { Label string `json:"label"` Value string `json:"value"` Children []*LabelOption `json:"children"` }
LabelOption 通用返回结构体,用于前后端交互的数据格式
type OperationData ¶
type RefreshClaims ¶
type SelectOption ¶
type SelectOptionInt ¶
type SilenceResponse ¶
type UserClaims ¶
type UserInfo ¶
type UserInfo struct { UserID int `json:"userId"` Username string `json:"username"` IP string `json:"ip"` UserAgent string `json:"userAgent"` }
UserInfo 用户信息结构体
func GetUserInfoFromContext ¶
GetUserInfoFromContext 从context.Context中获取用户信息
func GetUserInfoFromGinContext ¶
GetUserInfoFromGinContext 从gin.Context中获取用户信息
func GetUserInfoFromHTTPRequest ¶
GetUserInfoFromHTTPRequest 从http.Request中获取用户信息