Browse Source

lingering changes

Signed-off-by: Derek McQuay <derekmcquay@gmail.com>
Derek McQuay 11 months ago
parent
commit
0ff0a31567
No known key found for this signature in database
1 changed files with 86 additions and 38 deletions
  1. 86
    38
      main.go

+ 86
- 38
main.go View File

@@ -6,8 +6,9 @@ import (
6 6
 	"fmt"
7 7
 	"log"
8 8
 	"os/exec"
9
+	"regexp"
10
+	"strconv"
9 11
 	"strings"
10
-	"sync"
11 12
 
12 13
 	"github.com/fatih/color"
13 14
 )
@@ -73,11 +74,11 @@ func getServiceIPs() []serviceIPs {
73 74
 	}
74 75
 
75 76
 	// get rid of kubernetes pod
76
-	for i, n := range s {
77
-		if n.Name == "kubernetes" {
78
-			s = append(s[:i], s[i+1:]...)
79
-		}
80
-	}
77
+	//for i, n := range s {
78
+	//	if n.Name == "kubernetes" {
79
+	//		s = append(s[:i], s[i+1:]...)
80
+	//	}
81
+	//}
81 82
 	return s
82 83
 }
83 84
 
@@ -102,53 +103,100 @@ func stripHealthCheck(n string, hcs healthCheck) string {
102 103
 	return ""
103 104
 }
104 105
 
106
+func getPodInstanceIndex(n string) (int, error) {
107
+	re := regexp.MustCompile("[0-9]")
108
+	index := re.FindString(n)
109
+	i, err := strconv.Atoi(index)
110
+	return i, err
111
+}
112
+
105 113
 func buildCommands(hcs healthCheck, ips []serviceIPs) []command {
106 114
 	commands := []command{}
107 115
 	for _, s := range ips {
108
-		if strings.Contains(s.Name, "apiserver") || strings.Contains(s.Name, "etcd") {
109
-			ip := s.Statuses[0].ContainerStatus.NetworkInfos[0].IPAddresses[0].IPAddress
110
-			c := strings.Replace(stripHealthCheck(s.Name, hcs), "$LIBPROCESS_IP", ip, -1)
116
+		if strings.Contains(s.Name, "apiserver") {
117
+			index, err := getPodInstanceIndex(s.Name)
118
+			if err != nil {
119
+				log.Fatal("failed to get pod index for build command: ", err)
120
+			}
121
+			c := strings.Replace(stripHealthCheck(s.Name, hcs), "$POD_INSTANCE_INDEX", strconv.Itoa(index), -1)
122
+			commands = append(commands, command{node: s.Name, hc: c})
123
+		} else if strings.Contains(s.Name, "etcd") {
124
+			index, err := getPodInstanceIndex(s.Name)
125
+			if err != nil {
126
+				log.Fatal("failed to get pod index for build command: ", err)
127
+			}
128
+			c := strings.Replace(stripHealthCheck(s.Name, hcs), "$POD_INSTANCE_INDEX", strconv.Itoa(index), -1)
129
+			c = strings.Replace(c, "$ETCD_LISTEN_CLIENT_PORT", "2379", -1)
111 130
 			commands = append(commands, command{node: s.Name, hc: c})
131
+			//https://etcd-$POD_INSTANCE_INDEX-peer.{{FRAMEWORK_NAME}}.mesos:$ETCD_LISTEN_CLIENT_PORT/health
112 132
 		} else {
113
-			commands = append(commands, command{node: s.Name, hc: stripHealthCheck(s.Name, hcs)})
133
+			//commands = append(commands, command{node: s.Name, hc: stripHealthCheck(s.Name, hcs)})
114 134
 		}
115 135
 	}
116
-	fmt.Println(commands)
117 136
 	return commands
118 137
 }
119 138
 
120 139
 func main() {
121
-	var wg sync.WaitGroup
140
+	//var wg sync.WaitGroup
122 141
 	hcs := getHealthCheck()
123 142
 	ips := getServiceIPs()
143
+	//for _, i := range hcs.PodSpecs {
144
+	//	fmt.Println(i)
145
+	//}
146
+	//fmt.Println("\n\n\n")
147
+	//fmt.Printf("%+v\n", hcs)
148
+	//fmt.Println("\n\n\n")
149
+	//fmt.Printf("%+v\n", ips)
150
+	//fmt.Println("\n\n\n")
124 151
 	hosts := buildCommands(hcs, ips)
152
+	//for i, j := range hosts {
153
+	//	fmt.Printf("%d %+v\n", i, j)
154
+	//}
155
+	//fmt.Println(hosts)
156
+	//time.Sleep(time.Second * 5)
125 157
 
126 158
 	for _, n := range hosts {
127
-		wg.Add(1)
128
-		go func(c command) {
129
-			defer wg.Done()
130
-			s := strings.Split(c.hc, " ")
131
-			cmd := exec.Command(
132
-				"dcos",
133
-				"task",
134
-				"exec",
135
-				c.node,
136
-				s[0],
137
-				s[1],
138
-				s[2],
139
-			)
140
-			var out bytes.Buffer
141
-			cmd.Stdout = &out
142
-			err := cmd.Run()
143
-			if err != nil {
144
-				log.Fatal(err)
145
-			}
146
-			if strings.Contains(out.String(), "ok") || strings.Contains(out.String(), "true") {
147
-				color.Green(fmt.Sprintf("%v: %q\n", c, out.String()))
148
-			} else {
149
-				color.Red(fmt.Sprintf("%v: %q\n", c, out.String()))
150
-			}
151
-		}(n)
159
+		//wg.Add(1)
160
+		//go func(c command) {
161
+		//defer wg.Done()
162
+		//	s := strings.Split(n.hc, " ")
163
+		//if len(s) != 3 {
164
+		//	log.Printf("could not be split: %v", s)
165
+		//	return
166
+		//}
167
+		//for i, j := range s {
168
+		//	fmt.Println(i, j)
169
+		//}
170
+		cmd := exec.Command(
171
+			"dcos",
172
+			"task",
173
+			"exec",
174
+			n.node,
175
+			n.hc,
176
+			//s[0],
177
+			//s[1],
178
+			//s[2],
179
+			//s[3],
180
+			//s[4],
181
+			//s[5],
182
+			//s[6],
183
+			//s[7],
184
+			//s[8],
185
+		)
186
+		var out bytes.Buffer
187
+		cmd.Stdout = &out
188
+		err := cmd.Run()
189
+		if err != nil {
190
+			log.Printf("failed for %v with:", n, err)
191
+			return
192
+		}
193
+
194
+		if strings.Contains(out.String(), "ok") || strings.Contains(out.String(), "true") {
195
+			color.Green("%s", n.node)
196
+		} else {
197
+			color.Red(fmt.Sprintf("%s: \t%q\n", n.node, out.String()))
198
+		}
199
+		//}(n)
152 200
 	}
153
-	wg.Wait()
201
+	//	wg.Wait()
154 202
 }

Loading…
Cancel
Save