Skip to content
2 changes: 1 addition & 1 deletion config/config.development.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ server:
port: "8889"
log:
dir: "./logs"
level: "debug"
level: "warn"
jwt:
key1: "ebe3vxIP7sblVvUHXb7ZaiMPuz4oXo0l"
key2: "ebe3vxIP7sblVvUHXb7ZaiMPuz4oXo0z"
Expand Down
2 changes: 1 addition & 1 deletion config/config.production.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ server:
port: "8889"
log:
dir: "./logs"
level: "debug"
level: "warn"
jwt:
key1: "ebe3vxIP7sblVvUHXb7ZaiMPuz4oXo0l"
key2: "ebe3vxIP7sblVvUHXb7ZaiMPuz4oXo0z"
Expand Down
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module github.com/GoSimplicity/AI-CloudOps
go 1.24.6

require (
github.com/aliyun/alibaba-cloud-sdk-go v1.63.107
github.com/casbin/casbin/v2 v2.93.0
github.com/fatih/color v1.16.0
github.com/gin-contrib/cors v1.7.2
Expand Down Expand Up @@ -169,6 +170,7 @@ require (
github.com/oklog/run v1.2.0 // indirect
github.com/oklog/ulid v1.3.1 // indirect
github.com/onsi/ginkgo v1.16.5 // indirect
github.com/opentracing/opentracing-go v1.2.1-0.20220228012449-10b1cf09e00b // indirect
github.com/pelletier/go-toml/v2 v2.2.3 // indirect
github.com/peterbourgon/diskv v2.0.1+incompatible // indirect
github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c // indirect
Expand Down
30 changes: 30 additions & 0 deletions go.sum

Large diffs are not rendered by default.

14 changes: 1 addition & 13 deletions internal/k8s/manager/pod_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,6 @@ func (m *podManager) DeletePod(ctx context.Context, clusterID int, namespace, na

func (m *podManager) GetPodLogs(ctx context.Context, clusterID int, namespace, name string, logOptions *corev1.PodLogOptions) (io.ReadCloser, error) {
kubeClient, err := m.getKubeClient(clusterID)

if err != nil {
return nil, err
}
Expand All @@ -230,18 +229,14 @@ func (m *podManager) GetPodLogs(ctx context.Context, clusterID int, namespace, n
}

// BatchDeletePods 批量删除 Pod
// 使用并发+重试机制提高批量操作的效率和可靠性
// 并发度为3是经过测试的平衡值:既能提高性能,又不会对API Server造成过大压力
func (m *podManager) BatchDeletePods(ctx context.Context, clusterID int, namespace string, podNames []string, deleteOpts metav1.DeleteOptions) error {
kubeClient, err := m.getKubeClient(clusterID)

if err != nil {
return err
}

tasks := make([]retry.WrapperTask, 0, len(podNames))
for _, name := range podNames {

tasks = append(tasks, retry.WrapperTask{
Backoff: retry.DefaultBackoff,

Expand Down Expand Up @@ -279,7 +274,6 @@ func (m *podManager) PodTerminalSession(
namespace, pod, container, shell string,
conn *websocket.Conn,
) error {

kubeClient, err := m.clientFactory.GetKubeClient(clusterID)
if err != nil {
return err
Expand All @@ -301,7 +295,6 @@ func (m *podManager) PodTerminalSession(
}

func (m *podManager) UploadFileToPod(ctx *gin.Context, clusterID int, namespace, pod, container, filePath string) error {

if namespace == "" {
return fmt.Errorf("命名空间不能为空")
}
Expand Down Expand Up @@ -440,7 +433,6 @@ func (m *podManager) UploadFileToPod(ctx *gin.Context, clusterID int, namespace,
Stderr: &uploadStderr,
TerminalSizeQueue: nil,
})

if err != nil {
m.logger.Error("执行上传失败",
zap.Error(err),
Expand All @@ -463,7 +455,6 @@ func (m *podManager) UploadFileToPod(ctx *gin.Context, clusterID int, namespace,
}

func (m *podManager) PortForward(ctx context.Context, ports []string, dialer httpstream.Dialer) error {

// 创建 PortForwarder
stopChan := make(chan struct{}, 1)
readyChan := make(chan struct{})
Expand Down Expand Up @@ -574,7 +565,6 @@ func (m *podManager) PodPortForward(ctx context.Context, clusterID int, namespac
}

func (m *podManager) DownloadPodFile(ctx context.Context, clusterID int, namespace, pod, container, filePath string) (*k8sutils.PodFileStreamPipe, error) {

if namespace == "" {
return nil, fmt.Errorf("命名空间不能为空")
}
Expand Down Expand Up @@ -631,7 +621,6 @@ func (m *podManager) DownloadPodFile(ctx context.Context, clusterID int, namespa

reader, err := k8sutils.NewPodFileStreamPipe(
ctx, restConfig, kubeClient, namespace, pod, container, filePath)

if err != nil {
m.logger.Error("创建Pod文件流失败",
zap.Error(err),
Expand Down Expand Up @@ -776,7 +765,7 @@ func writeFilesToTar(files []fileWithHeader, w io.Writer) error {

hdr := &tar.Header{
Name: filename,
Mode: 0644,
Mode: 0o644,
Size: fileInfo.header.Size,
}

Expand All @@ -796,7 +785,6 @@ func writeFilesToTar(files []fileWithHeader, w io.Writer) error {

return nil
}(f, i)

if err != nil {
return err
}
Expand Down
Loading