Skip to content

Commit

Permalink
Add features in blb,Fix bug in mcp
Browse files Browse the repository at this point in the history
  • Loading branch information
liegu committed Jan 7, 2025
1 parent 45a1fc2 commit 35bc54d
Show file tree
Hide file tree
Showing 7 changed files with 197 additions and 8 deletions.
6 changes: 6 additions & 0 deletions Changelog
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
发行说明:记录每次SDK更新的说明,最新版本的SDK包含以前所有版本的更新内容。
---------------------------------------------------------------------

【版本:v0.9.212】
涉及产品:BLB
BLB 应用型BLB-IP组开放协议支持健康检查协议切换
涉及产品:MCP
MCP Insert text修改为指针类型

【版本:v0.9.211】
涉及产品:DDC
创建实例支持设置参数、备份列表及binlog备份列表新增返回值、新增多实例批量修改的参数的接口
Expand Down
2 changes: 1 addition & 1 deletion bce/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (

// Constants and default values for the package bce
const (
SDK_VERSION = "0.9.211"
SDK_VERSION = "0.9.212"
URI_PREFIX = "/" // now support uri without prefix "v1" so just set root path
DEFAULT_DOMAIN = "baidubce.com"
DEFAULT_PROTOCOL = "http"
Expand Down
2 changes: 2 additions & 0 deletions services/appblb/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -699,6 +699,7 @@ type CreateAppIpGroupBackendPolicyArgs struct {
IpGroupId string `json:"ipGroupId"`
Type string `json:"type"`
EnableHealthCheck *bool `json:"enableHealthCheck,omitempty"`
HealthCheck string `json:"healthCheck,omitempty"`
HealthCheckPort int `json:"healthCheckPort,omitempty"`
HealthCheckHost string `json:"healthCheckHost,omitempty"`
HealthCheckTimeoutInSecond int `json:"healthCheckTimeoutInSecond,omitempty"`
Expand All @@ -715,6 +716,7 @@ type UpdateAppIpGroupBackendPolicyArgs struct {
IpGroupId string `json:"ipGroupId"`
Id string `json:"id"`
EnableHealthCheck *bool `json:"enableHealthCheck,omitempty"`
HealthCheck string `json:"healthCheck,omitempty"`
HealthCheckPort int `json:"healthCheckPort,omitempty"`
HealthCheckHost string `json:"healthCheckHost,omitempty"`
HealthCheckUrlPath string `json:"healthCheckUrlPath,omitempty"`
Expand Down
166 changes: 162 additions & 4 deletions services/cce/v2/ccev2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"time"

bccapi "github.com/baidubce/bce-sdk-go/services/bcc/api"
"github.com/baidubce/bce-sdk-go/services/cce/v2/model"
"github.com/baidubce/bce-sdk-go/services/cce/v2/types"
"github.com/baidubce/bce-sdk-go/util/log"
)
Expand Down Expand Up @@ -67,7 +68,8 @@ func setup() {

// ExpectEqual is the helper function for test each case
func ExpectEqual(alert func(format string, args ...interface{}),
expected interface{}, actual interface{}) bool {
expected interface{}, actual interface{},
) bool {
expectedValue, actualValue := reflect.ValueOf(expected), reflect.ValueOf(actual)
equal := false
switch {
Expand Down Expand Up @@ -202,7 +204,7 @@ func TestClient_CreateCluster(t *testing.T) {
s, _ := json.MarshalIndent(resp, "", "\t")
fmt.Println("Response:" + string(s))

//等集群创建完成
// 等集群创建完成
time.Sleep(time.Duration(180) * time.Second)
}

Expand Down Expand Up @@ -427,7 +429,7 @@ func TestClient_UpdateInstanceGroupClusterAutoscalerSpec(t *testing.T) {
func TestClient_GetKubeConfig(t *testing.T) {
args := &GetKubeConfigArgs{
ClusterID: CCE_CLUSTER_ID,
KubeConfigType: KubeConfigTypeVPC,
KubeConfigType: model.KubeConfigTypeVPC,
}

resp, err := CCE_CLIENT.GetKubeConfig(args)
Expand Down Expand Up @@ -657,7 +659,6 @@ func TestClient_InstanceCRD(t *testing.T) {

func TestClient_UpdateClusterCRD(t *testing.T) {
getClusterCRDArgs := &GetClusterCRDArgs{

ClusterID: "cce-bvyohjkg",
}

Expand Down Expand Up @@ -686,3 +687,160 @@ func TestClient_UpdateClusterCRD(t *testing.T) {

fmt.Printf("Resuest ID: %s", commonResp.RequestID)
}

// TestClient_AttachInstancesToInstanceGroup 添加已有节点至节点组
func TestClient_AttachInstancesToInstanceGroup(t *testing.T) {
var (
ak = ""
sk = ""
endpoint = ""
clusterID = ""
instanceGroupID = ""
existInstanceID = ""
AdminPassword = ""
// rebuild 是否重装操作系统
rebuild = true
// useInstanceGroupConfig 是否使用节点组配置
useInstanceGroupConfig = true
// useLocalDiskForContainer 是否使用本地盘保存数据
useLocalDiskForContainer = false
imageID = ""
)

cceClient, err := NewClient(ak, sk, endpoint)
if err != nil {
fmt.Printf("NewClient error: %s", err.Error())
return
}

attachInstanceToInstanceGroupArgs := func() *AttachInstancesToInstanceGroupArgs {
args := AttachInstancesToInstanceGroupArgs{}
args.ClusterID = clusterID
args.InstanceGroupID = instanceGroupID
args.Request = &AttachInstancesToInstanceGroupRequest{
ExistedInstances: make([]*InstanceSet, 0),
UseInstanceGroupConfig: useInstanceGroupConfig,
}
existInstance := &InstanceSet{
InstanceSpec: types.InstanceSpec{
Existed: true,
ExistedOption: types.ExistedOption{
// bcc 实例 id
ExistedInstanceID: existInstanceID,
Rebuild: &rebuild,
},
// 看具体的类型,bcc,bbc,ebc
MachineType: types.MachineTypeBCC,
ClusterRole: types.ClusterRoleNode,

// 二选一
AdminPassword: AdminPassword,
SSHKeyID: "",
},
}

// 如果需要重装操作系统,需要配置这里
if rebuild {
existInstance.InstanceSpec.InstanceOS = types.InstanceOS{
ImageType: bccapi.ImageTypeSystem,
}
existInstance.InstanceSpec.ImageID = imageID
}

if useLocalDiskForContainer {
// 将容器数据存储在数据盘或本地盘中
existInstance.InstanceSpec.InstanceResource = types.InstanceResource{
CDSList: types.CDSConfigList{
{
DataDevice: "/dev/xxx",
Path: "/home/cce",
},
},
}
}
if !useInstanceGroupConfig {
existInstance.InstanceSpec.VPCConfig = types.VPCConfig{
SecurityGroups: []types.SecurityGroupV2{
{
ID: "",
Name: "",
Type: types.SecurityGroupTypeNormal,
},
},
}
existInstance.InstanceSpec.DeployCustomConfig = types.DeployCustomConfig{
KubeletRootDir: "",
PreUserScript: "",
PostUserScript: "",
}
// 标签配置
existInstance.InstanceSpec.Tags = types.TagList{
{
TagKey: "",
TagValue: "",
},
}
}
args.Request.ExistedInstances = append(args.Request.ExistedInstances, existInstance)
return &args
}()
commonResp, err := cceClient.AttachInstancesToInstanceGroup(attachInstanceToInstanceGroupArgs)
if err != nil {
fmt.Printf("attach instance to instance group failed, errir: %v", err)
return
}
fmt.Printf("Request ID: %s", commonResp.RequestID)
}

func TestClient_CreateScaleDownInstanceGroupTask(t *testing.T) {
type fields struct {
ak, sk, endpoint string
}
type args struct {
args *CreateScaleDownInstanceGroupTaskArgs
}
tests := []struct {
name string
fields fields
args args
}{
{
name: "移出已有节点",
fields: fields{
ak: "",
sk: "",
endpoint: "",
},
args: args{
args: &CreateScaleDownInstanceGroupTaskArgs{
InstancesToBeRemoved: []string{""},
ClusterID: "",
InstanceGroupID: "",
CleanPolicy: CleanPolicyDelete,
DeleteOption: &types.DeleteOption{
DeleteCDSSnapshot: false,
DeleteResource: false,
DrainNode: false,
MoveOut: true,
},
},
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
c, err := NewClient(tt.fields.ak, tt.fields.sk, tt.fields.endpoint)
if err != nil {
t.Errorf("failed init client, error = %v", err)
return
}
if resp, err := c.CreateScaleDownInstanceGroupTask(tt.args.args); err != nil {
t.Errorf("CreateScaleDownInstanceGroupTask() error = %v", err)

} else {
t.Logf("request id is: %s", resp.RequestID)
}

})
}
}
24 changes: 23 additions & 1 deletion services/cce/v2/types/instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import (

// InstanceSpec 已有节点需要用户提供:ClusterRole 、短ID,密码,镜像ID,镜像类型, docker storage(可选); BBC要额外加preservedData、raidId、sysRootSize
type InstanceSpec struct {

// 用于 CCE 唯一标识 Instance
CCEInstanceID string `json:"cceInstanceID,omitempty"`
InstanceName string `json:"instanceName"`
Expand Down Expand Up @@ -111,6 +110,8 @@ type VPCConfig struct {
SecurityGroup SecurityGroup `json:"securityGroup,omitempty"`

SecurityGroupType string `json:"securityGroupType"`

SecurityGroups []SecurityGroupV2 `json:"securityGroups"`
}

// SecurityGroup 定义 Instance 安全组配置
Expand All @@ -123,6 +124,23 @@ type SecurityGroup struct {
CustomSecurityGroupIDs []string `json:"customSecurityGroups,omitempty"`
}

type SecurityGroupV2 struct {
Name string `json:"name"`
Type SecurityGroupType `json:"type"`
ID string `json:"id"`
}

type SecurityGroupType string

const (
// 普通安全组
SecurityGroupTypeNormal SecurityGroupType = "normal"
// 企业安全组
SecurityGroupTypeEnterprise SecurityGroupType = "enterprise"
SecurityGroupTypeNormalIDPrefix string = "g-"
SecurityGroupTypeEnterpriseIDPrefix string = "esg-"
)

// InstanceResource 定义 Instance CPU/MEM/Disk 配置
type InstanceResource struct {
MachineSpec string `json:"machineSpec,omitempty"` // 机器规格,例:bcc.g5.c2m8
Expand Down Expand Up @@ -210,6 +228,7 @@ type DeleteOption struct {
MoveOut bool `json:"moveOut,omitempty"`
DeleteResource bool `json:"deleteResource,omitempty"`
DeleteCDSSnapshot bool `json:"deleteCDSSnapshot,omitempty"`
DrainNode bool `json:"drainNode,omitempty"`
}

// BBCOption BBC 相关配置
Expand Down Expand Up @@ -272,6 +291,7 @@ type DeployCustomConfig struct {
// KubeletBindAddressType, kubelet bind address
KubeletBindAddressType KubeletBindAddressType `json:"kubeletBindAddressType,omitempty"`

// PostUserScriptFailedAutoCordon 部署后执行脚本失败自动封锁节点
PostUserScriptFailedAutoCordon bool `json:"postUserScriptFailedAutoCordon,omitempty"`
}

Expand Down Expand Up @@ -320,6 +340,8 @@ type CDSConfig struct {
StorageType bccapi.StorageType `json:"storageType,omitempty"`
CDSSize int `json:"cdsSize,omitempty"`
SnapshotID string `json:"snapshotID,omitempty"`
DataDevice string `json:"dataDevice,omitempty"`
NeedFormat bool `json:"needFormat,omitempty"`
}

// MountConfig - 磁盘挂载信息
Expand Down
3 changes: 2 additions & 1 deletion services/cce/v2/url.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"fmt"

"github.com/baidubce/bce-sdk-go/bce"
"github.com/baidubce/bce-sdk-go/services/cce/v2/model"
"github.com/baidubce/bce-sdk-go/services/cce/v2/types"
)

Expand Down Expand Up @@ -216,7 +217,7 @@ func getAutoscalerURI(clusterID string) string {
return URI_PREFIX + REQUEST_AUTOSCALER + "/" + clusterID
}

func getKubeconfigURI(clusterID string, kubeConfigType KubeConfigType) string {
func getKubeconfigURI(clusterID string, kubeConfigType model.KubeConfigType) string {
return URI_PREFIX + fmt.Sprintf(REQUEST_KUBECONFIG, clusterID, kubeConfigType)
}

Expand Down
2 changes: 1 addition & 1 deletion services/media/api/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ type Insert struct {
Bucket string `json:"bucket,omitempty"`
Key string `json:"key,omitempty"`
Type string `json:"type,omitempty"`
Text string `json:"text"`
Text *string `json:"text"`
Font *Font `json:"font,omitempty"`
Timeline *Timeline `json:"timeline"`
Layout *Layout `json:"layout,omitempty"`
Expand Down

0 comments on commit 35bc54d

Please sign in to comment.