CRUD for tencent
auth through aksk with a single config file
This commit is contained in:
parent
65a77e7d07
commit
9a18bf3c47
|
@ -1,65 +1,17 @@
|
||||||
[pod_create_conf]
|
[pod_create_conf]
|
||||||
#测试账号ak
|
region_id=cn-hangzhou #region 对应阿里 RegionId(阿里必需)
|
||||||
access_key =
|
container_group_name=pcm-test-ali-pod #容器实例名称(pod名) 对应阿里 ContainerGroupName(阿里必需)
|
||||||
secret_key =
|
container_image=registry-vpc.cn-hangzhou.aliyuncs.com/eci_open/nginx #镜像地址 对应阿里 Container.Image(阿里必需)
|
||||||
#region 对应阿里 RegionId(阿里必需)
|
container_name=pcm-test-ali-container #容器名称 对应阿里 Container.Name(阿里必需)
|
||||||
region_id=cn-hangzhou
|
|
||||||
#容器实例名称(pod名) 对应阿里 ContainerGroupName(阿里必需)
|
|
||||||
container_group_name=pcm-test-ali-pod
|
|
||||||
#镜像地址 对应阿里 Container.Image(阿里必需)
|
|
||||||
container_image=registry-vpc.cn-hangzhou.aliyuncs.com/eci_open/nginx
|
|
||||||
#容器名称 对应阿里 Container.Name(阿里必需)
|
|
||||||
container_name=pcm-test-ali-container
|
|
||||||
|
|
||||||
[pod_delete_conf]
|
[pod_delete_conf]
|
||||||
# 必需参数
|
region_id=cn-hangzhou # 地域id
|
||||||
# 地域id
|
container_group_id=eci-bp1c3eqfq98nz2kbiooo #容器实例ID
|
||||||
region_id=cn-hangzhou
|
|
||||||
#容器实例ID
|
|
||||||
container_group_id=eci-bp100utqw03jci4583xg
|
|
||||||
|
|
||||||
[pod_list_conf]
|
[pod_list_conf]
|
||||||
# 必需参数
|
region_id=cn-hangzhou # 地域id
|
||||||
# 地域id
|
|
||||||
region_id=cn-hangzhou
|
|
||||||
|
|
||||||
|
|
||||||
[pod_update_conf]
|
[pod_update_conf]
|
||||||
# 必需参数
|
region_id=cn-hangzhou # 地域id
|
||||||
# 地域id
|
container_group_id=eci-bp1c3eqfq98nz2kbiooo #容器实例ID
|
||||||
region_id=cn-hangzhou
|
restart_policy=Never #可选 这里用重启策略做更新测试
|
||||||
#容器实例ID
|
|
||||||
container_group_id=eci-bp100utqw03jci4583xg
|
|
||||||
|
|
||||||
#可选 这里做更新测试
|
|
||||||
#重启策略
|
|
||||||
restart_policy=Always
|
|
||||||
|
|
||||||
|
|
||||||
#
|
|
||||||
# ##下面为非必需参数
|
|
||||||
# #安全组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_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,20 +1,21 @@
|
||||||
package eci
|
package eci
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"PCM/adaptor/container_api_adaptor/common/auth/aksk"
|
||||||
"PCM/adaptor/container_api_adaptor/common/config"
|
"PCM/adaptor/container_api_adaptor/common/config"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/aliyun/alibaba-cloud-sdk-go/services/eci"
|
"github.com/aliyun/alibaba-cloud-sdk-go/services/eci"
|
||||||
)
|
)
|
||||||
|
|
||||||
// CreateContainerGroup 创建
|
// CreateContainerGroup 创建
|
||||||
func CreateContainerGroup(configPath string) string {
|
func CreateContainerGroup(cloudStack string, akskPath string, configPath string) string {
|
||||||
|
|
||||||
var client *eci.Client
|
var client *eci.Client
|
||||||
var configCommon config.PCMContainerConfig
|
configCommon, _ := config.PCMconfig(configPath)
|
||||||
configCommon, _ = config.PCMconfig(configPath)
|
configAksk, _ := aksk.AkskConfig(cloudStack, akskPath)
|
||||||
|
|
||||||
//创建客户端
|
//创建客户端
|
||||||
client, _ = eci.NewClientWithAccessKey(configCommon.RegionId, configCommon.AccessKey, configCommon.SecretKey)
|
client, _ = eci.NewClientWithAccessKey(configCommon.RegionId, configAksk.AccessKey, configAksk.SecretKey)
|
||||||
// 生成创建请求
|
// 生成创建请求
|
||||||
createContainerRequest := eci.CreateCreateContainerGroupRequest()
|
createContainerRequest := eci.CreateCreateContainerGroupRequest()
|
||||||
// 必需参数
|
// 必需参数
|
||||||
|
@ -39,12 +40,12 @@ func CreateContainerGroup(configPath string) string {
|
||||||
}
|
}
|
||||||
|
|
||||||
// DescribeContainerGroup 查询Pod
|
// DescribeContainerGroup 查询Pod
|
||||||
func DescribeContainerGroup(configPath string) eci.DescribeContainerGroupsContainerGroup0 {
|
func DescribeContainerGroup(cloudStack string, akskPath string, configPath string) eci.DescribeContainerGroupsContainerGroup0 {
|
||||||
var client *eci.Client
|
var client *eci.Client
|
||||||
|
|
||||||
var configCommon config.PCMContainerConfig
|
configCommon, _ := config.PCMconfig(configPath)
|
||||||
configCommon, _ = config.PCMconfig(configPath)
|
configAksk, _ := aksk.AkskConfig(cloudStack, akskPath)
|
||||||
client, _ = eci.NewClientWithAccessKey(configCommon.RegionId, configCommon.AccessKey, configCommon.SecretKey)
|
client, _ = eci.NewClientWithAccessKey(configCommon.RegionId, configAksk.AccessKey, configAksk.SecretKey)
|
||||||
|
|
||||||
// 生成查询请求
|
// 生成查询请求
|
||||||
describeContainerGroupsRequest := eci.CreateDescribeContainerGroupsRequest()
|
describeContainerGroupsRequest := eci.CreateDescribeContainerGroupsRequest()
|
||||||
|
@ -68,11 +69,13 @@ func DescribeContainerGroup(configPath string) eci.DescribeContainerGroupsContai
|
||||||
}
|
}
|
||||||
|
|
||||||
// UpdateContainerGroup 更新Pod
|
// UpdateContainerGroup 更新Pod
|
||||||
func UpdateContainerGroup(configPath string) string {
|
func UpdateContainerGroup(cloudStack string, akskPath string, configPath string) string {
|
||||||
var client *eci.Client
|
var client *eci.Client
|
||||||
var configCommon config.PCMContainerConfig
|
|
||||||
configCommon, _ = config.PCMconfig(configPath)
|
configCommon, _ := config.PCMconfig(configPath)
|
||||||
client, _ = eci.NewClientWithAccessKey(configCommon.RegionId, configCommon.AccessKey, configCommon.SecretKey)
|
configAksk, _ := aksk.AkskConfig(cloudStack, akskPath)
|
||||||
|
|
||||||
|
client, _ = eci.NewClientWithAccessKey(configCommon.RegionId, configAksk.AccessKey, configAksk.SecretKey)
|
||||||
|
|
||||||
//生成更新请求
|
//生成更新请求
|
||||||
updateContainerGroupRequest := eci.CreateUpdateContainerGroupRequest()
|
updateContainerGroupRequest := eci.CreateUpdateContainerGroupRequest()
|
||||||
|
@ -96,11 +99,11 @@ func UpdateContainerGroup(configPath string) string {
|
||||||
}
|
}
|
||||||
|
|
||||||
// DeleteContainerGroup 删除Pod
|
// DeleteContainerGroup 删除Pod
|
||||||
func DeleteContainerGroup(configPath string) string {
|
func DeleteContainerGroup(cloudStack string, akskPath string, configPath string) string {
|
||||||
var client *eci.Client
|
var client *eci.Client
|
||||||
var configCommon config.PCMContainerConfig
|
configCommon, _ := config.PCMconfig(configPath)
|
||||||
configCommon, _ = config.PCMconfig(configPath)
|
configAksk, _ := aksk.AkskConfig(cloudStack, akskPath)
|
||||||
client, _ = eci.NewClientWithAccessKey(configCommon.RegionId, configCommon.AccessKey, configCommon.SecretKey)
|
client, _ = eci.NewClientWithAccessKey(configCommon.RegionId, configAksk.AccessKey, configAksk.SecretKey)
|
||||||
|
|
||||||
//生成删除请求
|
//生成删除请求
|
||||||
deleteContainerGroupRequest := eci.CreateDeleteContainerGroupRequest()
|
deleteContainerGroupRequest := eci.CreateDeleteContainerGroupRequest()
|
||||||
|
|
|
@ -2,20 +2,20 @@ package api
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"PCM/adaptor/container_api_adaptor/alibaba/eci"
|
"PCM/adaptor/container_api_adaptor/alibaba/eci"
|
||||||
cci "PCM/adaptor/container_api_adaptor/huawei/demos/pod"
|
|
||||||
cciAksk "PCM/adaptor/container_api_adaptor/huawei/pkg/auth/aksk"
|
cciAksk "PCM/adaptor/container_api_adaptor/huawei/pkg/auth/aksk"
|
||||||
|
cci "PCM/adaptor/container_api_adaptor/huawei/resources/pod"
|
||||||
"PCM/adaptor/container_api_adaptor/tencent/eks"
|
"PCM/adaptor/container_api_adaptor/tencent/eks"
|
||||||
)
|
)
|
||||||
|
|
||||||
//CreatePod 创建Pod通用方法
|
//CreatePod 创建Pod通用方法
|
||||||
func CreatePod(cloudStack string, configPath string) {
|
func CreatePod(cloudStack string, akskPath string, configPath string) {
|
||||||
switch cloudStack {
|
switch cloudStack {
|
||||||
|
|
||||||
case "alibaba":
|
case "alibaba":
|
||||||
eci.CreateContainerGroup(configPath)
|
eci.CreateContainerGroup(cloudStack, akskPath, configPath)
|
||||||
|
|
||||||
case "huawei":
|
case "huawei":
|
||||||
cs, err := cciAksk.NewClient(configPath)
|
cs, err := cciAksk.NewClient(cloudStack, akskPath, configPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
@ -25,21 +25,21 @@ func CreatePod(cloudStack string, configPath string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
case "tencent":
|
case "tencent":
|
||||||
eks.CreateTkeInstance(configPath)
|
eks.CreateEksInstance(cloudStack, akskPath, configPath)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// DeletePod 删除Pod 通用方法
|
// DeletePod 删除Pod 通用方法
|
||||||
func DeletePod(cloudStack string, configPath string) {
|
func DeletePod(cloudStack string, akskPath string, configPath string) {
|
||||||
|
|
||||||
switch cloudStack {
|
switch cloudStack {
|
||||||
|
|
||||||
case "alibaba":
|
case "alibaba":
|
||||||
eci.DeleteContainerGroup(configPath)
|
eci.DeleteContainerGroup(cloudStack, akskPath, configPath)
|
||||||
|
|
||||||
case "huawei":
|
case "huawei":
|
||||||
cs, err := cciAksk.NewClient(configPath)
|
cs, err := cciAksk.NewClient(cloudStack, akskPath, configPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
@ -49,19 +49,20 @@ func DeletePod(cloudStack string, configPath string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
case "tencent":
|
case "tencent":
|
||||||
|
eks.DeleteEksInstance(cloudStack, akskPath, configPath)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//UpdatePod 更新Pod通用方法
|
//UpdatePod 更新Pod通用方法
|
||||||
func UpdatePod(cloudStack string, configPath string) {
|
func UpdatePod(cloudStack string, akskPath string, configPath string) {
|
||||||
|
|
||||||
switch cloudStack {
|
switch cloudStack {
|
||||||
|
|
||||||
case "alibaba":
|
case "alibaba":
|
||||||
eci.UpdateContainerGroup(configPath)
|
eci.UpdateContainerGroup(cloudStack, akskPath, configPath)
|
||||||
|
|
||||||
case "huawei":
|
case "huawei":
|
||||||
cs, err := cciAksk.NewClient(configPath)
|
cs, err := cciAksk.NewClient(cloudStack, akskPath, configPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
@ -70,19 +71,20 @@ func UpdatePod(cloudStack string, configPath string) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
case "tencent":
|
case "tencent":
|
||||||
|
eks.UpdateEksInstance(cloudStack, akskPath, configPath)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//ListPod 查询Pod通用方法
|
//ListPod 查询Pod通用方法
|
||||||
func ListPod(cloudStack string, configPath string) {
|
func ListPod(cloudStack string, akskPath string, configPath string) {
|
||||||
|
|
||||||
switch cloudStack {
|
switch cloudStack {
|
||||||
|
|
||||||
case "alibaba":
|
case "alibaba":
|
||||||
eci.DescribeContainerGroup(configPath)
|
eci.DescribeContainerGroup(cloudStack, akskPath, configPath)
|
||||||
|
|
||||||
case "huawei":
|
case "huawei":
|
||||||
cs, err := cciAksk.NewClient(configPath)
|
cs, err := cciAksk.NewClient(cloudStack, akskPath, configPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
@ -92,5 +94,6 @@ func ListPod(cloudStack string, configPath string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
case "tencent":
|
case "tencent":
|
||||||
|
eks.ListEksInstance(cloudStack, akskPath, configPath)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,14 @@
|
||||||
|
#阿里
|
||||||
|
[alibaba]
|
||||||
|
access_key = LTAI5tSCnrhQAdbFhGyWkSL2
|
||||||
|
secret_key = KN4tqu8lalQdo47SoUQBb88qOWjzYC
|
||||||
|
|
||||||
|
#华为
|
||||||
|
[huawei]
|
||||||
|
access_key = ATQTIWUT9K66VRMMXKVY
|
||||||
|
secret_key = Wa0aixDVuhZOfDZGWvgIJQBHnyiDlGdgDn1Ai5Yy
|
||||||
|
|
||||||
|
#腾讯
|
||||||
|
[tencent]
|
||||||
|
access_key = AKIDRefQxnhmuqTU1KRWFl58wQeCE0XoAeEZ
|
||||||
|
secret_key = LUMVRmGj2kFrEahhZzA5pKvHNSMASntj
|
|
@ -0,0 +1,43 @@
|
||||||
|
package aksk
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"github.com/Unknwon/goconfig"
|
||||||
|
"os"
|
||||||
|
)
|
||||||
|
|
||||||
|
type AkskContainerConfig struct {
|
||||||
|
AccessKey string
|
||||||
|
SecretKey string
|
||||||
|
}
|
||||||
|
|
||||||
|
func AkskConfig(cloudStack string, akskPath string) (AkskContainerConfig, error) {
|
||||||
|
var cfg *goconfig.ConfigFile
|
||||||
|
config, err := goconfig.LoadConfigFile(akskPath)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println("get config file error:", err.Error())
|
||||||
|
os.Exit(-1)
|
||||||
|
}
|
||||||
|
cfg = config
|
||||||
|
var accessKey string
|
||||||
|
var secretKey string
|
||||||
|
switch cloudStack {
|
||||||
|
|
||||||
|
case "alibaba":
|
||||||
|
accessKey, _ = cfg.GetValue(cloudStack, "access_key")
|
||||||
|
secretKey, _ = cfg.GetValue(cloudStack, "secret_key")
|
||||||
|
|
||||||
|
case "huawei":
|
||||||
|
accessKey, _ = cfg.GetValue(cloudStack, "access_key")
|
||||||
|
secretKey, _ = cfg.GetValue(cloudStack, "secret_key")
|
||||||
|
case "tencent":
|
||||||
|
accessKey, _ = cfg.GetValue(cloudStack, "access_key")
|
||||||
|
secretKey, _ = cfg.GetValue(cloudStack, "secret_key")
|
||||||
|
}
|
||||||
|
|
||||||
|
var akskConfig = AkskContainerConfig{
|
||||||
|
AccessKey: accessKey,
|
||||||
|
SecretKey: secretKey,
|
||||||
|
}
|
||||||
|
return akskConfig, nil
|
||||||
|
}
|
|
@ -8,8 +8,6 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
type PCMContainerConfig struct {
|
type PCMContainerConfig struct {
|
||||||
AccessKey string
|
|
||||||
SecretKey string
|
|
||||||
RegionId string
|
RegionId string
|
||||||
ContainerGroupName string
|
ContainerGroupName string
|
||||||
ContainerImage string
|
ContainerImage string
|
||||||
|
@ -44,17 +42,14 @@ type PCMContainerConfig struct {
|
||||||
|
|
||||||
func PCMconfig(configPath string) (PCMContainerConfig, error) {
|
func PCMconfig(configPath string) (PCMContainerConfig, error) {
|
||||||
|
|
||||||
|
//加载配置文件
|
||||||
var cfg *goconfig.ConfigFile
|
var cfg *goconfig.ConfigFile
|
||||||
//"/home/Senna/GolandProjects/PCM/adaptor/container_api_adaptor/alibaba/eci/config_eci.conf"
|
config, err := goconfig.LoadConfigFile(configPath)
|
||||||
config, err := goconfig.LoadConfigFile(configPath) //加载配置文件
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("get config file error:", err.Error())
|
fmt.Println("get config file error:", err.Error())
|
||||||
os.Exit(-1)
|
os.Exit(-1)
|
||||||
}
|
}
|
||||||
cfg = config
|
cfg = config
|
||||||
//AKSK
|
|
||||||
accessKey, _ := cfg.GetValue("pod_create_conf", "access_key")
|
|
||||||
secretKey, _ := cfg.GetValue("pod_create_conf", "secret_key")
|
|
||||||
|
|
||||||
//[创建]通用创建必需信息
|
//[创建]通用创建必需信息
|
||||||
regionId, _ := cfg.GetValue("pod_create_conf", "region_id")
|
regionId, _ := cfg.GetValue("pod_create_conf", "region_id")
|
||||||
|
@ -102,8 +97,6 @@ func PCMconfig(configPath string) (PCMContainerConfig, error) {
|
||||||
ContainerGroupNameUpdate, _ := cfg.GetValue("pod_update_conf", "container_group_name")
|
ContainerGroupNameUpdate, _ := cfg.GetValue("pod_update_conf", "container_group_name")
|
||||||
|
|
||||||
var configCommon = PCMContainerConfig{
|
var configCommon = PCMContainerConfig{
|
||||||
AccessKey: accessKey,
|
|
||||||
SecretKey: secretKey,
|
|
||||||
RegionId: regionId,
|
RegionId: regionId,
|
||||||
ContainerGroupName: containerGroupName,
|
ContainerGroupName: containerGroupName,
|
||||||
ContainerImage: containerImage,
|
ContainerImage: containerImage,
|
||||||
|
|
|
@ -6,23 +6,26 @@ func main() {
|
||||||
|
|
||||||
aliConfigPath := "/home/Senna/GolandProjects/PCM/adaptor/container_api_adaptor/alibaba/eci/config_eci.conf"
|
aliConfigPath := "/home/Senna/GolandProjects/PCM/adaptor/container_api_adaptor/alibaba/eci/config_eci.conf"
|
||||||
huaweiConfigPath := "/home/Senna/GolandProjects/PCM/adaptor/container_api_adaptor/huawei/cci/config_cci.conf"
|
huaweiConfigPath := "/home/Senna/GolandProjects/PCM/adaptor/container_api_adaptor/huawei/cci/config_cci.conf"
|
||||||
tencentConfigPath := "/home/Senna/GolandProjects/PCM/adaptor/container_api_adaptor/tencent/eks/config_eks.conf" //api.CreatePod("alibaba")
|
tencentConfigPath := "/home/Senna/GolandProjects/PCM/adaptor/container_api_adaptor/tencent/eks/config_eks.conf"
|
||||||
|
akskPath := "/home/Senna/GolandProjects/PCM/adaptor/auth/aksk/aksk.conf"
|
||||||
println(aliConfigPath)
|
println(aliConfigPath)
|
||||||
println(huaweiConfigPath)
|
println(huaweiConfigPath)
|
||||||
println(tencentConfigPath)
|
println(tencentConfigPath)
|
||||||
|
println(akskPath)
|
||||||
|
|
||||||
//api.ListPod("alibaba", aliConfigPath)
|
//api.CreatePod("alibaba", akskPath, aliConfigPath)
|
||||||
//api.UpdatePod("alibaba")
|
//api.ListPod("alibaba", akskPath, aliConfigPath)
|
||||||
//api.DeletePod("alibaba")
|
//api.UpdatePod("alibaba", akskPath, aliConfigPath)
|
||||||
|
//api.DeletePod("alibaba", akskPath, aliConfigPath)
|
||||||
|
|
||||||
//api.CreatePod("huawei")
|
//api.CreatePod("huawei", akskPath, huaweiConfigPath)
|
||||||
//api.ListPod("huawei")
|
//api.ListPod("huawei", akskPath, huaweiConfigPath)
|
||||||
//api.UpdatePod("huawei", huaweiConfigPath)
|
//api.UpdatePod("huawei", akskPath, huaweiConfigPath)
|
||||||
//api.DeletePod("huawei", huaweiConfigPath)
|
//api.DeletePod("huawei", akskPath, huaweiConfigPath)
|
||||||
|
|
||||||
api.CreatePod("tencent", tencentConfigPath)
|
//api.CreatePod("tencent", akskPath, tencentConfigPath)
|
||||||
//api.ListPod("tencent", tencentConfigPath)
|
//api.ListPod("tencent", akskPath, tencentConfigPath)
|
||||||
//api.UpdatePod("tencent")
|
//api.UpdatePod("tencent", akskPath, tencentConfigPath)
|
||||||
//api.DeletePod("tencent")
|
api.DeletePod("tencent", akskPath, tencentConfigPath)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,74 +1,24 @@
|
||||||
[pod_create_conf]
|
[pod_create_conf]
|
||||||
#测试账号ak
|
region_id=cn-north-4 #region 对应华为 Region (华为创建Namespace必需)
|
||||||
access_key =
|
namespace=test-k8s-client-namespace1 #namespace 华为CCI基于K8S namespace进行管理,需要单独提供namespace 对应Pod.ObjectMeta.Namespace (华为必需)
|
||||||
secret_key =
|
container_group_name=pcm-test-huawei-pod #容器实例名称(pod名) 对应华为 Pod.ObjectMeta.Name (华为必需)
|
||||||
#region 对应华为 Region (华为创建Namespace必需)
|
container_image=library/nginx:stable-alpine-perl #镜像地址 对应华为 Pod.PodSpec.Containers.Container.Image (华为必需)
|
||||||
region_id=cn-north-4
|
container_name=pcm-test-huawei-container #容器名称 对应华为 Pod.PodSpec.Containers.Container.Name (华为必需)
|
||||||
#namespace 华为CCI基于K8S namespace进行管理,需要单独提供namespace 对应Pod.ObjectMeta.Namespace (华为必需)
|
cpu_pod=500m #Pod拥有核数 对应华为 Pod.PodSpec.Containers.Container.Resources.Limits.ResourceCPU (华为必需)
|
||||||
namespace=test-k8s-client-namespace1
|
memory_pod=1024Mi #Pod拥有内存大小 对应华为 Pod.PodSpec.Containers.Container.Resources.Limits.ResourceMemory (华为必需)
|
||||||
#容器实例名称(pod名) 对应华为 Pod.ObjectMeta.Name (华为必需)
|
|
||||||
container_group_name=pcm-test-huawei-pod
|
|
||||||
#镜像地址 对应华为 Pod.PodSpec.Containers.Container.Image (华为必需)
|
|
||||||
container_image=library/nginx:stable-alpine-perl
|
|
||||||
#容器名称 对应华为 Pod.PodSpec.Containers.Container.Name (华为必需)
|
|
||||||
container_name=pcm-test-huawei-container
|
|
||||||
#Pod拥有核数 对应华为 Pod.PodSpec.Containers.Container.Resources.Limits.ResourceCPU (华为必需)
|
|
||||||
cpu_pod=500m
|
|
||||||
#Pod拥有内存大小 对应华为 Pod.PodSpec.Containers.Container.Resources.Limits.ResourceMemory (华为必需)
|
|
||||||
memory_pod=1024Mi
|
|
||||||
|
|
||||||
|
|
||||||
[pod_delete_conf]
|
[pod_delete_conf]
|
||||||
# 必需参数
|
namespace=test-k8s-client-namespace1 # 地域id
|
||||||
# 地域id
|
container_group_name=pcm-test-huawei-pod #容器实例名称(pod名) 对应华为 Pod.ObjectMeta.Name (华为必需)
|
||||||
namespace=test-k8s-client-namespace1
|
|
||||||
#容器实例名称(pod名) 对应华为 Pod.ObjectMeta.Name (华为必需)
|
|
||||||
container_group_name=pcm-test-huawei-pod
|
|
||||||
|
|
||||||
[pod_list_conf]
|
[pod_list_conf]
|
||||||
# 必需参数
|
region_id=cn-hangzhou # 地域id
|
||||||
# 地域id
|
|
||||||
region_id=cn-hangzhou
|
|
||||||
|
|
||||||
|
|
||||||
[pod_update_conf]
|
[pod_update_conf]
|
||||||
# 必需参数
|
container_group_name=pcm-test-huawei-pod #容器实例名称(pod名) 对应华为 Pod.ObjectMeta.Name (华为必需)
|
||||||
#容器实例名称(pod名) 对应华为 Pod.ObjectMeta.Name (华为必需)
|
container_image=library/nginx:stable-alpine-perl #镜像地址 对应华为 Pod.PodSpec.Containers.Container.Image (华为必需)
|
||||||
container_group_name=pcm-test-huawei-pod
|
container_name=pcm-test-huawei-container-new #容器名称 对应华为 Pod.PodSpec.Containers.Container.Name (华为必需)
|
||||||
#镜像地址 对应华为 Pod.PodSpec.Containers.Container.Image (华为必需)
|
cpu_pod=500m #Pod拥有核数 对应华为 Pod.PodSpec.Containers.Container.Resources.Limits.ResourceCPU (华为必需)
|
||||||
container_image=library/nginx:stable-alpine-perl
|
memory_pod=2048Mi #Pod拥有内存大小 对应华为 Pod.PodSpec.Containers.Container.Resources.Limits.ResourceMemory (华为必需)
|
||||||
#容器名称 对应华为 Pod.PodSpec.Containers.Container.Name (华为必需)
|
|
||||||
container_name=pcm-test-huawei-container-new
|
|
||||||
#Pod拥有核数 对应华为 Pod.PodSpec.Containers.Container.Resources.Limits.ResourceCPU (华为必需)
|
|
||||||
cpu_pod=500m
|
|
||||||
#Pod拥有内存大小 对应华为 Pod.PodSpec.Containers.Container.Resources.Limits.ResourceMemory (华为必需)
|
|
||||||
memory_pod=2048Mi
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# 地域id
|
|
||||||
namespace=test-k8s-client-namespace1
|
namespace=test-k8s-client-namespace1
|
||||||
#可选 这里做更新测试
|
|
||||||
#重启策略
|
|
||||||
restart_policy=Always
|
restart_policy=Always
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# ##下面为非必需参数
|
|
||||||
# #安全组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
|
|
||||||
# #容器所需核数
|
|
||||||
# cpu_container=500m
|
|
||||||
# #容器所需内存大小
|
|
||||||
# memory_container=1024Mi
|
|
||||||
# #镜像拉取策略
|
|
||||||
# image_pull_policy=IfNotPresent
|
|
|
@ -1,72 +0,0 @@
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"PCM/adaptor/container_api_adaptor/huawei/demos/pod"
|
|
||||||
"PCM/adaptor/container_api_adaptor/huawei/pkg/auth/aksk"
|
|
||||||
"fmt"
|
|
||||||
)
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
// 有多种认证方式,具体请参考
|
|
||||||
//《使用cci-iam-authenticator进行认证并创建client》,https://support.huaweicloud.com/sdkreference-cci/cci_09_0004.html
|
|
||||||
cs, err := aksk.NewClient("")
|
|
||||||
//networkCs, err := aksk.NewNetworkClient()
|
|
||||||
if err != nil {
|
|
||||||
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 network created")
|
|
||||||
//_, err = network.CreateNetwork(networkCs)
|
|
||||||
//if err != nil {
|
|
||||||
// panic(err)
|
|
||||||
//}
|
|
||||||
|
|
||||||
//创建deployment
|
|
||||||
//fmt.Println("start to create deployment")
|
|
||||||
//_, err = deployment.CreateDeployment(cs)
|
|
||||||
//if err != nil {
|
|
||||||
// panic(err)
|
|
||||||
//}
|
|
||||||
//fmt.Println("deployment created")
|
|
||||||
|
|
||||||
//创建pod
|
|
||||||
fmt.Println("start to create pod")
|
|
||||||
_, err = pod.CreatePod(cs, "")
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
fmt.Println("pod created")
|
|
||||||
|
|
||||||
//删除deployment
|
|
||||||
//fmt.Println("start to delete deployment")
|
|
||||||
//err = deployment.DeleteDeployment(cs)
|
|
||||||
//if err != nil {
|
|
||||||
// panic(err)
|
|
||||||
//}
|
|
||||||
//fmt.Println("deployment deleted")
|
|
||||||
|
|
||||||
//删除pod
|
|
||||||
//fmt.Println("start to delete pod")
|
|
||||||
//err = pod.DeletePod(cs)
|
|
||||||
//if err != nil {
|
|
||||||
// panic(err)
|
|
||||||
//}
|
|
||||||
//fmt.Println("pod deleted")
|
|
||||||
|
|
||||||
//删除命名空间
|
|
||||||
//fmt.Println("start to delete namespace")
|
|
||||||
//err = namespace.DeleteNamespace(cs)
|
|
||||||
//if err != nil {
|
|
||||||
// panic(err)
|
|
||||||
//}
|
|
||||||
//fmt.Println("namespace terminating")
|
|
||||||
}
|
|
|
@ -1,23 +0,0 @@
|
||||||
//go:build tools
|
|
||||||
// +build tools
|
|
||||||
|
|
||||||
/*
|
|
||||||
Copyright 2019 The Kubernetes Authors.
|
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
you may not use this file except in compliance with the License.
|
|
||||||
You may obtain a copy of the License at
|
|
||||||
|
|
||||||
http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
|
|
||||||
Unless required by applicable law or agreed to in writing, software
|
|
||||||
distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
See the License for the specific language governing permissions and
|
|
||||||
limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
// This package imports things required by build scripts, to force `go mod` to see them as dependencies
|
|
||||||
package hack
|
|
||||||
|
|
||||||
import _ "k8s.io/code-generator"
|
|
|
@ -1,38 +0,0 @@
|
||||||
#!/usr/bin/env bash
|
|
||||||
|
|
||||||
# Copyright 2017 The Kubernetes Authors.
|
|
||||||
#
|
|
||||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
# you may not use this file except in compliance with the License.
|
|
||||||
# You may obtain a copy of the License at
|
|
||||||
#
|
|
||||||
# http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
#
|
|
||||||
# Unless required by applicable law or agreed to in writing, software
|
|
||||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
# See the License for the specific language governing permissions and
|
|
||||||
# limitations under the License.
|
|
||||||
|
|
||||||
set -o errexit
|
|
||||||
set -o nounset
|
|
||||||
set -o pipefail
|
|
||||||
|
|
||||||
SCRIPT_ROOT=$(dirname "${BASH_SOURCE[0]}")/..
|
|
||||||
CODEGEN_PKG=${CODEGEN_PKG:-$(cd "${SCRIPT_ROOT}"; ls -d -1 ./vendor/k8s.io/code-generator 2>/dev/null || echo ../code-generator)}
|
|
||||||
|
|
||||||
# generate the code with:
|
|
||||||
# --output-base because this script should also be able to run inside the vendor dir of
|
|
||||||
# k8s.io/kubernetes. The output-base is needed for the generators to output into the vendor dir
|
|
||||||
# instead of the $GOPATH directly. For normal projects this can be dropped.
|
|
||||||
# generators deepcopy,client,informer,lister
|
|
||||||
export CLIENTSET_PKG_NAME=networking.cci.io
|
|
||||||
export CLIENTSET_NAME_VERSIONED=v1beta1
|
|
||||||
"${CODEGEN_PKG}"/generate-groups.sh "deepcopy,client" \
|
|
||||||
PCM/adaptor/container_api_adaptor/huawei/pkg/client PCM/adaptor/container_api_adaptor/huawei/pkg/apis \
|
|
||||||
networking.cci.io:v1beta1 \
|
|
||||||
--output-base "$(dirname "${BASH_SOURCE[0]}")/../../.." \
|
|
||||||
--go-header-file "${SCRIPT_ROOT}"/hack/boilerplate.go.txt
|
|
||||||
|
|
||||||
# To use your own boilerplate text append:
|
|
||||||
# --go-header-file "${SCRIPT_ROOT}"/hack/custom-boilerplate.go.txt
|
|
|
@ -1,6 +1,7 @@
|
||||||
package aksk
|
package aksk
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"PCM/adaptor/container_api_adaptor/common/auth/aksk"
|
||||||
"PCM/adaptor/container_api_adaptor/common/config"
|
"PCM/adaptor/container_api_adaptor/common/config"
|
||||||
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"
|
||||||
|
@ -33,13 +34,13 @@ const (
|
||||||
)
|
)
|
||||||
|
|
||||||
// NewClient 通过AK/SK认证创建Clientset
|
// NewClient 通过AK/SK认证创建Clientset
|
||||||
func NewClient(configPath string) (*kubernetes.Clientset, error) {
|
func NewClient(cloudStack string, akskPath string, configPath string) (*kubernetes.Clientset, error) {
|
||||||
|
|
||||||
var configCommon config.PCMContainerConfig
|
configAksk, _ := aksk.AkskConfig(cloudStack, akskPath)
|
||||||
configCommon, _ = config.PCMconfig(configPath)
|
configCommon, _ := config.PCMconfig(configPath)
|
||||||
|
|
||||||
ak := configCommon.AccessKey
|
ak := configAksk.AccessKey
|
||||||
sk := configCommon.SecretKey
|
sk := configAksk.SecretKey
|
||||||
regionId := configCommon.RegionId
|
regionId := configCommon.RegionId
|
||||||
cciEndpoint := "https://cci." + regionId + ".myhuaweicloud.com"
|
cciEndpoint := "https://cci." + regionId + ".myhuaweicloud.com"
|
||||||
|
|
||||||
|
@ -61,13 +62,13 @@ func NewClient(configPath string) (*kubernetes.Clientset, error) {
|
||||||
return kubernetes.NewForConfig(cciConfig)
|
return kubernetes.NewForConfig(cciConfig)
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewNetworkClient(configPath string) (*clientset.Clientset, error) {
|
func NewNetworkClient(cloudStack string, akskPath string, configPath string) (*clientset.Clientset, error) {
|
||||||
|
|
||||||
var configCommon config.PCMContainerConfig
|
configAksk, _ := aksk.AkskConfig(cloudStack, akskPath)
|
||||||
configCommon, _ = config.PCMconfig(configPath)
|
configCommon, _ := config.PCMconfig(configPath)
|
||||||
|
|
||||||
ak := configCommon.AccessKey
|
ak := configAksk.AccessKey
|
||||||
sk := configCommon.SecretKey
|
sk := configAksk.SecretKey
|
||||||
regionId := configCommon.RegionId
|
regionId := configCommon.RegionId
|
||||||
cciEndpoint := "https://cci." + regionId + ".myhuaweicloud.com"
|
cciEndpoint := "https://cci." + regionId + ".myhuaweicloud.com"
|
||||||
|
|
||||||
|
|
|
@ -99,12 +99,12 @@ func UpdatePod(client *kubernetes.Clientset, configPath string) (*corev1.Pod, er
|
||||||
Image: containerImage,
|
Image: containerImage,
|
||||||
Resources: corev1.ResourceRequirements{
|
Resources: corev1.ResourceRequirements{
|
||||||
Limits: map[corev1.ResourceName]resource.Quantity{
|
Limits: map[corev1.ResourceName]resource.Quantity{
|
||||||
corev1.ResourceCPU: resource.MustParse("500m"),
|
corev1.ResourceLimitsCPU: resource.MustParse("500m"),
|
||||||
corev1.ResourceMemory: resource.MustParse("1Gi"),
|
corev1.ResourceLimitsMemory: resource.MustParse("1Gi"),
|
||||||
},
|
},
|
||||||
Requests: map[corev1.ResourceName]resource.Quantity{
|
Requests: map[corev1.ResourceName]resource.Quantity{
|
||||||
corev1.ResourceCPU: resource.MustParse("500m"),
|
corev1.ResourceRequestsCPU: resource.MustParse("500m"),
|
||||||
corev1.ResourceMemory: resource.MustParse("1Gi"),
|
corev1.ResourceRequestsMemory: resource.MustParse("1Gi"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
|
@ -1,37 +1,21 @@
|
||||||
[pod_create_conf]
|
[pod_create_conf]
|
||||||
#测试账号ak
|
region_id=ap-beijing #区域ID
|
||||||
access_key =
|
container_group_name=pcm-test-tencent-pod #容器实例名称(pod名) 对应腾讯EksCiName(腾讯必需)
|
||||||
secret_key =
|
container_image=library/nginx:stable-alpine-perl #镜像地址 对应腾讯 Container.Image(腾讯必需)
|
||||||
#region
|
container_name=pcm-test-tencent-container #容器名称 对应腾讯 Container.Name(腾讯必需)
|
||||||
region_id=ap-beijing
|
cpu_pod=1 #Pod拥有核数 对应腾讯 Cpu(腾讯必需)
|
||||||
#容器实例名称(pod名) 对应腾讯EksCiName(腾讯必需)
|
memory_pod=2 #Pod拥有内存大小 对应腾讯 Memory(腾讯必需)
|
||||||
container_group_name=pcm-test-tencent-pod
|
security_group_id=sg-owzbdinl #安全组ID 对应腾讯 SecurityGroupIds(腾讯必需)
|
||||||
#镜像地址 对应腾讯 Container.Image(腾讯必需)
|
subnet_id=subnet-n4h73049 #子网ID 对应腾讯 SubnetId(腾讯必需)
|
||||||
container_image=library/nginx:stable-alpine-perl
|
vpc_id=vpc-e8hdbla8 #VPC ID 对应腾讯 VpcId(腾讯必需)
|
||||||
#容器名称 对应腾讯 Container.Name(腾讯必需)
|
|
||||||
container_name=pcm-test-tencent-container
|
|
||||||
#Pod拥有核数 对应腾讯 Cpu(腾讯必需)
|
|
||||||
cpu_pod=1
|
|
||||||
#Pod拥有内存大小 对应腾讯 Memory(腾讯必需)
|
|
||||||
memory_pod=2
|
|
||||||
#安全组ID 对应腾讯 SecurityGroupIds(腾讯必需)
|
|
||||||
security_group_id=sg-owzbdinl
|
|
||||||
#子网ID 对应腾讯 SubnetId(腾讯必需)
|
|
||||||
subnet_id=subnet-n4h73049
|
|
||||||
#VPC ID 对应腾讯 VpcId(腾讯必需)
|
|
||||||
vpc_id=vpc-e8hdbla8
|
|
||||||
|
|
||||||
|
[pod_list_conf]
|
||||||
|
region_id=ap-beijing #区域ID
|
||||||
|
|
||||||
# ##下面为非必需参数
|
[pod_update_conf]
|
||||||
# #交换机ID
|
region_id=ap-beijing #区域ID
|
||||||
# v_switch_id=vsw-bp176sh32kcq79d1uu8fp
|
container_group_id=eksci-pawu7qad #容器实例ID 对应腾讯EksCiName(腾讯必需)
|
||||||
# #可用区
|
container_group_name=eksci-pawu7qad #容器实例名称(pod名) 对应腾讯EksCiName(腾讯必需)
|
||||||
# zone_id=cn-hangzhou-h
|
|
||||||
# #重启策略
|
[pod_delete_conf]
|
||||||
# restart_policy=Never
|
container_group_id=eksci-pawu7qad
|
||||||
# #容器所需核数
|
|
||||||
# cpu_container=1
|
|
||||||
# #容器所需内存大小
|
|
||||||
# memory_container=2
|
|
||||||
# #镜像拉取策略
|
|
||||||
# image_pull_policy=IfNotPresent
|
|
||||||
|
|
|
@ -0,0 +1,138 @@
|
||||||
|
package eks
|
||||||
|
|
||||||
|
import (
|
||||||
|
"PCM/adaptor/container_api_adaptor/common/auth/aksk"
|
||||||
|
pcmCommon "PCM/adaptor/container_api_adaptor/common/config"
|
||||||
|
"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 CreateEksInstance(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.NewCreateEKSContainerInstancesRequest()
|
||||||
|
|
||||||
|
eksCiName := &configCommon.ContainerGroupName
|
||||||
|
containerName := &configCommon.ContainerName
|
||||||
|
containerImage := &configCommon.ContainerImage
|
||||||
|
eksCpu := &configCommon.CpuPodFloat
|
||||||
|
eksMemory := &configCommon.MemoryPodFloat
|
||||||
|
securityGroupId := &configCommon.SecurityGroupId
|
||||||
|
securityGroupIds := make([]*string, 1)
|
||||||
|
securityGroupIds[0] = securityGroupId
|
||||||
|
subNetId := &configCommon.SubnetId
|
||||||
|
vpcId := &configCommon.VpcId
|
||||||
|
|
||||||
|
request.EksCiName = eksCiName
|
||||||
|
container := make([]*tke.Container, 1)
|
||||||
|
container[0] = new(tke.Container)
|
||||||
|
container[0].Name = containerName
|
||||||
|
container[0].Image = containerImage
|
||||||
|
//container[0].Cpu = containerCpuPt
|
||||||
|
//container[0].Memory = containerMemoryPt
|
||||||
|
|
||||||
|
request.Containers = container
|
||||||
|
request.Cpu = eksCpu
|
||||||
|
request.Memory = eksMemory
|
||||||
|
request.SecurityGroupIds = securityGroupIds
|
||||||
|
request.SubnetId = subNetId
|
||||||
|
request.VpcId = vpcId
|
||||||
|
|
||||||
|
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())
|
||||||
|
}
|
||||||
|
|
||||||
|
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())
|
||||||
|
}
|
|
@ -1,77 +0,0 @@
|
||||||
package eks
|
|
||||||
|
|
||||||
import (
|
|
||||||
pcmCommon "PCM/adaptor/container_api_adaptor/common/config"
|
|
||||||
"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 CreateTkeInstance(configPath string) {
|
|
||||||
|
|
||||||
var configCommon pcmCommon.PCMContainerConfig
|
|
||||||
configCommon, _ = pcmCommon.PCMconfig(configPath)
|
|
||||||
|
|
||||||
credential := common.NewCredential(
|
|
||||||
configCommon.AccessKey,
|
|
||||||
configCommon.SecretKey,
|
|
||||||
)
|
|
||||||
cpf := profile.NewClientProfile()
|
|
||||||
cpf.HttpProfile.Endpoint = "eks.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
|
|
||||||
|
|
||||||
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())
|
|
||||||
}
|
|
|
@ -1,9 +0,0 @@
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"PCM/adaptor/container_api_adaptor/tencent/eks"
|
|
||||||
)
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
eks.CreateTkeInstance("")
|
|
||||||
}
|
|
Loading…
Reference in New Issue