-
Notifications
You must be signed in to change notification settings - Fork 0
/
daemonsets.go
81 lines (69 loc) · 3.17 KB
/
daemonsets.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
package main
import (
"time"
"github.com/360EntSecGroup-Skylar/excelize"
"github.com/tidwall/gjson"
)
func createDaemonsetSheet() {
var csvHeader = []string{"Cluster", "Namespace", "Name", "Ready", "Current", "UpToDate", "Available", "Misscheduled", "NodeSelector",
"UpdateStrategy", "CreationDate", "Version", "UID"}
var csvData []interface{}
var startTime time.Time
var duration time.Duration
var xR int = 1
var sheetName string = "DaemonSets"
var apiurl string
// Initialize Excel sheet
index := xf.NewSheet(sheetName)
xf.SetActiveSheet(index)
xf.SetSheetRow(sheetName, "A1", &csvHeader)
info.Printf("%s: Section started\n", sheetName)
startTime = time.Now()
for i := 0; i < len(cfg.Clusters); i++ {
if !cfg.Clusters[i].Enable {
continue
}
boolCheck, msg := checkClusterAPI(cfg.Clusters[i].BaseURL, cfg.Clusters[i].Token)
if !boolCheck {
erro.Printf("%s: %s: %s\n", sheetName, cfg.Clusters[i].Name, msg)
continue
}
info.Printf("%s: Working on %s\n", sheetName, cfg.Clusters[i].Name)
apiurl = cfg.Clusters[i].BaseURL + "/apis/apps/v1/daemonsets?limit=1000"
body, _ := getRest(apiurl, cfg.Clusters[i].Token)
// Loop in list items and export data into Excel file
items := gjson.GetBytes(body, "items")
items.ForEach(func(key, value gjson.Result) bool {
vars := gjson.GetMany(value.String(),
`metadata.namespace`, `metadata.name`, `status.desiredNumberScheduled`, `status.currentNumberScheduled`, `status.numberReady`,
`status.updatedNumberScheduled`, `status.numberAvailable`, `status.numberMisscheduled`,
`spec.template.spec.nodeSelector`, `spec.updateStrategy.type`,
`metadata.creationTimestamp`, `metadata.resourceVersion`, `metadata.uid`)
readyReplicas := "0"
if vars[4].String() != "" {
readyReplicas = vars[4].String()
}
csvData = nil
csvData = append(csvData, cfg.Clusters[i].Name) // Cluster Name
csvData = append(csvData, vars[0].String()) // Namespace Name
csvData = append(csvData, vars[1].String()) // DaemonSet Name
csvData = append(csvData, readyReplicas+"/"+vars[2].String()) // DaemonSet Ready / Desired
csvData = append(csvData, vars[3].String()) // DaemonSet Currently Scheduled
csvData = append(csvData, vars[5].String()) // DaemonSet Updated Scheduled
csvData = append(csvData, vars[6].String()) // DaemonSet Available Scheduled
csvData = append(csvData, vars[7].String()) // DaemonSet Misscheduled
csvData = append(csvData, vars[8].String()) // Node Selector(s)
csvData = append(csvData, vars[9].String()) // Update Strategy Type
csvData = append(csvData, formatDate(vars[10].String())) // Creation Timestamp
csvData = append(csvData, vars[11].String()) // Resource Version
csvData = append(csvData, vars[12].String()) // UID
xR++
cell, _ := excelize.CoordinatesToCellName(1, xR)
xf.SetSheetRow(sheetName, cell, &csvData)
return true
})
}
formatTable(sheetName, len(csvHeader))
duration = time.Since(startTime)
info.Printf("%s: Section ended in %s\n", sheetName, duration)
}