/
main.go
71 lines (58 loc) · 1.38 KB
/
main.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
package main
import (
"encoding/json"
"flag"
"fmt"
"os"
"strconv"
"github.com/olekukonko/tablewriter"
)
func main() {
nodes := flag.Int("n", 3, "Number of nodes")
scale := flag.Int("s", 1, "Number of scale nodes")
maxPods := flag.Int("p", 30, "Max pods per node")
isvc := flag.Int("l", 1, "Number of expected internal LoadBalancer services")
table := flag.Bool("t", false, "Set true for output table")
flag.Parse()
r := calculator{MaxPods: *maxPods, Nodes: *nodes, Scale: *scale, Isvc: *isvc}
r.validate()
r.calculateRequiredIPs()
err := r.getCIDR()
if err != nil {
fmt.Println(err.Error())
os.Exit(1)
}
if !*table {
renderJson(r)
} else {
renderTable(r)
}
os.Exit(0)
}
func renderTable(r calculator) {
data := [][]string{
{
strconv.Itoa(r.Nodes),
strconv.Itoa(r.Scale),
strconv.Itoa(r.MaxPods),
strconv.Itoa(r.Isvc),
strconv.Itoa(r.RequiredIPs),
r.CIDR},
}
table := tablewriter.NewWriter(os.Stdout)
table.SetHeader([]string{"Nodes", "Scale", "maxPods", "isvc", "IPs", "CIDR"})
table.SetHeaderAlignment(tablewriter.ALIGN_LEFT)
table.SetAlignment(tablewriter.ALIGN_RIGHT)
table.SetColumnSeparator("")
table.SetRowSeparator("")
table.SetHeaderLine(false)
table.SetBorder(false)
for _, v := range data {
table.Append(v)
}
table.Render()
}
func renderJson(r calculator) {
j, _:= json.MarshalIndent(r, "", " ")
fmt.Println(string(j))
}