| @@ -56,6 +56,8 @@ func CreateContainerGroup(request *CreateContainerGroupRequest) (response *Creat | |||||
| memoryPod = strconv.FormatFloat(memoryPodFloat, 'f', 0, 64) + "Gi" | memoryPod = strconv.FormatFloat(memoryPodFloat, 'f', 0, 64) + "Gi" | ||||
| case 3: | case 3: | ||||
| regionId, _ = tenanter.GetK8SRegionId(request.RegionId) | regionId, _ = tenanter.GetK8SRegionId(request.RegionId) | ||||
| cpuPod = strconv.FormatFloat(cpuPodFloat*1000, 'f', 0, 64) + "m" | |||||
| memoryPod = strconv.FormatFloat(memoryPodFloat, 'f', 0, 64) + "Gi" | |||||
| } | } | ||||
| requestPCM := &pbpod.CreatePodReq{ | requestPCM := &pbpod.CreatePodReq{ | ||||
| @@ -72,6 +72,9 @@ func DeleteContainerGroup(request *DeleteContainerGroupRequest) (response *Delet | |||||
| resp, err := server.DeletePod(nil, requestPCM) | resp, err := server.DeletePod(nil, requestPCM) | ||||
| if err != nil { | |||||
| return nil, err | |||||
| } | |||||
| response = &DeleteContainerGroupResponse{ | response = &DeleteContainerGroupResponse{ | ||||
| BaseResponse: nil, | BaseResponse: nil, | ||||
| RequestId: resp.RequestId, | RequestId: resp.RequestId, | ||||
| @@ -72,7 +72,7 @@ func UpdateContainerGroup(request *UpdateContainerGroupRequest) (response *Updat | |||||
| CpuPod: string(containers[0].Cpu), | CpuPod: string(containers[0].Cpu), | ||||
| MemoryPod: string(containers[0].Memory), | MemoryPod: string(containers[0].Memory), | ||||
| RestartPolicy: request.RestartPolicy, | RestartPolicy: request.RestartPolicy, | ||||
| Labels: "", | |||||
| Labels: "sss", | |||||
| } | } | ||||
| resp, err := server.UpdatePod(nil, requestPCM) | resp, err := server.UpdatePod(nil, requestPCM) | ||||
| @@ -94,6 +94,7 @@ type UpdateContainerGroupRequest struct { | |||||
| AccountName string `position:"Query" name:"AccountName"` | AccountName string `position:"Query" name:"AccountName"` | ||||
| Namespace string `position:"Query" name:"Namespace"` | Namespace string `position:"Query" name:"Namespace"` | ||||
| PcmId string `position:"Query" name:"PcmId"` | PcmId string `position:"Query" name:"PcmId"` | ||||
| PodName string `position:"Query" name:"PodName"` | |||||
| ContainerGroupName string `position:"Query" name:"ContainerGroupName"` | ContainerGroupName string `position:"Query" name:"ContainerGroupName"` | ||||
| /*********PCM param************/ | /*********PCM param************/ | ||||
| OwnerId requests.Integer `position:"Query" name:"OwnerId"` | OwnerId requests.Integer `position:"Query" name:"OwnerId"` | ||||
| @@ -126,7 +126,7 @@ func (eci *AliEci) DeletePod(ctx context.Context, req *pbpod.DeletePodReq) (*pbp | |||||
| isFinished := true | isFinished := true | ||||
| if err != nil { | if err != nil { | ||||
| isFinished = false | isFinished = false | ||||
| return nil, errors.Wrap(err, "Aliyun DeletePod error") | |||||
| return nil, err | |||||
| } | } | ||||
| glog.Infof("--------------------Aliyun ECI Instance deleted--------------------") | glog.Infof("--------------------Aliyun ECI Instance deleted--------------------") | ||||
| @@ -157,7 +157,7 @@ func (eci *AliEci) UpdatePod(ctx context.Context, req *pbpod.UpdatePodReq) (*pbp | |||||
| isFinished := true | isFinished := true | ||||
| if err != nil { | if err != nil { | ||||
| isFinished = false | isFinished = false | ||||
| return nil, errors.Wrap(err, "Aliyun UpdatePod error") | |||||
| return nil, err | |||||
| } | } | ||||
| glog.Infof("--------------------Aliyun ECI Instance updated--------------------") | glog.Infof("--------------------Aliyun ECI Instance updated--------------------") | ||||
| @@ -176,7 +176,7 @@ func (eci *AliEci) ListPodDetail(ctx context.Context, req *pbpod.ListPodDetailRe | |||||
| resp, err := eci.cli.DescribeContainerGroups(request) | resp, err := eci.cli.DescribeContainerGroups(request) | ||||
| if err != nil { | if err != nil { | ||||
| return nil, errors.Wrap(err, "Aliyun ListDetail error") | |||||
| return nil, err | |||||
| } | } | ||||
| var ecies = make([]*pbpod.PodInstance, len(resp.ContainerGroups)) | var ecies = make([]*pbpod.PodInstance, len(resp.ContainerGroups)) | ||||
| @@ -128,7 +128,7 @@ func (cci *HuaweiCci) CreatePod(ctx context.Context, req *pbpod.CreatePodReq) (* | |||||
| resp, err := cci.cli.CoreV1().Pods(req.Namespace).Create(context.TODO(), &pod, metav1.CreateOptions{}) | resp, err := cci.cli.CoreV1().Pods(req.Namespace).Create(context.TODO(), &pod, metav1.CreateOptions{}) | ||||
| if err != nil { | if err != nil { | ||||
| return nil, errors.Wrap(err, "Huaweiyun CreatePod error") | |||||
| return nil, err | |||||
| } | } | ||||
| isFinished := false | isFinished := false | ||||
| @@ -152,8 +152,7 @@ func (cci *HuaweiCci) DeletePod(ctx context.Context, req *pbpod.DeletePodReq) (* | |||||
| isFinished := true | isFinished := true | ||||
| if err != nil { | if err != nil { | ||||
| isFinished = false | |||||
| return nil, errors.Wrap(err, "Huaweiyun DeletePod error") | |||||
| return nil, err | |||||
| } | } | ||||
| glog.Infof("--------------------Huawei CCI Instance deleted--------------------") | glog.Infof("--------------------Huawei CCI Instance deleted--------------------") | ||||
| @@ -171,7 +170,7 @@ func (cci *HuaweiCci) UpdatePod(ctx context.Context, req *pbpod.UpdatePodReq) (* | |||||
| qresp, err := cci.cli.CoreV1().Pods(req.GetNamespace()).Get(context.TODO(), req.PcmId, metav1.GetOptions{}) | qresp, err := cci.cli.CoreV1().Pods(req.GetNamespace()).Get(context.TODO(), req.PcmId, metav1.GetOptions{}) | ||||
| if err != nil { | if err != nil { | ||||
| return nil, errors.Wrap(err, "Huaweiyun UpdatePod error") | |||||
| return nil, err | |||||
| } | } | ||||
| pod := corev1.Pod{ | pod := corev1.Pod{ | ||||
| TypeMeta: qresp.TypeMeta, | TypeMeta: qresp.TypeMeta, | ||||
| @@ -210,7 +209,7 @@ func (cci *HuaweiCci) ListPodDetail(ctx context.Context, req *pbpod.ListPodDetai | |||||
| resp, err := cci.cli.CoreV1().Pods(req.GetNamespace()).List(context.TODO(), metav1.ListOptions{}) | resp, err := cci.cli.CoreV1().Pods(req.GetNamespace()).List(context.TODO(), metav1.ListOptions{}) | ||||
| if err != nil { | if err != nil { | ||||
| return nil, errors.Wrap(err, "Huaweiyun ListDetail pod error") | |||||
| return nil, err | |||||
| } | } | ||||
| glog.Info("Huaweiyun ListDetail pod success", resp.Items) | glog.Info("Huaweiyun ListDetail pod success", resp.Items) | ||||
| var pods = make([]*pbpod.PodInstance, len(resp.Items)) | var pods = make([]*pbpod.PodInstance, len(resp.Items)) | ||||
| @@ -114,7 +114,7 @@ func (k *K8SPoder) CreatePod(ctx context.Context, req *pbpod.CreatePodReq) (*pbp | |||||
| resp, err := k.cli.CoreV1().Pods(req.Namespace).Create(context.TODO(), &pod, metav1.CreateOptions{}) | resp, err := k.cli.CoreV1().Pods(req.Namespace).Create(context.TODO(), &pod, metav1.CreateOptions{}) | ||||
| if err != nil { | if err != nil { | ||||
| return nil, errors.Wrap(err, "K8S CreatePod error") | |||||
| return nil, err | |||||
| } | } | ||||
| glog.Infof("--------------------K8S Pod Instance created--------------------") | glog.Infof("--------------------K8S Pod Instance created--------------------") | ||||
| @@ -143,8 +143,7 @@ func (k K8SPoder) DeletePod(ctx context.Context, req *pbpod.DeletePodReq) (*pbpo | |||||
| isFinished := true | isFinished := true | ||||
| if err != nil { | if err != nil { | ||||
| isFinished = false | |||||
| return nil, errors.Wrap(err, "K8S DeletePod error") | |||||
| return nil, err | |||||
| } | } | ||||
| return &pbpod.DeletePodResp{ | return &pbpod.DeletePodResp{ | ||||
| @@ -174,7 +173,7 @@ func (k K8SPoder) UpdatePod(ctx context.Context, req *pbpod.UpdatePodReq) (*pbpo | |||||
| pod.Spec.Containers[0].Image = req.ContainerImage | pod.Spec.Containers[0].Image = req.ContainerImage | ||||
| resp, err := k.cli.CoreV1().Pods(req.Namespace).Update(context.TODO(), &pod, metav1.UpdateOptions{}) | resp, err := k.cli.CoreV1().Pods(req.Namespace).Update(context.TODO(), &pod, metav1.UpdateOptions{}) | ||||
| if err != nil { | if err != nil { | ||||
| return nil, errors.Wrap(err, "K8S UpdatePod error") | |||||
| return nil, err | |||||
| } | } | ||||
| glog.Infof("--------------------K8S Pod Instance updated--------------------") | glog.Infof("--------------------K8S Pod Instance updated--------------------") | ||||
| @@ -196,7 +195,7 @@ func (k K8SPoder) UpdatePod(ctx context.Context, req *pbpod.UpdatePodReq) (*pbpo | |||||
| func (k K8SPoder) ListPodDetail(ctx context.Context, req *pbpod.ListPodDetailReq) (*pbpod.ListPodDetailResp, error) { | func (k K8SPoder) ListPodDetail(ctx context.Context, req *pbpod.ListPodDetailReq) (*pbpod.ListPodDetailResp, error) { | ||||
| resp, err := k.cli.CoreV1().Pods(req.GetNamespace()).List(context.TODO(), metav1.ListOptions{}) | resp, err := k.cli.CoreV1().Pods(req.GetNamespace()).List(context.TODO(), metav1.ListOptions{}) | ||||
| if err != nil { | if err != nil { | ||||
| return nil, errors.Wrap(err, "K8S ListDetail pod error") | |||||
| return nil, err | |||||
| } | } | ||||
| var pods = make([]*pbpod.PodInstance, len(resp.Items)) | var pods = make([]*pbpod.PodInstance, len(resp.Items)) | ||||
| @@ -155,6 +155,7 @@ func (eks *TencentEks) UpdatePod(ctx context.Context, req *pbpod.UpdatePodReq) ( | |||||
| //创建更新pod请求 | //创建更新pod请求 | ||||
| request := tencenteks.NewUpdateEKSContainerInstanceRequest() | request := tencenteks.NewUpdateEKSContainerInstanceRequest() | ||||
| request.EksCiId = &req.PcmId | request.EksCiId = &req.PcmId | ||||
| request.Name = &req.PodName | |||||
| request.RestartPolicy = &req.RestartPolicy | request.RestartPolicy = &req.RestartPolicy | ||||
| request.Containers = make([]*tencenteks.Container, 1) | request.Containers = make([]*tencenteks.Container, 1) | ||||
| request.Containers[0] = new(tencenteks.Container) | request.Containers[0] = new(tencenteks.Container) | ||||
| @@ -83,7 +83,7 @@ func aliDelete(client eci.Client) (_err error) { | |||||
| return _err | return _err | ||||
| } | } | ||||
| func main() { | func main() { | ||||
| client, _ := CreateClient(tea.String("LTAI5tJbog28gBTVzBmvqCBG"), tea.String("CXTClnd0ZQhxn4C2b5NN1nmra7hl1z")) | |||||
| client, _ := CreateClient(tea.String(""), tea.String("")) | |||||
| err := aliDelete(*client) | err := aliDelete(*client) | ||||
| @@ -12,14 +12,14 @@ import ( | |||||
| "k8s.io/client-go/tools/clientcmd/api" | "k8s.io/client-go/tools/clientcmd/api" | ||||
| ) | ) | ||||
| //const ( | |||||
| // apiVersion = "client.authentication.k8s.io/v1beta1" | |||||
| // cciEndpoint = "https://cci.cn-east-3.myhuaweicloud.com" | |||||
| // iamEndpoint = "https://iam.cn-east-3.myhuaweicloud.com" | |||||
| // projectName = "cn-east-3" | |||||
| // ak = "ATQTIWUT9K66VRMMXKVY" | |||||
| // sk = "Wa0aixDVuhZOfDZGWvgIJQBHnyiDlGdgDn1Ai5Yy" | |||||
| //) | |||||
| const ( | |||||
| apiVersion = "client.authentication.k8s.io/v1beta1" | |||||
| cciEndpoint = "https://cci.cn-east-3.myhuaweicloud.com" | |||||
| iamEndpoint = "https://iam.cn-east-3.myhuaweicloud.com" | |||||
| projectName = "cn-east-3" | |||||
| ak = "" | |||||
| sk = "" | |||||
| ) | |||||
| // NewClientOrigin 通过AK/SK认证创建ClientSet | // NewClientOrigin 通过AK/SK认证创建ClientSet | ||||
| func NewClientOrigin() (*kubernetes.Clientset, error) { | func NewClientOrigin() (*kubernetes.Clientset, error) { | ||||
| @@ -105,8 +105,8 @@ func UpdatePodOrigin(client *kubernetes.Clientset) error { | |||||
| Image: "library/nginx:stable-alpine-perl", | Image: "library/nginx:stable-alpine-perl", | ||||
| Resources: corev1.ResourceRequirements{ | Resources: corev1.ResourceRequirements{ | ||||
| Limits: map[corev1.ResourceName]resource.Quantity{ | Limits: map[corev1.ResourceName]resource.Quantity{ | ||||
| corev1.ResourceCPU: resource.MustParse("500m"), | |||||
| corev1.ResourceMemory: resource.MustParse("1Gi"), | |||||
| corev1.ResourceCPU: resource.MustParse("1000m"), | |||||
| corev1.ResourceMemory: resource.MustParse("2Gi"), | |||||
| }, | }, | ||||
| }, | }, | ||||
| }, | }, | ||||
| @@ -121,7 +121,7 @@ func UpdatePodOrigin(client *kubernetes.Clientset) error { | |||||
| // DeletePodOrigin 删除Pod | // DeletePodOrigin 删除Pod | ||||
| func DeletePodOrigin(client *kubernetes.Clientset) error { | func DeletePodOrigin(client *kubernetes.Clientset) error { | ||||
| return client.CoreV1().Pods("pcm").Delete(context.TODO(), "podName", metav1.DeleteOptions{}) | |||||
| return client.CoreV1().Pods("pcm").Delete(context.TODO(), "hw-sdk-test", metav1.DeleteOptions{}) | |||||
| } | } | ||||
| // ListPodOrigin 查询Pod | // ListPodOrigin 查询Pod | ||||
| @@ -135,20 +135,9 @@ func main() { | |||||
| cs, _ := NewClientOrigin() | cs, _ := NewClientOrigin() | ||||
| fmt.Println("start to create Pod") | |||||
| CreatePodOrigin(cs) | |||||
| fmt.Println("Pod created") | |||||
| fmt.Println("start to get Pod details") | |||||
| ListPodOrigin(cs) | |||||
| fmt.Println("Pod details got") | |||||
| fmt.Println("start to update Pod") | |||||
| UpdatePodOrigin(cs) | |||||
| fmt.Println("Pod updated") | |||||
| fmt.Println("start to delete Pod") | |||||
| //CreatePodOrigin(cs) | |||||
| //ListPodOrigin(cs) | |||||
| //UpdatePodOrigin(cs) | |||||
| DeletePodOrigin(cs) | DeletePodOrigin(cs) | ||||
| fmt.Println("Pod deleted") | |||||
| } | } | ||||
| @@ -4,18 +4,23 @@ import ( | |||||
| pcm_pod_ali "code.gitlink.org.cn/JCCE/PCM.git/adaptor/pod/server/ali" | pcm_pod_ali "code.gitlink.org.cn/JCCE/PCM.git/adaptor/pod/server/ali" | ||||
| ) | ) | ||||
| /***** | |||||
| regionId ali:cn-hangzhou tc:ap-guangzhou hw: cn-east-3 | |||||
| image: tencent nginx:latest | |||||
| ali registry-vpc.cn-hangzhou.aliyuncs.com/eci_open/nginx | |||||
| huawei library/nginx:stable-alpine-perl | |||||
| *****/ | |||||
| func aliCreatePCM() (_err error) { | func aliCreatePCM() (_err error) { | ||||
| request := pcm_pod_ali.CreateCreateContainerGroupRequest() | request := pcm_pod_ali.CreateCreateContainerGroupRequest() | ||||
| /****************PCM params******************/ | /****************PCM params******************/ | ||||
| request.ProviderId = 1 | |||||
| //ali:cn-hangzhou tc:ap-guangzhou hw: cn-east-3 | |||||
| request.RegionId = "ap-guangzhou" | |||||
| request.ProviderId = 3 | |||||
| request.RegionId = "cn-east-3" | |||||
| request.Namespace = "pcm" | request.Namespace = "pcm" | ||||
| /****************PCM params******************/ | /****************PCM params******************/ | ||||
| request.ContainerGroupName = "pcm0517" | |||||
| request.ContainerGroupName = "pcm0518" | |||||
| requestContainer := make([]pcm_pod_ali.CreateContainerGroupContainer, 1) | requestContainer := make([]pcm_pod_ali.CreateContainerGroupContainer, 1) | ||||
| requestContainer[0].Image = "nginx:latest" | |||||
| requestContainer[0].Image = "nginx/nginx:latest" | |||||
| requestContainer[0].Name = "pcm" | requestContainer[0].Name = "pcm" | ||||
| requestContainer[0].Cpu = "1" | requestContainer[0].Cpu = "1" | ||||
| requestContainer[0].Memory = "2" | requestContainer[0].Memory = "2" | ||||
| @@ -31,14 +36,14 @@ func aliDescribePCM() (_err error) { | |||||
| request := pcm_pod_ali.CreateDescribeContainerGroupsRequest() | request := pcm_pod_ali.CreateDescribeContainerGroupsRequest() | ||||
| /****************PCM params******************/ | /****************PCM params******************/ | ||||
| request.ProviderId = 1 | |||||
| request.ProviderId = 3 | |||||
| //ali:cn-hangzhou tc:ap-guangzhou hw: cn-east-3 | //ali:cn-hangzhou tc:ap-guangzhou hw: cn-east-3 | ||||
| request.RegionId = "ap-guangzhou" | |||||
| request.RegionId = "cn-east-3" | |||||
| request.Namespace = "pcm" | request.Namespace = "pcm" | ||||
| /****************PCM params******************/ | /****************PCM params******************/ | ||||
| resp, _err := pcm_pod_ali.DescribeContainerGroups(request) | resp, _err := pcm_pod_ali.DescribeContainerGroups(request) | ||||
| println(resp.ContainerGroups[0].ContainerGroupId) | |||||
| println(resp.ContainerGroups[0].ContainerGroupName) | |||||
| return _err | return _err | ||||
| } | } | ||||
| @@ -47,18 +52,18 @@ func aliUpdatePCM() (_err error) { | |||||
| request := pcm_pod_ali.CreateUpdateContainerGroupRequest() | request := pcm_pod_ali.CreateUpdateContainerGroupRequest() | ||||
| /****************PCM params******************/ | /****************PCM params******************/ | ||||
| request.ProviderId = 1 | |||||
| //ali:cn-hangzhou tc:ap-guangzhou hw: cn-east-3 | |||||
| request.RegionId = "ap-guangzhou" | |||||
| request.ProviderId = 3 | |||||
| request.RegionId = "cn-east-3" | |||||
| request.Namespace = "pcm" | request.Namespace = "pcm" | ||||
| request.PcmId = "eksci-ofdhm7h0" | |||||
| request.PcmId = "pcm0517" | |||||
| /****************PCM params******************/ | /****************PCM params******************/ | ||||
| request.RestartPolicy = "Always" | |||||
| request.PodName = "pcm0517" | |||||
| request.RestartPolicy = "Never" | |||||
| requestContainer := make([]pcm_pod_ali.UpdateContainerGroupContainer, 1) | requestContainer := make([]pcm_pod_ali.UpdateContainerGroupContainer, 1) | ||||
| requestContainer[0].Cpu = "1" | |||||
| requestContainer[0].Memory = "2" | |||||
| requestContainer[0].Image = "nginx" | |||||
| requestContainer[0].Name = "pc-mNew" | |||||
| requestContainer[0].Cpu = "2" | |||||
| requestContainer[0].Memory = "4" | |||||
| requestContainer[0].Image = "nginx:latest" | |||||
| requestContainer[0].Name = "pcm" | |||||
| request.Container = &requestContainer | request.Container = &requestContainer | ||||
| resp, _err := pcm_pod_ali.UpdateContainerGroup(request) | resp, _err := pcm_pod_ali.UpdateContainerGroup(request) | ||||
| @@ -71,19 +76,19 @@ func aliDeletePCM() (_err error) { | |||||
| request := pcm_pod_ali.CreateDeleteContainerGroupRequest() | request := pcm_pod_ali.CreateDeleteContainerGroupRequest() | ||||
| /****************PCM params******************/ | /****************PCM params******************/ | ||||
| request.ProviderId = 1 | |||||
| request.ProviderId = 3 | |||||
| //ali:cn-hangzhou tc:ap-guangzhou hw: cn-east-3 | //ali:cn-hangzhou tc:ap-guangzhou hw: cn-east-3 | ||||
| request.RegionId = "ap-guangzhou" | |||||
| request.RegionId = "cn-east-3" | |||||
| request.Namespace = "pcm" | request.Namespace = "pcm" | ||||
| request.PcmId = "eksci-ofdhm7h0" | |||||
| request.PcmId = "hw-sdk-hwk8s" | |||||
| /****************PCM params******************/ | /****************PCM params******************/ | ||||
| request.ContainerGroupId = "eksci-hhfpfms6" | |||||
| resp, _err := pcm_pod_ali.DeleteContainerGroup(request) | resp, _err := pcm_pod_ali.DeleteContainerGroup(request) | ||||
| println(resp.RequestId) | |||||
| if _err != nil { | if _err != nil { | ||||
| return _err | return _err | ||||
| } | } | ||||
| println(resp.RequestId) | |||||
| return _err | return _err | ||||
| } | } | ||||
| @@ -13,29 +13,29 @@ import ( | |||||
| ) | ) | ||||
| const ( | const ( | ||||
| apiVersion = "client.authentication.k8s.io/v1beta1" | |||||
| cciEndpoint = "https://cci.cn-east-3.myhuaweicloud.com" | |||||
| iamEndpoint = "https://iam.cn-east-3.myhuaweicloud.com" | |||||
| projectName = "cn-east-3" | |||||
| ak = "ATQTIWUT9K66VRMMXKVY" | |||||
| sk = "Wa0aixDVuhZOfDZGWvgIJQBHnyiDlGdgDn1Ai5Yy" | |||||
| apiVersionPCM = "client.authentication.k8s.io/v1beta1" | |||||
| cciEndpointPCM = "https://cci.cn-east-3.myhuaweicloud.com" | |||||
| iamEndpointPCM = "https://iam.cn-east-3.myhuaweicloud.com" | |||||
| projectNamePCM = "cn-east-3" | |||||
| akPCM = "" | |||||
| skPCM = "" | |||||
| ) | ) | ||||
| // NewClient 通过AK/SK认证创建ClientSet | // NewClient 通过AK/SK认证创建ClientSet | ||||
| func NewClient() (*kubernetes.Clientset, error) { | func NewClient() (*kubernetes.Clientset, error) { | ||||
| config, err := clientcmd.BuildConfigFromFlags(cciEndpoint, "") | |||||
| config, err := clientcmd.BuildConfigFromFlags(cciEndpointPCM, "") | |||||
| if err != nil { | if err != nil { | ||||
| return nil, err | return nil, err | ||||
| } | } | ||||
| var optionArgs []string | var optionArgs []string | ||||
| optionArgs = append(optionArgs, fmt.Sprintf("--iam-endpoint=%s", iamEndpoint)) | |||||
| optionArgs = append(optionArgs, fmt.Sprintf("--project-name=%s", projectName)) | |||||
| optionArgs = append(optionArgs, fmt.Sprintf("--iam-endpoint=%s", iamEndpointPCM)) | |||||
| optionArgs = append(optionArgs, fmt.Sprintf("--project-name=%s", projectNamePCM)) | |||||
| optionArgs = append(optionArgs, fmt.Sprintf("--token-only=false")) | optionArgs = append(optionArgs, fmt.Sprintf("--token-only=false")) | ||||
| optionArgs = append(optionArgs, fmt.Sprintf("--ak=%s", ak)) | |||||
| optionArgs = append(optionArgs, fmt.Sprintf("--sk=%s", sk)) | |||||
| optionArgs = append(optionArgs, fmt.Sprintf("--ak=%s", akPCM)) | |||||
| optionArgs = append(optionArgs, fmt.Sprintf("--sk=%s", skPCM)) | |||||
| config.ExecProvider = &api.ExecConfig{ | config.ExecProvider = &api.ExecConfig{ | ||||
| Command: "cci-iam-authenticator", | Command: "cci-iam-authenticator", | ||||
| APIVersion: apiVersion, | |||||
| APIVersion: apiVersionPCM, | |||||
| Args: append([]string{"token"}, optionArgs...), | Args: append([]string{"token"}, optionArgs...), | ||||
| Env: make([]api.ExecEnvVar, 0), | Env: make([]api.ExecEnvVar, 0), | ||||
| } | } | ||||
| @@ -51,22 +51,22 @@ func CreatePod(client *kubernetes.Clientset) (*corev1.Pod, error) { | |||||
| Kind: "Pod", | Kind: "Pod", | ||||
| }, | }, | ||||
| ObjectMeta: metav1.ObjectMeta{ | ObjectMeta: metav1.ObjectMeta{ | ||||
| Name: "hw-sdk-hwk8s01", | |||||
| Name: "hw-sdk-hwk8s02", | |||||
| Namespace: "pcm", | Namespace: "pcm", | ||||
| Labels: map[string]string{"name": "test_api"}, | Labels: map[string]string{"name": "test_api"}, | ||||
| }, | }, | ||||
| Spec: corev1.PodSpec{ | Spec: corev1.PodSpec{ | ||||
| /****************PCM params******************/ | /****************PCM params******************/ | ||||
| //0: ali, 1: tencent, 2: huawei,3: k8s | //0: ali, 1: tencent, 2: huawei,3: k8s | ||||
| ProviderId: 0, | |||||
| ProviderId: 3, | |||||
| //ali:cn-hangzhou tc:ap-guangzhou hw: cn-east-3 | //ali:cn-hangzhou tc:ap-guangzhou hw: cn-east-3 | ||||
| RegionId: "cn-hangzhou", | |||||
| RegionId: "cn-east-3", | |||||
| /****************PCM params******************/ | /****************PCM params******************/ | ||||
| RestartPolicy: corev1.RestartPolicyAlways, | RestartPolicy: corev1.RestartPolicyAlways, | ||||
| Containers: []corev1.Container{ | Containers: []corev1.Container{ | ||||
| { | { | ||||
| Name: "sdk-hwk8s01-container", | Name: "sdk-hwk8s01-container", | ||||
| Image: "registry-vpc.cn-hangzhou.aliyuncs.com/eci_open/alpine:3.5", | |||||
| Image: "library/nginx:stable-alpine-perl", | |||||
| Resources: corev1.ResourceRequirements{ | Resources: corev1.ResourceRequirements{ | ||||
| Limits: map[corev1.ResourceName]resource.Quantity{ | Limits: map[corev1.ResourceName]resource.Quantity{ | ||||
| corev1.ResourceCPU: resource.MustParse("1000m"), | corev1.ResourceCPU: resource.MustParse("1000m"), | ||||
| @@ -98,14 +98,15 @@ func ListPod(client *kubernetes.Clientset) (*corev1.PodList, error) { | |||||
| Spec: corev1.PodSpec{ | Spec: corev1.PodSpec{ | ||||
| /****************PCM params******************/ | /****************PCM params******************/ | ||||
| //0: ali, 1: tencent, 2: huawei,3: k8s | //0: ali, 1: tencent, 2: huawei,3: k8s | ||||
| ProviderId: 0, | |||||
| ProviderId: 3, | |||||
| //ali:cn-hangzhou tc:ap-guangzhou hw: cn-east-3 | //ali:cn-hangzhou tc:ap-guangzhou hw: cn-east-3 | ||||
| //RegionId: "cn-hangzhou", | |||||
| //RegionId: "cn-east-3", | |||||
| /****************PCM params******************/ | /****************PCM params******************/ | ||||
| }, | }, | ||||
| } | } | ||||
| podList, _ := client.CoreV1().Pods("pcm").List(context.TODO(), &pod, metav1.ListOptions{}) | podList, _ := client.CoreV1().Pods("pcm").List(context.TODO(), &pod, metav1.ListOptions{}) | ||||
| println(podList.Items[0].Spec.Containers[0].Name) | |||||
| return podList, nil | return podList, nil | ||||
| } | } | ||||
| @@ -117,26 +118,26 @@ func UpdatePod(client *kubernetes.Clientset) error { | |||||
| Kind: "Pod", | Kind: "Pod", | ||||
| }, | }, | ||||
| ObjectMeta: metav1.ObjectMeta{ | ObjectMeta: metav1.ObjectMeta{ | ||||
| Name: "hw-sdk-test002", | |||||
| Name: "hw-sdk-hwk8s01", | |||||
| Namespace: "pcm", | Namespace: "pcm", | ||||
| UID: "eci-bp123wba1qv9xymntd24", | |||||
| UID: "hw-sdk-hwk8s01", | |||||
| Labels: map[string]string{"name": "test_api222"}, | Labels: map[string]string{"name": "test_api222"}, | ||||
| }, | }, | ||||
| Spec: corev1.PodSpec{ | Spec: corev1.PodSpec{ | ||||
| /****************PCM params******************/ | /****************PCM params******************/ | ||||
| //0: ali, 1: tencent, 2: huawei,3: k8s | //0: ali, 1: tencent, 2: huawei,3: k8s | ||||
| ProviderId: 0, | |||||
| ProviderId: 2, | |||||
| //ali:cn-hangzhou tc:ap-guangzhou hw: cn-east-3 | //ali:cn-hangzhou tc:ap-guangzhou hw: cn-east-3 | ||||
| RegionId: "cn-hangzhou", | |||||
| RegionId: "cn-east-3", | |||||
| /****************PCM params******************/ | /****************PCM params******************/ | ||||
| RestartPolicy: corev1.RestartPolicyAlways, | |||||
| RestartPolicy: corev1.RestartPolicyNever, | |||||
| Containers: []corev1.Container{ | Containers: []corev1.Container{ | ||||
| { | { | ||||
| Name: "pcm-sdk-huawei-contai", | |||||
| Name: "pcm-sdk-huawei-conta22i", | |||||
| Image: "nginx:latest", | Image: "nginx:latest", | ||||
| Resources: corev1.ResourceRequirements{ | Resources: corev1.ResourceRequirements{ | ||||
| Limits: map[corev1.ResourceName]resource.Quantity{ | Limits: map[corev1.ResourceName]resource.Quantity{ | ||||
| corev1.ResourceCPU: resource.MustParse("2000m"), | |||||
| corev1.ResourceCPU: resource.MustParse("500m"), | |||||
| corev1.ResourceMemory: resource.MustParse("1Gi"), | corev1.ResourceMemory: resource.MustParse("1Gi"), | ||||
| }, | }, | ||||
| }, | }, | ||||
| @@ -156,37 +157,17 @@ func UpdatePod(client *kubernetes.Clientset) error { | |||||
| // DeletePod 删除Pod | // DeletePod 删除Pod | ||||
| func DeletePod(client *kubernetes.Clientset) error { | func DeletePod(client *kubernetes.Clientset) error { | ||||
| //多出5个参数 namespace providerId regionName accountName pcmId | //多出5个参数 namespace providerId regionName accountName pcmId | ||||
| return client.CoreV1().Pods("pcm").Delete(context.TODO(), "pcm", 0, "cn-hangzhou", | |||||
| "", "eci-bp123wba1qv9xymntd24", metav1.DeleteOptions{}) | |||||
| return client.CoreV1().Pods("pcm").Delete(context.TODO(), "pcm", 3, "cn-east-3", | |||||
| "", "hw-sdk-hwk8s02", metav1.DeleteOptions{}) | |||||
| } | } | ||||
| func main() { | func main() { | ||||
| cs, _ := NewClient() | cs, _ := NewClient() | ||||
| fmt.Println("start to create Pod") | |||||
| _, err := CreatePod(cs) | |||||
| if err != nil { | |||||
| return | |||||
| } | |||||
| fmt.Println("Pod created") | |||||
| //fmt.Println("start to get Pod details") | |||||
| //_, err = ListPod(cs) | |||||
| //if err != nil { | |||||
| // return | |||||
| //} | |||||
| //fmt.Println("Pod details got") | |||||
| //fmt.Println("start to update Pod") | |||||
| //err = UpdatePod(cs) | |||||
| //if err != nil { | |||||
| // return | |||||
| //} | |||||
| //fmt.Println("Pod updated") | |||||
| //fmt.Println("start to delete Pod") | |||||
| //err = DeletePod(cs) | |||||
| //if err != nil { | |||||
| // return | |||||
| //} | |||||
| //fmt.Println("Pod deleted") | |||||
| //CreatePod(cs) | |||||
| //ListPod(cs) | |||||
| //UpdatePod(cs) | |||||
| DeletePod(cs) | |||||
| } | } | ||||