added oc monitor cwd to conf for better handling of filesé
This commit is contained in:
		| @@ -9,6 +9,7 @@ type Config struct { | ||||
| 	OcCatalogUrl string | ||||
| 	MongoUrl     string | ||||
| 	Database     string | ||||
| 	MonitorDir	 string | ||||
| } | ||||
|  | ||||
| var instance *Config | ||||
|   | ||||
							
								
								
									
										19
									
								
								main.go
									
									
									
									
									
								
							
							
						
						
									
										19
									
								
								main.go
									
									
									
									
									
								
							| @@ -37,6 +37,7 @@ const defaultConfigFile = "/etc/oc/ocmonitor_conf.json" | ||||
| const localConfigFile = "./conf/ocmonitor_conf.json" | ||||
|  | ||||
| func main() { | ||||
|  | ||||
| 	monitorLocal = false | ||||
| 	// Test if monitor is launched outside (with parameters) or in a k8s environment (env variables sets)  | ||||
| 	if os.Getenv("KUBERNETES_SERVICE_HOST") == ""{ | ||||
| @@ -54,19 +55,24 @@ func main() { | ||||
| 	logs.SetAppName("oc-monitor") | ||||
| 	logger = logs.CreateLogger("oc-monitor", conf.GetConfig().LokiURL) | ||||
| 	 | ||||
| 	 | ||||
| 	logger.Debug().Msg("Loki URL : " + conf.GetConfig().LokiURL) | ||||
| 	logger.Debug().Msg("Workflow executed : " + conf.GetConfig().ExecutionID) | ||||
| 	 | ||||
| 	oclib.SetConfig(conf.GetConfig().MongoUrl,conf.GetConfig().Database) | ||||
| 	oclib.Init("oc-monitor") | ||||
|  | ||||
|  | ||||
|  | ||||
|  | ||||
|  | ||||
| 	wf_id := getWorkflowId(conf.GetConfig().ExecutionID) | ||||
| 	conf.GetConfig().WorkflowID = wf_id | ||||
|  | ||||
| 	logger.Debug().Msg("Starting construction of yaml argo for workflow :" + wf_id) | ||||
|  | ||||
| 	if _, err := os.Stat("./argo_workflows/"); os.IsNotExist(err) { | ||||
| 		os.Mkdir("./argo_workflows/",0755) | ||||
| 	if _, err := os.Stat(conf.GetConfig().MonitorDir + "/argo_workflows/"); os.IsNotExist(err) { | ||||
| 		os.Mkdir(conf.GetConfig().MonitorDir + "/argo_workflows/",0755) | ||||
| 		logger.Info().Msg("Created argo_workflows/") | ||||
| 	} | ||||
|  | ||||
| @@ -115,7 +121,7 @@ func executeWorkflow(argo_file_path string) { | ||||
| 	// var stderr 	io.ReadCloser | ||||
| 	var err error | ||||
|  | ||||
| 	cmd := exec.Command("argo", "submit", "--watch", "argo_workflows/"+argo_file_path, "--serviceaccount=argo", "-n","argo") | ||||
| 	cmd := exec.Command("argo", "submit", "--watch", conf.GetConfig().MonitorDir + "/argo_workflows/"+argo_file_path, "--serviceaccount=argo", "-n","argo") | ||||
| 	if stdout, err = cmd.StdoutPipe(); err != nil{ | ||||
| 		wf_logger.Error().Msg("Could not retrieve stdoutpipe " + err.Error()) | ||||
| 		return | ||||
| @@ -221,8 +227,13 @@ func loadConfig(is_k8s bool, parser *argparse.Parser){ | ||||
| 	 | ||||
| 	o = initOnion(o) | ||||
|  | ||||
| 	conf.GetConfig().OcCatalogUrl = o.GetStringDefault("oc-catalog","https://localhost:8087") | ||||
| 	current_path, err := os.Getwd() | ||||
| 	if err != nil { | ||||
| 		logger.Error().Msg("Could not get the working directory path") | ||||
| 	} | ||||
|  | ||||
| 	conf.GetConfig().OcCatalogUrl = o.GetStringDefault("oc-catalog","https://localhost:8087") | ||||
| 	conf.GetConfig().MonitorDir = current_path	 | ||||
|  | ||||
| 	// These variables can only be retrieved in the onion | ||||
| 	// Variables that don't depend on the environmen (from conf file), can be loaded after | ||||
|   | ||||
| @@ -6,6 +6,7 @@ package workflow_builder | ||||
|  | ||||
| import ( | ||||
| 	"fmt" | ||||
| 	"oc-monitor/conf" | ||||
| 	"oc-monitor/logger" | ||||
| 	. "oc-monitor/models" | ||||
| 	"os" | ||||
| @@ -40,7 +41,7 @@ type Spec struct { | ||||
| } | ||||
|  | ||||
| func (b *ArgoBuilder) CreateDAG() (string, error) { | ||||
|  | ||||
| 	 | ||||
| 	b.createTemplates() | ||||
| 	b.createDAGstep() | ||||
| 	b.createVolumes() | ||||
| @@ -60,7 +61,7 @@ func (b *ArgoBuilder) CreateDAG() (string, error) { | ||||
| 	// Give a unique name to each argo file with its timestamp DD:MM:YYYY_hhmmss | ||||
| 	current_timestamp := time.Now().Format("02_01_2006_150405") | ||||
| 	file_name := random_name + "_" + current_timestamp + ".yml" | ||||
| 	workflows_dir := "argo_workflows/" | ||||
| 	workflows_dir := conf.GetConfig().MonitorDir+"/argo_workflows/" | ||||
| 	err = os.WriteFile(workflows_dir+file_name, []byte(yamlified), 0660) | ||||
| 	if err != nil { | ||||
| 		logger.Logger.Error().Msg("Could not write the yaml file") | ||||
|   | ||||
		Reference in New Issue
	
	Block a user