Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added cce verion and move sdk to go mod #4714

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ import (
"context"
"fmt"

huaweicloudsdkasmodel "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/as/v1/model"
apiv1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/sets"
"k8s.io/autoscaler/cluster-autoscaler/cloudprovider"
huaweicloudsdkasmodel "k8s.io/autoscaler/cluster-autoscaler/cloudprovider/huaweicloud/huaweicloud-sdk-go-v3/services/as/v1/model"
"k8s.io/autoscaler/cluster-autoscaler/config"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/tools/clientcmd"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ import (
"io"
"os"

huaweicloudsdkbasic "github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic"
huaweicloudsdkconfig "github.com/huaweicloud/huaweicloud-sdk-go-v3/core/config"
huaweicloudsdkas "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/as/v1"
huaweicloudsdkecs "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/ecs/v2"
"gopkg.in/gcfg.v1"
huaweicloudsdkbasic "k8s.io/autoscaler/cluster-autoscaler/cloudprovider/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic"
huaweicloudsdkconfig "k8s.io/autoscaler/cluster-autoscaler/cloudprovider/huaweicloud/huaweicloud-sdk-go-v3/core/config"
huaweicloudsdkas "k8s.io/autoscaler/cluster-autoscaler/cloudprovider/huaweicloud/huaweicloud-sdk-go-v3/services/as/v1"
huaweicloudsdkecs "k8s.io/autoscaler/cluster-autoscaler/cloudprovider/huaweicloud/huaweicloud-sdk-go-v3/services/ecs/v2"
)

// CloudConfig is the cloud config file for huaweicloud.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ import (
"strings"
"time"

huaweicloudsdkas "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/as/v1"
huaweicloudsdkasmodel "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/as/v1/model"
huaweicloudsdkecs "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/ecs/v2"
huaweicloudsdkecsmodel "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/ecs/v2/model"
apiv1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/wait"
"k8s.io/autoscaler/cluster-autoscaler/cloudprovider"
huaweicloudsdkas "k8s.io/autoscaler/cluster-autoscaler/cloudprovider/huaweicloud/huaweicloud-sdk-go-v3/services/as/v1"
huaweicloudsdkasmodel "k8s.io/autoscaler/cluster-autoscaler/cloudprovider/huaweicloud/huaweicloud-sdk-go-v3/services/as/v1/model"
huaweicloudsdkecs "k8s.io/autoscaler/cluster-autoscaler/cloudprovider/huaweicloud/huaweicloud-sdk-go-v3/services/ecs/v2"
huaweicloudsdkecsmodel "k8s.io/autoscaler/cluster-autoscaler/cloudprovider/huaweicloud/huaweicloud-sdk-go-v3/services/ecs/v2/model"
"k8s.io/autoscaler/cluster-autoscaler/utils/gpu"
"k8s.io/klog/v2"
)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/*
Copyright 2020 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.
*/

package huaweicloud

import (
huaweicloudsdkbasic "github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic"
huaweicloudsdkconfig "github.com/huaweicloud/huaweicloud-sdk-go-v3/core/config"
huaweicloudsdkcce "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/cce/v3"
huaweicloudsdkecs "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/ecs/v2"
)

// CloudConfig is the cloud config file for huaweicloud.
type CloudConfig struct {
Global struct {
CCEEndpoint string `gcfg:"cce-endpoint"`
ECSEndpoint string `gcfg:"ecs-endpoint"`
ProjectID string `gcfg:"project-id"`
AccessKey string `gcfg:"access-key"`
SecretKey string `gcfg:"secret-key"`
Region string `gcfg:"region"` // example: "cn-north-4"
DomainID string `gcfg:"domain-id"` // The ACCOUNT ID. example: "a0e8ff63c0fb4fd49cc2dbdf1dea14e2"
}
}

func (c *CloudConfig) getCCEClient() *huaweicloudsdkcce.CceClient {
// There are two types of services provided by HUAWEI CLOUD according to scope:
// - Regional services: most of services belong to this classification, such as ECS.
// - Global services: such as IAM, TMS, EPS.
// For Regional services' authentication, projectId is required.
// For global services' authentication, domainId is required.
// More details please refer to:
// https://github.com/huaweicloud/huaweicloud-sdk-go-v3/blob/0281b9734f0f95ed5565729e54d96e9820262426/README.md#use-go-sdk
credentials := huaweicloudsdkbasic.NewCredentialsBuilder().
WithAk(c.Global.AccessKey).
WithSk(c.Global.SecretKey).
WithProjectId(c.Global.ProjectID).
Build()

client := huaweicloudsdkcce.CceClientBuilder().
WithEndpoint(c.Global.CCEEndpoint).
WithCredential(credentials).
WithHttpConfig(huaweicloudsdkconfig.DefaultHttpConfig()).
Build()

return huaweicloudsdkcce.NewCceClient(client)
}

func (c *CloudConfig) getECSClient() *huaweicloudsdkecs.EcsClient {
// There are two types of services provided by HUAWEI CLOUD according to scope:
// - Regional services: most of services belong to this classification, such as ECS.
// - Global services: such as IAM, TMS, EPS.
// For Regional services' authentication, projectId is required.
// For global services' authentication, domainId is required.
// More details please refer to:
// https://github.com/huaweicloud/huaweicloud-sdk-go-v3/blob/0281b9734f0f95ed5565729e54d96e9820262426/README.md#use-go-sdk
credentials := huaweicloudsdkbasic.NewCredentialsBuilder().
WithAk(c.Global.AccessKey).
WithSk(c.Global.SecretKey).
WithProjectId(c.Global.ProjectID).
Build()

client := huaweicloudsdkecs.EcsClientBuilder().
WithEndpoint(c.Global.ECSEndpoint).
WithCredential(credentials).
WithHttpConfig(huaweicloudsdkconfig.DefaultHttpConfig()).
Build()

return huaweicloudsdkecs.NewEcsClient(client)
}
Loading