added a step to connect the monitord container to the 'oc' network
This commit is contained in:
parent
6c3a20999b
commit
1b21c142f1
@ -70,11 +70,11 @@ func (cm *ContainerMonitor) LaunchMonitor(args []string, l zerolog.Logger) {
|
|||||||
|
|
||||||
var containerID string
|
var containerID string
|
||||||
imageName := "oc-monitord"
|
imageName := "oc-monitord"
|
||||||
url := "http://" + conf.GetConfig().KubeHost + ":2375"
|
url := "http://" + cm.KubeHost + ":2375"
|
||||||
|
|
||||||
resp, err := http.Get(url + "/images/" + imageName + "/json")
|
resp, err := http.Get(url + "/images/" + imageName + "/json")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
l.Fatal().Msg("Error when contacting the docker API on " + conf.GetConfig().KubeHost + ": " + err.Error())
|
l.Fatal().Msg("Error when contacting the docker API on " + url + ": " + err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
if resp.StatusCode != http.StatusOK {
|
if resp.StatusCode != http.StatusOK {
|
||||||
@ -92,7 +92,7 @@ func (cm *ContainerMonitor) LaunchMonitor(args []string, l zerolog.Logger) {
|
|||||||
r.Header.Add("Content-Type","application/json")
|
r.Header.Add("Content-Type","application/json")
|
||||||
resp, err = http.DefaultClient.Do(r)
|
resp, err = http.DefaultClient.Do(r)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
l.Fatal().Msg("Error when contacting the docker API on " + conf.GetConfig().KubeHost + ": " + err.Error())
|
l.Fatal().Msg("Error when contacting the docker API on " + url + ": " + err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
if resp.StatusCode == 201 {
|
if resp.StatusCode == 201 {
|
||||||
@ -111,18 +111,32 @@ func (cm *ContainerMonitor) LaunchMonitor(args []string, l zerolog.Logger) {
|
|||||||
containerID = d["Id"].(string)
|
containerID = d["Id"].(string)
|
||||||
} else {
|
} else {
|
||||||
d, _ := io.ReadAll(resp.Body)
|
d, _ := io.ReadAll(resp.Body)
|
||||||
l.Fatal().Msg("Error when creating the container on " + conf.GetConfig().KubeHost + "\n " + string(d))
|
l.Fatal().Msg("Error when creating the container on " + url + "\n " + string(d))
|
||||||
|
}
|
||||||
|
|
||||||
|
networkName := "oc"
|
||||||
|
|
||||||
|
dataNetwork, _ := json.Marshal(map[string]string{"Container" : containerID})
|
||||||
|
r, _ = http.NewRequest("POST",url + "/networks/" + networkName + "/connect", bytes.NewBuffer(dataNetwork))
|
||||||
|
r.Header.Add("Content-Type","application/json")
|
||||||
|
resp, err = http.DefaultClient.Do(r)
|
||||||
|
if err != nil {
|
||||||
|
l.Fatal().Msg("Error when contacting the docker API on " + url + ": " + err.Error())
|
||||||
|
}
|
||||||
|
if resp.StatusCode != 200 {
|
||||||
|
d, _ := io.ReadAll(resp.Body)
|
||||||
|
l.Error().Msg("Error when adding container to the network : " + string(d))
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
resp, err = http.Post( url + "/containers/" + containerID + "/start", "", nil)
|
resp, err = http.Post( url + "/containers/" + containerID + "/start", "", nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
l.Fatal().Msg("Error when contacting the docker API on " + conf.GetConfig().KubeHost + ": " + err.Error())
|
l.Fatal().Msg("Error when contacting the docker API on " + url + ": " + err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
if resp.StatusCode >= 300 {
|
if resp.StatusCode >= 300 {
|
||||||
d, _ := io.ReadAll(resp.Body)
|
d, _ := io.ReadAll(resp.Body)
|
||||||
l.Fatal().Msg("Error when starting the container on " + conf.GetConfig().KubeHost + "\n " + string(d))
|
l.Fatal().Msg("Error when starting the container on " + url + "\n " + string(d))
|
||||||
}
|
}
|
||||||
|
|
||||||
l.Info().Msg("Started container " + containerID)
|
l.Info().Msg("Started container " + containerID)
|
||||||
|
13
main.go
13
main.go
@ -27,12 +27,15 @@ func main() {
|
|||||||
conf.GetConfig().NatsUrl = c.NATSUrl
|
conf.GetConfig().NatsUrl = c.NATSUrl
|
||||||
conf.GetConfig().LokiUrl = c.LokiUrl
|
conf.GetConfig().LokiUrl = c.LokiUrl
|
||||||
conf.GetConfig().Mode = o.GetStringDefault("MODE", "")
|
conf.GetConfig().Mode = o.GetStringDefault("MODE", "")
|
||||||
conf.GetConfig().KubeHost = o.GetStringDefault("KUBERNETES_SERVICE_HOST", "")
|
|
||||||
conf.GetConfig().KubePort = o.GetStringDefault("KUBERNETES_SERVICE_PORT", "6443")
|
|
||||||
|
|
||||||
conf.GetConfig().KubeCA = o.GetStringDefault("KUBE_CA", "")
|
if conf.GetConfig().Mode == "container"{
|
||||||
conf.GetConfig().KubeCert = o.GetStringDefault("KUBE_CERT", "")
|
conf.GetConfig().KubeHost = o.GetStringDefault("KUBERNETES_SERVICE_HOST", "")
|
||||||
conf.GetConfig().KubeData = o.GetStringDefault("KUBE_DATA", "")
|
conf.GetConfig().KubePort = o.GetStringDefault("KUBERNETES_SERVICE_PORT", "6443")
|
||||||
|
|
||||||
|
conf.GetConfig().KubeCA = o.GetStringDefault("KUBE_CA", "")
|
||||||
|
conf.GetConfig().KubeCert = o.GetStringDefault("KUBE_CERT", "")
|
||||||
|
conf.GetConfig().KubeData = o.GetStringDefault("KUBE_DATA", "")
|
||||||
|
}
|
||||||
|
|
||||||
// Test if oc-monitor binary is reachable
|
// Test if oc-monitor binary is reachable
|
||||||
// For local executions
|
// For local executions
|
||||||
|
Loading…
Reference in New Issue
Block a user