Add huawei create pod impl
Signed-off-by: devad <cossjie@foxmail.com>
This commit is contained in:
parent
635b52b5c8
commit
299a10a6ce
|
@ -5,6 +5,8 @@ import (
|
|||
"fmt"
|
||||
"sync"
|
||||
|
||||
"k8s.io/apimachinery/pkg/api/resource"
|
||||
|
||||
"github.com/golang/glog"
|
||||
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
|
@ -12,11 +14,11 @@ import (
|
|||
"gitlink.org.cn/JCCE/PCM/lan_trans/idl/pbpod"
|
||||
"gitlink.org.cn/JCCE/PCM/lan_trans/idl/pbtenant"
|
||||
|
||||
corev1 "k8s.io/api/core/v1"
|
||||
huaweicci "k8s.io/client-go/kubernetes"
|
||||
"k8s.io/client-go/tools/clientcmd"
|
||||
"k8s.io/client-go/tools/clientcmd/api"
|
||||
|
||||
huaweicci "k8s.io/client-go/kubernetes"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"gitlink.org.cn/JCCE/PCM/common/tenanter"
|
||||
)
|
||||
|
@ -76,8 +78,8 @@ func newHuaweiCciClient(region tenanter.Region, tenant tenanter.Tenanter) (Poder
|
|||
}, nil
|
||||
}
|
||||
|
||||
func (pod *HuaweiCci) ListPodDetail(ctx context.Context, req *pbpod.ListPodDetailReq) (*pbpod.ListPodDetailResp, error) {
|
||||
resp, err := pod.cli.CoreV1().Pods(req.GetNamespace()).List(metav1.ListOptions{})
|
||||
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")
|
||||
}
|
||||
|
@ -86,10 +88,10 @@ func (pod *HuaweiCci) ListPodDetail(ctx context.Context, req *pbpod.ListPodDetai
|
|||
for k, v := range resp.Items {
|
||||
podes[k] = &pbpod.PodInstance{
|
||||
Provider: pbtenant.CloudProvider_huawei,
|
||||
AccountName: pod.tenanter.AccountName(),
|
||||
AccountName: cci.tenanter.AccountName(),
|
||||
PodId: string(v.GetUID()),
|
||||
PodName: v.Name,
|
||||
RegionId: pod.region.GetId(),
|
||||
RegionId: cci.region.GetId(),
|
||||
ContainerImage: v.Spec.Containers[0].Image,
|
||||
ContainerName: v.Spec.Containers[0].Name,
|
||||
CpuPod: v.Spec.Containers[0].Resources.Requests.Cpu().String(),
|
||||
|
@ -113,43 +115,49 @@ func (pod *HuaweiCci) ListPodDetail(ctx context.Context, req *pbpod.ListPodDetai
|
|||
}, nil
|
||||
}
|
||||
|
||||
func (pod *HuaweiCci) CreatePod(ctx context.Context, req *pbpod.CreatePodReq) (*pbpod.CreatePodResp, error) {
|
||||
//resp, err := pod.cli.CoreV1().Pods(req.GetNamespace()).List(metav1.ListOptions{})
|
||||
//if err != nil {
|
||||
// return nil, errors.Wrap(err, "Huaweiyun ListDetail pod error")
|
||||
//}
|
||||
//glog.Info("Huaweiyun ListDetail pod success", resp.Items)
|
||||
//var podes = make([]*pbpod.PodInstance, len(resp.Items))
|
||||
//for k, v := range resp.Items {
|
||||
// podes[k] = &pbpod.PodInstance{
|
||||
// Provider: pbtenant.CloudProvider_huawei,
|
||||
// AccountName: pod.tenanter.AccountName(),
|
||||
// InstanceId: string(v.GetUID()),
|
||||
// InstanceName: v.Name,
|
||||
// RegionName: pod.region.GetName(),
|
||||
// PublicIps: v.Status.PodIP,
|
||||
// //InstanceType: v.InstanceType,
|
||||
// //Cpu: v.Spec.Containers[0].Resources.Requests.Cpu(),
|
||||
// //Memory: v.Spec.Containers[0].Resources.Requests.Memory(),
|
||||
// //Description: v.Description,
|
||||
// Status: string(v.Status.Phase),
|
||||
// CreationTime: v.CreationTimestamp.String(),
|
||||
// //ExpireTime: v.ExpiredTime,
|
||||
// //InnerIps: v.IntranetIp,
|
||||
// //VpcId: v.VpcId,
|
||||
// //SecurityGroupId: v.SecurityGroupId
|
||||
// }
|
||||
//}
|
||||
//
|
||||
//isFinished := false
|
||||
//if len(podes) < int(req.PageSize) {
|
||||
// isFinished = true
|
||||
//}
|
||||
//
|
||||
func (cci *HuaweiCci) CreatePod(ctx context.Context, req *pbpod.CreatePodReq) (*pbpod.CreatePodResp, error) {
|
||||
pod := corev1.Pod{
|
||||
TypeMeta: metav1.TypeMeta{
|
||||
APIVersion: "core/V1",
|
||||
Kind: "Pod",
|
||||
},
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: req.PodName,
|
||||
Namespace: req.Namespace,
|
||||
Labels: map[string]string{"name": "testapi"},
|
||||
},
|
||||
Spec: corev1.PodSpec{
|
||||
RestartPolicy: corev1.RestartPolicyAlways,
|
||||
Containers: []corev1.Container{
|
||||
{
|
||||
Name: req.ContainerName,
|
||||
Image: req.ContainerImage,
|
||||
Resources: corev1.ResourceRequirements{
|
||||
Limits: map[corev1.ResourceName]resource.Quantity{
|
||||
corev1.ResourceCPU: resource.MustParse(req.CpuPod),
|
||||
corev1.ResourceMemory: resource.MustParse(req.MemoryPod),
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
Status: corev1.PodStatus{},
|
||||
}
|
||||
|
||||
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")
|
||||
}
|
||||
|
||||
isFinished := false
|
||||
if len(resp.UID) > 0 {
|
||||
isFinished = true
|
||||
}
|
||||
|
||||
return &pbpod.CreatePodResp{
|
||||
Pods: nil,
|
||||
//Finished: isFinished,
|
||||
Pods: nil,
|
||||
Finished: isFinished,
|
||||
//RequestId: resp.RequestId,
|
||||
}, nil
|
||||
|
||||
}
|
||||
|
|
5
go.mod
5
go.mod
|
@ -11,9 +11,12 @@ require (
|
|||
github.com/pkg/errors v0.9.1
|
||||
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.377
|
||||
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cvm v1.0.377
|
||||
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tke v1.0.377
|
||||
google.golang.org/genproto v0.0.0-20220317150908-0efb43f6373e
|
||||
google.golang.org/grpc v1.45.0
|
||||
google.golang.org/protobuf v1.28.0
|
||||
k8s.io/api v0.0.0-20190620084959-7cf5895f2711
|
||||
k8s.io/apimachinery v0.0.0-20190612205821-1799e75a0719
|
||||
k8s.io/client-go v0.0.0-20190620085101-78d2af792bab
|
||||
)
|
||||
|
||||
|
@ -42,8 +45,6 @@ require (
|
|||
gopkg.in/inf.v0 v0.9.0 // indirect
|
||||
gopkg.in/ini.v1 v1.66.2 // indirect
|
||||
gopkg.in/yaml.v2 v2.4.0 // indirect
|
||||
k8s.io/api v0.0.0-20190620084959-7cf5895f2711 // indirect
|
||||
k8s.io/apimachinery v0.0.0-20190612205821-1799e75a0719 // indirect
|
||||
k8s.io/klog v0.3.1 // indirect
|
||||
k8s.io/utils v0.0.0-20190221042446-c2654d5206da // indirect
|
||||
sigs.k8s.io/yaml v1.3.0 // indirect
|
||||
|
|
|
@ -106,24 +106,24 @@ enum TencentRegionId {
|
|||
// 华为云区域,需要将对应的 _ 转化为 -
|
||||
enum HuaweiRegionId {
|
||||
hw_all = 0;
|
||||
hw_cn_north_1 = 1;
|
||||
hw_cn_north_4 = 2;
|
||||
hw_cn_south_1 = 3;
|
||||
hw_cn_east_2 = 4;
|
||||
hw_cn_east_3 = 5;
|
||||
hw_cn_southwest_2 = 6;
|
||||
hw_ap_southeast_1 = 7;
|
||||
hw_ap_southeast_2 = 8;
|
||||
hw_ap_southeast_3 = 9;
|
||||
hw_af_south_1 = 10;
|
||||
hw_cn_south_2 = 11;
|
||||
hw_cn_north_1 = 1; // 华北-北京一
|
||||
hw_cn_north_4 = 2; // 华北-北京四
|
||||
hw_cn_south_1 = 3; // 华南-广州
|
||||
hw_cn_east_2 = 4; // 华东-上海二
|
||||
hw_cn_east_3 = 5; // 华东-上海一
|
||||
hw_cn_southwest_2 = 6; // 西南-贵阳一
|
||||
hw_ap_southeast_1 = 7; // 中国-香港
|
||||
hw_ap_southeast_2 = 8; // 亚太-曼谷
|
||||
hw_ap_southeast_3 = 9; // 亚太-新加坡
|
||||
hw_af_south_1 = 10; //非洲-约翰内斯堡
|
||||
hw_cn_south_2 = 11; // 华南-深圳
|
||||
}
|
||||
|
||||
// 亚马逊云区域,需要将对应的 _ 转化为 -
|
||||
enum AwsRegionId {
|
||||
aws_all = 0;
|
||||
aws_us_east_2 = 1; // US East (Ohio)
|
||||
aws_us_east_1 = 2; // US East (N. Virginia)
|
||||
aws_us_east_1 = 2; // US East (N. Virginia)
|
||||
aws_us_west_1 = 3; // US West (N. California)
|
||||
aws_us_west_2 = 4; // US West (Oregon)
|
||||
aws_af_south_1 = 5; // Africa (Cape Town)
|
||||
|
|
|
@ -363,17 +363,17 @@ type HuaweiRegionId int32
|
|||
|
||||
const (
|
||||
HuaweiRegionId_hw_all HuaweiRegionId = 0
|
||||
HuaweiRegionId_hw_cn_north_1 HuaweiRegionId = 1
|
||||
HuaweiRegionId_hw_cn_north_4 HuaweiRegionId = 2
|
||||
HuaweiRegionId_hw_cn_south_1 HuaweiRegionId = 3
|
||||
HuaweiRegionId_hw_cn_east_2 HuaweiRegionId = 4
|
||||
HuaweiRegionId_hw_cn_east_3 HuaweiRegionId = 5
|
||||
HuaweiRegionId_hw_cn_southwest_2 HuaweiRegionId = 6
|
||||
HuaweiRegionId_hw_ap_southeast_1 HuaweiRegionId = 7
|
||||
HuaweiRegionId_hw_ap_southeast_2 HuaweiRegionId = 8
|
||||
HuaweiRegionId_hw_ap_southeast_3 HuaweiRegionId = 9
|
||||
HuaweiRegionId_hw_af_south_1 HuaweiRegionId = 10
|
||||
HuaweiRegionId_hw_cn_south_2 HuaweiRegionId = 11
|
||||
HuaweiRegionId_hw_cn_north_1 HuaweiRegionId = 1 // 华北-北京一
|
||||
HuaweiRegionId_hw_cn_north_4 HuaweiRegionId = 2 // 华北-北京四
|
||||
HuaweiRegionId_hw_cn_south_1 HuaweiRegionId = 3 // 华南-广州
|
||||
HuaweiRegionId_hw_cn_east_2 HuaweiRegionId = 4 // 华东-上海二
|
||||
HuaweiRegionId_hw_cn_east_3 HuaweiRegionId = 5 // 华东-上海一
|
||||
HuaweiRegionId_hw_cn_southwest_2 HuaweiRegionId = 6 // 西南-贵阳一
|
||||
HuaweiRegionId_hw_ap_southeast_1 HuaweiRegionId = 7 // 中国-香港
|
||||
HuaweiRegionId_hw_ap_southeast_2 HuaweiRegionId = 8 // 亚太-曼谷
|
||||
HuaweiRegionId_hw_ap_southeast_3 HuaweiRegionId = 9 // 亚太-新加坡
|
||||
HuaweiRegionId_hw_af_south_1 HuaweiRegionId = 10 //非洲-约翰内斯堡
|
||||
HuaweiRegionId_hw_cn_south_2 HuaweiRegionId = 11 // 华南-深圳
|
||||
)
|
||||
|
||||
// Enum value maps for HuaweiRegionId.
|
||||
|
|
Loading…
Reference in New Issue