-
Notifications
You must be signed in to change notification settings - Fork 0
/
launch.go
100 lines (73 loc) · 2.33 KB
/
launch.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
package main
import (
"fmt"
"github.com/codeskyblue/go-sh"
"github.com/fatih/color"
"io/ioutil"
"path/filepath"
)
/**
* [func description]
* @param {[type]} app *appConfig) Launch(distDir string [description]
* @return {[type]} [description]
*/
func (app *appConfig) Launch(distDir string) {
app.LaunchTemplatesFromFolder(distDir)
app.GetClusterStatus()
}
/**
* [func description]
* @param {[type]} app *appConfig) LaunchTemplatesFromFolder(sourceDir string [description]
* @return {[type]} [description]
*/
func (app *appConfig) LaunchTemplatesFromFolder(sourceDir string) {
// Get list of files in sourceDir
files, err := ioutil.ReadDir(sourceDir)
// Check for error finding files
if err != nil {
color.Red(fmt.Sprintf("%s", err))
}
// Deploy generated template files to kubernetes endpoint
for _, file := range files {
filename := sourceDir + file.Name()
// If file is dir, recurse function
if file.IsDir() {
app.LaunchTemplatesFromFolder(filename + "/")
continue
}
// Only handle file if a yaml
if filepath.Ext(file.Name()) != ".yaml" {
color.Yellow(fmt.Sprintf("File %s is not a template", filename))
continue
}
// Run create command on specified server
msg, err := sh.Command("kubectl", "--kubeconfig="+app.envFile, "create", "-f", filename).Output()
if err != nil {
color.Red(fmt.Sprintf("%s", err))
}
color.White(string(msg[:]))
}
}
/**
* [func description]
* @param {[type]} config *appConfig) GetClusterStatus( [description]
* @return {[type]} [description]
*/
func (app *appConfig) GetClusterStatus() {
var msg []byte
msg, _ = sh.Command("kubectl", "--kubeconfig="+app.envFile, "cluster-info").Output()
color.Green("Cluster Info")
color.White(string(msg[:]))
msg, _ = sh.Command("kubectl", "--kubeconfig="+app.envFile, "get", "minions").Output()
color.Green("Minions")
color.White(string(msg[:]))
msg, _ = sh.Command("kubectl", "--kubeconfig="+app.envFile, "get", "services").Output()
color.Green("Services")
color.White(string(msg[:]))
msg, _ = sh.Command("kubectl", "--kubeconfig="+app.envFile, "get", "replicationcontrollers").Output()
color.Green("Replication Controllers")
color.White(string(msg[:]))
msg, _ = sh.Command("kubectl", "--kubeconfig="+app.envFile, "get", "pods").Output()
color.Green("Pods")
color.White(string(msg[:]))
}