| @@ -1,63 +0,0 @@ | |||
| // This file is auto-generated, don't edit it. Thanks. | |||
| package main | |||
| import ( | |||
| "fmt" | |||
| openapi "github.com/alibabacloud-go/darabonba-openapi/client" | |||
| eci20180808 "github.com/alibabacloud-go/eci-20180808/client" | |||
| "github.com/alibabacloud-go/tea/tea" | |||
| "os" | |||
| ) | |||
| /** | |||
| * 使用AK&SK初始化账号Client | |||
| * @param accessKeyId | |||
| * @param accessKeySecret | |||
| * @return Client | |||
| * @throws Exception | |||
| */ | |||
| func CreateClient(accessKeyId *string, accessKeySecret *string) (_result *eci20180808.Client, _err error) { | |||
| config := &openapi.Config{ | |||
| AccessKeyId: accessKeyId, | |||
| AccessKeySecret: accessKeySecret, | |||
| } | |||
| // 访问的域名 | |||
| config.Endpoint = tea.String("eci.aliyuncs.com") | |||
| _result = &eci20180808.Client{} | |||
| _result, _err = eci20180808.NewClient(config) | |||
| return _result, _err | |||
| } | |||
| func _main(args []*string) (_err error) { | |||
| client, _err := CreateClient(tea.String("LTAI4GKsRHtEqUu8bzq5dt6N"), tea.String("j96G9E2ijwpiN987VC03HmcFsaJngt")) | |||
| if _err != nil { | |||
| return _err | |||
| } | |||
| describeContainerGroupsRequest := &eci20180808.DescribeContainerGroupsRequest{ | |||
| OwnerAccount: tea.String("test"), | |||
| RegionId: tea.String("cn-hangzhou"), | |||
| } | |||
| //deleteContainerGroupRequest := &eci20180808.DeleteContainerGroupRequest{ | |||
| // ResourceOwnerAccount: tea.String("test"), | |||
| // ResourceOwnerId: tea.Int64(1), | |||
| // OwnerAccount: tea.String("test"), | |||
| // RegionId: tea.String("test"), | |||
| //} | |||
| // 复制代码运行请自行打印 API 的返回值 | |||
| _, _err = client.DescribeContainerGroups(describeContainerGroupsRequest) | |||
| //describeContainerGroupsResponse := client.DescribeContainerGroups(describeContainerGroupsRequest) | |||
| fmt.Println(_err) | |||
| if _err != nil { | |||
| return _err | |||
| } | |||
| return _err | |||
| } | |||
| func main() { | |||
| err := _main(tea.StringSlice(os.Args[1:])) | |||
| if err != nil { | |||
| panic(err) | |||
| } | |||
| } | |||
| @@ -1,42 +0,0 @@ | |||
| package huawei | |||
| import ( | |||
| "fmt" | |||
| "k8s.io/client-go/kubernetes" | |||
| "k8s.io/client-go/tools/clientcmd" | |||
| "k8s.io/client-go/tools/clientcmd/api" | |||
| ) | |||
| const ( | |||
| apiVersion = "client.authentication.k8s.io/v1beta1" | |||
| // 云容器实例 CCI,参考https://developer.huaweicloud.com/endpoint | |||
| cciEndpoint = "<例如华北-北京四: https://cci.cn-north-4.myhuaweicloud.com>" | |||
| // 统一身份认证服务 IAM,参考https://developer.huaweicloud.com/endpoint | |||
| iamEndpoint = "<例如华北-北京四: https://iam.cn-north-4.myhuaweicloud.com>" | |||
| // 地区和终端节点,参考https://developer.huaweicloud.com/endpoint | |||
| projectName = "<例如华北-北京四: 'cn-north-4'>" | |||
| // 获取AK/SK参考: https://support.huaweicloud.com/devg-cci/cci_kubectl_01.html#cci_kubectl_01__section17023744719 | |||
| ak = "NVZH8MA2QCWFC3KPLHWJ" | |||
| sk = "CACGSvC4BPq0aQkgFkLfsbc7RUzBw0dD92wXZWuL" | |||
| ) | |||
| // NewClient 通过AK/SK认证创建Clientset | |||
| func NewClient() (*kubernetes.Clientset, error) { | |||
| config, err := clientcmd.BuildConfigFromFlags(cciEndpoint, "") | |||
| if err != nil { | |||
| return nil, err | |||
| } | |||
| 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("--token-only=false")) | |||
| optionArgs = append(optionArgs, fmt.Sprintf("--ak=%s", ak)) | |||
| optionArgs = append(optionArgs, fmt.Sprintf("--sk=%s", sk)) | |||
| config.ExecProvider = &api.ExecConfig{ | |||
| Command: "cci-iam-authenticator", | |||
| APIVersion: apiVersion, | |||
| Args: append([]string{"token"}, optionArgs...), | |||
| Env: make([]api.ExecEnvVar, 0), | |||
| } | |||
| return kubernetes.NewForConfig(config) | |||
| } | |||
| @@ -1,33 +0,0 @@ | |||
| package huawei | |||
| import ( | |||
| "fmt" | |||
| "github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic" | |||
| cce "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/cce/v3" | |||
| "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/cce/v3/model" | |||
| region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/cce/v3/region" | |||
| ) | |||
| func main() { | |||
| ak := "NVZH8MA2QCWFC3KPLHWJ" | |||
| sk := "CACGSvC4BPq0aQkgFkLfsbc7RUzBw0dD92wXZWuL" | |||
| auth := basic.NewCredentialsBuilder(). | |||
| WithAk(ak). | |||
| WithSk(sk). | |||
| Build() | |||
| client := cce.NewCceClient( | |||
| cce.CceClientBuilder(). | |||
| WithRegion(region.ValueOf("cn-north-4")). | |||
| WithCredential(auth). | |||
| Build()) | |||
| request := &model.ListClustersRequest{} | |||
| response, err := client.ListClusters(request) | |||
| if err == nil { | |||
| fmt.Printf("%+v\n", response) | |||
| } else { | |||
| fmt.Println(err) | |||
| } | |||
| } | |||
| @@ -1,66 +0,0 @@ | |||
| package huawei | |||
| import ( | |||
| "fmt" | |||
| ) | |||
| func main() { | |||
| // 有多种认证方式,具体请参考 | |||
| //《使用cci-iam-authenticator进行认证并创建client》,https://support.huaweicloud.com/sdkreference-cci/cci_09_0004.html | |||
| cs, err := NewClient() | |||
| if err != nil { | |||
| panic(err) | |||
| } | |||
| fmt.Println("start to create namespace") | |||
| _, err = namespace.CreateNamespace(cs) | |||
| if err != nil { | |||
| panic(err) | |||
| } | |||
| fmt.Println("namespace created") | |||
| fmt.Println("waiting for namespace to be active") | |||
| err = namespace.WaitNamespaceActive(cs) | |||
| if err != nil { | |||
| panic(err) | |||
| } | |||
| fmt.Println("namespace is active") | |||
| // Network为CRD对象,创建Network对象请参考 | |||
| //《使用client-go访问CCI的CRD资源Network》,https://support.huaweicloud.com/sdkreference-cci/cci_09_0004.html | |||
| //《Namespace和Network》,https://support.huaweicloud.com/devg-cci/cci_05_0023.html#section3 | |||
| fmt.Println("start to create network") | |||
| _, err = network.CreateNetwork() | |||
| if err != nil { | |||
| panic(err) | |||
| } | |||
| fmt.Println("network created") | |||
| fmt.Println("start to create deployment") | |||
| _, err = deployment.CreateDeployment(cs) | |||
| if err != nil { | |||
| panic(err) | |||
| } | |||
| fmt.Println("deployment created") | |||
| fmt.Println("start to get deployment details") | |||
| _, err = deployment.GetDeployment(cs) | |||
| if err != nil { | |||
| panic(err) | |||
| } | |||
| fmt.Println("deployment details got") | |||
| fmt.Println("start to delete deployment") | |||
| err = deployment.DeleteDeployment(cs) | |||
| if err != nil { | |||
| panic(err) | |||
| } | |||
| fmt.Println("deployment deleted") | |||
| fmt.Println("start to delete namespace") | |||
| err = namespace.DeleteNamespace(cs) | |||
| if err != nil { | |||
| panic(err) | |||
| } | |||
| fmt.Println("namespace terminating") | |||
| } | |||
| @@ -1,54 +0,0 @@ | |||
| package huawei | |||
| import ( | |||
| "time" | |||
| corev1 "k8s.io/api/core/v1" | |||
| metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | |||
| "k8s.io/apimachinery/pkg/util/wait" | |||
| "k8s.io/client-go/kubernetes" | |||
| ) | |||
| const ( | |||
| namespace = "test-k8s-client-namespace" | |||
| ) | |||
| // CreateNamespace 创建命名空间 | |||
| // API参考:https://support.huaweicloud.com/api-cci/createCoreV1Namespace.html | |||
| func CreateNamespace(cs *kubernetes.Clientset) (*corev1.Namespace, error) { | |||
| namespace := &corev1.Namespace{ | |||
| TypeMeta: metav1.TypeMeta{}, | |||
| ObjectMeta: metav1.ObjectMeta{ | |||
| Name: namespace, | |||
| Annotations: map[string]string{ | |||
| "namespace.kubernetes.io/flavor": "general-computing", | |||
| "network.cci.io/warm-pool-size": "10", | |||
| }, | |||
| Labels: map[string]string{ | |||
| "rbac.authorization.cci.io/enable-k8s-rbac": "false", | |||
| }, | |||
| }, | |||
| } | |||
| return cs.CoreV1().Namespaces().Create(namespace) | |||
| } | |||
| // DeleteNamespace 删除Namespace | |||
| // API参考:https://support.huaweicloud.com/api-cci/deleteCoreV1Namespace.html | |||
| func DeleteNamespace(cs *kubernetes.Clientset) error { | |||
| return cs.CoreV1().Namespaces().Delete(namespace, &metav1.DeleteOptions{}) | |||
| } | |||
| // WaitNamespaceActive 查询Namespace状态,等待其状态变为"Active" | |||
| // API参考:https://support.huaweicloud.com/api-cci/readCoreV1Namespace.html | |||
| func WaitNamespaceActive(cs *kubernetes.Clientset) error { | |||
| return wait.Poll(time.Second*5, time.Second*30, func() (done bool, err error) { | |||
| ns, err := cs.CoreV1().Namespaces().Get(namespace, metav1.GetOptions{}) | |||
| if err != nil { | |||
| return false, err | |||
| } | |||
| if ns.Status.Phase == corev1.NamespaceActive { | |||
| return true, nil | |||
| } | |||
| return false, nil | |||
| }) | |||
| } | |||
| @@ -1,33 +0,0 @@ | |||
| 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) | |||
| 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()) | |||
| } | |||