lingering changes
Signed-off-by: Derek McQuay <derekmcquay@gmail.com>
This commit is contained in:
parent
849279a07f
commit
0ff0a31567
98
main.go
98
main.go
@ -6,8 +6,9 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
|
"regexp"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
|
||||||
|
|
||||||
"github.com/fatih/color"
|
"github.com/fatih/color"
|
||||||
)
|
)
|
||||||
@ -73,11 +74,11 @@ func getServiceIPs() []serviceIPs {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// get rid of kubernetes pod
|
// get rid of kubernetes pod
|
||||||
for i, n := range s {
|
//for i, n := range s {
|
||||||
if n.Name == "kubernetes" {
|
// if n.Name == "kubernetes" {
|
||||||
s = append(s[:i], s[i+1:]...)
|
// s = append(s[:i], s[i+1:]...)
|
||||||
}
|
// }
|
||||||
}
|
//}
|
||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -102,53 +103,100 @@ func stripHealthCheck(n string, hcs healthCheck) string {
|
|||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getPodInstanceIndex(n string) (int, error) {
|
||||||
|
re := regexp.MustCompile("[0-9]")
|
||||||
|
index := re.FindString(n)
|
||||||
|
i, err := strconv.Atoi(index)
|
||||||
|
return i, err
|
||||||
|
}
|
||||||
|
|
||||||
func buildCommands(hcs healthCheck, ips []serviceIPs) []command {
|
func buildCommands(hcs healthCheck, ips []serviceIPs) []command {
|
||||||
commands := []command{}
|
commands := []command{}
|
||||||
for _, s := range ips {
|
for _, s := range ips {
|
||||||
if strings.Contains(s.Name, "apiserver") || strings.Contains(s.Name, "etcd") {
|
if strings.Contains(s.Name, "apiserver") {
|
||||||
ip := s.Statuses[0].ContainerStatus.NetworkInfos[0].IPAddresses[0].IPAddress
|
index, err := getPodInstanceIndex(s.Name)
|
||||||
c := strings.Replace(stripHealthCheck(s.Name, hcs), "$LIBPROCESS_IP", ip, -1)
|
if err != nil {
|
||||||
|
log.Fatal("failed to get pod index for build command: ", err)
|
||||||
|
}
|
||||||
|
c := strings.Replace(stripHealthCheck(s.Name, hcs), "$POD_INSTANCE_INDEX", strconv.Itoa(index), -1)
|
||||||
commands = append(commands, command{node: s.Name, hc: c})
|
commands = append(commands, command{node: s.Name, hc: c})
|
||||||
|
} else if strings.Contains(s.Name, "etcd") {
|
||||||
|
index, err := getPodInstanceIndex(s.Name)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal("failed to get pod index for build command: ", err)
|
||||||
|
}
|
||||||
|
c := strings.Replace(stripHealthCheck(s.Name, hcs), "$POD_INSTANCE_INDEX", strconv.Itoa(index), -1)
|
||||||
|
c = strings.Replace(c, "$ETCD_LISTEN_CLIENT_PORT", "2379", -1)
|
||||||
|
commands = append(commands, command{node: s.Name, hc: c})
|
||||||
|
//https://etcd-$POD_INSTANCE_INDEX-peer.{{FRAMEWORK_NAME}}.mesos:$ETCD_LISTEN_CLIENT_PORT/health
|
||||||
} else {
|
} else {
|
||||||
commands = append(commands, command{node: s.Name, hc: stripHealthCheck(s.Name, hcs)})
|
//commands = append(commands, command{node: s.Name, hc: stripHealthCheck(s.Name, hcs)})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fmt.Println(commands)
|
|
||||||
return commands
|
return commands
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
var wg sync.WaitGroup
|
//var wg sync.WaitGroup
|
||||||
hcs := getHealthCheck()
|
hcs := getHealthCheck()
|
||||||
ips := getServiceIPs()
|
ips := getServiceIPs()
|
||||||
|
//for _, i := range hcs.PodSpecs {
|
||||||
|
// fmt.Println(i)
|
||||||
|
//}
|
||||||
|
//fmt.Println("\n\n\n")
|
||||||
|
//fmt.Printf("%+v\n", hcs)
|
||||||
|
//fmt.Println("\n\n\n")
|
||||||
|
//fmt.Printf("%+v\n", ips)
|
||||||
|
//fmt.Println("\n\n\n")
|
||||||
hosts := buildCommands(hcs, ips)
|
hosts := buildCommands(hcs, ips)
|
||||||
|
//for i, j := range hosts {
|
||||||
|
// fmt.Printf("%d %+v\n", i, j)
|
||||||
|
//}
|
||||||
|
//fmt.Println(hosts)
|
||||||
|
//time.Sleep(time.Second * 5)
|
||||||
|
|
||||||
for _, n := range hosts {
|
for _, n := range hosts {
|
||||||
wg.Add(1)
|
//wg.Add(1)
|
||||||
go func(c command) {
|
//go func(c command) {
|
||||||
defer wg.Done()
|
//defer wg.Done()
|
||||||
s := strings.Split(c.hc, " ")
|
// s := strings.Split(n.hc, " ")
|
||||||
|
//if len(s) != 3 {
|
||||||
|
// log.Printf("could not be split: %v", s)
|
||||||
|
// return
|
||||||
|
//}
|
||||||
|
//for i, j := range s {
|
||||||
|
// fmt.Println(i, j)
|
||||||
|
//}
|
||||||
cmd := exec.Command(
|
cmd := exec.Command(
|
||||||
"dcos",
|
"dcos",
|
||||||
"task",
|
"task",
|
||||||
"exec",
|
"exec",
|
||||||
c.node,
|
n.node,
|
||||||
s[0],
|
n.hc,
|
||||||
s[1],
|
//s[0],
|
||||||
s[2],
|
//s[1],
|
||||||
|
//s[2],
|
||||||
|
//s[3],
|
||||||
|
//s[4],
|
||||||
|
//s[5],
|
||||||
|
//s[6],
|
||||||
|
//s[7],
|
||||||
|
//s[8],
|
||||||
)
|
)
|
||||||
var out bytes.Buffer
|
var out bytes.Buffer
|
||||||
cmd.Stdout = &out
|
cmd.Stdout = &out
|
||||||
err := cmd.Run()
|
err := cmd.Run()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Printf("failed for %v with:", n, err)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if strings.Contains(out.String(), "ok") || strings.Contains(out.String(), "true") {
|
if strings.Contains(out.String(), "ok") || strings.Contains(out.String(), "true") {
|
||||||
color.Green(fmt.Sprintf("%v: %q\n", c, out.String()))
|
color.Green("%s", n.node)
|
||||||
} else {
|
} else {
|
||||||
color.Red(fmt.Sprintf("%v: %q\n", c, out.String()))
|
color.Red(fmt.Sprintf("%s: \t%q\n", n.node, out.String()))
|
||||||
}
|
}
|
||||||
}(n)
|
//}(n)
|
||||||
}
|
}
|
||||||
wg.Wait()
|
// wg.Wait()
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user