| @@ -1,8 +1,39 @@ | |||||
| [eci_conf] | |||||
| [container_conf] | |||||
| #测试账号ak | #测试账号ak | ||||
| access_key = | |||||
| secret_key = | |||||
| access_key = LTAI4GKsRHtEqUu8bzq5dt6N | |||||
| secret_key = j96G9E2ijwpiN987VC03HmcFsaJngt | |||||
| #region | #region | ||||
| region_id=cn-shanghai | |||||
| region_id=cn-hangzhou | |||||
| #容器实例名称(pod名) | |||||
| container_group_name=pcm-test-ali-pod | |||||
| #镜像地址 | |||||
| container_image=registry-vpc.cn-hangzhou.aliyuncs.com/eci_open/nginx | |||||
| #容器名称 | |||||
| container_name=pcm-test-ali-container | |||||
| ##下面为非必需参数 | |||||
| #安全组ID | |||||
| security_group_id=sg-bp17raa25u0wy0sb1qw5 | |||||
| #交换机ID | |||||
| v_switch_id=vsw-bp176sh32kcq79d1uu8fp | |||||
| #可用区 | |||||
| zone_id=cn-hangzhou-h | |||||
| #容器实例名称(pod名) | |||||
| container_group_name=pcm-test-ali-pod | |||||
| #重启策略 | |||||
| restart_policy=Never | |||||
| #Pod拥有核数 | |||||
| cpu_pod=1.00 | |||||
| #Pod拥有内存大小 | |||||
| memory_pod=2.00 | |||||
| #容器所需核数 | |||||
| cpu_container=1.00 | |||||
| #容器所需内存大小 | |||||
| memory_container=2.00 | |||||
| #镜像拉取策略 | |||||
| image_pull_policy=IfNotPresent | |||||
| #每个region下的资源信息,json格式 | #每个region下的资源信息,json格式 | ||||
| region_info={"cn-hangzhou": {"securityGroupId": "sg-bp118knl07ymorgzfhyw","vSwitchId": "vsw-bp1jrgfqqy54kg5hcf8bc","zoneId": "cn-hangzhou-h"},"cn-shanghai": {"securityGroupId": "sg-uf62jug0dt92nfy630cs","vSwitchId": "vsw-uf6cb39ub5urw82bv3w70","zoneId": "cn-shanghai-g"},"cn-beijing": {"securityGroupId": "sg-2ze6uv80a8s4yk04dmyu","vSwitchId": "vsw-2zegtxf8q29d8tt1xtcjk","zoneId": "cn-beijing-h"},"cn-shenzhen":{"securityGroupId": "sg-wz96x4kv4edy97q6jjzn","vSwitchId": "vsw-wz9rn33jwilodp24klo0q","zoneId": "cn-shenzhen-a"},"cn-hongkong":{"securityGroupId": "sg-j6cjajpf7f4ybda7h19w","vSwitchId": "vsw-j6c9c9fit5owbbc0ids6c","zoneId": "cn-hongkong-b"},"us-west-1":{"securityGroupId": "sg-u19hbpj9x","vSwitchId": "vsw-rj9h5vvzhb4fjkuzuyi8j","zoneId": "us-west-1a"},"us-east-1":{"securityGroupId": "sg-0xih51sfoldxzxfsbja5","vSwitchId": "vsw-0xisefewxoqe4f849jbnl","zoneId": "us-east-1b"},"ap-southeast-1":{"securityGroupId": "sg-t4n23ppw7fm5to7cnib9","vSwitchId": "vsw-t4nr1xt8zupxg00unnmg9","zoneId": "ap-southeast-1b"},"cn-zhangjiakou": {"securityGroupId": "sg-8vb96lku1dgq71ckh98g","vSwitchId": "vsw-8vbtnz5878r3bcio7cpyx", "nfs":"9cbb94a474-oav34.cn-zhangjiakou.nas.aliyuncs.com", "zoneId": "cn-zhangjiakou-a"}} | |||||
| ##region_info={"cn-hangzhou": {"securityGroupId": "sg-bp17raa25u0wy0sb1qw5","vSwitchId": "vsw-bp176sh32kcq79d1uu8fp","zoneId": "cn-hangzhou-h"},"cn-shanghai": {"securityGroupId": "sg-uf62jug0dt92nfy630cs","vSwitchId": "vsw-uf6cb39ub5urw82bv3w70","zoneId": "cn-shanghai-g"},"cn-beijing": {"securityGroupId": "sg-2ze6uv80a8s4yk04dmyu","vSwitchId": "vsw-2zegtxf8q29d8tt1xtcjk","zoneId": "cn-beijing-h"},"cn-shenzhen":{"securityGroupId": "sg-wz96x4kv4edy97q6jjzn","vSwitchId": "vsw-wz9rn33jwilodp24klo0q","zoneId": "cn-shenzhen-a"},"cn-hongkong":{"securityGroupId": "sg-j6cjajpf7f4ybda7h19w","vSwitchId": "vsw-j6c9c9fit5owbbc0ids6c","zoneId": "cn-hongkong-b"},"us-west-1":{"securityGroupId": "sg-u19hbpj9x","vSwitchId": "vsw-rj9h5vvzhb4fjkuzuyi8j","zoneId": "us-west-1a"},"us-east-1":{"securityGroupId": "sg-0xih51sfoldxzxfsbja5","vSwitchId": "vsw-0xisefewxoqe4f849jbnl","zoneId": "us-east-1b"},"ap-southeast-1":{"securityGroupId": "sg-t4n23ppw7fm5to7cnib9","vSwitchId": "vsw-t4nr1xt8zupxg00unnmg9","zoneId": "ap-southeast-1b"},"cn-zhangjiakou": {"securityGroupId": "sg-8vb96lku1dgq71ckh98g","vSwitchId": "vsw-8vbtnz5878r3bcio7cpyx", "nfs":"9cbb94a474-oav34.cn-zhangjiakou.nas.aliyuncs.com", "zoneId": "cn-zhangjiakou-a"}} | |||||
| @@ -1,81 +1,53 @@ | |||||
| package eci | package eci | ||||
| import ( | import ( | ||||
| "PCM/adaptor/container_api_adaptor/common" | |||||
| "encoding/json" | "encoding/json" | ||||
| "fmt" | "fmt" | ||||
| "github.com/Unknwon/goconfig" | |||||
| "github.com/aliyun/alibaba-cloud-sdk-go/sdk/requests" | "github.com/aliyun/alibaba-cloud-sdk-go/sdk/requests" | ||||
| "github.com/aliyun/alibaba-cloud-sdk-go/services/eci" | "github.com/aliyun/alibaba-cloud-sdk-go/services/eci" | ||||
| "os" | |||||
| "time" | |||||
| ) | ) | ||||
| var accessKey string | |||||
| var secretKey string | |||||
| var regionId string | |||||
| var zoneId string | |||||
| var securityGroupId string | |||||
| var vSwitchId string | |||||
| var client *eci.Client | |||||
| /** | |||||
| 获取配置信息 | |||||
| */ | |||||
| func init() { | |||||
| var cfg *goconfig.ConfigFile | |||||
| config, err := goconfig.LoadConfigFile("/home/Senna/GolandProjects/PCM/adaptor/container_api_adaptor/alibaba/eci/config.conf") //加载配置文件 | |||||
| if err != nil { | |||||
| fmt.Println("get config file error:", err.Error()) | |||||
| os.Exit(-1) | |||||
| } | |||||
| cfg = config | |||||
| accessKey, _ = cfg.GetValue("eci_conf", "access_key") | |||||
| secretKey, _ = cfg.GetValue("eci_conf", "secret_key") | |||||
| regionId, _ = cfg.GetValue("eci_conf", "region_id") | |||||
| var regionInfo map[string](map[string](string)) | |||||
| value, _ := cfg.GetValue("eci_conf", "region_info") | |||||
| json.Unmarshal([]byte(value), ®ionInfo) | |||||
| zoneId = regionInfo[regionId]["zoneId"] | |||||
| securityGroupId = regionInfo[regionId]["securityGroupId"] | |||||
| vSwitchId = regionInfo[regionId]["vSwitchId"] | |||||
| fmt.Printf("init success[ access_key:%s, secret_key:%s, region_id:%s, zoneId:%s, vSwitchId:%s, securityGroupId:%s]\n", | |||||
| accessKey, secretKey, regionId, zoneId, vSwitchId, securityGroupId) | |||||
| //初始化client | |||||
| client, err = eci.NewClientWithAccessKey(regionId, accessKey, secretKey) | |||||
| if err != nil { | |||||
| panic(err) | |||||
| } | |||||
| } | |||||
| /** | /** | ||||
| 创建 | 创建 | ||||
| */ | */ | ||||
| func createContainerGroup() string { | func createContainerGroup() string { | ||||
| var client *eci.Client | |||||
| var configCommon common.PCMContainerConfig | |||||
| configCommon, _ = common.ConfigGet("/home/Senna/GolandProjects/PCM/adaptor/container_api_adaptor/alibaba/eci/config.conf") | |||||
| //Create Client | |||||
| client, _ = eci.NewClientWithAccessKey(configCommon.RegionId, configCommon.AccessKey, configCommon.SecretKey) | |||||
| // Create Container Group | // Create Container Group | ||||
| createContainerRequest := eci.CreateCreateContainerGroupRequest() | createContainerRequest := eci.CreateCreateContainerGroupRequest() | ||||
| // required | // required | ||||
| createContainerRequest.RegionId = regionId | |||||
| createContainerRequest.SecurityGroupId = securityGroupId | |||||
| createContainerRequest.VSwitchId = vSwitchId | |||||
| createContainerRequest.ContainerGroupName = "test-go-sdk" | |||||
| createContainerRequest.RestartPolicy = "Never" | |||||
| createContainerRequestVolume := make([]eci.CreateContainerGroupVolume, 1) | |||||
| volume1 := &eci.CreateContainerGroupNFSVolume{ | |||||
| Path: "/", | |||||
| Server: "0a1bf4a604-jaq68.cn-hangzhou.nas.aliyuncs.com", | |||||
| } | |||||
| createContainerRequestVolume[0].Name = "volume1" | |||||
| createContainerRequestVolume[0].Type = "NFSVolume" | |||||
| createContainerRequestVolume[0].NFSVolume = *volume1 | |||||
| createContainerRequest.Volume = &createContainerRequestVolume | |||||
| //区域ID | |||||
| createContainerRequest.RegionId = configCommon.RegionId | |||||
| //POD名称 | |||||
| createContainerRequest.ContainerGroupName = configCommon.ContainerGroupName | |||||
| //容器 | |||||
| createContainerRequestContainer := make([]eci.CreateContainerGroupContainer, 1) | createContainerRequestContainer := make([]eci.CreateContainerGroupContainer, 1) | ||||
| createContainerRequestContainer[0].Image = "nginx" | |||||
| createContainerRequestContainer[0].Name = "nginx-liu" | |||||
| // option | |||||
| createContainerRequestContainer[0].Cpu = requests.NewFloat(0.25) | |||||
| createContainerRequestContainer[0].Memory = requests.NewFloat(0.5) | |||||
| createContainerRequestContainer[0].ImagePullPolicy = "IfNotPresent" | |||||
| createContainerRequestContainer[0].Image = configCommon.ContainerImage | |||||
| createContainerRequestContainer[0].Name = configCommon.ContainerName | |||||
| createContainerRequest.Container = &createContainerRequestContainer | createContainerRequest.Container = &createContainerRequestContainer | ||||
| // option | |||||
| //createContainerRequest.SecurityGroupId = securityGroupId | |||||
| //createContainerRequest.VSwitchId = vSwitchId | |||||
| //createContainerRequest.RestartPolicy = restartPolicy | |||||
| //createContainerRequestVolume := make([]eci.CreateContainerGroupVolume, 1) | |||||
| //volume1 := &eci.CreateContainerGroupNFSVolume{ | |||||
| // Path: "/", | |||||
| // Server: "0a1bf4a604-jaq68.cn-hangzhou.nas.aliyuncs.com", | |||||
| //} | |||||
| //createContainerRequestVolume[0].Name = "volume1" | |||||
| //createContainerRequestVolume[0].Type = "NFSVolume" | |||||
| //createContainerRequestVolume[0].NFSVolume = *volume1 | |||||
| //createContainerRequest.Volume = &createContainerRequestVolume | |||||
| createContainerRequestContainer[0].Cpu = requests.NewFloat(configCommon.CpuContainerFloat) | |||||
| createContainerRequestContainer[0].Memory = requests.NewFloat(configCommon.MemoryContainerFloat) | |||||
| //createContainerRequestContainer[0].ImagePullPolicy = "IfNotPresent" | |||||
| //sdk-core默认的重试次数为3,在没有加幂等的条件下,资源创建的接口底层不需要自动重试 | //sdk-core默认的重试次数为3,在没有加幂等的条件下,资源创建的接口底层不需要自动重试 | ||||
| client.GetConfig().MaxRetryTime = 0 | client.GetConfig().MaxRetryTime = 0 | ||||
| createContainerGroupResponse, err := client.CreateContainerGroup(createContainerRequest) | createContainerGroupResponse, err := client.CreateContainerGroup(createContainerRequest) | ||||
| @@ -91,8 +63,12 @@ func createContainerGroup() string { | |||||
| 删除 | 删除 | ||||
| */ | */ | ||||
| func deleteContainerGroup(containerGroupId string) { | func deleteContainerGroup(containerGroupId string) { | ||||
| var client *eci.Client | |||||
| var configCommon common.PCMContainerConfig | |||||
| configCommon, _ = common.ConfigGet("/home/Senna/GolandProjects/PCM/adaptor/container_api_adaptor/alibaba/eci/config.conf") | |||||
| deleteContainerGroupRequest := eci.CreateDeleteContainerGroupRequest() | deleteContainerGroupRequest := eci.CreateDeleteContainerGroupRequest() | ||||
| deleteContainerGroupRequest.RegionId = regionId | |||||
| deleteContainerGroupRequest.RegionId = configCommon.RegionId | |||||
| deleteContainerGroupRequest.ContainerGroupId = containerGroupId | deleteContainerGroupRequest.ContainerGroupId = containerGroupId | ||||
| _, err := client.DeleteContainerGroup(deleteContainerGroupRequest) | _, err := client.DeleteContainerGroup(deleteContainerGroupRequest) | ||||
| if err != nil { | if err != nil { | ||||
| @@ -105,9 +81,13 @@ func deleteContainerGroup(containerGroupId string) { | |||||
| 查询 | 查询 | ||||
| */ | */ | ||||
| func describeContainerGroup(containerGroupId string) eci.DescribeContainerGroupsContainerGroup0 { | func describeContainerGroup(containerGroupId string) eci.DescribeContainerGroupsContainerGroup0 { | ||||
| var client *eci.Client | |||||
| var configCommon common.PCMContainerConfig | |||||
| configCommon, _ = common.ConfigGet("/home/Senna/GolandProjects/PCM/adaptor/container_api_adaptor/alibaba/eci/config.conf") | |||||
| // Describe Container Groups | // Describe Container Groups | ||||
| describeContainerGroupsRequest := eci.CreateDescribeContainerGroupsRequest() | describeContainerGroupsRequest := eci.CreateDescribeContainerGroupsRequest() | ||||
| describeContainerGroupsRequest.RegionId = regionId | |||||
| describeContainerGroupsRequest.RegionId = configCommon.RegionId | |||||
| containerGroupIds := append([]string{}, containerGroupId) | containerGroupIds := append([]string{}, containerGroupId) | ||||
| containerGroupIdsString, err := json.Marshal(containerGroupIds) | containerGroupIdsString, err := json.Marshal(containerGroupIds) | ||||
| describeContainerGroupsRequest.ContainerGroupIds = string(containerGroupIdsString) | describeContainerGroupsRequest.ContainerGroupIds = string(containerGroupIdsString) | ||||
| @@ -125,8 +105,12 @@ func describeContainerGroup(containerGroupId string) eci.DescribeContainerGroups | |||||
| return describeContainerGroupsResponse.ContainerGroups[0] | return describeContainerGroupsResponse.ContainerGroups[0] | ||||
| } | } | ||||
| func describeContainerGroupMetric(containerGroupId string) { | func describeContainerGroupMetric(containerGroupId string) { | ||||
| var client *eci.Client | |||||
| var configCommon common.PCMContainerConfig | |||||
| configCommon, _ = common.ConfigGet("/home/Senna/GolandProjects/PCM/adaptor/container_api_adaptor/alibaba/eci/config.conf") | |||||
| describeContainerGroupMetricRequest := eci.CreateDescribeContainerGroupMetricRequest() | describeContainerGroupMetricRequest := eci.CreateDescribeContainerGroupMetricRequest() | ||||
| describeContainerGroupMetricRequest.RegionId = regionId | |||||
| describeContainerGroupMetricRequest.RegionId = configCommon.RegionId | |||||
| describeContainerGroupMetricRequest.ContainerGroupId = containerGroupId | describeContainerGroupMetricRequest.ContainerGroupId = containerGroupId | ||||
| response, err := client.DescribeContainerGroupMetric(describeContainerGroupMetricRequest) | response, err := client.DescribeContainerGroupMetric(describeContainerGroupMetricRequest) | ||||
| if err != nil { | if err != nil { | ||||
| @@ -136,8 +120,12 @@ func describeContainerGroupMetric(containerGroupId string) { | |||||
| fmt.Printf("Metrics for %s:%s\n", containerGroupId, string(data)) | fmt.Printf("Metrics for %s:%s\n", containerGroupId, string(data)) | ||||
| } | } | ||||
| func describeMultiContainerGroupMetric(containerGroupIds []string) { | func describeMultiContainerGroupMetric(containerGroupIds []string) { | ||||
| var client *eci.Client | |||||
| var configCommon common.PCMContainerConfig | |||||
| configCommon, _ = common.ConfigGet("/home/Senna/GolandProjects/PCM/adaptor/container_api_adaptor/alibaba/eci/config.conf") | |||||
| describeContainerGroupMetricRequest := eci.CreateDescribeMultiContainerGroupMetricRequest() | describeContainerGroupMetricRequest := eci.CreateDescribeMultiContainerGroupMetricRequest() | ||||
| describeContainerGroupMetricRequest.RegionId = regionId | |||||
| describeContainerGroupMetricRequest.RegionId = configCommon.RegionId | |||||
| data, _ := json.Marshal(containerGroupIds) | data, _ := json.Marshal(containerGroupIds) | ||||
| describeContainerGroupMetricRequest.ContainerGroupIds = string(data) | describeContainerGroupMetricRequest.ContainerGroupIds = string(data) | ||||
| response, err := client.DescribeMultiContainerGroupMetric(describeContainerGroupMetricRequest) | response, err := client.DescribeMultiContainerGroupMetric(describeContainerGroupMetricRequest) | ||||
| @@ -156,19 +144,19 @@ func Test() { | |||||
| containerGroupIds <- containerGroupId | containerGroupIds <- containerGroupId | ||||
| } | } | ||||
| }() | }() | ||||
| go func() { | |||||
| for containerGroupId := range containerGroupIds { | |||||
| for i := 0; i < 10; i++ { | |||||
| status := describeContainerGroup(containerGroupId).Status | |||||
| if Running == ContainerGroupStatus(status) { | |||||
| break | |||||
| } else { | |||||
| time.Sleep(5 * time.Second) | |||||
| } | |||||
| } | |||||
| //deleteContainerGroupById(containerGroupId) | |||||
| } | |||||
| }() | |||||
| //go func() { | |||||
| // for containerGroupId := range containerGroupIds { | |||||
| // for i := 0; i < 10; i++ { | |||||
| // status := describeContainerGroup(containerGroupId).Status | |||||
| // if Running == ContainerGroupStatus(status) { | |||||
| // break | |||||
| // } else { | |||||
| // time.Sleep(5 * time.Second) | |||||
| // } | |||||
| // } | |||||
| // //deleteContainerGroupById(containerGroupId) | |||||
| // } | |||||
| //}() | |||||
| //阻塞等待异步执行完,不然会提前退出。 | //阻塞等待异步执行完,不然会提前退出。 | ||||
| var input string | var input string | ||||
| fmt.Println("waiting for input to finish:") | fmt.Println("waiting for input to finish:") | ||||
| @@ -1,6 +1,8 @@ | |||||
| package main | package main | ||||
| import "PCM/adaptor/container_api_adaptor/alibaba/eci" | |||||
| import ( | |||||
| "PCM/adaptor/container_api_adaptor/alibaba/eci" | |||||
| ) | |||||
| func main() { | func main() { | ||||
| eci.Test() | eci.Test() | ||||
| @@ -0,0 +1,82 @@ | |||||
| package common | |||||
| import ( | |||||
| "fmt" | |||||
| "github.com/Unknwon/goconfig" | |||||
| "os" | |||||
| "strconv" | |||||
| ) | |||||
| type PCMContainerConfig struct { | |||||
| AccessKey string | |||||
| SecretKey string | |||||
| RegionId string | |||||
| ContainerGroupName string | |||||
| ContainerImage string | |||||
| ContainerName string | |||||
| CpuPod string | |||||
| MemoryPod string | |||||
| CpuContainer string | |||||
| MemoryContainer string | |||||
| CpuPodFloat float64 | |||||
| MemoryPodFloat float64 | |||||
| CpuContainerFloat float64 | |||||
| MemoryContainerFloat float64 | |||||
| NameSpace string | |||||
| SecurityGroupId string | |||||
| SubnetId string | |||||
| VpcId string | |||||
| } | |||||
| func ConfigGet(configPath string) (PCMContainerConfig, error) { | |||||
| var cfg *goconfig.ConfigFile | |||||
| //"/home/Senna/GolandProjects/PCM/adaptor/container_api_adaptor/alibaba/eci/config.conf" | |||||
| config, err := goconfig.LoadConfigFile(configPath) //加载配置文件 | |||||
| if err != nil { | |||||
| fmt.Println("get config file error:", err.Error()) | |||||
| os.Exit(-1) | |||||
| } | |||||
| cfg = config | |||||
| accessKey, _ := cfg.GetValue("container_conf", "access_key") | |||||
| secretKey, _ := cfg.GetValue("container_conf", "secret_key") | |||||
| regionId, _ := cfg.GetValue("container_conf", "region_id") | |||||
| containerGroupName, _ := cfg.GetValue("container_conf", "container_group_name") | |||||
| containerImage, _ := cfg.GetValue("container_conf", "container_image") | |||||
| containerName, _ := cfg.GetValue("container_conf", "container_name") | |||||
| cpuPod, _ := cfg.GetValue("container_conf", "cpu_pod") | |||||
| memoryPod, _ := cfg.GetValue("container_conf", "memory_pod") | |||||
| cpuContainer, _ := cfg.GetValue("container_conf", "cpu_container") | |||||
| memoryContainer, _ := cfg.GetValue("container_conf", "memory_container") | |||||
| cpuPodFloat, _ := strconv.ParseFloat(cpuPod, 64) | |||||
| memoryPodFloat, _ := strconv.ParseFloat(memoryPod, 64) | |||||
| cpuContainerFloat, _ := strconv.ParseFloat(cpuContainer, 64) | |||||
| memoryContainerFloat, _ := strconv.ParseFloat(memoryContainer, 64) | |||||
| nameSpace, _ := cfg.GetValue("container_conf", "namespace") | |||||
| securityGroupId, _ := cfg.GetValue("container_conf", "security_group_id") | |||||
| subnetId, _ := cfg.GetValue("container_conf", "subnet_id") | |||||
| vpcId, _ := cfg.GetValue("container_conf", "vpc_id") | |||||
| var configCommon = PCMContainerConfig{ | |||||
| AccessKey: accessKey, | |||||
| SecretKey: secretKey, | |||||
| RegionId: regionId, | |||||
| ContainerGroupName: containerGroupName, | |||||
| ContainerImage: containerImage, | |||||
| ContainerName: containerName, | |||||
| CpuPod: cpuPod, | |||||
| MemoryPod: memoryPod, | |||||
| CpuContainer: cpuContainer, | |||||
| MemoryContainer: memoryContainer, | |||||
| CpuPodFloat: cpuPodFloat, | |||||
| MemoryPodFloat: memoryPodFloat, | |||||
| CpuContainerFloat: cpuContainerFloat, | |||||
| MemoryContainerFloat: memoryContainerFloat, | |||||
| NameSpace: nameSpace, | |||||
| SecurityGroupId: securityGroupId, | |||||
| SubnetId: subnetId, | |||||
| VpcId: vpcId, | |||||
| } | |||||
| return configCommon, nil | |||||
| } | |||||
| @@ -0,0 +1,36 @@ | |||||
| [container_conf] | |||||
| #测试账号ak | |||||
| access_key = ATQTIWUT9K66VRMMXKVY | |||||
| secret_key = Wa0aixDVuhZOfDZGWvgIJQBHnyiDlGdgDn1Ai5Yy | |||||
| #region | |||||
| region_id=cn-north-4 | |||||
| #namespace(华为单独的必需参数) | |||||
| namespace=test-k8s-client-namespace1 | |||||
| #容器实例名称(pod名) | |||||
| container_group_name=pcm-test-huawei-pod | |||||
| #镜像地址 | |||||
| container_image=library/nginx:stable-alpine-perl | |||||
| #容器名称 | |||||
| container_name=pcm-test-huawei-container | |||||
| ##下面为非必需参数 | |||||
| #安全组ID | |||||
| security_group_id=sg-bp17raa25u0wy0sb1qw5 | |||||
| #交换机ID | |||||
| v_switch_id=vsw-bp176sh32kcq79d1uu8fp | |||||
| #可用区 | |||||
| zone_id=cn-hangzhou-h | |||||
| #容器实例名称(pod名) | |||||
| container_group_name=pcm-test-huawei-pod | |||||
| #重启策略 | |||||
| restart_policy=Never | |||||
| #Pod拥有核数 | |||||
| cpu_pod=500m | |||||
| #Pod拥有内存大小 | |||||
| memory_pod=1024Mi | |||||
| #容器所需核数 | |||||
| cpu_container=500m | |||||
| #容器所需内存大小 | |||||
| memory_container=1024Mi | |||||
| #镜像拉取策略 | |||||
| image_pull_policy=IfNotPresent | |||||
| @@ -1,7 +1,7 @@ | |||||
| package main | package main | ||||
| import ( | import ( | ||||
| "PCM/adaptor/container_api_adaptor/huawei/demos/namespace" | |||||
| "PCM/adaptor/container_api_adaptor/huawei/demos/pod" | |||||
| "PCM/adaptor/container_api_adaptor/huawei/pkg/auth/aksk" | "PCM/adaptor/container_api_adaptor/huawei/pkg/auth/aksk" | ||||
| "fmt" | "fmt" | ||||
| ) | ) | ||||
| @@ -15,15 +15,15 @@ func main() { | |||||
| panic(err) | panic(err) | ||||
| } | } | ||||
| //创建命名空间 | |||||
| fmt.Println("start to namespace created") | |||||
| _, err = namespace.CreateNamespace(cs) | |||||
| if err != nil { | |||||
| panic(err) | |||||
| } | |||||
| fmt.Println("namespace created") | |||||
| ////创建命名空间 | |||||
| //fmt.Println("start to namespace created") | |||||
| //_, err = namespace.CreateNamespace(cs) | |||||
| //if err != nil { | |||||
| // panic(err) | |||||
| //} | |||||
| //fmt.Println("namespace created") | |||||
| //创建网络 | |||||
| ////创建网络 | |||||
| //fmt.Println("start to network created") | //fmt.Println("start to network created") | ||||
| //_, err = network.CreateNetwork(networkCs) | //_, err = network.CreateNetwork(networkCs) | ||||
| //if err != nil { | //if err != nil { | ||||
| @@ -39,12 +39,12 @@ func main() { | |||||
| //fmt.Println("deployment created") | //fmt.Println("deployment created") | ||||
| //创建pod | //创建pod | ||||
| //fmt.Println("start to create pod") | |||||
| //_, err = pod.CreatePod(cs) | |||||
| //if err != nil { | |||||
| // panic(err) | |||||
| //} | |||||
| //fmt.Println("pod created") | |||||
| fmt.Println("start to create pod") | |||||
| _, err = pod.CreatePod(cs) | |||||
| if err != nil { | |||||
| panic(err) | |||||
| } | |||||
| fmt.Println("pod created") | |||||
| //删除deployment | //删除deployment | ||||
| //fmt.Println("start to delete deployment") | //fmt.Println("start to delete deployment") | ||||
| @@ -1,22 +1,27 @@ | |||||
| package pod | package pod | ||||
| import ( | import ( | ||||
| "PCM/adaptor/container_api_adaptor/common" | |||||
| corev1 "k8s.io/api/core/v1" | corev1 "k8s.io/api/core/v1" | ||||
| "k8s.io/apimachinery/pkg/api/resource" | "k8s.io/apimachinery/pkg/api/resource" | ||||
| metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||||
| "k8s.io/client-go/kubernetes" | "k8s.io/client-go/kubernetes" | ||||
| ) | ) | ||||
| const ( | |||||
| app = "test-k8s-client-deployment" | |||||
| podName = "test-k8s-client-pod" | |||||
| namespace = "test-k8s-client-namespace1" | |||||
| ) | |||||
| // CreateDeployment 创建Deployment | |||||
| // API参考:https://support.huaweicloud.com/api-cci/createAppsV1NamespacedDeployment.html | |||||
| // CreatePod 创建Pod | |||||
| func CreatePod(client *kubernetes.Clientset) (*corev1.Pod, error) { | func CreatePod(client *kubernetes.Clientset) (*corev1.Pod, error) { | ||||
| var configCommon common.PCMContainerConfig | |||||
| configCommon, _ = common.ConfigGet("/home/Senna/GolandProjects/PCM/adaptor/container_api_adaptor/huawei/cci/config.conf") | |||||
| nameSpace := configCommon.NameSpace | |||||
| podName := configCommon.ContainerGroupName | |||||
| containerImage := configCommon.ContainerImage | |||||
| containerName := configCommon.ContainerName | |||||
| cpuPod := configCommon.CpuPod | |||||
| memoryPod := configCommon.MemoryPod | |||||
| cpuContainer := configCommon.CpuContainer | |||||
| memoryContainer := configCommon.MemoryContainer | |||||
| pod := corev1.Pod{ | pod := corev1.Pod{ | ||||
| TypeMeta: metav1.TypeMeta{ | TypeMeta: metav1.TypeMeta{ | ||||
| APIVersion: "core/V1", | APIVersion: "core/V1", | ||||
| @@ -31,16 +36,16 @@ func CreatePod(client *kubernetes.Clientset) (*corev1.Pod, error) { | |||||
| RestartPolicy: corev1.RestartPolicyAlways, | RestartPolicy: corev1.RestartPolicyAlways, | ||||
| Containers: []corev1.Container{ | Containers: []corev1.Container{ | ||||
| corev1.Container{ | corev1.Container{ | ||||
| Name: "container-0", | |||||
| Image: "library/nginx:stable-alpine-perl", | |||||
| Name: containerName, | |||||
| Image: containerImage, | |||||
| Resources: corev1.ResourceRequirements{ | Resources: corev1.ResourceRequirements{ | ||||
| Requests: map[corev1.ResourceName]resource.Quantity{ | Requests: map[corev1.ResourceName]resource.Quantity{ | ||||
| corev1.ResourceCPU: resource.MustParse("500m"), | |||||
| corev1.ResourceMemory: resource.MustParse("1024Mi"), | |||||
| corev1.ResourceCPU: resource.MustParse(cpuContainer), | |||||
| corev1.ResourceMemory: resource.MustParse(memoryContainer), | |||||
| }, | }, | ||||
| Limits: map[corev1.ResourceName]resource.Quantity{ | Limits: map[corev1.ResourceName]resource.Quantity{ | ||||
| corev1.ResourceCPU: resource.MustParse("500m"), | |||||
| corev1.ResourceMemory: resource.MustParse("1024Mi"), | |||||
| corev1.ResourceCPU: resource.MustParse(cpuPod), | |||||
| corev1.ResourceMemory: resource.MustParse(memoryPod), | |||||
| }, | }, | ||||
| }, | }, | ||||
| }, | }, | ||||
| @@ -49,17 +54,28 @@ func CreatePod(client *kubernetes.Clientset) (*corev1.Pod, error) { | |||||
| Status: corev1.PodStatus{}, | Status: corev1.PodStatus{}, | ||||
| } | } | ||||
| return client.CoreV1().Pods(namespace).Create(&pod) | |||||
| return client.CoreV1().Pods(nameSpace).Create(&pod) | |||||
| } | } | ||||
| // DeletePod 删除Pod | // DeletePod 删除Pod | ||||
| // API参考:https://support.huaweicloud.com/api-cci/deleteAppsV1NamespacedDeployment.html | |||||
| func DeletePod(client *kubernetes.Clientset) error { | func DeletePod(client *kubernetes.Clientset) error { | ||||
| return client.CoreV1().Pods(namespace).Delete(podName, &metav1.DeleteOptions{}) | |||||
| var configCommon common.PCMContainerConfig | |||||
| configCommon, _ = common.ConfigGet("/home/Senna/GolandProjects/PCM/adaptor/container_api_adaptor/huawei/cci/config.conf") | |||||
| nameSpace := configCommon.NameSpace | |||||
| podName := configCommon.ContainerGroupName | |||||
| return client.CoreV1().Pods(nameSpace).Delete(podName, &metav1.DeleteOptions{}) | |||||
| } | } | ||||
| // GetPod 查询Pod | // GetPod 查询Pod | ||||
| // API参考:https://support.huaweicloud.com/api-cci/readAppsV1NamespacedDeployment.html | |||||
| func GetPod(client *kubernetes.Clientset) (*corev1.Pod, error) { | func GetPod(client *kubernetes.Clientset) (*corev1.Pod, error) { | ||||
| return client.CoreV1().Pods(namespace).Get(podName, metav1.GetOptions{}) | |||||
| var configCommon common.PCMContainerConfig | |||||
| configCommon, _ = common.ConfigGet("/home/Senna/GolandProjects/PCM/adaptor/container_api_adaptor/huawei/cci/config.conf") | |||||
| nameSpace := configCommon.NameSpace | |||||
| podName := configCommon.ContainerGroupName | |||||
| return client.CoreV1().Pods(nameSpace).Get(podName, metav1.GetOptions{}) | |||||
| } | } | ||||
| @@ -1,6 +1,7 @@ | |||||
| package aksk | package aksk | ||||
| import ( | import ( | ||||
| "PCM/adaptor/container_api_adaptor/common" | |||||
| clientset "PCM/adaptor/container_api_adaptor/huawei/pkg/client/networking.cci.io/v1beta1" | clientset "PCM/adaptor/container_api_adaptor/huawei/pkg/client/networking.cci.io/v1beta1" | ||||
| "fmt" | "fmt" | ||||
| "k8s.io/client-go/kubernetes" | "k8s.io/client-go/kubernetes" | ||||
| @@ -11,14 +12,15 @@ import ( | |||||
| const ( | const ( | ||||
| apiVersion = "client.authentication.k8s.io/v1beta1" | apiVersion = "client.authentication.k8s.io/v1beta1" | ||||
| // 云容器实例 CCI,参考https://developer.huaweicloud.com/endpoint | // 云容器实例 CCI,参考https://developer.huaweicloud.com/endpoint | ||||
| cciEndpoint = "https://cci.cn-north-4.myhuaweicloud.com" | |||||
| //cciEndpoint = "https://cci.cn-north-4.myhuaweicloud.com" | |||||
| // 统一身份认证服务 IAM,参考https://developer.huaweicloud.com/endpoint | // 统一身份认证服务 IAM,参考https://developer.huaweicloud.com/endpoint | ||||
| iamEndpoint = "https://iam.myhuaweicloud.com" | iamEndpoint = "https://iam.myhuaweicloud.com" | ||||
| // 地区和终端节点,参考https://developer.huaweicloud.com/endpoint | // 地区和终端节点,参考https://developer.huaweicloud.com/endpoint | ||||
| projectName = "cn-north-4" | |||||
| //projectName = "cn-north-4" | |||||
| // 获取AK/SK参考: https://support.huaweicloud.com/devg-cci/cci_kubectl_01.html#cci_kubectl_01__section17023744719 | // 获取AK/SK参考: https://support.huaweicloud.com/devg-cci/cci_kubectl_01.html#cci_kubectl_01__section17023744719 | ||||
| ak = "ATQTIWUT9K66VRMMXKVY" | |||||
| sk = "Wa0aixDVuhZOfDZGWvgIJQBHnyiDlGdgDn1Ai5Yy" | |||||
| //ak = "ATQTIWUT9K66VRMMXKVY" | |||||
| //sk = "Wa0aixDVuhZOfDZGWvgIJQBHnyiDlGdgDn1Ai5Yy" | |||||
| DomainId = "0a4e7f245680f3040fdfc011720e50a0" //账号ID,可以在我的凭证获取 | DomainId = "0a4e7f245680f3040fdfc011720e50a0" //账号ID,可以在我的凭证获取 | ||||
| ProjectId = "0a62ffb0d48026c12fbfc011b8d23f0b" //项目ID,可以在我的凭证获取 | ProjectId = "0a62ffb0d48026c12fbfc011b8d23f0b" //项目ID,可以在我的凭证获取 | ||||
| @@ -32,32 +34,50 @@ const ( | |||||
| // NewClient 通过AK/SK认证创建Clientset | // NewClient 通过AK/SK认证创建Clientset | ||||
| func NewClient() (*kubernetes.Clientset, error) { | func NewClient() (*kubernetes.Clientset, error) { | ||||
| config, err := clientcmd.BuildConfigFromFlags(cciEndpoint, "") | |||||
| var configCommon common.PCMContainerConfig | |||||
| configCommon, _ = common.ConfigGet("/home/Senna/GolandProjects/PCM/adaptor/container_api_adaptor/huawei/cci/config.conf") | |||||
| ak := configCommon.AccessKey | |||||
| sk := configCommon.SecretKey | |||||
| regionId := configCommon.RegionId | |||||
| cciEndpoint := "https://cci." + regionId + ".myhuaweicloud.com" | |||||
| cciConfig, err := clientcmd.BuildConfigFromFlags(cciEndpoint, "") | |||||
| 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("--iam-endpoint=%s", iamEndpoint)) | ||||
| optionArgs = append(optionArgs, fmt.Sprintf("--project-name=%s", projectName)) | |||||
| optionArgs = append(optionArgs, fmt.Sprintf("--project-name=%s", regionId)) | |||||
| optionArgs = append(optionArgs, fmt.Sprintf("--ak=%s", ak)) | optionArgs = append(optionArgs, fmt.Sprintf("--ak=%s", ak)) | ||||
| optionArgs = append(optionArgs, fmt.Sprintf("--sk=%s", sk)) | optionArgs = append(optionArgs, fmt.Sprintf("--sk=%s", sk)) | ||||
| config.ExecProvider = &api.ExecConfig{ | |||||
| cciConfig.ExecProvider = &api.ExecConfig{ | |||||
| Command: "cci-iam-authenticator", | Command: "cci-iam-authenticator", | ||||
| APIVersion: apiVersion, | APIVersion: apiVersion, | ||||
| Args: append([]string{"token"}, optionArgs...), | Args: append([]string{"token"}, optionArgs...), | ||||
| Env: make([]api.ExecEnvVar, 0), | Env: make([]api.ExecEnvVar, 0), | ||||
| } | } | ||||
| return kubernetes.NewForConfig(config) | |||||
| return kubernetes.NewForConfig(cciConfig) | |||||
| } | } | ||||
| func NewNetworkClient() (*clientset.Clientset, error) { | func NewNetworkClient() (*clientset.Clientset, error) { | ||||
| var configCommon common.PCMContainerConfig | |||||
| configCommon, _ = common.ConfigGet("/home/Senna/GolandProjects/PCM/adaptor/container_api_adaptor/alibaba/eci/config.conf") | |||||
| ak := configCommon.AccessKey | |||||
| sk := configCommon.SecretKey | |||||
| regionId := configCommon.RegionId | |||||
| cciEndpoint := "https://cci." + regionId + ".myhuaweicloud.com" | |||||
| config, err := clientcmd.BuildConfigFromFlags(cciEndpoint, "") | config, err := clientcmd.BuildConfigFromFlags(cciEndpoint, "") | ||||
| 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("--iam-endpoint=%s", iamEndpoint)) | ||||
| optionArgs = append(optionArgs, fmt.Sprintf("--project-name=%s", projectName)) | |||||
| optionArgs = append(optionArgs, fmt.Sprintf("--project-name=%s", regionId)) | |||||
| optionArgs = append(optionArgs, fmt.Sprintf("--ak=%s", ak)) | optionArgs = append(optionArgs, fmt.Sprintf("--ak=%s", ak)) | ||||
| optionArgs = append(optionArgs, fmt.Sprintf("--sk=%s", sk)) | optionArgs = append(optionArgs, fmt.Sprintf("--sk=%s", sk)) | ||||
| config.ExecProvider = &api.ExecConfig{ | config.ExecProvider = &api.ExecConfig{ | ||||
| @@ -1,44 +1,70 @@ | |||||
| package main | package main | ||||
| import ( | |||||
| "fmt" | |||||
| "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common" | |||||
| "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/errors" | |||||
| "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/profile" | |||||
| tke "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tke/v20180525" | |||||
| ) | |||||
| func main() { | |||||
| credential := common.NewCredential( | |||||
| "AKIDRefQxnhmuqTU1KRWFl58wQeCE0XoAeEZ", | |||||
| "LUMVRmGj2kFrEahhZzA5pKvHNSMASntj", | |||||
| ) | |||||
| cpf := profile.NewClientProfile() | |||||
| cpf.HttpProfile.Endpoint = "tke.tencentcloudapi.com" | |||||
| client, _ := tke.NewClient(credential, "ap-beijing", cpf) | |||||
| var ( | |||||
| name = "sds" | |||||
| vpcId = "" | |||||
| subnetId = "" | |||||
| memory float64 = 4.00 | |||||
| cpu float64 = 4.00 | |||||
| ) | |||||
| request := tke.NewCreateEKSContainerInstancesRequest() | |||||
| request.EksCiName = &name | |||||
| request.VpcId = &vpcId | |||||
| request.SubnetId = &subnetId | |||||
| request.Memory = &memory | |||||
| request.Cpu = &cpu | |||||
| response, err := client.CreateEKSContainerInstances(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()) | |||||
| } | |||||
| // | |||||
| //import ( | |||||
| // "fmt" | |||||
| // "github.com/Unknwon/goconfig" | |||||
| // "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common" | |||||
| // "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/errors" | |||||
| // "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/profile" | |||||
| // tke "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tke/v20180525" | |||||
| // "os" | |||||
| //) | |||||
| // | |||||
| //func main() { | |||||
| // /** | |||||
| // 认证 | |||||
| // */ | |||||
| // | |||||
| // var accessKey string | |||||
| // var secretKey string | |||||
| // var cfg *goconfig.ConfigFile | |||||
| // config, err := goconfig.LoadConfigFile("/home/Senna/GolandProjects/PCM/adaptor/container_api_adaptor/tencent/tke/config.conf") //加载配置文件 | |||||
| // if err != nil { | |||||
| // fmt.Println("get config file error:", err.Error()) | |||||
| // os.Exit(-1) | |||||
| // } | |||||
| // cfg = config | |||||
| // accessKey, _ = cfg.GetValue("tke_conf", "access_key") | |||||
| // secretKey, _ = cfg.GetValue("tke_conf", "secret_key") | |||||
| // | |||||
| // credential := common.NewCredential( | |||||
| // accessKey, | |||||
| // secretKey, | |||||
| // ) | |||||
| // | |||||
| // cpf := profile.NewClientProfile() | |||||
| // cpf.HttpProfile.Endpoint = "tke.tencentcloudapi.com" | |||||
| // client, err := tke.NewClient(credential, "", cpf) | |||||
| // | |||||
| // var ( | |||||
| // name = "sds" | |||||
| // vpcId = "" | |||||
| // subnetId = "" | |||||
| // memory float64 = 0.50 | |||||
| // cpu float64 = 0.50 | |||||
| // ) | |||||
| // | |||||
| // container := make([]*tke.Container, 1) | |||||
| // containerName, _ := cfg.GetValue("tke_conf", "containerName") | |||||
| // containerImage, _ := cfg.GetValue("tke_conf", "containerImage") | |||||
| // container[0].Name = &containerName | |||||
| // container[0].Image = &containerImage | |||||
| // request := tke.NewCreateEKSContainerInstancesRequest() | |||||
| // request.EksCiName = &name | |||||
| // request.VpcId = &vpcId | |||||
| // request.SubnetId = &subnetId | |||||
| // request.Memory = &memory | |||||
| // request.Cpu = &cpu | |||||
| // request.Containers = container | |||||
| // | |||||
| // response, err := client.CreateEKSContainerInstances(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()) | |||||
| //} | |||||
| @@ -0,0 +1,38 @@ | |||||
| [container_conf] | |||||
| #测试账号ak | |||||
| access_key = AKIDRefQxnhmuqTU1KRWFl58wQeCE0XoAeEZ | |||||
| secret_key = LUMVRmGj2kFrEahhZzA5pKvHNSMASntj | |||||
| #region | |||||
| region_id=ap-beijing | |||||
| #namespace(华为单独的必需参数) | |||||
| namespace=test-k8s-client-namespace1 | |||||
| #容器实例名称(pod名) | |||||
| container_group_name=pcm-test-tencent-pod | |||||
| #镜像地址 | |||||
| container_image=library/nginx:stable-alpine-perl | |||||
| #容器名称 | |||||
| container_name=pcm-test-tencent-container | |||||
| ##下面为非必需参数 | |||||
| #安全组ID | |||||
| security_group_id=sg-owzbdinl | |||||
| #交换机ID | |||||
| v_switch_id=vsw-bp176sh32kcq79d1uu8fp | |||||
| #可用区 | |||||
| zone_id=cn-hangzhou-h | |||||
| #重启策略 | |||||
| restart_policy=Never | |||||
| #Pod拥有核数 | |||||
| cpu_pod=1 | |||||
| #Pod拥有内存大小 | |||||
| memory_pod=2 | |||||
| #容器所需核数 | |||||
| cpu_container=1 | |||||
| #容器所需内存大小 | |||||
| memory_container=2 | |||||
| #镜像拉取策略 | |||||
| image_pull_policy=IfNotPresent | |||||
| #子网ID | |||||
| subnet_id=subnet-n4h73049 | |||||
| #VPC ID | |||||
| vpc_id=vpc-e8hdbla8 | |||||
| @@ -0,0 +1,83 @@ | |||||
| package main | |||||
| import ( | |||||
| pcmCommon "PCM/adaptor/container_api_adaptor/common" | |||||
| "fmt" | |||||
| "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common" | |||||
| "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/errors" | |||||
| "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/profile" | |||||
| tke "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tke/v20180525" | |||||
| ) | |||||
| func main() { | |||||
| var configCommon pcmCommon.PCMContainerConfig | |||||
| configCommon, _ = pcmCommon.ConfigGet("/home/Senna/GolandProjects/PCM/adaptor/container_api_adaptor/tencent/tke/config.conf") | |||||
| credential := common.NewCredential( | |||||
| configCommon.AccessKey, | |||||
| configCommon.SecretKey, | |||||
| ) | |||||
| cpf := profile.NewClientProfile() | |||||
| cpf.HttpProfile.Endpoint = "tke.tencentcloudapi.com" | |||||
| client, _ := tke.NewClient(credential, configCommon.RegionId, cpf) | |||||
| request := tke.NewCreateEKSContainerInstancesRequest() | |||||
| eksCiName := configCommon.ContainerGroupName | |||||
| var eksCiNamePt = &eksCiName | |||||
| containerName := configCommon.ContainerName | |||||
| var containerNamePt = &containerName | |||||
| containerImage := configCommon.ContainerImage | |||||
| var containerImagePt = &containerImage | |||||
| containerCpu := configCommon.CpuContainerFloat | |||||
| var containerCpuPt = &containerCpu | |||||
| containerMemory := configCommon.MemoryContainerFloat | |||||
| var containerMemoryPt = &containerMemory | |||||
| eksCpu := configCommon.CpuPodFloat | |||||
| var eksCpuPt = &eksCpu | |||||
| eksMemory := configCommon.MemoryPodFloat | |||||
| var eksMemoryPt = &eksMemory | |||||
| securityGroupId := configCommon.SecurityGroupId | |||||
| var securityGroupIdPt = &securityGroupId | |||||
| securityGroupIdsPt := make([]*string, 1) | |||||
| securityGroupIdsPt[0] = securityGroupIdPt | |||||
| subNetId := configCommon.SubnetId | |||||
| var subNetIdPt = &subNetId | |||||
| vpcId := configCommon.VpcId | |||||
| var vpcIdPt = &vpcId | |||||
| request.EksCiName = eksCiNamePt | |||||
| container := make([]*tke.Container, 1) | |||||
| container[0] = new(tke.Container) | |||||
| container[0].Name = containerNamePt | |||||
| container[0].Image = containerImagePt | |||||
| container[0].Cpu = containerCpuPt | |||||
| container[0].Memory = containerMemoryPt | |||||
| request.Containers = container | |||||
| request.Cpu = eksCpuPt | |||||
| request.Memory = eksMemoryPt | |||||
| request.SecurityGroupIds = securityGroupIdsPt | |||||
| request.SubnetId = subNetIdPt | |||||
| request.VpcId = vpcIdPt | |||||
| response, err := client.CreateEKSContainerInstances(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()) | |||||
| } | |||||