Files
ocdp-go/backend
Ivan087 47849042a7 feat: complete E2E deployment flow with storage layered config and values template versioning
- Instance deployment: charts browser, deploy modal, instances list
- Values Template version management (create/history/rollback)
- Storage layered config (cluster > workspace > shared priority)
- Cluster credential decryptIfNeeded for mixed encrypted/plaintext kubeconfig
- YAML syntax validation (client-side + server-side warning)
- Frontend: charts, instances, storage, templates, admin pages
- Backend: storage service, instance service, cluster service, helm client
- Multi-Tenant Kubeconfig.md: added by user
2026-04-30 16:31:00 +08:00
..
2025-11-13 02:54:06 +00:00
2025-11-13 02:54:06 +00:00
2025-11-13 02:54:06 +00:00
2025-11-13 02:54:06 +00:00
2025-11-13 02:54:06 +00:00
2025-11-13 02:54:06 +00:00
2025-11-13 02:54:06 +00:00
2025-11-13 02:54:06 +00:00

OCDP Backend

Go 后端服务,提供 Kubernetes Helm Chart 部署能力。

技术栈

  • Go 1.21+
  • gorilla/mux (HTTP 路由)
  • ORAS Go SDK v2 (OCI 操作)
  • Helm SDK (Helm 操作)
  • Kubernetes client-go
  • PostgreSQL

启动

# Mock 模式(无需数据库,无需外部服务)
ADAPTER_MODE=mock go run cmd/api/main.go

# 生产模式(需要 PostgreSQL + K8s/Harbor 连接验证)
# 启动 PostgreSQL
docker compose up -d postgres

# 启动后端(生产模式)
cd backend
export DATABASE_URL="postgres://postgres:postgres@localhost:5432/ocdp?sslmode=disable"
export JWT_SECRET="your-jwt-secret"
export ENCRYPTION_KEY="your-32-byte-encryption-key"
export PORT=8081
export ADAPTER_MODE=production
export KUBECONFIG=/home/ivanwu/.kube/config  # 或你的 kubeconfig 路径

# Harbor 凭证(可选,用于验证 Registry 连接)
export HARBOR_URL="https://harbor.bwgdi.com"
export HARBOR_USERNAME="your-harbor-user"
export HARBOR_PASSWORD="your-harbor-password"

# NFS 配置(可选)
export NFS_SERVER="10.6.80.11"
export NFS_SHARE="/volume1/NFS"

go run cmd/api/main.go

环境变量说明

变量 必需 说明
DATABASE_URL PostgreSQL 连接字符串
JWT_SECRET JWT 签名密钥
ENCRYPTION_KEY 32位加密密钥
PORT 服务端口,默认 8080
ADAPTER_MODE mockproduction,默认 production
KUBECONFIG 生产模式 Kubernetes kubeconfig 文件路径
HARBOR_URL Harbor URL用于 Registry 验证
HARBOR_USERNAME Harbor 用户名
HARBOR_PASSWORD Harbor 密码

连接验证

在生产模式下,创建 Cluster 或 Registry 时会自动验证连接:

  • Cluster: 尝试使用提供的凭证连接 K8s API Server
  • Registry: 尝试使用提供的凭证登录 Harbor

如果验证失败,创建会返回错误信息。

API 访问

项目结构

backend/
├── cmd/api/               # 入口
├── internal/
│   ├── domain/            # 领域层
│   │   ├── entity/        # 实体
│   │   ├── service/       # 业务逻辑
│   │   └── repository/    # 接口
│   ├── adapter/
│   │   ├── input/http/    # REST API
│   │   └── output/        # 数据库、OCI、Helm
│   └── bootstrap/         # 启动配置
└── docs/                  # OpenAPI 规范