full argo yaml, NEED TO BE TESTED

This commit is contained in:
pb 2024-05-07 19:45:20 +02:00
parent a4a8f8cb51
commit 567caf3b07
4 changed files with 90 additions and 8 deletions

View File

@ -11,6 +11,7 @@ import (
"strings" "strings"
"github.com/beego/beego/v2/core/logs" "github.com/beego/beego/v2/core/logs"
"github.com/nwtgck/go-fakelish"
"gopkg.in/yaml.v3" "gopkg.in/yaml.v3"
) )
@ -21,16 +22,33 @@ type ArgoBuilder struct {
} }
type Workflow struct { type Workflow struct {
Templates []Template `yaml:"templates"` ApiVersion string `yaml:"apiVersion"`
Kind string `yaml:"kind"`
Metadata struct {
GenerateName string `yaml:"generateName"`
} `yaml:"metadata"`
Spec Spec `yaml:"spec,omitempty"`
} }
type Spec struct {
Entrypoint string `yaml:"entrypoint"`
Arguments []Parameter `yaml:"arguments,omitempty"`
Volumes []VolumeClaimTemplate `yaml:"volumeClaimTemplates,omitempty"`
Templates []Template `yaml:"templates"`
}
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.createTemplates()
b.createDAGstep() b.createDAGstep()
b.createVolumes()
b.Workflow.Spec.Entrypoint = "dag"
b.Workflow.ApiVersion = "argoproj.io/v1alpha1"
b.Workflow.Kind = "Workflow"
b.Workflow.Metadata.GenerateName = "oc-test-" + generateName()
yamlified, err := yaml.Marshal(b.Workflow) yamlified, err := yaml.Marshal(b.Workflow)
if err != nil { if err != nil {
@ -61,7 +79,8 @@ func (b *ArgoBuilder) createTemplates() {
new_temp := Template{Name: comp.Name + "_" + comp.ID, Container: temp_container} new_temp := Template{Name: comp.Name + "_" + comp.ID, Container: temp_container}
new_temp.Inputs.Parameters = inputs_container new_temp.Inputs.Parameters = inputs_container
b.Workflow.Templates = append(b.Workflow.Templates, new_temp) 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)
} }
@ -94,11 +113,21 @@ func (b *ArgoBuilder) createDAGstep() {
} }
b.Workflow.Templates = append (b.Workflow.Templates, Template{Name: "dag", Dag: new_dag}) b.Workflow.Spec.Templates = append (b.Workflow.Spec.Templates, Template{Name: "dag", Dag: new_dag})
} }
func (b *ArgoBuilder) getDependency (current_computing_id string, branch []string) string { func (b *ArgoBuilder) createVolumes() {
// For testing purposes we only declare one volume, mounted in each computing
new_volume := VolumeClaimTemplate{}
new_volume.Metadata.Name = "workdir"
new_volume.Spec.AccessModes = []string{"ReadWriteOnce"}
new_volume.Spec.Resources.Requests.Storage = "1Gi"
b.Workflow.Spec.Volumes = append(b.Workflow.Spec.Volumes, new_volume)
}
func (b *ArgoBuilder) getDependency(current_computing_id string, branch []string) string {
for i := len(branch)-1; i >= 0 ; i-- { for i := len(branch)-1; i >= 0 ; i-- {
current_link := b.graph.Links[branch[i]] current_link := b.graph.Links[branch[i]]
@ -197,3 +226,36 @@ func getComputingEnvironmentName(user_input []string) (list_names []string){
return return
} }
func generateName() (Name string){
Name = fakelish.GenerateFakeWord(5, 8) + "-" + fakelish.GenerateFakeWord(5, 8)
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 printYAML(data interface{}) {
yamlData, err := yaml.Marshal(data)
if err != nil {
fmt.Printf("Error marshalling YAML: %v\n", err)
return
}
fmt.Println(string(yamlData))
}

3
go.mod
View File

@ -6,8 +6,8 @@ require (
cloud.o-forge.io/core/oc-catalog v0.0.0-20240416165405-9bd5be775813 cloud.o-forge.io/core/oc-catalog v0.0.0-20240416165405-9bd5be775813
github.com/beego/beego/v2 v2.2.0 github.com/beego/beego/v2 v2.2.0
github.com/goraz/onion v0.1.3 github.com/goraz/onion v0.1.3
github.com/nwtgck/go-fakelish v0.1.3
github.com/rs/zerolog v1.32.0 github.com/rs/zerolog v1.32.0
github.com/sbabiv/xml2map v1.2.1
github.com/tidwall/gjson v1.17.1 github.com/tidwall/gjson v1.17.1
gopkg.in/yaml.v3 v3.0.1 gopkg.in/yaml.v3 v3.0.1
) )
@ -35,6 +35,7 @@ require (
github.com/shiena/ansicolor v0.0.0-20200904210342-c7312218db18 // indirect github.com/shiena/ansicolor v0.0.0-20200904210342-c7312218db18 // indirect
github.com/tidwall/match v1.1.1 // indirect github.com/tidwall/match v1.1.1 // indirect
github.com/tidwall/pretty v1.2.0 // indirect github.com/tidwall/pretty v1.2.0 // indirect
github.com/ugorji/go/codec v1.1.7 // indirect
github.com/vk496/cron v1.2.0 // indirect github.com/vk496/cron v1.2.0 // indirect
github.com/xdg/scram v0.0.0-20180814205039-7eeb5667e42c // indirect github.com/xdg/scram v0.0.0-20180814205039-7eeb5667e42c // indirect
github.com/xdg/stringprep v0.0.0-20180714160509-73f8eece6fdc // indirect github.com/xdg/stringprep v0.0.0-20180714160509-73f8eece6fdc // indirect

View File

@ -1,7 +1,7 @@
package main package main
type Parameter struct { type Parameter struct {
Name string `yaml:"name"` Name string `yaml:"name,omitempty"`
Value string `yaml:"value,omitempty"` Value string `yaml:"value,omitempty"`
} }

19
volume_models.go Normal file
View File

@ -0,0 +1,19 @@
package main
type VolumeClaimTemplate struct {
Metadata struct {
Name string `yaml:"name"`
} `yaml:"metadata"`
Spec VolumeSpec `yaml:"spec"`
}
type VolumeSpec struct {
AccessModes []string `yaml:"accessModes,flow"`
Resources struct {
Requests struct {
Storage string `yaml:"storage"`
} `yaml:"requests"`
} `yaml:"resources"`
}