get available region for product
Signed-off-by: zhouqunjie <450705171@qq.com>
This commit is contained in:
parent
e6760ae532
commit
c752e46538
|
@ -14,8 +14,8 @@ import (
|
|||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
// GetPodRegions get the available region for pod
|
||||
func GetPodRegions(ctx context.Context, req *pbpod.GetPodRegionReq) (resp *pbpod.GetPodRegionResp, err error) {
|
||||
// GetPodRegion get the available region for pod
|
||||
func GetPodRegion(ctx context.Context, req *pbpod.GetPodRegionReq) (resp *pbpod.GetPodRegionResp, err error) {
|
||||
var (
|
||||
regionInit tenanter.Region
|
||||
regions []*pbtenant.Region
|
||||
|
@ -27,24 +27,7 @@ func GetPodRegions(ctx context.Context, req *pbpod.GetPodRegionReq) (resp *pbpod
|
|||
case pbtenant.CloudProvider_tencent:
|
||||
regionInit, _ = tenanter.NewRegion(req.GetProvider(), 5)
|
||||
case pbtenant.CloudProvider_huawei:
|
||||
//type result struct {
|
||||
// Args string `json:"args"`
|
||||
// Headers map[string]string `json:"headers"`
|
||||
// Origin string `json:"origin"`
|
||||
// Url string `json:"url"`
|
||||
//}
|
||||
////todo
|
||||
//resp, err := http.Get("https://apiexplorer.developer.huaweicloud.com/v4/regions?product_short=CCI&api_name=createCoreV1NamespacedPod")
|
||||
//if err != nil {
|
||||
// println("error")
|
||||
//}
|
||||
//defer resp.Body.Close()
|
||||
//body, _ := ioutil.ReadAll(resp.Body)
|
||||
//fmt.Println(string(body))
|
||||
//var res result
|
||||
//_ = json.Unmarshal(body, &res)
|
||||
//regions = append(regions, nil)
|
||||
return nil, nil
|
||||
regionInit, _ = tenanter.NewRegion(req.GetProvider(), 5)
|
||||
}
|
||||
tenanters, err := tenanter.GetTenanters(req.GetProvider())
|
||||
if err != nil {
|
||||
|
@ -231,17 +214,16 @@ func ListPod(ctx context.Context, req *pbpod.ListPodReq) (*pbpod.ListPodResp, er
|
|||
return nil, errors.WithMessage(err, "getTenanters error")
|
||||
}
|
||||
|
||||
regions := tenanter.GetAllRegionIds(req.Provider)
|
||||
//regions := tenanter.GetAllRegionIds(req.Provider)
|
||||
reqPodRegion := &pbpod.GetPodRegionReq{Provider: req.GetProvider()}
|
||||
respPodRegion, err := GetPodRegions(ctx, reqPodRegion)
|
||||
respPodRegion, err := GetPodRegion(ctx, reqPodRegion)
|
||||
if err != nil {
|
||||
return nil, errors.WithMessage(err, "getPodRegion error")
|
||||
}
|
||||
fmt.Println(respPodRegion)
|
||||
|
||||
wg.Add(len(tenanters) * len(regions))
|
||||
wg.Add(len(tenanters) * len(respPodRegion.Regions))
|
||||
for _, t := range tenanters {
|
||||
for _, region := range regions {
|
||||
for _, region := range respPodRegion.Regions {
|
||||
go func(tenant tenanter.Tenanter, region tenanter.Region) {
|
||||
defer wg.Done()
|
||||
pod, err := poder.NewPodClient(req.Provider, region, tenant)
|
||||
|
|
|
@ -2,18 +2,17 @@ package poder
|
|||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/aliyun/alibaba-cloud-sdk-go/sdk/requests"
|
||||
alieci "github.com/aliyun/alibaba-cloud-sdk-go/services/eci"
|
||||
"github.com/bitly/go-simplejson"
|
||||
"github.com/golang/glog"
|
||||
"strconv"
|
||||
"sync"
|
||||
|
||||
"github.com/aliyun/alibaba-cloud-sdk-go/sdk/requests"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"gitlink.org.cn/JCCE/PCM/common/tenanter"
|
||||
"gitlink.org.cn/JCCE/PCM/lan_trans/idl/pbpod"
|
||||
pbtenant "gitlink.org.cn/JCCE/PCM/lan_trans/idl/pbtenant"
|
||||
|
||||
alieci "github.com/aliyun/alibaba-cloud-sdk-go/services/eci"
|
||||
"github.com/pkg/errors"
|
||||
"gitlink.org.cn/JCCE/PCM/lan_trans/idl/pbtenant"
|
||||
)
|
||||
|
||||
var aliClientMutex sync.Mutex
|
||||
|
@ -28,24 +27,36 @@ func (eci *AliEci) GetPodRegion(ctx context.Context, req *pbpod.GetPodRegionReq)
|
|||
|
||||
regions := make([]*pbtenant.Region, 0)
|
||||
|
||||
request := alieci.CreateDescribeRegionsRequest()
|
||||
request.RegionId = "cn-beijing"
|
||||
resp, err := eci.cli.DescribeRegions(request)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "ali eci describe region error")
|
||||
}
|
||||
for _, eciRegion := range resp.Regions {
|
||||
requestRegion := requests.NewCommonRequest()
|
||||
requestRegion.Method = "POST"
|
||||
requestRegion.Scheme = "https" // https | http
|
||||
requestRegion.Domain = "eci.aliyuncs.com"
|
||||
requestRegion.Version = "2018-08-08"
|
||||
requestRegion.ApiName = "DescribeRegions"
|
||||
//这里需要给一个空字符串的RegionId
|
||||
requestRegion.QueryParams["RegionId"] = ""
|
||||
|
||||
regionId, err := strconv.ParseInt(eciRegion.RegionId, 10, 32)
|
||||
if err == nil {
|
||||
fmt.Printf("%T, %v\n", regionId, err)
|
||||
resp, err := eci.cli.ProcessCommonRequest(requestRegion)
|
||||
|
||||
var respRegion *simplejson.Json
|
||||
respRegion, err = simplejson.NewJson([]byte(resp.GetHttpContentString()))
|
||||
if err != nil {
|
||||
panic("解析失败")
|
||||
}
|
||||
|
||||
i := 0
|
||||
for i < len(respRegion.Get("Regions").MustArray()) {
|
||||
regionsJson := respRegion.Get("Regions").GetIndex(i)
|
||||
regionName, _ := regionsJson.Get("RegionId").String()
|
||||
regionId, _ := tenanter.GetAliRegionId(regionName)
|
||||
regionPod := &pbtenant.Region{
|
||||
Id: int32(regionId),
|
||||
Name: eciRegion.RegionEndpoint,
|
||||
Id: regionId,
|
||||
Name: regionName,
|
||||
}
|
||||
regions = append(regions, regionPod)
|
||||
i++
|
||||
}
|
||||
|
||||
return &pbpod.GetPodRegionResp{Regions: regions}, nil
|
||||
|
||||
}
|
||||
|
@ -95,45 +106,45 @@ func (eci *AliEci) CreatePod(ctx context.Context, req *pbpod.CreatePodReq) (*pbp
|
|||
if len(resp.ContainerGroupId) > 0 {
|
||||
isFinished = true
|
||||
}
|
||||
glog.Infof("--------------------Aliyun ECI Instance created--------------------")
|
||||
|
||||
return &pbpod.CreatePodResp{
|
||||
Pods: nil,
|
||||
Finished: isFinished,
|
||||
RequestId: "ali pod ID:" + resp.ContainerGroupId,
|
||||
RequestId: "Create Ali pod request ID:" + resp.RequestId,
|
||||
PodId: resp.ContainerGroupId,
|
||||
PodName: req.PodName,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (eci *AliEci) DeletePod(ctx context.Context, req *pbpod.DeletePodReq) (*pbpod.DeletePodResp, error) {
|
||||
|
||||
//生成删除请求
|
||||
deleteContainerGroupRequest := alieci.CreateDeleteContainerGroupRequest()
|
||||
deleteContainerGroupRequest.RegionId = eci.region.GetName()
|
||||
deleteContainerGroupRequest.ContainerGroupId = req.PodId
|
||||
|
||||
deleteContainerGroupResponse, err := eci.cli.DeleteContainerGroup(deleteContainerGroupRequest)
|
||||
resp, err := eci.cli.DeleteContainerGroup(deleteContainerGroupRequest)
|
||||
isFinished := true
|
||||
if err != nil {
|
||||
isFinished = false
|
||||
return nil, errors.Wrap(err, "Aliyun DeletePod error")
|
||||
}
|
||||
|
||||
requestId := deleteContainerGroupResponse.RequestId
|
||||
glog.Infof("--------------------Aliyun ECI Instance deleted--------------------")
|
||||
|
||||
return &pbpod.DeletePodResp{
|
||||
//Pods: nil,
|
||||
Finished: isFinished,
|
||||
RequestId: requestId,
|
||||
RequestId: "Delete Ali pod request ID:" + resp.RequestId,
|
||||
PodId: req.PodId,
|
||||
PodName: req.PodName,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (eci *AliEci) UpdatePod(ctx context.Context, req *pbpod.UpdatePodReq) (*pbpod.UpdatePodResp, error) {
|
||||
//TODO implement ali eci update pod
|
||||
//生成更新请求
|
||||
|
||||
updateContainerGroupRequest := alieci.CreateUpdateContainerGroupRequest()
|
||||
updateContainerGroupRequest.RegionId = eci.region.GetName()
|
||||
updateContainerGroupRequest.ContainerGroupId = req.PodId
|
||||
|
||||
//容器实体内容,这里测试可以修改配置文件中的重启策略
|
||||
updateContainerRequestContainer := make([]alieci.UpdateContainerGroupContainer, 1)
|
||||
updateContainerRequestContainer[0].Image = req.ContainerImage
|
||||
updateContainerRequestContainer[0].Name = req.ContainerName
|
||||
|
@ -142,19 +153,20 @@ func (eci *AliEci) UpdatePod(ctx context.Context, req *pbpod.UpdatePodReq) (*pbp
|
|||
updateContainerGroupRequest.Container = &updateContainerRequestContainer
|
||||
updateContainerGroupRequest.RestartPolicy = req.RestartPolicy
|
||||
|
||||
updateContainerGroupResponse, err := eci.cli.UpdateContainerGroup(updateContainerGroupRequest)
|
||||
resp, err := eci.cli.UpdateContainerGroup(updateContainerGroupRequest)
|
||||
isFinished := true
|
||||
if err != nil {
|
||||
isFinished = false
|
||||
return nil, errors.Wrap(err, "Aliyun DeletePod error")
|
||||
return nil, errors.Wrap(err, "Aliyun UpdatePod error")
|
||||
}
|
||||
|
||||
requestId := updateContainerGroupResponse.RequestId
|
||||
glog.Infof("--------------------Aliyun ECI Instance updated--------------------")
|
||||
|
||||
return &pbpod.UpdatePodResp{
|
||||
//Pods: nil,
|
||||
Finished: isFinished,
|
||||
RequestId: requestId,
|
||||
RequestId: "Update Ali pod request ID:" + resp.RequestId,
|
||||
PodId: req.PodId,
|
||||
PodName: req.PodName,
|
||||
}, nil
|
||||
}
|
||||
|
||||
|
@ -162,6 +174,7 @@ func (eci *AliEci) ListPodDetail(ctx context.Context, req *pbpod.ListPodDetailRe
|
|||
request := alieci.CreateDescribeContainerGroupsRequest()
|
||||
request.NextToken = req.NextToken
|
||||
resp, err := eci.cli.DescribeContainerGroups(request)
|
||||
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "Aliyun ListDetail error")
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@ package poder
|
|||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
util "github.com/alibabacloud-go/tea-utils/service"
|
||||
"sync"
|
||||
|
||||
"k8s.io/apimachinery/pkg/api/resource"
|
||||
|
@ -32,13 +33,14 @@ type HuaweiCci struct {
|
|||
}
|
||||
|
||||
func (cci *HuaweiCci) GetPodRegion(ctx context.Context, req *pbpod.GetPodRegionReq) (*pbpod.GetPodRegionResp, error) {
|
||||
//TODO implement me
|
||||
//todo
|
||||
var (
|
||||
regions []*pbtenant.Region
|
||||
)
|
||||
huaweiRegionName, _ := tenanter.GetHuaweiRegionName(5)
|
||||
region := &pbtenant.Region{
|
||||
Id: 1,
|
||||
Name: "region",
|
||||
Id: 5,
|
||||
Name: huaweiRegionName,
|
||||
}
|
||||
regions = append(regions, region)
|
||||
resp := &pbpod.GetPodRegionResp{
|
||||
|
@ -48,6 +50,7 @@ func (cci *HuaweiCci) GetPodRegion(ctx context.Context, req *pbpod.GetPodRegionR
|
|||
return resp, nil
|
||||
}
|
||||
|
||||
//CCI auth through iam
|
||||
const (
|
||||
apiVersion = "client.authentication.k8s.io/v1beta1"
|
||||
iamEndpoint = "https://iam.myhuaweicloud.com"
|
||||
|
@ -124,7 +127,6 @@ func (cci *HuaweiCci) CreatePod(ctx context.Context, req *pbpod.CreatePodReq) (*
|
|||
}
|
||||
|
||||
resp, err := cci.cli.CoreV1().Pods(req.Namespace).Create(&pod)
|
||||
glog.Info("Huawei create pod resp", resp)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "Huaweiyun CreatePod error")
|
||||
}
|
||||
|
@ -134,33 +136,39 @@ func (cci *HuaweiCci) CreatePod(ctx context.Context, req *pbpod.CreatePodReq) (*
|
|||
isFinished = true
|
||||
}
|
||||
|
||||
glog.Infof("--------------------Huawei CCI Instance created--------------------")
|
||||
|
||||
return &pbpod.CreatePodResp{
|
||||
Pods: nil,
|
||||
Finished: isFinished,
|
||||
RequestId: "huawei pod Name:" + resp.Name,
|
||||
RequestId: "Create huawei pod request ID:" + resp.GenerateName,
|
||||
PodId: string(resp.Generation),
|
||||
PodName: resp.Name,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (cci *HuaweiCci) DeletePod(ctx context.Context, req *pbpod.DeletePodReq) (*pbpod.DeletePodResp, error) {
|
||||
podName := req.PodName
|
||||
fmt.Println("Huawei ContainerGroup:", podName, " Deleted")
|
||||
err := cci.cli.CoreV1().Pods(req.Namespace).Delete(podName, &metav1.DeleteOptions{})
|
||||
|
||||
glog.Info("Huawei delete pod resp", err)
|
||||
err := cci.cli.CoreV1().Pods(req.GetNamespace()).Delete(req.PodName, &metav1.DeleteOptions{})
|
||||
|
||||
isFinished := true
|
||||
if err != nil {
|
||||
isFinished = false
|
||||
return nil, errors.Wrap(err, "Huaweiyun DeletePod error")
|
||||
}
|
||||
|
||||
glog.Infof("--------------------Huawei CCI Instance deleted--------------------")
|
||||
glog.Infof(*util.ToJSONString(util.ToMap(err)))
|
||||
|
||||
return &pbpod.DeletePodResp{
|
||||
//Pods: err,
|
||||
Finished: isFinished,
|
||||
//RequestId: resp.RequestId,
|
||||
RequestId: "Delete huawei pod request ID:" + req.PodName,
|
||||
PodId: req.PodName,
|
||||
PodName: req.PodName,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (cci *HuaweiCci) UpdatePod(ctx context.Context, req *pbpod.UpdatePodReq) (*pbpod.UpdatePodResp, error) {
|
||||
|
||||
qresp, err := cci.cli.CoreV1().Pods(req.GetNamespace()).Get(req.PodName, metav1.GetOptions{})
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "Huaweiyun UpdatePod error")
|
||||
|
@ -182,20 +190,25 @@ func (cci *HuaweiCci) UpdatePod(ctx context.Context, req *pbpod.UpdatePodReq) (*
|
|||
return nil, errors.Wrap(err, "Huaweiyun UpdatePod error")
|
||||
}
|
||||
|
||||
glog.Infof("--------------------Huawei CCI Instance updated--------------------")
|
||||
|
||||
isFinished := false
|
||||
if len(resp.UID) > 0 {
|
||||
isFinished = true
|
||||
}
|
||||
|
||||
return &pbpod.UpdatePodResp{
|
||||
Pod: nil,
|
||||
Finished: isFinished,
|
||||
//RequestId: resp.RequestId,
|
||||
RequestId: "Update huawei pod request ID:" + resp.GenerateName,
|
||||
PodId: string(resp.Generation),
|
||||
PodName: resp.Name,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (cci *HuaweiCci) ListPodDetail(ctx context.Context, req *pbpod.ListPodDetailReq) (*pbpod.ListPodDetailResp, error) {
|
||||
|
||||
resp, err := cci.cli.CoreV1().Pods(req.GetNamespace()).List(metav1.ListOptions{})
|
||||
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "Huaweiyun ListDetail pod error")
|
||||
}
|
||||
|
@ -217,6 +230,8 @@ func (cci *HuaweiCci) ListPodDetail(ctx context.Context, req *pbpod.ListPodDetai
|
|||
}
|
||||
}
|
||||
|
||||
glog.Infof("--------------------Huawei CCI Instance updated--------------------")
|
||||
|
||||
isFinished := false
|
||||
if len(pods) < int(req.PageSize) {
|
||||
isFinished = true
|
||||
|
@ -227,7 +242,5 @@ func (cci *HuaweiCci) ListPodDetail(ctx context.Context, req *pbpod.ListPodDetai
|
|||
Finished: isFinished,
|
||||
PageNumber: req.PageNumber + 1,
|
||||
PageSize: req.PageSize,
|
||||
//NextToken: resp.NextToken,
|
||||
//RequestId: resp.RequestId,
|
||||
}, nil
|
||||
}
|
||||
|
|
|
@ -31,12 +31,14 @@ type K8SPoder struct {
|
|||
}
|
||||
|
||||
func (k K8SPoder) GetPodRegion(ctx context.Context, req *pbpod.GetPodRegionReq) (*pbpod.GetPodRegionResp, error) {
|
||||
//todo
|
||||
var (
|
||||
regions []*pbtenant.Region
|
||||
)
|
||||
huaweiRegionName, _ := tenanter.GetK8SRegionName(0)
|
||||
region := &pbtenant.Region{
|
||||
Id: 1,
|
||||
Name: "region",
|
||||
Id: 0,
|
||||
Name: huaweiRegionName,
|
||||
}
|
||||
regions = append(regions, region)
|
||||
resp := &pbpod.GetPodRegionResp{
|
||||
|
@ -80,45 +82,6 @@ func newK8SClient(tenant tenanter.Tenanter) (Poder, error) {
|
|||
}, nil
|
||||
}
|
||||
|
||||
func (k K8SPoder) ListPodDetail(ctx context.Context, req *pbpod.ListPodDetailReq) (*pbpod.ListPodDetailResp, error) {
|
||||
//TODO implement me
|
||||
resp, err := k.cli.CoreV1().Pods(req.GetNamespace()).List(metav1.ListOptions{})
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "K8S ListDetail pod error")
|
||||
}
|
||||
glog.Info("K8S ListDetail pod success", resp.Items)
|
||||
var pods = make([]*pbpod.PodInstance, len(resp.Items))
|
||||
for k, v := range resp.Items {
|
||||
pods[k] = &pbpod.PodInstance{
|
||||
Provider: pbtenant.CloudProvider_k8s,
|
||||
AccountName: req.AccountName,
|
||||
PodId: string(v.GetUID()),
|
||||
PodName: v.Name,
|
||||
ContainerImage: v.Spec.Containers[0].Image,
|
||||
ContainerName: v.Spec.Containers[0].Name,
|
||||
CpuPod: v.Spec.Containers[0].Resources.Requests.Cpu().String(),
|
||||
MemoryPod: v.Spec.Containers[0].Resources.Requests.Memory().String(),
|
||||
Namespace: v.Namespace,
|
||||
Status: string(v.Status.Phase),
|
||||
}
|
||||
}
|
||||
|
||||
isFinished := false
|
||||
if len(pods) < int(req.PageSize) {
|
||||
isFinished = true
|
||||
}
|
||||
|
||||
return &pbpod.ListPodDetailResp{
|
||||
Pods: pods,
|
||||
Finished: isFinished,
|
||||
PageNumber: req.PageNumber + 1,
|
||||
PageSize: req.PageSize,
|
||||
//NextToken: resp.NextToken,
|
||||
//RequestId: resp.RequestId,
|
||||
}, nil
|
||||
|
||||
}
|
||||
|
||||
func (k *K8SPoder) CreatePod(ctx context.Context, req *pbpod.CreatePodReq) (*pbpod.CreatePodResp, error) {
|
||||
|
||||
pod := corev1.Pod{
|
||||
|
@ -150,21 +113,22 @@ func (k *K8SPoder) CreatePod(ctx context.Context, req *pbpod.CreatePodReq) (*pbp
|
|||
}
|
||||
|
||||
resp, err := k.cli.CoreV1().Pods(req.Namespace).Create(&pod)
|
||||
|
||||
glog.Info("K8S create pod resp", resp)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "K8S CreatePod error")
|
||||
}
|
||||
|
||||
glog.Infof("--------------------K8S Pod Instance created--------------------")
|
||||
|
||||
isFinished := false
|
||||
if len(resp.UID) > 0 {
|
||||
isFinished = true
|
||||
}
|
||||
|
||||
return &pbpod.CreatePodResp{
|
||||
Pods: nil,
|
||||
Finished: isFinished,
|
||||
RequestId: "K8S pod Name:" + resp.Name,
|
||||
PodId: string(resp.UID),
|
||||
PodName: resp.Name,
|
||||
}, nil
|
||||
|
||||
}
|
||||
|
@ -175,7 +139,8 @@ func (k K8SPoder) DeletePod(ctx context.Context, req *pbpod.DeletePodReq) (*pbpo
|
|||
fmt.Println("K8S ContainerGroup:", podName, " Deleted")
|
||||
err := k.cli.CoreV1().Pods(req.Namespace).Delete(podName, &metav1.DeleteOptions{})
|
||||
|
||||
glog.Info("K8S delete pod resp", err)
|
||||
glog.Infof("--------------------K8S Pod Instance deleted--------------------")
|
||||
|
||||
isFinished := true
|
||||
if err != nil {
|
||||
isFinished = false
|
||||
|
@ -183,9 +148,10 @@ func (k K8SPoder) DeletePod(ctx context.Context, req *pbpod.DeletePodReq) (*pbpo
|
|||
}
|
||||
|
||||
return &pbpod.DeletePodResp{
|
||||
//Pods: err,
|
||||
Finished: isFinished,
|
||||
//RequestId: resp.RequestId,
|
||||
RequestId: "K8S pod Name:" + req.PodName,
|
||||
PodId: req.PodName,
|
||||
PodName: req.PodName,
|
||||
}, nil
|
||||
}
|
||||
|
||||
|
@ -207,20 +173,60 @@ func (k K8SPoder) UpdatePod(ctx context.Context, req *pbpod.UpdatePodReq) (*pbpo
|
|||
}
|
||||
pod.Spec.Containers[0].Image = req.ContainerImage
|
||||
resp, err := k.cli.CoreV1().Pods(req.Namespace).Update(&pod)
|
||||
glog.Info("K8S update pod resp", resp)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "K8S UpdatePod error")
|
||||
}
|
||||
|
||||
glog.Infof("--------------------K8S Pod Instance updated--------------------")
|
||||
|
||||
isFinished := false
|
||||
if len(resp.UID) > 0 {
|
||||
isFinished = true
|
||||
}
|
||||
|
||||
return &pbpod.UpdatePodResp{
|
||||
Pod: nil,
|
||||
Finished: isFinished,
|
||||
//RequestId: resp.RequestId,
|
||||
RequestId: "K8S pod Name:" + req.PodName,
|
||||
PodId: string(resp.UID),
|
||||
PodName: req.PodName,
|
||||
}, nil
|
||||
|
||||
}
|
||||
|
||||
func (k K8SPoder) ListPodDetail(ctx context.Context, req *pbpod.ListPodDetailReq) (*pbpod.ListPodDetailResp, error) {
|
||||
resp, err := k.cli.CoreV1().Pods(req.GetNamespace()).List(metav1.ListOptions{})
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "K8S ListDetail pod error")
|
||||
}
|
||||
|
||||
var pods = make([]*pbpod.PodInstance, len(resp.Items))
|
||||
for k, v := range resp.Items {
|
||||
pods[k] = &pbpod.PodInstance{
|
||||
Provider: pbtenant.CloudProvider_k8s,
|
||||
AccountName: req.AccountName,
|
||||
PodId: string(v.GetUID()),
|
||||
PodName: v.Name,
|
||||
ContainerImage: v.Spec.Containers[0].Image,
|
||||
ContainerName: v.Spec.Containers[0].Name,
|
||||
CpuPod: v.Spec.Containers[0].Resources.Requests.Cpu().String(),
|
||||
MemoryPod: v.Spec.Containers[0].Resources.Requests.Memory().String(),
|
||||
Namespace: v.Namespace,
|
||||
Status: string(v.Status.Phase),
|
||||
}
|
||||
}
|
||||
|
||||
glog.Infof("--------------------Huawei CCI Instance updated--------------------")
|
||||
|
||||
isFinished := false
|
||||
if len(pods) < int(req.PageSize) {
|
||||
isFinished = true
|
||||
}
|
||||
|
||||
return &pbpod.ListPodDetailResp{
|
||||
Pods: pods,
|
||||
Finished: isFinished,
|
||||
PageNumber: req.PageNumber + 1,
|
||||
PageSize: req.PageSize,
|
||||
}, nil
|
||||
|
||||
}
|
||||
|
|
|
@ -67,7 +67,7 @@ func newTencentEksClient(region tenanter.Region, tenant tenanter.Tenanter) (Pode
|
|||
}
|
||||
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "init ali ecs client error")
|
||||
return nil, errors.Wrap(err, "init tencent eks client error")
|
||||
}
|
||||
|
||||
return &TencentEks{
|
||||
|
@ -97,8 +97,6 @@ func (eks TencentEks) CreatePod(ctx context.Context, req *pbpod.CreatePodReq) (*
|
|||
container[0] = new(tencenteks.Container)
|
||||
container[0].Name = &containerName
|
||||
container[0].Image = &containerImage
|
||||
//container[0].Cpu = containerCpuPt
|
||||
//container[0].Memory = containerMemoryPt
|
||||
|
||||
request.Containers = container
|
||||
eksCpu64, err := strconv.ParseFloat(eksCpu, 64)
|
||||
|
@ -115,15 +113,17 @@ func (eks TencentEks) CreatePod(ctx context.Context, req *pbpod.CreatePodReq) (*
|
|||
}
|
||||
|
||||
isFinished := false
|
||||
|
||||
if resp.Response.RequestId != nil {
|
||||
isFinished = true
|
||||
}
|
||||
|
||||
glog.Infof("--------------------K8S Pod Instance created--------------------")
|
||||
|
||||
return &pbpod.CreatePodResp{
|
||||
Pods: nil,
|
||||
Finished: isFinished,
|
||||
RequestId: *resp.Response.RequestId,
|
||||
RequestId: "tencent pod create request id:" + *resp.Response.RequestId,
|
||||
PodId: *resp.Response.EksCiIds[0],
|
||||
PodName: req.PodName,
|
||||
}, nil
|
||||
|
||||
}
|
||||
|
@ -140,12 +140,13 @@ func (eks *TencentEks) DeletePod(ctx context.Context, req *pbpod.DeletePodReq) (
|
|||
return nil, errors.Wrap(err, "Tencent DeletePod error")
|
||||
}
|
||||
|
||||
requestId := resp.Response.RequestId
|
||||
glog.Infof("--------------------K8S Pod Instance deleted--------------------")
|
||||
|
||||
return &pbpod.DeletePodResp{
|
||||
Pods: nil,
|
||||
Finished: isFinished,
|
||||
RequestId: *requestId,
|
||||
RequestId: "tencent pod delete request id:" + *resp.Response.RequestId,
|
||||
PodId: req.PodId,
|
||||
PodName: req.PodName,
|
||||
}, nil
|
||||
}
|
||||
|
||||
|
@ -167,14 +168,16 @@ func (eks *TencentEks) UpdatePod(ctx context.Context, req *pbpod.UpdatePodReq) (
|
|||
isFinished := true
|
||||
if err != nil {
|
||||
isFinished = false
|
||||
glog.Errorf("Tencent UpdatePod error: %v", err)
|
||||
return nil, errors.Wrap(err, "Tencent UpdatePod error")
|
||||
}
|
||||
|
||||
glog.Infof("--------------------K8S Pod Instance deleted--------------------")
|
||||
|
||||
return &pbpod.UpdatePodResp{
|
||||
Pod: nil,
|
||||
Finished: isFinished,
|
||||
RequestId: "tencent pod ID:" + *resp.Response.EksCiId,
|
||||
RequestId: "tencent pod update request id:" + *resp.Response.RequestId,
|
||||
PodId: req.PodId,
|
||||
PodName: req.PodName,
|
||||
}, nil
|
||||
}
|
||||
|
||||
|
@ -208,88 +211,14 @@ func (eks TencentEks) ListPodDetail(ctx context.Context, req *pbpod.ListPodDetai
|
|||
if len(ekspods) < int(req.PageSize) {
|
||||
isFinished = true
|
||||
}
|
||||
|
||||
glog.Infof("--------------------K8S Pod Instance deleted--------------------")
|
||||
|
||||
return &pbpod.ListPodDetailResp{
|
||||
Pods: ekspods,
|
||||
Finished: isFinished,
|
||||
PageNumber: req.PageNumber + 1,
|
||||
PageSize: req.PageSize,
|
||||
//NextToken: resp.NextToken,
|
||||
RequestId: *resp.Response.RequestId,
|
||||
}, nil
|
||||
}
|
||||
|
||||
//
|
||||
//func ListEksInstance(cloudStack string, akskPath string, configPath string) {
|
||||
//
|
||||
// configCommon, _ := pcmCommon.PCMconfig(configPath)
|
||||
// configAksk, _ := aksk.AkskConfig(cloudStack, akskPath)
|
||||
//
|
||||
// credential := common.NewCredential(configAksk.AccessKey, configAksk.SecretKey)
|
||||
// cpf := profile.NewClientProfile()
|
||||
// cpf.HttpProfile.Endpoint = "tke.tencentcloudapi.com"
|
||||
// client, _ := tke.NewClient(credential, configCommon.RegionId, cpf)
|
||||
//
|
||||
// request := tke.NewDescribeEKSContainerInstancesRequest()
|
||||
//
|
||||
// response, err := client.DescribeEKSContainerInstances(request)
|
||||
// if _, ok := err.(*errors.TencentCloudSDKError); ok {
|
||||
// fmt.Printf("An API error has returned: %s", err)
|
||||
// return
|
||||
// }
|
||||
// if err != nil {
|
||||
// panic(err)
|
||||
// }
|
||||
// fmt.Printf("%s", response.ToJsonString())
|
||||
//}
|
||||
//
|
||||
//func UpdateEksInstance(cloudStack string, akskPath string, configPath string) {
|
||||
//
|
||||
// configCommon, _ := pcmCommon.PCMconfig(configPath)
|
||||
// configAksk, _ := aksk.AkskConfig(cloudStack, akskPath)
|
||||
//
|
||||
// credential := common.NewCredential(configAksk.AccessKey, configAksk.SecretKey)
|
||||
// cpf := profile.NewClientProfile()
|
||||
// cpf.HttpProfile.Endpoint = "tke.tencentcloudapi.com"
|
||||
// client, _ := tke.NewClient(credential, configCommon.RegionId, cpf)
|
||||
//
|
||||
// request := tke.NewUpdateEKSContainerInstanceRequest()
|
||||
// request.EksCiId = &configCommon.ContainerGroupIdUpdate
|
||||
// request.Name = &configCommon.ContainerGroupNameUpdate
|
||||
//
|
||||
// response, err := client.UpdateEKSContainerInstance(request)
|
||||
// if _, ok := err.(*errors.TencentCloudSDKError); ok {
|
||||
// fmt.Printf("An API error has returned: %s", err)
|
||||
// return
|
||||
// }
|
||||
// if err != nil {
|
||||
// panic(err)
|
||||
// }
|
||||
// fmt.Printf("%s", response.ToJsonString())
|
||||
//}
|
||||
//
|
||||
//func DeleteEksInstance(cloudStack string, akskPath string, configPath string) {
|
||||
//
|
||||
// configCommon, _ := pcmCommon.PCMconfig(configPath)
|
||||
// configAksk, _ := aksk.AkskConfig(cloudStack, akskPath)
|
||||
//
|
||||
// credential := common.NewCredential(configAksk.AccessKey, configAksk.SecretKey)
|
||||
// cpf := profile.NewClientProfile()
|
||||
// cpf.HttpProfile.Endpoint = "tke.tencentcloudapi.com"
|
||||
// client, _ := tke.NewClient(credential, configCommon.RegionId, cpf)
|
||||
//
|
||||
// request := tke.NewDeleteEKSContainerInstancesRequest()
|
||||
// eksCiIds := make([]*string, 1)
|
||||
// eksCiIds[0] = &configCommon.ContainerGroupIdDelete
|
||||
//
|
||||
// request.EksCiIds = eksCiIds
|
||||
//
|
||||
// response, err := client.DeleteEKSContainerInstances(request)
|
||||
// if _, ok := err.(*errors.TencentCloudSDKError); ok {
|
||||
// fmt.Printf("An API error has returned: %s", err)
|
||||
// return
|
||||
// }
|
||||
// if err != nil {
|
||||
// panic(err)
|
||||
// }
|
||||
// fmt.Printf("%s", response.ToJsonString())
|
||||
//}
|
||||
|
|
|
@ -13,7 +13,7 @@ import (
|
|||
|
||||
// GetProdRegions get available region for product
|
||||
func (s *Server) GetProdRegions(ctx context.Context, req *pbpod.GetPodRegionReq) (*pbpod.GetPodRegionResp, error) {
|
||||
resp, err := pod.GetPodRegions(ctx, req)
|
||||
resp, err := pod.GetPodRegion(ctx, req)
|
||||
if err != nil {
|
||||
glog.Errorf("CreatePods error %+v", err)
|
||||
return nil, status.Errorf(codes.Internal, err.Error())
|
||||
|
|
|
@ -35,11 +35,11 @@ func NewRegion(provider pbtenant.CloudProvider, regionId int32) (Region, error)
|
|||
|
||||
switch provider {
|
||||
case pbtenant.CloudProvider_ali:
|
||||
r.regionName, err = getAliRegionName(regionId)
|
||||
r.regionName, err = GetAliRegionName(regionId)
|
||||
case pbtenant.CloudProvider_tencent:
|
||||
r.regionName, err = getTencentRegionName(regionId)
|
||||
r.regionName, err = GetTencentRegionName(regionId)
|
||||
case pbtenant.CloudProvider_huawei:
|
||||
r.regionName, err = getHuaweiRegionName(regionId)
|
||||
r.regionName, err = GetHuaweiRegionName(regionId)
|
||||
//case pbtenant.CloudProvider_aws:
|
||||
// r.regionName, err = getAwsRegionName(regionId)
|
||||
}
|
||||
|
@ -87,8 +87,8 @@ func GetAllRegionIds(provider pbtenant.CloudProvider) (regions []Region) {
|
|||
return
|
||||
}
|
||||
|
||||
// prefix ali_
|
||||
func getAliRegionName(regionId int32) (string, error) {
|
||||
// GetAliRegionName prefix ali_
|
||||
func GetAliRegionName(regionId int32) (string, error) {
|
||||
name, ok := pbtenant.AliRegionId_name[regionId]
|
||||
if !ok || regionId == int32(pbtenant.AliRegionId_ali_all) {
|
||||
return "", errors.WithMessagef(ErrNoExistAliRegionId, "input region id is %d", regionId)
|
||||
|
@ -97,8 +97,18 @@ func getAliRegionName(regionId int32) (string, error) {
|
|||
return region[4:], nil
|
||||
}
|
||||
|
||||
// prefix tc_
|
||||
func getTencentRegionName(regionId int32) (string, error) {
|
||||
// GetAliRegionId prefix ali_
|
||||
func GetAliRegionId(regionName string) (int32, error) {
|
||||
regionName = "ali_" + strings.ReplaceAll(regionName, "-", "_")
|
||||
id, ok := pbtenant.AliRegionId_value[regionName]
|
||||
if !ok || regionName == "" {
|
||||
return 0, errors.WithMessagef(ErrNoExistAliRegionId, "input region id is %s", regionName)
|
||||
}
|
||||
return id, nil
|
||||
}
|
||||
|
||||
// GetTencentRegionName prefix tencent
|
||||
func GetTencentRegionName(regionId int32) (string, error) {
|
||||
name, ok := pbtenant.TencentRegionId_name[regionId]
|
||||
if !ok || regionId == int32(pbtenant.TencentRegionId_tc_all) {
|
||||
return "", errors.WithMessagef(ErrNoExistTencentRegionId, "input region id is %d", regionId)
|
||||
|
@ -107,8 +117,8 @@ func getTencentRegionName(regionId int32) (string, error) {
|
|||
return region[3:], nil
|
||||
}
|
||||
|
||||
// prefix hw_
|
||||
func getHuaweiRegionName(regionId int32) (string, error) {
|
||||
// GetHuaweiRegionName prefix huawei
|
||||
func GetHuaweiRegionName(regionId int32) (string, error) {
|
||||
name, ok := pbtenant.HuaweiRegionId_name[regionId]
|
||||
if !ok || regionId == int32(pbtenant.HuaweiRegionId_hw_all) {
|
||||
return "", errors.WithMessagef(ErrNoExistHuaweiRegionId, "input region id is %d", regionId)
|
||||
|
@ -117,8 +127,38 @@ func getHuaweiRegionName(regionId int32) (string, error) {
|
|||
return region[3:], nil
|
||||
}
|
||||
|
||||
// prefix aws_
|
||||
func getAwsRegionName(regionId int32) (string, error) {
|
||||
// GetHuaweiRegionId prefix huawei
|
||||
func GetHuaweiRegionId(regionName string) (int32, error) {
|
||||
regionName = "hw_" + strings.ReplaceAll(regionName, "-", "_")
|
||||
id, ok := pbtenant.AliRegionId_value[regionName]
|
||||
if !ok || regionName == "" {
|
||||
return 0, errors.WithMessagef(ErrNoExistAliRegionId, "input region id is %s", regionName)
|
||||
}
|
||||
return id, nil
|
||||
}
|
||||
|
||||
// GetK8SRegionName prefix ali_
|
||||
func GetK8SRegionName(regionId int32) (string, error) {
|
||||
name, ok := pbtenant.AliRegionId_name[regionId]
|
||||
if !ok || regionId == int32(pbtenant.AliRegionId_ali_all) {
|
||||
return "", errors.WithMessagef(ErrNoExistAliRegionId, "input region id is %d", regionId)
|
||||
}
|
||||
region := strings.ReplaceAll(name, "_", "-")
|
||||
return region[4:], nil
|
||||
}
|
||||
|
||||
// GetK8SRegionId prefix ali_
|
||||
func GetK8SRegionId(regionName string) (int32, error) {
|
||||
regionName = "ali_" + strings.ReplaceAll(regionName, "-", "_")
|
||||
id, ok := pbtenant.AliRegionId_value[regionName]
|
||||
if !ok || regionName == "" {
|
||||
return 0, errors.WithMessagef(ErrNoExistAliRegionId, "input region id is %s", regionName)
|
||||
}
|
||||
return id, nil
|
||||
}
|
||||
|
||||
// GetAwsRegionName prefix aws_
|
||||
func GetAwsRegionName(regionId int32) (string, error) {
|
||||
name, ok := pbtenant.AwsRegionId_name[regionId]
|
||||
if !ok || regionId == int32(pbtenant.AwsRegionId_aws_all) {
|
||||
return "", errors.WithMessagef(ErrNoExistAwsRegionId, "input region id is %d", regionId)
|
||||
|
|
2
go.mod
2
go.mod
|
@ -9,6 +9,7 @@ require (
|
|||
github.com/alibabacloud-go/tea v1.1.15
|
||||
github.com/alibabacloud-go/tea-utils v1.3.9
|
||||
github.com/aliyun/alibaba-cloud-sdk-go v1.61.1530
|
||||
github.com/bitly/go-simplejson v0.5.0
|
||||
github.com/go-yaml/yaml v2.1.0+incompatible
|
||||
github.com/golang/glog v1.0.0
|
||||
github.com/grpc-ecosystem/grpc-gateway/v2 v2.10.0
|
||||
|
@ -30,6 +31,7 @@ require (
|
|||
github.com/alibabacloud-go/endpoint-util v1.1.0 // indirect
|
||||
github.com/alibabacloud-go/openapi-util v0.0.7 // indirect
|
||||
github.com/aliyun/credentials-go v1.1.2 // indirect
|
||||
github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869 // indirect
|
||||
github.com/davecgh/go-spew v1.1.1 // indirect
|
||||
github.com/gogo/protobuf v0.0.0-20171007142547-342cbe0a0415 // indirect
|
||||
github.com/golang/protobuf v1.5.2 // indirect
|
||||
|
|
|
@ -82,12 +82,14 @@ message CreatePodReq {
|
|||
}
|
||||
|
||||
message CreatePodResp {
|
||||
// Pod集合
|
||||
repeated PodInstance pods = 1;
|
||||
// 查询是否完成,如果为否-false,则可以将下面三个分页参数填入到请求中,继续查询
|
||||
bool finished = 2;
|
||||
bool finished = 1;
|
||||
// 请求id,出现问题后提供给云厂商,排查问题
|
||||
string request_id = 3;
|
||||
string request_id = 2;
|
||||
// podId
|
||||
string pod_id = 3;
|
||||
// podName
|
||||
string pod_name = 4;
|
||||
}
|
||||
|
||||
message DeletePodReq {
|
||||
|
@ -106,12 +108,14 @@ message DeletePodReq {
|
|||
}
|
||||
|
||||
message DeletePodResp {
|
||||
// Pod集合
|
||||
repeated PodInstance pods = 1;
|
||||
// 查询是否完成,如果为否-false,则可以将下面三个分页参数填入到请求中,继续查询
|
||||
bool finished = 2;
|
||||
bool finished = 1;
|
||||
// 请求id,出现问题后提供给云厂商,排查问题
|
||||
string request_id = 3;
|
||||
string request_id = 2;
|
||||
// podId
|
||||
string pod_id = 3;
|
||||
// podName
|
||||
string pod_name = 4;
|
||||
}
|
||||
|
||||
message UpdatePodReq {
|
||||
|
@ -142,12 +146,14 @@ message UpdatePodReq {
|
|||
}
|
||||
|
||||
message UpdatePodResp {
|
||||
// Pod集合
|
||||
PodInstance pod = 1;
|
||||
// 查询是否完成,如果为否-false,则可以将下面三个分页参数填入到请求中,继续查询
|
||||
bool finished = 2;
|
||||
bool finished = 1;
|
||||
// 请求id,出现问题后提供给云厂商,排查问题
|
||||
string request_id = 3;
|
||||
string request_id = 2;
|
||||
// podId
|
||||
string pod_id = 3;
|
||||
// podName
|
||||
string pod_name = 4;
|
||||
}
|
||||
|
||||
message ListPodDetailReq {
|
||||
|
@ -212,7 +218,6 @@ message GetPodRegionResp {
|
|||
|
||||
message ListPodAllReq{}
|
||||
|
||||
|
||||
// Pod类产品接口
|
||||
// 阿里云 - ECI
|
||||
// 腾讯云 - TKS
|
||||
|
|
Loading…
Reference in New Issue