initial commit
Signed-off-by: Derek McQuay <derekmcquay@gmail.com>
This commit is contained in:
parent
0dab283700
commit
56b562f6cc
121
main.go
Normal file
121
main.go
Normal file
@ -0,0 +1,121 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"log"
|
||||
"os/exec"
|
||||
"strings"
|
||||
"sync"
|
||||
)
|
||||
|
||||
type command struct {
|
||||
node string
|
||||
port int
|
||||
url string
|
||||
health string
|
||||
}
|
||||
|
||||
type dcosJSON struct {
|
||||
Name string `json:"name"`
|
||||
Statuses []struct {
|
||||
ContainerStatus struct {
|
||||
ContainerID struct {
|
||||
Value string `json:"value"`
|
||||
} `json:"container_id"`
|
||||
NetworkInfos []struct {
|
||||
IPAddresses []struct {
|
||||
IPAddress string `json:"ip_address"`
|
||||
} `json:"ip_addresses"`
|
||||
} `json:"network_infos"`
|
||||
} `json:"container_status"`
|
||||
State string `json:"state"`
|
||||
Timestamp float64 `json:"timestamp"`
|
||||
} `json:"statuses"`
|
||||
}
|
||||
|
||||
type apiserverIPs struct {
|
||||
name string
|
||||
ip string
|
||||
}
|
||||
|
||||
func getAPIServerIPs() []apiserverIPs {
|
||||
cmd := exec.Command("dcos", "task", "--json")
|
||||
var out bytes.Buffer
|
||||
cmd.Stdout = &out
|
||||
err := cmd.Run()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
d := []dcosJSON{}
|
||||
if err := json.Unmarshal([]byte(out.String()), &d); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
ips := []apiserverIPs{}
|
||||
for _, i := range d {
|
||||
if strings.Contains(i.Name, "apiserver") {
|
||||
ips = append(
|
||||
ips,
|
||||
apiserverIPs{
|
||||
name: i.Name,
|
||||
ip: i.Statuses[0].ContainerStatus.NetworkInfos[0].IPAddresses[0].IPAddress,
|
||||
},
|
||||
)
|
||||
}
|
||||
}
|
||||
return ips
|
||||
}
|
||||
|
||||
func addAPIServer(n string, ips []apiserverIPs) string {
|
||||
for _, i := range ips {
|
||||
if strings.Contains(i.name, n) {
|
||||
return i.ip
|
||||
}
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func main() {
|
||||
var wg sync.WaitGroup
|
||||
ips := getAPIServerIPs()
|
||||
hosts := []command{
|
||||
command{node: "kube-controller-manager-0-node", port: 10252, url: "localhost", health: "healthz"},
|
||||
command{node: "kube-controller-manager-1-node", port: 10252, url: "localhost", health: "healthz"},
|
||||
command{node: "kube-controller-manager-2-node", port: 10252, url: "localhost", health: "healthz"},
|
||||
command{node: "kube-scheduler-0-node", port: 10252, url: "localhost", health: "healthz"},
|
||||
command{node: "kube-scheduler-1-node", port: 10251, url: "localhost", health: "healthz"},
|
||||
command{node: "kube-scheduler-2-node", port: 10251, url: "localhost", health: "healthz"},
|
||||
command{node: "kube-apiserver-0-node", port: 9000, url: addAPIServer("0", ips), health: "healthz"},
|
||||
command{node: "kube-apiserver-1-node", port: 9000, url: addAPIServer("1", ips), health: "healthz"},
|
||||
command{node: "kube-apiserver-2-node", port: 9000, url: addAPIServer("2", ips), health: "healthz"},
|
||||
command{node: "etcd-0-node", port: 2379, url: "localhost", health: "health"},
|
||||
command{node: "etcd-1-node", port: 2379, url: "localhost", health: "health"},
|
||||
command{node: "etcd-2-node", port: 2379, url: "localhost", health: "health"},
|
||||
}
|
||||
|
||||
for _, n := range hosts {
|
||||
wg.Add(1)
|
||||
go func(c command) {
|
||||
defer wg.Done()
|
||||
cmd := exec.Command(
|
||||
"dcos",
|
||||
"task",
|
||||
"exec",
|
||||
c.node,
|
||||
"/usr/bin/curl",
|
||||
"-sSf",
|
||||
fmt.Sprintf("%s:%d/%s", c.url, c.port, c.health),
|
||||
)
|
||||
var out bytes.Buffer
|
||||
cmd.Stdout = &out
|
||||
err := cmd.Run()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
fmt.Printf("%v: %q\n", c, out.String())
|
||||
}(n)
|
||||
}
|
||||
wg.Wait()
|
||||
}
|
Loading…
Reference in New Issue
Block a user