Skip to content

Commit 5ff0f26

Browse files
author
olegs-codefresh
committed
Add table to the final report
1 parent cd4b9a0 commit 5ff0f26

22 files changed

+2930
-8
lines changed

Godeps/Godeps.json

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

create-clusters.go

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ func create(cli *cli.Context) {
4040
} else {
4141
goOverCurrentContext(c)
4242
}
43+
reportResult()
4344
log.Info("Operation is done, check your account setting")
4445
}
4546

@@ -59,6 +60,7 @@ func goOverAllContexts(cnf api.Config) {
5960
config := clientcmd.NewNonInteractiveClientConfig(cnf, contextName, &override, nil)
6061
err := goOverContext(contextName, config, logger)
6162
if err != nil {
63+
addClusterToFinalReport(contextName, failed, err.Error())
6264
continue
6365
}
6466
}
@@ -69,20 +71,26 @@ func getOverContextByName(cnf api.Config, contextName string) {
6971
override := getDefaultOverride()
7072
config := clientcmd.NewNonInteractiveClientConfig(cnf, contextName, &override, nil)
7173
logger := getLogger(contextName)
72-
goOverContext(contextName, config, logger)
74+
err := goOverContext(contextName, config, logger)
75+
if err != nil {
76+
addClusterToFinalReport(contextName, failed, err.Error())
77+
}
7378
}
7479

75-
func goOverCurrentContext(cnf api.Config) error {
80+
func goOverCurrentContext(cnf api.Config) {
7681
override := getDefaultOverride()
7782
config := clientcmd.NewDefaultClientConfig(cnf, &override)
7883
rawConfig, err := config.RawConfig()
84+
if err != nil {
85+
addClusterToFinalReport("current-context", failed, err.Error())
86+
}
7987
contextName := rawConfig.CurrentContext
8088
logger := getLogger(contextName)
89+
90+
err = goOverContext(contextName, config, logger)
8191
if err != nil {
82-
return err
92+
addClusterToFinalReport(contextName, failed, err.Error())
8393
}
84-
goOverContext(contextName, config, logger)
85-
return nil
8694
}
8795

8896
func goOverContext(contextName string, config clientcmd.ClientConfig, logger *log.Entry) error {
@@ -127,12 +135,13 @@ func goOverContext(contextName string, config clientcmd.ClientConfig, logger *lo
127135
logger.Info(fmt.Sprint("Found secret"))
128136

129137
logger.Info(fmt.Sprint("Creating cluster in Codefresh"))
130-
_, e = addCluser(clientCnf.Host, contextName, secret.Data["token"], secret.Data["ca.crt"])
138+
result, e := addCluser(clientCnf.Host, contextName, secret.Data["token"], secret.Data["ca.crt"])
131139
if e != nil {
132140
message := fmt.Sprintf("Failed to add cluster with error:\n%s", e)
133141
logger.Error(message)
134142
return e
135143
}
144+
addClusterToFinalReport(contextName, success, string(result))
136145
logger.Warn(fmt.Sprint("Cluster added!"))
137146
return nil
138147
}

dist/bin/stevedore

215 KB
Binary file not shown.

main.go

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,26 @@ package main
22

33
import (
44
"os"
5+
"os/signal"
56
)
67

7-
func main() {
8+
const (
9+
clusterAddedEventName = "cluster:added"
10+
)
811

12+
func main() {
13+
handleUnexpectedExit()
914
app := setupCli()
10-
// app.Action = runDryRun // just for debug the runDryRun
1115
app.Run(os.Args)
1216
}
17+
18+
func handleUnexpectedExit() {
19+
c := make(chan os.Signal, 1)
20+
signal.Notify(c, os.Interrupt)
21+
go func() {
22+
for _ = range c {
23+
reportResult()
24+
os.Exit(1)
25+
}
26+
}()
27+
}

reporter.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package main
2+
3+
import (
4+
"os"
5+
6+
"github.com/olekukonko/tablewriter"
7+
)
8+
9+
const (
10+
success = "SUCCESS"
11+
failed = "FAILED"
12+
)
13+
14+
var table = tablewriter.NewWriter(os.Stdout)
15+
16+
func init() {
17+
table.SetHeader([]string{"Context Name", "Status", "Message"})
18+
table.SetAutoMergeCells(true)
19+
table.SetRowLine(true)
20+
}
21+
22+
func addClusterToFinalReport(contextName string, status string, message string) {
23+
table.Append([]string{contextName, status, message})
24+
}
25+
26+
func reportResult() {
27+
table.Render()
28+
}

vendor/github.com/mattn/go-runewidth/.travis.yml

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/mattn/go-runewidth/LICENSE

Lines changed: 21 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/mattn/go-runewidth/README.mkd

Lines changed: 27 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)