You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

updatetenantlogic.go 1.4 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. package cloud
  2. import (
  3. "context"
  4. "github.com/zeromicro/go-zero/core/logx"
  5. "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/svc"
  6. "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/types"
  7. "gitlink.org.cn/JointCloud/pcm-coordinator/pkg/models"
  8. "gitlink.org.cn/JointCloud/pcm-coordinator/pkg/utils"
  9. "gitlink.org.cn/JointCloud/pcm-kubernetes/kubernetes"
  10. )
  11. type UpdateTenantLogic struct {
  12. logx.Logger
  13. ctx context.Context
  14. svcCtx *svc.ServiceContext
  15. }
  16. func NewUpdateTenantLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateTenantLogic {
  17. return &UpdateTenantLogic{
  18. Logger: logx.WithContext(ctx),
  19. ctx: ctx,
  20. svcCtx: svcCtx,
  21. }
  22. }
  23. // UpdateTenant 更新租户数据
  24. func (l *UpdateTenantLogic) UpdateTenant(req *types.UpdateTenantReq) (resp *types.CloudResp, err error) {
  25. var tenants []*models.ScTenantInfo
  26. //从p端kubernetes获取租户信息
  27. namespace, err := l.svcCtx.K8sRpc.ListNamespace(context.Background(), &kubernetes.NamespaceListReq{})
  28. if err != nil {
  29. return nil, err
  30. }
  31. //先删除所有租户数据
  32. l.svcCtx.DbEngin.Where("type = 0").Delete(models.ScTenantInfo{})
  33. //遍历租户信息
  34. for k, v := range namespace.Data {
  35. tenants = append(tenants, &models.ScTenantInfo{
  36. Id: utils.GenSnowflakeID(),
  37. TenantName: k,
  38. Clusters: v,
  39. Type: 0,
  40. })
  41. }
  42. l.svcCtx.DbEngin.Save(&tenants)
  43. return
  44. }

PCM is positioned as Software stack over Cloud, aiming to build the standards and ecology of heterogeneous cloud collaboration for JCC in a non intrusive and autonomous peer-to-peer manner.