Conf Oclib Package Lightest
This commit is contained in:
@@ -8,29 +8,30 @@ import (
|
||||
"net/http"
|
||||
"oc-schedulerd/conf"
|
||||
|
||||
oclib "cloud.o-forge.io/core/oc-lib"
|
||||
"github.com/rs/zerolog"
|
||||
)
|
||||
|
||||
type ContainerMonitor struct {
|
||||
Monitor LocalMonitor
|
||||
KubeCA string
|
||||
KubeCert string
|
||||
KubeData string
|
||||
KubeHost string
|
||||
KubePort string
|
||||
Monitor LocalMonitor
|
||||
KubeCA string
|
||||
KubeCert string
|
||||
KubeData string
|
||||
KubeHost string
|
||||
KubePort string
|
||||
}
|
||||
|
||||
func NewContainerMonitor(UUID string, peerId string, duration int) (Executor){
|
||||
func NewContainerMonitor(UUID string, peerId string, duration int) Executor {
|
||||
return &ContainerMonitor{
|
||||
Monitor: LocalMonitor{
|
||||
Monitor: LocalMonitor{
|
||||
ExecutionID: UUID,
|
||||
PeerID: peerId,
|
||||
Duration: duration,
|
||||
LokiUrl: conf.GetConfig().LokiUrl,
|
||||
MongoUrl: conf.GetConfig().MongoUrl,
|
||||
DBName: conf.GetConfig().DBName,
|
||||
PeerID: peerId,
|
||||
Duration: duration,
|
||||
LokiUrl: oclib.GetConfig().LokiUrl,
|
||||
MongoUrl: oclib.GetConfig().MongoUrl,
|
||||
DBName: oclib.GetConfig().MongoDatabase,
|
||||
},
|
||||
KubeCA: conf.GetConfig().KubeCA,
|
||||
KubeCA: conf.GetConfig().KubeCA,
|
||||
KubeCert: conf.GetConfig().KubeCert,
|
||||
KubeData: conf.GetConfig().KubeData,
|
||||
KubeHost: conf.GetConfig().KubeHost,
|
||||
@@ -38,7 +39,7 @@ func NewContainerMonitor(UUID string, peerId string, duration int) (Executor){
|
||||
}
|
||||
}
|
||||
|
||||
func (cm *ContainerMonitor) PrepareMonitorExec() []string {
|
||||
func (cm *ContainerMonitor) PrepareMonitorExec() []string {
|
||||
|
||||
args := []string{
|
||||
"-e", cm.Monitor.ExecutionID,
|
||||
@@ -49,7 +50,7 @@ func (cm *ContainerMonitor) PrepareMonitorExec() []string {
|
||||
"-M", "kubernetes",
|
||||
"-H", cm.KubeHost,
|
||||
"-P", cm.KubePort,
|
||||
"-C", cm.KubeCert,
|
||||
"-C", cm.KubeCert,
|
||||
"-D", cm.KubeData,
|
||||
"-c", cm.KubeCA,
|
||||
}
|
||||
@@ -58,8 +59,8 @@ func (cm *ContainerMonitor) PrepareMonitorExec() []string {
|
||||
args = append(args, "-t", fmt.Sprintf("%d", cm.Monitor.Duration))
|
||||
}
|
||||
|
||||
return args
|
||||
|
||||
return args
|
||||
|
||||
}
|
||||
|
||||
// Contact the docker's API at the KubeHost's URL to :
|
||||
@@ -67,8 +68,8 @@ func (cm *ContainerMonitor) PrepareMonitorExec() []string {
|
||||
// - Create the container
|
||||
// - Start the container
|
||||
func (cm *ContainerMonitor) LaunchMonitor(args []string, l zerolog.Logger) {
|
||||
|
||||
var containerID string
|
||||
|
||||
var containerID string
|
||||
imageName := "oc-monitord"
|
||||
url := "http://" + cm.KubeHost + ":2375"
|
||||
|
||||
@@ -81,15 +82,15 @@ func (cm *ContainerMonitor) LaunchMonitor(args []string, l zerolog.Logger) {
|
||||
d, _ := io.ReadAll(resp.Body)
|
||||
l.Fatal().Msg("Couldn't find the oc-monitord image : " + string(d))
|
||||
}
|
||||
|
||||
dataCreation := map[string]interface{}{"Image": imageName, "Cmd" : args}
|
||||
|
||||
dataCreation := map[string]interface{}{"Image": imageName, "Cmd": args}
|
||||
byteData, err := json.Marshal(dataCreation)
|
||||
if err != nil {
|
||||
l.Fatal().Msg("Error when contacting the creating request body : " + err.Error())
|
||||
}
|
||||
|
||||
r, _ := http.NewRequest("POST",url + "/containers/create", bytes.NewBuffer(byteData))
|
||||
r.Header.Add("Content-Type","application/json")
|
||||
|
||||
r, _ := http.NewRequest("POST", url+"/containers/create", bytes.NewBuffer(byteData))
|
||||
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())
|
||||
@@ -116,9 +117,9 @@ func (cm *ContainerMonitor) LaunchMonitor(args []string, l zerolog.Logger) {
|
||||
|
||||
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")
|
||||
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())
|
||||
@@ -129,7 +130,7 @@ func (cm *ContainerMonitor) LaunchMonitor(args []string, l zerolog.Logger) {
|
||||
return
|
||||
}
|
||||
|
||||
resp, err = http.Post( url + "/containers/" + containerID + "/start", "", nil)
|
||||
resp, err = http.Post(url+"/containers/"+containerID+"/start", "", nil)
|
||||
if err != nil {
|
||||
l.Fatal().Msg("Error when contacting the docker API on " + url + ": " + err.Error())
|
||||
}
|
||||
@@ -143,4 +144,4 @@ func (cm *ContainerMonitor) LaunchMonitor(args []string, l zerolog.Logger) {
|
||||
// we can add logging with GET /containers/id/logs?stdout=true&follow=true
|
||||
|
||||
// logExecution(stdoutMonitord, l)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user