feat: add k8s cluster resource management module
- Add K8s module with kubeconfig storage in cluster_config table - Implement resource list APIs for 8 kinds: namespace, deployment, statefulset, service, configmap, pod, pv, pvc - Add K8sResourceList page with sidebar navigation and resource tables - Support YAML upload/input dialog for resource creation via dynamic client - Add kubeconfig settings drawer - Increase main content width from lg to xl for better table display - Add navigation link for cluster resources in top bar 🤖 Generated with [Qoder][https://qoder.com]
This commit is contained in:
54
internal/module/k8s/handler.config.go
Normal file
54
internal/module/k8s/handler.config.go
Normal file
@@ -0,0 +1,54 @@
|
||||
package k8s
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
|
||||
"gitea.loveuer.com/loveuer/cluster/internal/model"
|
||||
"gitea.loveuer.com/loveuer/cluster/pkg/resp"
|
||||
"gitea.loveuer.com/loveuer/cluster/pkg/store"
|
||||
"github.com/gofiber/fiber/v3"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
func ClusterConfigGet(ctx context.Context, db *gorm.DB, store store.Store) fiber.Handler {
|
||||
return func(c fiber.Ctx) error {
|
||||
var config model.ClusterConfig
|
||||
|
||||
if err := db.Where("key = ?", "kubeconfig").First(&config).Error; err != nil {
|
||||
if err == gorm.ErrRecordNotFound {
|
||||
return resp.R200(c, map[string]any{
|
||||
"kubeconfig": "",
|
||||
})
|
||||
}
|
||||
return resp.R500(c, "", nil, err)
|
||||
}
|
||||
|
||||
return resp.R200(c, map[string]any{
|
||||
"kubeconfig": config.Value,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func ClusterConfigSet(ctx context.Context, db *gorm.DB, store store.Store) fiber.Handler {
|
||||
return func(c fiber.Ctx) error {
|
||||
var req struct {
|
||||
Kubeconfig string `json:"kubeconfig"`
|
||||
}
|
||||
|
||||
if err := json.Unmarshal(c.Body(), &req); err != nil {
|
||||
return resp.R400(c, "", nil, err)
|
||||
}
|
||||
|
||||
config := model.ClusterConfig{
|
||||
Key: "kubeconfig",
|
||||
Value: req.Kubeconfig,
|
||||
}
|
||||
|
||||
if err := db.Where("key = ?", "kubeconfig").Assign(config).FirstOrCreate(&config).Error; err != nil {
|
||||
return resp.R500(c, "", nil, err)
|
||||
}
|
||||
|
||||
return resp.R200(c, nil)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user