succesfully create a working argo worflow for alpr
This commit is contained in:
@@ -67,17 +67,19 @@ func (b *ArgoBuilder) CreateDAG() bool {
|
||||
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)
|
||||
image_name := strings.Split(comp.Command," ")[0]
|
||||
temp_container := Container{Image: image_name} // TODO : edit computing model to store the container name:version
|
||||
temp_container.Command = getComputingCommands(comp.Command)
|
||||
temp_container.Args = getComputingArgs(comp.Arguments,comp.Command)
|
||||
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}
|
||||
|
||||
argo_name := getArgoName(comp.Name,comp.ID)
|
||||
new_temp := Template{Name: argo_name, Container: temp_container}
|
||||
new_temp.Inputs.Parameters = inputs_container
|
||||
new_temp.Container.VolumeMounts = append(new_temp.Container.VolumeMounts, VolumeMount{Name: "workdir",MountPath: "/mnt/vol"}) // TODO : replace this with a search of the storage / data source name
|
||||
b.Workflow.Spec.Templates = append(b.Workflow.Spec.Templates, new_temp)
|
||||
@@ -91,7 +93,7 @@ func (b *ArgoBuilder) createDAGstep() {
|
||||
new_dag := Dag{}
|
||||
|
||||
for _, comp := range b.graph.Computings{
|
||||
unique_name := comp.Name + "_" + comp.ID
|
||||
unique_name := getArgoName(comp.Name,comp.ID)
|
||||
step := Task{Name: unique_name, Template: unique_name}
|
||||
comp_envs := getComputingEnvironment(comp.Environment)
|
||||
|
||||
@@ -102,7 +104,7 @@ func (b *ArgoBuilder) createDAGstep() {
|
||||
// For each branch, check if the computing has a dependency
|
||||
for _, branch := range b.branches {
|
||||
if b.componentInBranch(comp.ID,branch) {
|
||||
// retrieves the name (computing.name_computing.ID)
|
||||
// retrieves the name (computing.name-computing.ID)
|
||||
dependency := b.getDependency(comp.ID,branch)
|
||||
if dependency != "" && !slices.Contains(step.Dependencies,dependency) {
|
||||
step.Dependencies = append(step.Dependencies,dependency)
|
||||
@@ -160,11 +162,11 @@ func (b *ArgoBuilder) findPreviousComputing(computing_id string, branch []string
|
||||
previousLink := b.graph.Links[branch[i]]
|
||||
|
||||
if previousLink.Source != computing_id && b.graph.getComponentType(previousLink.Source) == "computing"{
|
||||
name := b.graph.getComponentName(previousLink.Source) + "_" + previousLink.Source
|
||||
name := getArgoName(b.graph.getComponentName(previousLink.Source),previousLink.Source)
|
||||
return name
|
||||
}
|
||||
if previousLink.Destination != computing_id && b.graph.getComponentType(previousLink.Destination) == "computing"{
|
||||
name := b.graph.getComponentName(previousLink.Destination) + "_" + previousLink.Destination
|
||||
name := getArgoName(b.graph.getComponentName(previousLink.Destination),previousLink.Destination)
|
||||
return name
|
||||
}
|
||||
|
||||
@@ -173,21 +175,32 @@ func (b *ArgoBuilder) findPreviousComputing(computing_id string, branch []string
|
||||
}
|
||||
|
||||
func getComputingCommands(user_input string) (list_command []string) {
|
||||
user_input = removeImageName(user_input)
|
||||
if len(user_input) == 0 {
|
||||
return
|
||||
}
|
||||
|
||||
list_command = strings.Split(user_input, ",")
|
||||
|
||||
list_command = strings.Split(user_input, " ")
|
||||
for i := range list_command {
|
||||
list_command[i] = list_command[i]
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func getComputingArgs(user_input []string) (list_args []string) {
|
||||
func getComputingArgs(user_input []string, command string) (list_args []string) {
|
||||
if len(user_input) == 0 {
|
||||
return
|
||||
}
|
||||
|
||||
// quickfix that might need improvement
|
||||
if(strings.Contains(command,"sh -c")){
|
||||
list_args = append(list_args, strings.Join(user_input," "))
|
||||
return
|
||||
}
|
||||
|
||||
for _, arg := range user_input{
|
||||
list_args = append(list_args, "'" + arg + "'")
|
||||
list_args = append(list_args, arg)
|
||||
}
|
||||
|
||||
return
|
||||
@@ -232,23 +245,11 @@ func generateName() (Name string){
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
func testDoubleIndent(w Workflow) {
|
||||
for _, temp := range w.Spec.Templates{
|
||||
if temp.Name == "dag" {
|
||||
tasks := temp.Dag.Tasks
|
||||
fmt.Println("name")
|
||||
printYAML(tasks[0].Name)
|
||||
fmt.Println("template")
|
||||
printYAML(tasks[0].Template)
|
||||
fmt.Println("dependencies")
|
||||
printYAML(tasks[0].Dependencies)
|
||||
fmt.Println("arguments")
|
||||
printYAML(tasks[0].Arguments)
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
func getArgoName(raw_name string, component_id string) (formatedName string){
|
||||
formatedName = strings.ReplaceAll(raw_name," ","-")
|
||||
formatedName += "-" + component_id
|
||||
formatedName = strings.ToLower(formatedName)
|
||||
return
|
||||
}
|
||||
|
||||
func printYAML(data interface{}) {
|
||||
@@ -258,4 +259,17 @@ func printYAML(data interface{}) {
|
||||
return
|
||||
}
|
||||
fmt.Println(string(yamlData))
|
||||
}
|
||||
|
||||
func removeImageName(user_input string) string {
|
||||
// First command is the name of the container for now
|
||||
if len(strings.Split(user_input, " ")) == 1 {
|
||||
return ""
|
||||
}
|
||||
|
||||
slice_input := strings.Split(user_input, " ")
|
||||
new_slice := slice_input[1:]
|
||||
user_input = strings.Join(new_slice," ")
|
||||
|
||||
return user_input
|
||||
}
|
||||
Reference in New Issue
Block a user