-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsimple_k8s_test.go
98 lines (80 loc) · 2.98 KB
/
simple_k8s_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
package simple_k8s
import (
"fmt"
Set "github.com/geniussportsgroup/treaps"
"github.com/stretchr/testify/assert"
"testing"
"time"
)
const TestPathToKubeConfig = "../../.kube/config"
func TestNewKubernetesClient(t *testing.T) {
kubectl, err := NewKubernetesClient(TestPathToKubeConfig)
assert.Nil(t, err)
assert.NotNil(t, kubectl)
}
func Test_findDeploymentNames(t *testing.T) {
kubectl, err := NewKubernetesClient(TestPathToKubeConfig)
assert.Nil(t, err)
assert.NotNil(t, kubectl)
l, err := FindDeploymentNames(kubectl, "basketball-nba-uat", "versionsvc=2-2-3",
"score-diff", "score-total", "home-away", "race", "team-score-last",
"freethrow", "ponderate")
for it := Set.NewIterator(l); it.HasCurr(); it.Next() {
fmt.Println(it.GetCurr().(string))
assert.NotNil(t, l.Search(it.GetCurr()))
}
}
func TestGetNumberOfPods(t *testing.T) {
kubectl, err := NewKubernetesClient(TestPathToKubeConfig)
assert.Nil(t, err)
assert.NotNil(t, kubectl)
l, err := FindDeploymentNames(kubectl, "basketball-nba-uat", "versionsvc=2-2-3",
"score-diff", "score-total", "home-away", "race", "team-score-last",
"freethrow", "ponderate")
for it := Set.NewIterator(l); it.HasCurr(); it.Next() {
deployName := it.GetCurr().(string)
numPods, err := GetNumberOfPods(kubectl, "basketball-nba-uat", deployName)
assert.Nil(t, err)
fmt.Println(deployName, " =", numPods)
}
}
func TestSetNumberOfPods(t *testing.T) {
kubectl, err := NewKubernetesClient(TestPathToKubeConfig)
assert.Nil(t, err)
assert.NotNil(t, kubectl)
fmt.Println("Reading deployment names")
l, err := FindDeploymentNames(kubectl, "basketball-nba-uat", "versionsvc=2-2-3",
"score-diff", "score-total", "home-away", "race", "team-score-last",
"freethrow", "ponderate")
fmt.Println("These are the deploys")
for it := Set.NewIterator(l); it.HasCurr(); it.Next() {
fmt.Println(" ", it.GetCurr())
}
fmt.Println("Reading number of pods per deploy")
for it := Set.NewIterator(l); it.HasCurr(); it.Next() {
deployName := it.GetCurr().(string)
numPods, err := GetNumberOfPods(kubectl, "basketball-nba-uat", deployName)
ok, err := SetNumberOfPods(numPods+1, &numPods, kubectl, "basketball-nba-uat", deployName)
assert.True(t, ok)
assert.Nil(t, err)
fmt.Println(deployName, " =", numPods)
}
fmt.Println("Scaling every deploy in one pod")
for it := Set.NewIterator(l); it.HasCurr(); it.Next() {
deployName := it.GetCurr().(string)
numPods, err := GetNumberOfPods(kubectl, "basketball-nba-uat", deployName)
assert.Nil(t, err)
fmt.Println(deployName, " =", numPods)
}
fmt.Println("Waiting 30 second before to scale down")
time.Sleep(30 * time.Second)
fmt.Println("Scaling down")
for it := Set.NewIterator(l); it.HasCurr(); it.Next() {
deployName := it.GetCurr().(string)
numPods, err := GetNumberOfPods(kubectl, "basketball-nba-uat", deployName)
ok, err := SetNumberOfPods(numPods-1, &numPods, kubectl, "basketball-nba-uat", deployName)
assert.True(t, ok)
assert.Nil(t, err)
fmt.Println(deployName, " =", numPods)
}
}