-
Notifications
You must be signed in to change notification settings - Fork 0
/
main_test.go
68 lines (59 loc) · 1.46 KB
/
main_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
package main
import (
"fmt"
"math/rand"
"testing"
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes/fake"
)
const letterBytes = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
func RandStringBytes(n int) string {
b := make([]byte, n)
for i := range b {
b[i] = letterBytes[rand.Intn(len(letterBytes))]
}
return string(b)
}
func createNodes(count int) v1.NodeList {
// Create a list of Nodes to put into the Nodelist later
nodes := []v1.Node{}
// Iterate over the count needed
for i := 1; i < count; i++ {
// Set a hostname and IP address
nodeHostName := "control-plane-node-" + RandStringBytes(8)
nodeIPAddress := fmt.Sprintf("10.0.0.%d", i+10)
//
node := v1.Node{
Status: v1.NodeStatus{
Addresses: []v1.NodeAddress{
{
Type: "Hostname",
Address: nodeHostName,
},
{
Type: "InternalIP",
Address: nodeIPAddress,
},
},
},
ObjectMeta: metav1.ObjectMeta{
Name: nodeHostName,
Labels: map[string]string{
"node-role.kubernetes.io/control-plane": "",
},
},
}
nodes = append(nodes, node)
}
nodeList := v1.NodeList{Items: nodes}
return nodeList
}
func TestGrabControlPlaneNodes(t *testing.T) {
nodes := createNodes(10)
client := kubeClient{}
client.clientset = fake.NewSimpleClientset(&nodes)
//fmt.Println(fak8s.Discovery().ServerVersion())
roleName := "control-plane"
grabControlPlaneNodes(&roleName, &client)
}