Skip to content

Commit

Permalink
adding handlingfile func
Browse files Browse the repository at this point in the history
  • Loading branch information
framsouza committed Jul 25, 2022
1 parent 6b94132 commit 7deda33
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 30 deletions.
29 changes: 13 additions & 16 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,14 @@ import (
"os"

extract "github.com/framsouza/eck-diagnostics-parser/pkg/extract"
findfile "github.com/framsouza/eck-diagnostics-parser/pkg/findfile"
resources "github.com/framsouza/eck-diagnostics-parser/pkg/resources"
)

var (
zipfile = flag.String("zipfile", "", "Enter zip file name")
destination = flag.String("destination", "", "Enter the destination path")
destination = flag.String("destination", "./tmp/", "Enter the destination path")
)

// DON'T FORGET!!! REMEMBER TO FIND ANOTHER WAY TO PASS THE FILE NAMES TO THE FUNCITONS!!!!!

// CHECK IF STORAGECLASS FILE EXISTS AND PRINT IT

// TREAT ERRORS AND LOGS

// ADD OPERATOR INFORMATIONS

func main() {
flag.Parse()
if *zipfile == "" {
Expand Down Expand Up @@ -54,11 +45,17 @@ func main() {
resources.Deployment()
resources.PVC()
resources.Service()
fmt.Print("\n\n")
findfile.FindOpNS()
findfile.FindRsNS()
fmt.Print("FILES")
findfile.ListDir(*destination)
//resources.Events()
summary()

}

func summary() {
fmt.Print("\n\nBASED ON THE OUTPUT ABOVE, MAKE SURE THAT:\n")
fmt.Print("- All the services has an endpoint attached to it\n")
fmt.Print("- All the PVC has a Bound status\n")
fmt.Print("- All the Elasticsearch Resources are Green and the Phase is \"READY\"\n")
fmt.Print("- All the Kibana Resources are Green and the Phase is \"READY\"\n")
fmt.Print("- Every pod is RUNNING\n")
fmt.Print("- Every pod has the same MEM REQUEST & MEM LIMIT\n\n")

}
4 changes: 2 additions & 2 deletions pkg/extract/extract.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"strings"
)

var destination string
var Destination string

func UnzipSource(source, destination string) error {
// Open zip
Expand All @@ -20,7 +20,7 @@ func UnzipSource(source, destination string) error {
defer reader.Close()

// Get the path
destination, err = filepath.Abs(destination)
Destination, err = filepath.Abs(destination)
if err != nil {
return err
}
Expand Down
43 changes: 36 additions & 7 deletions pkg/findfile/findfile.go → pkg/handlingfiles/handlingfiles.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,39 @@
package findfile

import (
"fmt"
"log"
"os"
"path/filepath"
"strings"
"regexp"
)

var (
files []string
)

func FindFile(filename, d string) []string {
filepath.Walk(d, func(path string, f os.FileInfo, _ error) error {
if !f.IsDir() {
r, err := regexp.MatchString(filename, f.Name())
if err == nil && r {
absolutefilepath, err := filepath.Abs(path)
if err != nil {
log.Fatal(err)
}

files = append(files, absolutefilepath)

}

}
return nil
})

return files

}

/*
func FindOpNS() string {
str := "2022/03/10 07:44:23 ECK diagnostics with parameters: {DiagnosticImage:docker.elastic.co/eck-dev/support-diagnostics:8.1.4 ECKVersion: Kubeconfig: OperatorNamespaces:[elastic-system] ResourcesNamespaces:[default kube-system] OutputDir: RunStackDiagnostics:true Verbose:false}"
split := strings.Split(str, " ")
Expand All @@ -34,8 +60,10 @@ func FindRsNS() string {
}
// RETURN WORKS ONLY WHEN I CALL IT USING fmt.PrintLN and the function name (see main.go)
func ListDir(d string) []string {
var files []string
//var file string
err := filepath.Walk(d, func(path string, info os.FileInfo, err error) error {
if err != nil {
fmt.Println(err)
Expand All @@ -53,9 +81,10 @@ func ListDir(d string) []string {
log.Fatal(err)
}
var file []string
for _, file := range files {
fmt.Println(file)
}
return file
//fmt.Println(files)
//return files, err
return files
}
*/
3 changes: 2 additions & 1 deletion pkg/resources/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ func Deployment() {
w.Init(os.Stdout, 8, 8, 0, '\t', 0)
defer w.Flush()

config, _ := load.LoadDeploy("/Users/francismarasouza/finding-file/tmp/default/deployments.json")
config, _ := load.LoadDeploy("/Users/francismarasouza/eck-diagnostics-parser/tmp/default/deployments.json")

fmt.Fprintf(w, "\n\n%s\t\t\t%s\t\t", "DEPLOYMENT NAME", "REPLICAS")

for i := range config.Items {
Expand Down
8 changes: 7 additions & 1 deletion pkg/resources/nodes.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ func Nodes() {
w.Init(os.Stdout, 8, 8, 0, '\t', 0)
defer w.Flush()

config, _ := load.LoadNodes("/Users/francismarasouza/finding-file/tmp/nodes.json")
//for _, f := range handlingfiles.FindFile("nodes.json", extract.Destination) {
//fmt.Println("NODE FILE", f)
//config, _ := load.LoadNodes(f)
config, _ := load.LoadNodes("/Users/francismarasouza/eck-diagnostics-parser/tmp/nodes.json")
fmt.Fprintf(w, "\n%s\t%s\t%s\t%s\t\t%s\t\t%s\t%s\t", "NODE NAME", "CPU CAPACITY", "CPU ALLOCATED", "MEM CAPACITY", "MEM ALLOCATED", "VERSION", "NODE CONDITIONS")

for i := range config.Items {
Expand All @@ -29,4 +32,7 @@ func Nodes() {
fmt.Fprintf(w, "%s %s", config.Items[i].Status.Conditions[3].Type, config.Items[i].Status.Conditions[0].Status)

}

}

//}
13 changes: 10 additions & 3 deletions pkg/resources/pods.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,19 @@ import (
load "github.com/framsouza/eck-diagnostics-parser/pkg/load"
)

var pods = "pods.json"

func Pods() {
w := new(tabwriter.Writer)
w.Init(os.Stdout, 8, 8, 0, '\t', 0)
defer w.Flush()

config, _ := load.LoadPods("/Users/francismarasouza/eck-diagnostics-parser/pods.json")
//for _, f := range handlingfiles.FindFile(pods, extract.Destination) {
// fmt.Print("PODS FILENAME", f)
//}
//config, _ := load.LoadPods(p)

config, _ := load.LoadPods("/Users/francismarasouza/eck-diagnostics-parser/tmp/default/pods.json")
fmt.Fprintf(w, "\n\n%s\t%s\t\t%s\t%s\t%s\t%s\t%s\t", "PODS NAME", "STATUS", "MEM REQUEST", "MEM LIMIT", "CPU REQUEST", "CPU LIMIT", "INIT CONTAINERS STATUS")

for i := range config.Items {
Expand Down Expand Up @@ -45,13 +52,13 @@ func Pods() {

}
}

//Check initcontainers

for c := range config.Items[i].Status.InitContainerStatuses {
fmt.Fprintf(w, "%s %s, ", config.Items[i].Status.InitContainerStatuses[c].Name, config.Items[i].Status.InitContainerStatuses[c].State.Terminated.Reason)

}

}

// Print labels to compare with the service labels
}

0 comments on commit 7deda33

Please sign in to comment.