github.com/alibaba/sealer@v0.8.6-0.20220430115802-37a2bdaa8173/pkg/infra/test/infra_test.go (about) 1 // Copyright © 2021 Alibaba Group Holding Ltd. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package infra 16 17 import ( 18 "fmt" 19 "os" 20 "testing" 21 "time" 22 23 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 24 25 "github.com/alibaba/sealer/pkg/infra" 26 v1 "github.com/alibaba/sealer/types/api/v1" 27 ) 28 29 func TestApply(t *testing.T) { 30 //setup cluster 31 password := os.Getenv("SealerPassword") 32 cluster := v1.Cluster{ 33 TypeMeta: metav1.TypeMeta{ 34 Kind: "Cluster", 35 APIVersion: "zlink.aliyun.com/v1alpha1", 36 }, 37 ObjectMeta: metav1.ObjectMeta{ 38 Name: "my-cluster", 39 }, 40 Spec: v1.ClusterSpec{ 41 Masters: v1.Hosts{ 42 Count: "1", 43 CPU: "2", 44 Memory: "4", 45 SystemDisk: "100", 46 DataDisks: []string{"100"}, 47 }, 48 Nodes: v1.Hosts{ 49 Count: "1", 50 CPU: "2", 51 Memory: "4", 52 SystemDisk: "100", 53 DataDisks: []string{"100"}, 54 }, 55 Provider: "ALI_CLOUD", 56 SSH: v1.SSH{ 57 Passwd: password, 58 }, 59 }, 60 } 61 62 aliProvider, err := infra.NewDefaultProvider(&cluster) 63 if err != nil { 64 fmt.Printf("%v", err) 65 } else { 66 fmt.Printf("%v", aliProvider.Apply()) 67 } 68 69 t.Run("modify instance type", func(t *testing.T) { 70 cluster.Spec.Masters.CPU = "4" 71 cluster.Spec.Masters.Memory = "8" 72 cluster.Spec.Nodes.CPU = "4" 73 cluster.Spec.Nodes.Memory = "8" 74 fmt.Printf("%v", aliProvider.Apply()) 75 }) 76 77 t.Run("add instance count", func(t *testing.T) { 78 cluster.Spec.Masters.Count = "5" 79 cluster.Spec.Nodes.Count = "5" 80 fmt.Printf("%v", aliProvider.Apply()) 81 fmt.Printf("%v \n", cluster.Spec.Masters) 82 fmt.Printf("%v \n", cluster.Spec.Nodes) 83 }) 84 85 t.Run("reduce instance count", func(t *testing.T) { 86 cluster.Spec.Masters.Count = "1" 87 cluster.Spec.Nodes.Count = "1" 88 fmt.Printf("%v", aliProvider.Apply()) 89 }) 90 91 t.Run("modify instance type & count both", func(t *testing.T) { 92 cluster.Spec.Masters.CPU = "8" 93 cluster.Spec.Masters.Memory = "16" 94 cluster.Spec.Nodes.CPU = "8" 95 cluster.Spec.Nodes.Memory = "16" 96 cluster.Spec.Masters.Count = "5" 97 cluster.Spec.Nodes.Count = "5" 98 fmt.Printf("%v", aliProvider.Apply()) 99 }) 100 101 // todo 102 t.Run("modify instance system disk", func(t *testing.T) { 103 104 }) 105 106 //teardown 107 time.Sleep(60 * time.Second) 108 now := metav1.Now() 109 cluster.ObjectMeta.DeletionTimestamp = &now 110 fmt.Printf("%v", aliProvider.Apply()) 111 }