added template generation to argo builder
This commit is contained in:
parent
c79b693ba3
commit
6b6c54795c
@ -8,6 +8,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"slices"
|
"slices"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/beego/beego/v2/core/logs"
|
"github.com/beego/beego/v2/core/logs"
|
||||||
"gopkg.in/yaml.v3"
|
"gopkg.in/yaml.v3"
|
||||||
@ -28,21 +29,43 @@ type Workflow struct {
|
|||||||
func (b *ArgoBuilder) CreateDAG() bool {
|
func (b *ArgoBuilder) CreateDAG() bool {
|
||||||
fmt.Println("list of branches : ", b.branches)
|
fmt.Println("list of branches : ", b.branches)
|
||||||
|
|
||||||
|
b.createTemplates()
|
||||||
b.createDAGstep()
|
b.createDAGstep()
|
||||||
yamlified, err := yaml.Marshal(b.Workflow)
|
yamlified, err := yaml.Marshal(b.Workflow)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logs.Error("Could not transform object to yaml file")
|
logs.Error("Could not transform object to yaml file")
|
||||||
|
return false
|
||||||
}
|
}
|
||||||
fmt.Println(string(yamlified))
|
fmt.Println(string(yamlified))
|
||||||
err = os.WriteFile("argo.yml", []byte(yamlified), 0660)
|
err = os.WriteFile("argo.yml", []byte(yamlified), 0660)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logs.Error("Could not write the yaml file")
|
logs.Error("Could not write the yaml file")
|
||||||
|
return false
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (b *ArgoBuilder) createTemplates() {
|
||||||
|
|
||||||
|
for _, comp := range b.graph.Computings{
|
||||||
|
temp_container := Container{Image: comp.Name}
|
||||||
|
temp_container.Command = getComputingCommands(comp.Command)
|
||||||
|
temp_container.Args = getComputingArgs(comp.Arguments)
|
||||||
|
input_names := getComputingEnvironmentName(comp.Environment)
|
||||||
|
|
||||||
|
var inputs_container []Parameter
|
||||||
|
for _, name := range input_names {
|
||||||
|
inputs_container = append(inputs_container, Parameter{Name: name})
|
||||||
|
}
|
||||||
|
|
||||||
|
new_temp := Template{Name: comp.Name + "_" + comp.ID, Container: temp_container}
|
||||||
|
new_temp.Inputs.Parameters = inputs_container
|
||||||
|
b.Workflow.Templates = append(b.Workflow.Templates, new_temp)
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
func (b *ArgoBuilder) createDAGstep() {
|
func (b *ArgoBuilder) createDAGstep() {
|
||||||
|
|
||||||
@ -50,10 +73,13 @@ func (b *ArgoBuilder) createDAGstep() {
|
|||||||
|
|
||||||
for _, comp := range b.graph.Computings{
|
for _, comp := range b.graph.Computings{
|
||||||
unique_name := comp.Name + "_" + comp.ID
|
unique_name := comp.Name + "_" + comp.ID
|
||||||
var comp_params []Parameter
|
|
||||||
comp_params = append(comp_params, Parameter{"toto","titi"})
|
|
||||||
step := Task{Name: unique_name, Template: unique_name}
|
step := Task{Name: unique_name, Template: unique_name}
|
||||||
step.Arguments.Parameters = append(step.Arguments.Parameters, comp_params...)
|
|
||||||
|
comp_envs := getComputingEnvironment(comp.Environment)
|
||||||
|
for name, value := range comp_envs {
|
||||||
|
step.Arguments.Parameters = append(step.Arguments.Parameters, Parameter{Name: name, Value: value})
|
||||||
|
}
|
||||||
|
|
||||||
// For each branch, check if the computing has a dependency
|
// For each branch, check if the computing has a dependency
|
||||||
for _, branch := range b.branches {
|
for _, branch := range b.branches {
|
||||||
@ -118,4 +144,60 @@ func (b *ArgoBuilder) findPreviousComputing(computing_id string, branch []string
|
|||||||
|
|
||||||
}
|
}
|
||||||
return ""
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
func getComputingCommands(user_input string) (list_command []string) {
|
||||||
|
if len(user_input) == 0 {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
list_command = strings.Split(user_input, ",")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func getComputingArgs(user_input []string) (list_args []string) {
|
||||||
|
if len(user_input) == 0 {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
for _, arg := range user_input{
|
||||||
|
list_args = append(list_args, "'" + arg + "'")
|
||||||
|
}
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Currently implements code to overcome problems in data structure
|
||||||
|
func getComputingEnvironment(user_input []string) (map_env map[string]string) {
|
||||||
|
if len(user_input) == 0 {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if(len(user_input) == 1){
|
||||||
|
user_input = strings.Split(user_input[0],",")
|
||||||
|
}
|
||||||
|
|
||||||
|
map_env = make(map[string]string,0)
|
||||||
|
|
||||||
|
for _, str := range user_input {
|
||||||
|
new_pair := strings.Split(str,"=")
|
||||||
|
|
||||||
|
if(len(new_pair) != 2) {
|
||||||
|
logs.Error("Error extracting the environment variable from ", str)
|
||||||
|
panic(0)
|
||||||
|
}
|
||||||
|
|
||||||
|
map_env[new_pair[0]] = new_pair[1]
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func getComputingEnvironmentName(user_input []string) (list_names []string){
|
||||||
|
env_map := getComputingEnvironment(user_input)
|
||||||
|
for name, _ := range env_map {
|
||||||
|
list_names = append(list_names, name)
|
||||||
|
}
|
||||||
|
return
|
||||||
}
|
}
|
2
graph.go
2
graph.go
@ -266,7 +266,7 @@ func (g *Graph) ExportToArgo(id string) error {
|
|||||||
argo_builder := ArgoBuilder{graph : *g, branches: list_branches}
|
argo_builder := ArgoBuilder{graph : *g, branches: list_branches}
|
||||||
argo_builder.CreateDAG()
|
argo_builder.CreateDAG()
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return a list containing the IDs of each link that make up a branch in the graph
|
// Return a list containing the IDs of each link that make up a branch in the graph
|
||||||
|
@ -2,13 +2,13 @@ package main
|
|||||||
|
|
||||||
type Parameter struct {
|
type Parameter struct {
|
||||||
Name string `yaml:"name"`
|
Name string `yaml:"name"`
|
||||||
Value string `yaml:"value"`
|
Value string `yaml:"value,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type Container struct {
|
type Container struct {
|
||||||
Image string `yaml:"image"`
|
Image string `yaml:"image"`
|
||||||
Command []string `yaml:"command,omitempty"`
|
Command []string `yaml:"command,omitempty,flow"`
|
||||||
Args []string `yaml:"args,omitempty"`
|
Args []string `yaml:"args,omitempty,flow"`
|
||||||
VolumeMounts []VolumeMount `yaml:"volumeMounts,omitempty"`
|
VolumeMounts []VolumeMount `yaml:"volumeMounts,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user