@@ -11,6 +11,7 @@ import (
11
11
"time"
12
12
13
13
bccapi "github.com/baidubce/bce-sdk-go/services/bcc/api"
14
+ "github.com/baidubce/bce-sdk-go/services/cce/v2/model"
14
15
"github.com/baidubce/bce-sdk-go/services/cce/v2/types"
15
16
"github.com/baidubce/bce-sdk-go/util/log"
16
17
)
@@ -67,7 +68,8 @@ func setup() {
67
68
68
69
// ExpectEqual is the helper function for test each case
69
70
func ExpectEqual (alert func (format string , args ... interface {}),
70
- expected interface {}, actual interface {}) bool {
71
+ expected interface {}, actual interface {},
72
+ ) bool {
71
73
expectedValue , actualValue := reflect .ValueOf (expected ), reflect .ValueOf (actual )
72
74
equal := false
73
75
switch {
@@ -202,7 +204,7 @@ func TestClient_CreateCluster(t *testing.T) {
202
204
s , _ := json .MarshalIndent (resp , "" , "\t " )
203
205
fmt .Println ("Response:" + string (s ))
204
206
205
- //等集群创建完成
207
+ // 等集群创建完成
206
208
time .Sleep (time .Duration (180 ) * time .Second )
207
209
}
208
210
@@ -427,7 +429,7 @@ func TestClient_UpdateInstanceGroupClusterAutoscalerSpec(t *testing.T) {
427
429
func TestClient_GetKubeConfig (t * testing.T ) {
428
430
args := & GetKubeConfigArgs {
429
431
ClusterID : CCE_CLUSTER_ID ,
430
- KubeConfigType : KubeConfigTypeVPC ,
432
+ KubeConfigType : model . KubeConfigTypeVPC ,
431
433
}
432
434
433
435
resp , err := CCE_CLIENT .GetKubeConfig (args )
@@ -657,7 +659,6 @@ func TestClient_InstanceCRD(t *testing.T) {
657
659
658
660
func TestClient_UpdateClusterCRD (t * testing.T ) {
659
661
getClusterCRDArgs := & GetClusterCRDArgs {
660
-
661
662
ClusterID : "cce-bvyohjkg" ,
662
663
}
663
664
@@ -686,3 +687,160 @@ func TestClient_UpdateClusterCRD(t *testing.T) {
686
687
687
688
fmt .Printf ("Resuest ID: %s" , commonResp .RequestID )
688
689
}
690
+
691
+ // TestClient_AttachInstancesToInstanceGroup 添加已有节点至节点组
692
+ func TestClient_AttachInstancesToInstanceGroup (t * testing.T ) {
693
+ var (
694
+ ak = ""
695
+ sk = ""
696
+ endpoint = ""
697
+ clusterID = ""
698
+ instanceGroupID = ""
699
+ existInstanceID = ""
700
+ AdminPassword = ""
701
+ // rebuild 是否重装操作系统
702
+ rebuild = true
703
+ // useInstanceGroupConfig 是否使用节点组配置
704
+ useInstanceGroupConfig = true
705
+ // useLocalDiskForContainer 是否使用本地盘保存数据
706
+ useLocalDiskForContainer = false
707
+ imageID = ""
708
+ )
709
+
710
+ cceClient , err := NewClient (ak , sk , endpoint )
711
+ if err != nil {
712
+ fmt .Printf ("NewClient error: %s" , err .Error ())
713
+ return
714
+ }
715
+
716
+ attachInstanceToInstanceGroupArgs := func () * AttachInstancesToInstanceGroupArgs {
717
+ args := AttachInstancesToInstanceGroupArgs {}
718
+ args .ClusterID = clusterID
719
+ args .InstanceGroupID = instanceGroupID
720
+ args .Request = & AttachInstancesToInstanceGroupRequest {
721
+ ExistedInstances : make ([]* InstanceSet , 0 ),
722
+ UseInstanceGroupConfig : useInstanceGroupConfig ,
723
+ }
724
+ existInstance := & InstanceSet {
725
+ InstanceSpec : types.InstanceSpec {
726
+ Existed : true ,
727
+ ExistedOption : types.ExistedOption {
728
+ // bcc 实例 id
729
+ ExistedInstanceID : existInstanceID ,
730
+ Rebuild : & rebuild ,
731
+ },
732
+ // 看具体的类型,bcc,bbc,ebc
733
+ MachineType : types .MachineTypeBCC ,
734
+ ClusterRole : types .ClusterRoleNode ,
735
+
736
+ // 二选一
737
+ AdminPassword : AdminPassword ,
738
+ SSHKeyID : "" ,
739
+ },
740
+ }
741
+
742
+ // 如果需要重装操作系统,需要配置这里
743
+ if rebuild {
744
+ existInstance .InstanceSpec .InstanceOS = types.InstanceOS {
745
+ ImageType : bccapi .ImageTypeSystem ,
746
+ }
747
+ existInstance .InstanceSpec .ImageID = imageID
748
+ }
749
+
750
+ if useLocalDiskForContainer {
751
+ // 将容器数据存储在数据盘或本地盘中
752
+ existInstance .InstanceSpec .InstanceResource = types.InstanceResource {
753
+ CDSList : types.CDSConfigList {
754
+ {
755
+ DataDevice : "/dev/xxx" ,
756
+ Path : "/home/cce" ,
757
+ },
758
+ },
759
+ }
760
+ }
761
+ if ! useInstanceGroupConfig {
762
+ existInstance .InstanceSpec .VPCConfig = types.VPCConfig {
763
+ SecurityGroups : []types.SecurityGroupV2 {
764
+ {
765
+ ID : "" ,
766
+ Name : "" ,
767
+ Type : types .SecurityGroupTypeNormal ,
768
+ },
769
+ },
770
+ }
771
+ existInstance .InstanceSpec .DeployCustomConfig = types.DeployCustomConfig {
772
+ KubeletRootDir : "" ,
773
+ PreUserScript : "" ,
774
+ PostUserScript : "" ,
775
+ }
776
+ // 标签配置
777
+ existInstance .InstanceSpec .Tags = types.TagList {
778
+ {
779
+ TagKey : "" ,
780
+ TagValue : "" ,
781
+ },
782
+ }
783
+ }
784
+ args .Request .ExistedInstances = append (args .Request .ExistedInstances , existInstance )
785
+ return & args
786
+ }()
787
+ commonResp , err := cceClient .AttachInstancesToInstanceGroup (attachInstanceToInstanceGroupArgs )
788
+ if err != nil {
789
+ fmt .Printf ("attach instance to instance group failed, errir: %v" , err )
790
+ return
791
+ }
792
+ fmt .Printf ("Request ID: %s" , commonResp .RequestID )
793
+ }
794
+
795
+ func TestClient_CreateScaleDownInstanceGroupTask (t * testing.T ) {
796
+ type fields struct {
797
+ ak , sk , endpoint string
798
+ }
799
+ type args struct {
800
+ args * CreateScaleDownInstanceGroupTaskArgs
801
+ }
802
+ tests := []struct {
803
+ name string
804
+ fields fields
805
+ args args
806
+ }{
807
+ {
808
+ name : "移出已有节点" ,
809
+ fields : fields {
810
+ ak : "" ,
811
+ sk : "" ,
812
+ endpoint : "" ,
813
+ },
814
+ args : args {
815
+ args : & CreateScaleDownInstanceGroupTaskArgs {
816
+ InstancesToBeRemoved : []string {"" },
817
+ ClusterID : "" ,
818
+ InstanceGroupID : "" ,
819
+ CleanPolicy : CleanPolicyDelete ,
820
+ DeleteOption : & types.DeleteOption {
821
+ DeleteCDSSnapshot : false ,
822
+ DeleteResource : false ,
823
+ DrainNode : false ,
824
+ MoveOut : true ,
825
+ },
826
+ },
827
+ },
828
+ },
829
+ }
830
+ for _ , tt := range tests {
831
+ t .Run (tt .name , func (t * testing.T ) {
832
+ c , err := NewClient (tt .fields .ak , tt .fields .sk , tt .fields .endpoint )
833
+ if err != nil {
834
+ t .Errorf ("failed init client, error = %v" , err )
835
+ return
836
+ }
837
+ if resp , err := c .CreateScaleDownInstanceGroupTask (tt .args .args ); err != nil {
838
+ t .Errorf ("CreateScaleDownInstanceGroupTask() error = %v" , err )
839
+
840
+ } else {
841
+ t .Logf ("request id is: %s" , resp .RequestID )
842
+ }
843
+
844
+ })
845
+ }
846
+ }
0 commit comments