utils

package
v0.0.13 Latest Latest
Warning

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

Go to latest
Published: Oct 5, 2025 License: MIT Imports: 32 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// 通用状态
	StatusPending     = "Pending"
	StatusUnknown     = "Unknown"
	StatusReady       = "Ready"
	StatusTerminating = "Terminating"
	StatusRunning     = "Running"
	StatusUpdating    = "Updating"
	StatusSucceeded   = "Succeeded"
	StatusFailed      = "Failed"
	StatusEvicted     = "Evicted"
)

K8s资源状态常量定义

Variables

View Source
var NormalReasons = map[string]model.EventSeverity{
	"Scheduled":        model.EventSeverityLow,
	"Pulling":          model.EventSeverityLow,
	"Pulled":           model.EventSeverityLow,
	"Created":          model.EventSeverityLow,
	"Started":          model.EventSeverityLow,
	"Killing":          model.EventSeverityLow,
	"Preempting":       model.EventSeverityLow,
	"SuccessfulMount":  model.EventSeverityLow,
	"SuccessfulDelete": model.EventSeverityLow,
	"Sync":             model.EventSeverityLow,
}

NormalReasons 正常级别的事件原因

View Source
var WarningReasons = map[string]model.EventSeverity{
	"Failed":              model.EventSeverityHigh,
	"FailedMount":         model.EventSeverityHigh,
	"FailedScheduling":    model.EventSeverityHigh,
	"FailedSync":          model.EventSeverityMedium,
	"FailedValidation":    model.EventSeverityMedium,
	"Unhealthy":           model.EventSeverityHigh,
	"BackOff":             model.EventSeverityMedium,
	"DeadlineExceeded":    model.EventSeverityCritical,
	"Evicted":             model.EventSeverityHigh,
	"NodeNotReady":        model.EventSeverityCritical,
	"NodeNotSchedulable":  model.EventSeverityMedium,
	"OutOfDisk":           model.EventSeverityCritical,
	"OutOfMemory":         model.EventSeverityCritical,
	"FreeDiskSpaceFailed": model.EventSeverityHigh,
}

WarningReasons 警告级别的事件原因

Functions

func AddClusterResourceLimit

func AddClusterResourceLimit(ctx context.Context, client kubernetes.Interface, cluster *model.K8sCluster) error

func AddOrUpdateTaint

func AddOrUpdateTaint(taints []corev1.Taint, newTaint corev1.Taint) []corev1.Taint

func ApplySingleDocument

func ApplySingleDocument(ctx context.Context, document string, restMapper meta.RESTMapper, dynamicClient dynamic.Interface, docIndex int) error

func ApplyYamlToCluster

func ApplyYamlToCluster(ctx context.Context, discoveryClient discovery.DiscoveryInterface, dynamicClient dynamic.Interface, yamlContent string) error

func BuildClusterRoleBindingListOptions

func BuildClusterRoleBindingListOptions(req *model.GetClusterRoleBindingListReq) metav1.ListOptions

func BuildClusterRoleListOptions

func BuildClusterRoleListOptions(req *model.GetClusterRoleListReq) metav1.ListOptions

func BuildClusterRoleListQueryOptions

func BuildClusterRoleListQueryOptions(req *model.GetClusterRoleListReq) metav1.ListOptions

func BuildConfigMapListOptions

func BuildConfigMapListOptions(labelSelector string) metav1.ListOptions

func BuildDaemonSetFromRequest

func BuildDaemonSetFromRequest(req *model.CreateDaemonSetReq) (*appsv1.DaemonSet, error)

func BuildDaemonSetFromYaml added in v0.0.4

func BuildDaemonSetFromYaml(req *model.CreateDaemonSetByYamlReq) (*appsv1.DaemonSet, error)

func BuildDaemonSetFromYamlForUpdate added in v0.0.4

func BuildDaemonSetFromYamlForUpdate(req *model.UpdateDaemonSetByYamlReq) (*appsv1.DaemonSet, error)

func BuildDaemonSetListOptions

func BuildDaemonSetListOptions(req *model.GetDaemonSetListReq) metav1.ListOptions

func BuildDeleteOptions

func BuildDeleteOptions(gracePeriodSeconds int) metav1.DeleteOptions

func BuildDeploymentFromRequest

func BuildDeploymentFromRequest(req *model.CreateDeploymentReq) (*appsv1.Deployment, error)

func BuildDeploymentFromYaml

func BuildDeploymentFromYaml(req *model.CreateDeploymentByYamlReq) (*appsv1.Deployment, error)

func BuildDeploymentFromYamlForUpdate

func BuildDeploymentFromYamlForUpdate(req *model.UpdateDeploymentByYamlReq) (*appsv1.Deployment, error)

func BuildDeploymentListOptions

func BuildDeploymentListOptions(req *model.GetDeploymentListReq) metav1.ListOptions

func BuildDeploymentListPagination

func BuildDeploymentListPagination(deployments []appsv1.Deployment, page, size int) ([]appsv1.Deployment, int64)

func BuildIngressFromSpec

func BuildIngressFromSpec(req *model.CreateIngressReq) (*networkingv1.Ingress, error)

BuildIngressFromSpec 根据请求构建Ingress对象

func BuildIngressListOptions

func BuildIngressListOptions(req *model.GetIngressListReq) metav1.ListOptions

func BuildK8sClusterRole

func BuildK8sClusterRole(name string, labels, annotations model.KeyValueList, rules []model.PolicyRule) *rbacv1.ClusterRole

func BuildK8sClusterRoleBinding

func BuildK8sClusterRoleBinding(name string, labels, annotations model.KeyValueList, roleRef model.RoleRef, subjects []model.Subject) *rbacv1.ClusterRoleBinding

func BuildK8sDaemonSet

func BuildK8sDaemonSet(ctx context.Context, clusterID int, daemonSet appsv1.DaemonSet) (*model.K8sDaemonSet, error)

func BuildK8sDaemonSetHistory

func BuildK8sDaemonSetHistory(revision appsv1.ControllerRevision) (*model.K8sDaemonSetHistory, error)

func BuildK8sDeployment

func BuildK8sDeployment(ctx context.Context, clusterID int, deployment appsv1.Deployment) (*model.K8sDeployment, error)

func BuildK8sNode

func BuildK8sNode(ctx context.Context, clusterID int, node corev1.Node, kubeClient *kubernetes.Clientset, metricsClient interface{}) (*model.K8sNode, error)

func BuildK8sRole

func BuildK8sRole(name, namespace string, labels, annotations model.KeyValueList, rules []model.PolicyRule) *rbacv1.Role

func BuildK8sRoleBinding

func BuildK8sRoleBinding(name, namespace string, labels, annotations model.KeyValueList, roleRef model.RoleRef, subjects []model.Subject) *rbacv1.RoleBinding

func BuildK8sServiceAccount

func BuildK8sServiceAccount(name, namespace string, labels, annotations model.KeyValueList) *corev1.ServiceAccount

func BuildK8sServiceFromCore added in v0.0.8

func BuildK8sServiceFromCore(clusterID int, service corev1.Service) *model.K8sService

func BuildK8sStatefulSet

func BuildK8sStatefulSet(ctx context.Context, clusterID int, statefulSet appsv1.StatefulSet) (*model.K8sStatefulSet, error)

func BuildK8sStatefulSetHistory

func BuildK8sStatefulSetHistory(revision appsv1.ControllerRevision) (*model.K8sStatefulSetHistory, error)

func BuildNamespaceListOptions

func BuildNamespaceListOptions(req *model.K8sNamespaceListReq) metav1.ListOptions

func BuildNamespaceListPagination

func BuildNamespaceListPagination(namespaces []corev1.Namespace, page, size int) ([]corev1.Namespace, int64)

func BuildNodeListOptions

func BuildNodeListOptions(req *model.GetNodeListReq) metav1.ListOptions

func BuildNodeListPagination

func BuildNodeListPagination(nodes []corev1.Node, page, size int) ([]corev1.Node, int64)

func BuildNodeTaints

func BuildNodeTaints(taints []corev1.Taint) ([]*model.NodeTaint, int64)

func BuildPVCListOptions

func BuildPVCListOptions(req *model.GetPVCListReq) metav1.ListOptions

func BuildPVListOptions

func BuildPVListOptions(req *model.GetPVListReq) metav1.ListOptions

func BuildPodFromRequest

func BuildPodFromRequest(req *model.CreatePodReq) (*corev1.Pod, error)

func BuildRoleBindingListOptions

func BuildRoleBindingListOptions(req *model.GetRoleBindingListReq) metav1.ListOptions

func BuildRoleListOptions

func BuildRoleListOptions(req *model.GetRoleListReq) metav1.ListOptions

func BuildSecretFromRequest

func BuildSecretFromRequest(req *model.CreateSecretReq) (*corev1.Secret, error)

func BuildServiceAccountListOptions

func BuildServiceAccountListOptions(req *model.GetServiceAccountListReq) metav1.ListOptions

func BuildServiceAccountResponse

func BuildServiceAccountResponse(sa *corev1.ServiceAccount, clusterID int) *model.K8sServiceAccount

func BuildServiceFromRequest

func BuildServiceFromRequest(req *model.CreateServiceReq) (*corev1.Service, error)

func BuildServiceListOptions

func BuildServiceListOptions(req *model.GetServiceListReq) metav1.ListOptions

func BuildServiceListPagination

func BuildServiceListPagination(services []corev1.Service, page int, size int) ([]corev1.Service, int64)

func BuildStatefulSetFromRequest

func BuildStatefulSetFromRequest(req *model.CreateStatefulSetReq) (*appsv1.StatefulSet, error)

func BuildStatefulSetFromYaml added in v0.0.4

func BuildStatefulSetFromYaml(req *model.CreateStatefulSetByYamlReq) (*appsv1.StatefulSet, error)

func BuildStatefulSetFromYamlForUpdate added in v0.0.4

func BuildStatefulSetFromYamlForUpdate(req *model.UpdateStatefulSetByYamlReq) (*appsv1.StatefulSet, error)

func BuildStatefulSetListOptions

func BuildStatefulSetListOptions(req *model.GetStatefulSetListReq) metav1.ListOptions

func BuildStatefulSetListPagination added in v0.0.5

func BuildStatefulSetListPagination(statefulSets []appsv1.StatefulSet, page, size int) ([]appsv1.StatefulSet, int64)

func BuildTaintYaml

func BuildTaintYaml(taints []model.NodeTaint) (string, error)

func BuildTaintYamlFromK8sTaints

func BuildTaintYamlFromK8sTaints(taints []corev1.Taint) (string, error)

func CalculatePVCStorageUsage

func CalculatePVCStorageUsage(pvc corev1.PersistentVolumeClaim) (float64, error)

func CleanClusterSensitiveInfo

func CleanClusterSensitiveInfo(cluster *model.K8sCluster)

CleanClusterSensitiveInfo 清理集群敏感信息

func CleanClusterSensitiveInfoList

func CleanClusterSensitiveInfoList(clusters []*model.K8sCluster)

CleanClusterSensitiveInfoList 清理集群列表中的敏感信息

func CleanConfigMapForYAML

func CleanConfigMapForYAML(cm *corev1.ConfigMap) *corev1.ConfigMap

CleanConfigMapForYAML 清理系统字段,便于导出 YAML

func CleanSecretForYAML

func CleanSecretForYAML(secret *corev1.Secret) *corev1.Secret

CleanSecretForYAML 清理 Secret 对象中的系统字段,用于YAML输出

func ClusterRoleBindingToYAML

func ClusterRoleBindingToYAML(clusterRoleBinding *rbacv1.ClusterRoleBinding) (string, error)

ClusterRoleBindingToYAML 将ClusterRoleBinding转换为YAML

func ClusterRoleToYAML

func ClusterRoleToYAML(clusterRole *rbacv1.ClusterRole) (string, error)

ClusterRoleToYAML 将ClusterRole转换为YAML

func ComparePVCs

func ComparePVCs(pvc1, pvc2 *corev1.PersistentVolumeClaim) bool

ComparePVCs 比较两个PVC是否相同(用于检测更新)

func ConfigMapToYAML

func ConfigMapToYAML(cm *corev1.ConfigMap) (string, error)

ConfigMapToYAML 将 ConfigMap 转换为 YAML 字符串

func ConvertClusterRoleToModel

func ConvertClusterRoleToModel(clusterRole *rbacv1.ClusterRole, clusterID int) *model.K8sClusterRole

func ConvertClusterRoleToYAML

func ConvertClusterRoleToYAML(clusterRole *rbacv1.ClusterRole) (string, error)

func ConvertClusterRolesToModel

func ConvertClusterRolesToModel(clusterRoles []rbacv1.ClusterRole, clusterID int) []*model.K8sClusterRole

func ConvertCreatePVCReqToPVC

func ConvertCreatePVCReqToPVC(req *model.CreatePVCReq) *corev1.PersistentVolumeClaim

func ConvertCreatePVReqToPV

func ConvertCreatePVReqToPV(req *model.CreatePVReq) *corev1.PersistentVolume

func ConvertCreatePVReqToPVWithValidation added in v0.0.13

func ConvertCreatePVReqToPVWithValidation(req *model.CreatePVReq) (*corev1.PersistentVolume, error)

ConvertCreatePVReqToPVWithValidation 将请求转换为PV对象并验证卷源

func ConvertEndpointsToModel added in v0.0.8

func ConvertEndpointsToModel(endpoints *corev1.Endpoints) []model.K8sServiceEndpoint

func ConvertEventToK8sEvent

func ConvertEventToK8sEvent(event corev1.Event) model.K8sEvent

func ConvertK8sClusterRoleBindingToClusterRoleBindingInfo

func ConvertK8sClusterRoleBindingToClusterRoleBindingInfo(clusterRoleBinding *rbacv1.ClusterRoleBinding, clusterID int) model.K8sClusterRoleBinding

func ConvertK8sClusterRoleToClusterRoleInfo

func ConvertK8sClusterRoleToClusterRoleInfo(clusterRole *rbacv1.ClusterRole, clusterID int) model.K8sClusterRole

func ConvertK8sPolicyRulesToModel

func ConvertK8sPolicyRulesToModel(rules []rbacv1.PolicyRule) []model.PolicyRule

func ConvertK8sRoleBindingToRoleBindingInfo

func ConvertK8sRoleBindingToRoleBindingInfo(roleBinding *rbacv1.RoleBinding, clusterID int) *model.K8sRoleBinding

func ConvertK8sRoleRefToModel

func ConvertK8sRoleRefToModel(roleRef rbacv1.RoleRef) model.RoleRef

func ConvertK8sRoleToRoleInfo

func ConvertK8sRoleToRoleInfo(role *rbacv1.Role, clusterID int) model.K8sRole

func ConvertK8sSubjectsToModel

func ConvertK8sSubjectsToModel(subjects []rbacv1.Subject) []model.Subject

func ConvertKeyValueListToLabels

func ConvertKeyValueListToLabels(keyValues []model.KeyValue) map[string]string

func ConvertLabelsToKeyValueList

func ConvertLabelsToKeyValueList(labels map[string]string) model.KeyValueList

func ConvertPodContainers

func ConvertPodContainers(pod *corev1.Pod) []model.PodContainer

func ConvertPolicyRulesToK8s

func ConvertPolicyRulesToK8s(rules []model.PolicyRule) []rbacv1.PolicyRule

func ConvertRoleRefToK8s

func ConvertRoleRefToK8s(roleRef model.RoleRef) rbacv1.RoleRef

func ConvertSubjectsToK8s

func ConvertSubjectsToK8s(subjects []model.Subject) []rbacv1.Subject

func ConvertToCorePorts

func ConvertToCorePorts(ports []model.ServicePort) []corev1.ServicePort

func ConvertToK8sClusterRole

func ConvertToK8sClusterRole(req *model.CreateClusterRoleReq) *rbacv1.ClusterRole

func ConvertToK8sClusterRoleBinding

func ConvertToK8sClusterRoleBinding(crb *rbacv1.ClusterRoleBinding) *model.K8sClusterRoleBinding

ConvertToK8sClusterRoleBinding 将 K8s 对象构建为模型对象

func ConvertToK8sDaemonSet added in v0.0.4

func ConvertToK8sDaemonSet(daemonSet *appsv1.DaemonSet) *model.K8sDaemonSet

func ConvertToK8sDeployment

func ConvertToK8sDeployment(deployment *appsv1.Deployment) *model.K8sDeployment

func ConvertToK8sIngress

func ConvertToK8sIngress(ingress *networkingv1.Ingress, clusterID int) *model.K8sIngress

func ConvertToK8sNamespace

func ConvertToK8sNamespace(name string, labels, annotations model.KeyValueList) *corev1.Namespace

func ConvertToK8sPod

func ConvertToK8sPod(pod *corev1.Pod) *model.K8sPod

func ConvertToK8sPods

func ConvertToK8sPods(pods []corev1.Pod) []*model.K8sPod

func ConvertToK8sRole

func ConvertToK8sRole(req *model.CreateRoleReq) *rbacv1.Role

func ConvertToK8sRoleBinding

func ConvertToK8sRoleBinding(req *model.CreateRoleBindingReq) *rbacv1.RoleBinding

func ConvertToK8sServiceAccount

func ConvertToK8sServiceAccount(req *model.CreateServiceAccountReq) *corev1.ServiceAccount

func ConvertToK8sStatefulSet added in v0.0.4

func ConvertToK8sStatefulSet(statefulSet *appsv1.StatefulSet) *model.K8sStatefulSet

func ConvertToPVCEntities

func ConvertToPVCEntities(pvcs []corev1.PersistentVolumeClaim, clusterID int) []*model.K8sPVC

func ConvertToPVCEntity

func ConvertToPVCEntity(pvc *corev1.PersistentVolumeClaim, clusterID int) *model.K8sPVC

func ConvertToPVEntities

func ConvertToPVEntities(pvs []corev1.PersistentVolume, clusterID int) []*model.K8sPV

func ConvertToPVEntity

func ConvertToPVEntity(pv *corev1.PersistentVolume, clusterID int) *model.K8sPV

func ConvertUnstructuredToYAML

func ConvertUnstructuredToYAML(obj *unstructured.Unstructured) (string, error)

func ConvertUpdatePVCReqToPVC

func ConvertUpdatePVCReqToPVC(req *model.UpdatePVCReq) *corev1.PersistentVolumeClaim

func ConvertUpdatePVReqToPV

func ConvertUpdatePVReqToPV(req *model.UpdatePVReq, existingPV *corev1.PersistentVolume) *corev1.PersistentVolume

基于现有PV对象更新可变字段,保留不可变字段

func CreateServiceAccountToken

func CreateServiceAccountToken(ctx context.Context, kubeClient *kubernetes.Clientset, namespace, name string, expiryTime *int64) (*model.ServiceAccountTokenInfo, error)

func DaemonSetToYAML

func DaemonSetToYAML(daemonSet *appsv1.DaemonSet) (string, error)

DaemonSetToYAML 将DaemonSet对象转换为YAML

func DeploymentToYAML

func DeploymentToYAML(deployment *appsv1.Deployment) (string, error)

DeploymentToYAML 将Deployment转换为YAML

func ExtractDaemonSetFromRevision

func ExtractDaemonSetFromRevision(revision *appsv1.ControllerRevision, daemonSet *appsv1.DaemonSet) error

ExtractDaemonSetFromRevision 从ControllerRevision提取DaemonSet配置用于回滚

func ExtractStatefulSetFromRevision

func ExtractStatefulSetFromRevision(revision *appsv1.ControllerRevision, statefulSet *appsv1.StatefulSet) error

ExtractStatefulSetFromRevision 从ControllerRevision提取StatefulSet配置用于回滚

func FilterClusterRolesByName

func FilterClusterRolesByName(clusterRoles []rbacv1.ClusterRole, nameFilter string) []rbacv1.ClusterRole

FilterClusterRolesByName 根据名称过滤 ClusterRole 列表

func FilterDaemonSetsByStatus

func FilterDaemonSetsByStatus(daemonSets []*model.K8sDaemonSet, status string) []*model.K8sDaemonSet

FilterDaemonSetsByStatus 按状态过滤DaemonSet列表

func FilterDeploymentsByStatus

func FilterDeploymentsByStatus(deployments []appsv1.Deployment, status string) []appsv1.Deployment

FilterDeploymentsByStatus 根据部署状态过滤

func FilterEventsByObject

func FilterEventsByObject(events []corev1.Event, objectKind, objectName string) []corev1.Event

FilterEventsByObject 根据涉及对象过滤事件

func FilterEventsByReason

func FilterEventsByReason(events []corev1.Event, reason string) []corev1.Event

FilterEventsByReason 根据事件原因过滤事件

func FilterEventsByTimeRange

func FilterEventsByTimeRange(events []corev1.Event, startTime, endTime time.Time) []corev1.Event

FilterEventsByTimeRange 根据时间范围过滤事件

func FilterEventsByType

func FilterEventsByType(events []corev1.Event, eventType string) []corev1.Event

FilterEventsByType 根据事件类型过滤事件

func FilterNamespacesByLabels

func FilterNamespacesByLabels(namespaces []corev1.Namespace, labels map[string]string) []corev1.Namespace

FilterNamespacesByLabels 根据标签过滤命名空间

func FilterNamespacesByName

func FilterNamespacesByName(namespaces []corev1.Namespace, nameFilter string) []corev1.Namespace

FilterNamespacesByName 根据命名空间名称过滤

func FilterNamespacesBySearch

func FilterNamespacesBySearch(namespaces []corev1.Namespace, search string) []corev1.Namespace

FilterNamespacesBySearch 根据搜索关键字过滤命名空间

func FilterNamespacesByStatus

func FilterNamespacesByStatus(namespaces []corev1.Namespace, status string) []corev1.Namespace

FilterNamespacesByStatus 根据状态过滤命名空间

func FilterNodesByNames

func FilterNodesByNames(nodes []corev1.Node, nodeNames []string) []corev1.Node

FilterNodesByNames 根据节点名称过滤

func FilterNodesByRoles

func FilterNodesByRoles(nodes []corev1.Node, roles []string) []corev1.Node

FilterNodesByRoles 根据节点角色过滤

func FilterNodesByStatus

func FilterNodesByStatus(nodes []corev1.Node, statuses []model.NodeStatus) []corev1.Node

FilterNodesByStatus 根据节点状态过滤

func FilterPVCsByAccessMode

func FilterPVCsByAccessMode(pvcs []corev1.PersistentVolumeClaim, accessMode string) []corev1.PersistentVolumeClaim

FilterPVCsByAccessMode 根据访问模式过滤PVC列表

func FilterPVCsByStatus

func FilterPVCsByStatus(pvcs []corev1.PersistentVolumeClaim, status string) []corev1.PersistentVolumeClaim

FilterPVCsByStatus 根据状态过滤 PVC 列表

func FilterPVCsByStorageClass

func FilterPVCsByStorageClass(pvcs []corev1.PersistentVolumeClaim, storageClass string) []corev1.PersistentVolumeClaim

FilterPVCsByStorageClass 根据存储类过滤PVC列表

func FilterPVsByAccessMode

func FilterPVsByAccessMode(pvs []corev1.PersistentVolume, accessMode string) []corev1.PersistentVolume

FilterPVsByAccessMode 根据访问模式过滤PV列表

func FilterPVsByStatus

func FilterPVsByStatus(pvs []corev1.PersistentVolume, status string) []corev1.PersistentVolume

FilterPVsByStatus 根据状态过滤 PV 列表

func FilterPVsByStorageClass

func FilterPVsByStorageClass(pvs []corev1.PersistentVolume, storageClass string) []corev1.PersistentVolume

FilterPVsByStorageClass 根据存储类过滤PV列表

func FilterServicesByType

func FilterServicesByType(services []corev1.Service, serviceType string) []corev1.Service

FilterServicesByType 根据Service类型过滤

func FilterStatefulSetsByStatus

func FilterStatefulSetsByStatus(statefulSets []appsv1.StatefulSet, status string) []appsv1.StatefulSet

FilterStatefulSetsByStatus 根据StatefulSet状态过滤

func FindTaintByKey

func FindTaintByKey(taints []corev1.Taint, key string) (*corev1.Taint, bool)

FindTaintByKey 根据键查找污点

func FormatBytes added in v0.0.10

func FormatBytes(bytes int64) string

func FormatEventAge

func FormatEventAge(timestamp time.Time) string

func GetChangeReason added in v0.0.4

func GetChangeReason(annotations map[string]string) string

func GetClusterRoleAge

func GetClusterRoleAge(clusterRole rbacv1.ClusterRole) string

func GetClusterRolePermissions

func GetClusterRolePermissions(clusterRole rbacv1.ClusterRole) map[string][]string

func GetDeploymentAge

func GetDeploymentAge(deployment appsv1.Deployment) string

func GetDeploymentHistory

func GetDeploymentHistory(ctx context.Context, kubeClient *kubernetes.Clientset, namespace, deploymentName string) ([]*model.K8sDeploymentHistory, int64, error)

func GetDeploymentPods

func GetDeploymentPods(ctx context.Context, kubeClient *kubernetes.Clientset, namespace, deploymentName string) ([]*model.K8sPod, int64, error)

func GetEventSeverity

func GetEventSeverity(eventType, reason string) model.EventSeverity

func GetEventSummary

func GetEventSummary(events []corev1.Event) map[string]interface{}

func GetIngressAge

func GetIngressAge(ingress networkingv1.Ingress) string

func GetInt32Value

func GetInt32Value(ptr *int32) int32

func GetNamespaceResourceQuota

func GetNamespaceResourceQuota(namespace *corev1.Namespace) map[string]string

func GetNamespaceStatus

func GetNamespaceStatus(phase corev1.NamespacePhase) string

func GetNodeStatusMessage

func GetNodeStatusMessage(node corev1.Node) string

func GetNodeTaintsByEffect

func GetNodeTaintsByEffect(taints []corev1.Taint, effect corev1.TaintEffect) []corev1.Taint

func GetPVAge

func GetPVAge(pv corev1.PersistentVolume) string

func GetPVCAccessModes

func GetPVCAccessModes(pvc corev1.PersistentVolumeClaim) []string

func GetPVCActualStorageSize

func GetPVCActualStorageSize(pvc corev1.PersistentVolumeClaim) string

func GetPVCAge

func GetPVCAge(pvc corev1.PersistentVolumeClaim) string

func GetPVCCapacity

func GetPVCCapacity(pvc corev1.PersistentVolumeClaim) (string, int64)

func GetPVCStorageSize

func GetPVCStorageSize(pvc corev1.PersistentVolumeClaim) string

func GetPVCapacity

func GetPVCapacity(pv corev1.PersistentVolume) (string, int64)

func GetPodAge

func GetPodAge(pod corev1.Pod) string

func GetServiceAccountToken

func GetServiceAccountToken(ctx context.Context, kubeClient *kubernetes.Clientset, namespace, name string) (*model.ServiceAccountTokenInfo, error)

func GetStatefulSetAge added in v0.0.5

func GetStatefulSetAge(statefulSet appsv1.StatefulSet) string

func GetStatefulSetPods added in v0.0.5

func GetStatefulSetPods(ctx context.Context, kubeClient *kubernetes.Clientset, namespace, statefulSetName string) ([]*model.K8sPod, int64, error)

func GetTaintsByKeys

func GetTaintsByKeys(taints []corev1.Taint, keys []string) []corev1.Taint

func GroupEventsByObject

func GroupEventsByObject(events []corev1.Event) map[string][]corev1.Event

GroupEventsByObject 按涉及对象分组

func GroupEventsByReason

func GroupEventsByReason(events []corev1.Event) map[string][]corev1.Event

GroupEventsByReason 按事件原因分组

func GroupEventsByType

func GroupEventsByType(events []corev1.Event) map[string][]corev1.Event

GroupEventsByType 按事件类型分组

func HandleK8sError

func HandleK8sError(err error, operation, resource, name, namespace string, clusterID int) error

func HasMultipleDocuments

func HasMultipleDocuments(yamlContent string) bool

HasMultipleDocuments 检查是否为多文档YAML

func IngressStatus

func IngressStatus(item *networkingv1.Ingress) string

IngressStatus 获取Ingress状态

func IngressToYAML

func IngressToYAML(ingress *networkingv1.Ingress) (string, error)

IngressToYAML 将Ingress转换为YAML

func IsActivePod

func IsActivePod(pod corev1.Pod) bool

IsActivePod 判断Pod是否为活跃状态

func IsAlreadyExistsError

func IsAlreadyExistsError(err error) bool

IsAlreadyExistsError 检查是否为资源已存在错误

func IsConflictError

func IsConflictError(err error) bool

IsConflictError 检查是否为冲突错误

func IsDaemonSetPod

func IsDaemonSetPod(pod corev1.Pod) bool

IsDaemonSetPod 判断是否为DaemonSet Pod

func IsDeploymentReady

func IsDeploymentReady(deployment appsv1.Deployment) bool

IsDeploymentReady 判断Deployment是否就绪

func IsEventCritical

func IsEventCritical(eventType, reason string) bool

IsEventCritical 判断事件是否为关键事件

func IsForbiddenError

func IsForbiddenError(err error) bool

IsForbiddenError 检查是否为权限不足错误

func IsIngressReady

func IsIngressReady(ingress networkingv1.Ingress) bool

IsIngressReady 判断Ingress是否就绪

func IsNamespaceActive

func IsNamespaceActive(namespace *corev1.Namespace) bool

IsNamespaceActive 检查命名空间是否处于活跃状态

func IsNamespaceTerminating

func IsNamespaceTerminating(namespace *corev1.Namespace) bool

IsNamespaceTerminating 检查命名空间是否正在终止

func IsNodeReady

func IsNodeReady(node corev1.Node) bool

IsNodeReady 判断节点是否就绪

func IsNotFoundError

func IsNotFoundError(err error) bool

IsNotFoundError 检查是否为资源不存在错误

func IsPVAvailable

func IsPVAvailable(pv corev1.PersistentVolume) bool

IsPVAvailable 判断 PV 是否可用

func IsPVBound

func IsPVBound(pv corev1.PersistentVolume) bool

IsPVBound 判断 PV 是否已绑定

func IsPVCBound

func IsPVCBound(pvc corev1.PersistentVolumeClaim) bool

IsPVCBound 判断 PVC 是否已绑定

func IsPVCExpandable

func IsPVCExpandable(pvc corev1.PersistentVolumeClaim) bool

IsPVCExpandable 判断PVC是否支持扩容

func IsPVCPending

func IsPVCPending(pvc corev1.PersistentVolumeClaim) bool

IsPVCPending 判断 PVC 是否处于等待状态

func IsPodReady

func IsPodReady(pod corev1.Pod) bool

IsPodReady 判断Pod是否就绪

func IsStatefulSetReady added in v0.0.5

func IsStatefulSetReady(statefulSet appsv1.StatefulSet) bool

IsStatefulSetReady 判断StatefulSet是否就绪

func IsSystemClusterRole

func IsSystemClusterRole(clusterRole rbacv1.ClusterRole) bool

IsSystemClusterRole 判断是否为系统 ClusterRole

func IsSystemNamespace

func IsSystemNamespace(namespace string) bool

IsSystemNamespace 判断是否为系统命名空间

func LogAndWrapError

func LogAndWrapError(logger *zap.Logger, err error, operation string, fields ...zap.Field) error

LogAndWrapError 记录错误并包装

func PVCToYAML

func PVCToYAML(pvc *corev1.PersistentVolumeClaim) (string, error)

PVCToYAML 将 PVC 转换为 YAML

func PVToYAML

func PVToYAML(pv *corev1.PersistentVolume) (string, error)

PVToYAML 将 PV 转换为 YAML

func PaginateK8sClusterRoleBindings

func PaginateK8sClusterRoleBindings(clusterRoleBindings []*model.K8sClusterRoleBinding, page, pageSize int) ([]*model.K8sClusterRoleBinding, int64)

PaginateK8sClusterRoleBindings 对ClusterRoleBinding列表进行分页

func PaginateK8sClusterRoles

func PaginateK8sClusterRoles(clusterRoles []*model.K8sClusterRole, page, pageSize int) ([]*model.K8sClusterRole, int64)

PaginateK8sClusterRoles 对ClusterRole列表进行分页

func PaginateK8sDaemonSets

func PaginateK8sDaemonSets(daemonSets []*model.K8sDaemonSet, page, size int) ([]*model.K8sDaemonSet, int64)

PaginateK8sDaemonSets 对DaemonSet列表进行分页

func PaginateK8sDeployments

func PaginateK8sDeployments(deployments []*model.K8sDeployment, page, size int) ([]*model.K8sDeployment, int64)

PaginateK8sDeployments 对 K8sDeployment 列表进行分页

func PaginateK8sIngresses

func PaginateK8sIngresses(ingresses []*model.K8sIngress, page, size int) ([]*model.K8sIngress, int64)

PaginateK8sIngresses 对 K8sIngress 列表进行分页

func PaginateK8sRoleBindings

func PaginateK8sRoleBindings(roleBindings []*model.K8sRoleBinding, page, pageSize int) (model.ListResp[*model.K8sRoleBinding], error)

PaginateK8sRoleBindings 对RoleBinding列表进行分页(基于内部模型)

func PaginateK8sRoles

func PaginateK8sRoles(roles []*model.K8sRole, page, pageSize int) ([]*model.K8sRole, int64)

PaginateK8sRoles 对Role列表进行分页(基于内部模型)

func PaginateK8sServiceAccounts

func PaginateK8sServiceAccounts(serviceAccounts []corev1.ServiceAccount, page, pageSize int) []corev1.ServiceAccount

PaginateK8sServiceAccounts 对ServiceAccount列表进行分页

func PaginateK8sStatefulSets

func PaginateK8sStatefulSets(statefulSets []*model.K8sStatefulSet, page, size int) ([]*model.K8sStatefulSet, int64)

PaginateK8sStatefulSets 对 K8sStatefulSet 列表进行分页

func PaginatePVCList

func PaginatePVCList(pvcs []*model.K8sPVC, page, size int) ([]*model.K8sPVC, int64)

PaginatePVCList 对PVC列表进行分页处理

func PaginatePVList

func PaginatePVList(pvs []*model.K8sPV, page, size int) ([]*model.K8sPV, int64)

PaginatePVList 对PV列表进行分页处理

func ParseEventMessage

func ParseEventMessage(message string) map[string]string

func ParseTaintYaml

func ParseTaintYaml(taintYaml string) (taintsResult []corev1.Taint, returnErr error)

func ParseYAMLToClusterRole

func ParseYAMLToClusterRole(yamlContent string) (*rbacv1.ClusterRole, error)

ParseYAMLToClusterRole 将 YAML 转换为 ClusterRole

func ParseYamlTemplate

func ParseYamlTemplate(templateContent string, variables []string) (string, error)

func PodStatus

func PodStatus(pod *corev1.Pod) string

PodStatus 获取Pod状态

func PodToYAML

func PodToYAML(pod *corev1.Pod) (string, error)

PodToYAML 将Pod转换为YAML

func RemoveTaintByKey

func RemoveTaintByKey(taints []corev1.Taint, key string) []corev1.Taint

RemoveTaintByKey 根据键移除污点

func RoleBindingToYAML

func RoleBindingToYAML(roleBinding *rbacv1.RoleBinding) (string, error)

RoleBindingToYAML 将RoleBinding转换为YAML

func RoleToYAML

func RoleToYAML(role *rbacv1.Role) (string, error)

RoleToYAML 将Role转换为YAML

func SecretToYAML

func SecretToYAML(sec *corev1.Secret) (string, error)

SecretToYAML 将 Secret 转换为 YAML 字符串

func ServiceAccountToYAML

func ServiceAccountToYAML(serviceAccount *corev1.ServiceAccount) (string, error)

ServiceAccountToYAML 将ServiceAccount转换为YAML

func ServiceToYAML

func ServiceToYAML(service *corev1.Service) (string, error)

ServiceToYAML 将Service对象转换为YAML

func ShouldSkipPodDrain

func ShouldSkipPodDrain(pod corev1.Pod, options *DrainOptions) bool

ShouldSkipPodDrain 判断是否应该跳过Pod驱逐

func SortDaemonSetsByCreationTime

func SortDaemonSetsByCreationTime(daemonSets []*model.K8sDaemonSet, desc bool)

SortDaemonSetsByCreationTime 按创建时间排序DaemonSet列表

func SortEventsByTime

func SortEventsByTime(events []corev1.Event) []corev1.Event

SortEventsByTime 按时间排序事件(最新的在前)

func SortStatefulSetsByCreationTime

func SortStatefulSetsByCreationTime(statefulSets []*model.K8sStatefulSet, desc bool)

SortStatefulSetsByCreationTime 按创建时间排序StatefulSet列表

func SplitYamlDocuments

func SplitYamlDocuments(yamlContent string) []string

SplitYamlDocuments 分割多文档YAML

func StatefulSetToYAML

func StatefulSetToYAML(statefulSet *appsv1.StatefulSet) (string, error)

StatefulSetToYAML 将StatefulSet转换为YAML

func TaintExists

func TaintExists(taints []corev1.Taint, targetTaint corev1.Taint) bool

TaintExists 检查污点是否存在

func UpdateSecretFromRequest

func UpdateSecretFromRequest(existing *corev1.Secret, req *model.UpdateSecretReq) (*corev1.Secret, error)

func ValidateAnnotationKey

func ValidateAnnotationKey(key string) error

func ValidateAnnotationValue

func ValidateAnnotationValue(value string) error

func ValidateAnnotations

func ValidateAnnotations(annotations []model.KeyValue) error

func ValidateBasicParams

func ValidateBasicParams(clusterID int, nodeName string) error

func ValidateClusterCreateParams

func ValidateClusterCreateParams(name, apiServerAddr, kubeConfigContent string) error

func ValidateClusterExists

func ValidateClusterExists(cluster *model.K8sCluster, clusterID int) error

func ValidateClusterID

func ValidateClusterID(clusterID int) error

func ValidateClusterRole

func ValidateClusterRole(clusterRole *rbacv1.ClusterRole) error

func ValidateClusterUpdateParams

func ValidateClusterUpdateParams(id int) error

func ValidateContainerName

func ValidateContainerName(name string) error

func ValidateDaemonSet

func ValidateDaemonSet(daemonSet *appsv1.DaemonSet) error

func ValidateDeployment

func ValidateDeployment(deployment *appsv1.Deployment) error

func ValidateImageName

func ValidateImageName(image string) error

func ValidateIngress

func ValidateIngress(ingress *networkingv1.Ingress) error

func ValidateKubernetesName

func ValidateKubernetesName(name string) error

func ValidateLabelKey

func ValidateLabelKey(key string) error

func ValidateLabelKeys

func ValidateLabelKeys(labelKeys []string) error

func ValidateLabelPrefix

func ValidateLabelPrefix(prefix string) error

func ValidateLabelValue

func ValidateLabelValue(value string) error

func ValidateLabels

func ValidateLabels(labels []model.KeyValue) error

func ValidateName

func ValidateName(name string, resource string) error

func ValidateNamespace

func ValidateNamespace(namespace string) error

func ValidateNamespaceFilters

func ValidateNamespaceFilters(req *model.K8sNamespaceListReq) error

func ValidateNamespaceName

func ValidateNamespaceName(name string) error

func ValidateNodeLabels

func ValidateNodeLabels(labels map[string]string) error

func ValidateNodeLabelsMap

func ValidateNodeLabelsMap(labels map[string]string) error

func ValidateNodeName

func ValidateNodeName(nodeName string) error

func ValidatePV

func ValidatePV(pv *corev1.PersistentVolume) error

func ValidatePVC

func ValidatePVC(pvc *corev1.PersistentVolumeClaim) error

func ValidatePVCCreate

func ValidatePVCCreate(req *model.CreatePVCReq) error

func ValidatePVCUpdate

func ValidatePVCUpdate(req *model.UpdatePVCReq) error

func ValidatePVCreate

func ValidatePVCreate(req *model.CreatePVReq) error

func ValidatePVUpdate

func ValidatePVUpdate(req *model.UpdatePVReq) error

func ValidatePod

func ValidatePod(pod *corev1.Pod) error

func ValidateRequest

func ValidateRequest(req interface{}) error

func ValidateResourceQuantities

func ValidateResourceQuantities(cluster *model.K8sCluster) error

func ValidateResourceQuota

func ValidateResourceQuota(resources map[string]string) error

func ValidateSecretData

func ValidateSecretData(secretType corev1.SecretType, data map[string][]byte, stringData map[string]string) error

func ValidateService

func ValidateService(service *corev1.Service) error

func ValidateStatefulSet

func ValidateStatefulSet(statefulSet *appsv1.StatefulSet) error

func ValidateTaint

func ValidateTaint(taint *corev1.Taint) error

func ValidateYamlContent

func ValidateYamlContent(content string) error

func ValidateYamlWithCluster

func ValidateYamlWithCluster(ctx context.Context, discoveryClient discovery.DiscoveryInterface, dynamicClient dynamic.Interface, yamlContent string) error

func YAMLToClusterRole

func YAMLToClusterRole(yamlStr string) (*rbacv1.ClusterRole, error)

YAMLToClusterRole 将YAML转换为ClusterRole

func YAMLToClusterRoleBinding

func YAMLToClusterRoleBinding(yamlStr string) (*rbacv1.ClusterRoleBinding, error)

YAMLToClusterRoleBinding 将YAML转换为ClusterRoleBinding

func YAMLToConfigMap

func YAMLToConfigMap(y string) (*corev1.ConfigMap, error)

YAMLToConfigMap 将 YAML 反序列化为 ConfigMap

func YAMLToDaemonSet

func YAMLToDaemonSet(yamlContent string) (*appsv1.DaemonSet, error)

YAMLToDaemonSet 将YAML转换为DaemonSet对象

func YAMLToDeployment

func YAMLToDeployment(yamlContent string) (*appsv1.Deployment, error)

YAMLToDeployment 将YAML转换为Deployment

func YAMLToIngress

func YAMLToIngress(yamlContent string) (*networkingv1.Ingress, error)

YAMLToIngress 将YAML转换为Ingress

func YAMLToPV

func YAMLToPV(yamlContent string) (*corev1.PersistentVolume, error)

YAMLToPV 将 YAML 转换为 PV

func YAMLToPVC

func YAMLToPVC(yamlContent string) (*corev1.PersistentVolumeClaim, error)

YAMLToPVC 将 YAML 转换为 PVC

func YAMLToPod

func YAMLToPod(yamlContent string) (*corev1.Pod, error)

YAMLToPod 将YAML转换为Pod

func YAMLToRole

func YAMLToRole(yamlStr string) (*rbacv1.Role, error)

YAMLToRole 将YAML转换为Role

func YAMLToRoleBinding

func YAMLToRoleBinding(yamlStr string) (*rbacv1.RoleBinding, error)

YAMLToRoleBinding 将YAML转换为RoleBinding

func YAMLToSecret

func YAMLToSecret(y string) (*corev1.Secret, error)

YAMLToSecret 将 YAML 反序列化为 Secret

func YAMLToService

func YAMLToService(yamlContent string) (*corev1.Service, error)

YAMLToService 将YAML转换为Service对象

func YAMLToServiceAccount

func YAMLToServiceAccount(yamlStr string) (*corev1.ServiceAccount, error)

YAMLToServiceAccount 将YAML转换为ServiceAccount

func YAMLToStatefulSet

func YAMLToStatefulSet(yamlContent string) (*appsv1.StatefulSet, error)

YAMLToStatefulSet 将YAML转换为StatefulSet对象

Types

type DrainOptions

type DrainOptions struct {
	Force              int8 // 是否强制驱逐
	IgnoreDaemonSets   int8 // 是否忽略DaemonSet
	DeleteLocalData    int8 // 是否删除本地数据
	GracePeriodSeconds int  // 优雅关闭时间(秒)
	TimeoutSeconds     int  // 超时时间(秒)
}

type K8sError

type K8sError struct {
	Operation string
	Resource  string
	Name      string
	Namespace string
	ClusterID int
	Err       error
}

K8sError 定义Kubernetes相关错误类型

func NewK8sError

func NewK8sError(operation, resource, name, namespace string, clusterID int, err error) *K8sError

func (*K8sError) Error

func (e *K8sError) Error() string

type PodFileStreamPipe

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

PodFileStreamPipe pod内文件下载专用,简化实现

func NewPodFileStreamPipe

func NewPodFileStreamPipe(ctx context.Context, config *rest.Config, client kubernetes.Interface,
	namespace, pod, container, filePath string) (*PodFileStreamPipe, error)

func (*PodFileStreamPipe) Close

func (pfs *PodFileStreamPipe) Close() error

Close 关闭管道和资源

func (*PodFileStreamPipe) Read

func (pfs *PodFileStreamPipe) Read(p []byte) (int, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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