full argo yaml, NEED TO BE TESTED
This commit is contained in:
@@ -11,6 +11,7 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/beego/beego/v2/core/logs"
|
||||
"github.com/nwtgck/go-fakelish"
|
||||
"gopkg.in/yaml.v3"
|
||||
)
|
||||
|
||||
@@ -21,16 +22,33 @@ type ArgoBuilder 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 {
|
||||
fmt.Println("list of branches : ", b.branches)
|
||||
|
||||
b.createTemplates()
|
||||
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)
|
||||
|
||||
if err != nil {
|
||||
@@ -39,7 +57,7 @@ func (b *ArgoBuilder) CreateDAG() bool {
|
||||
}
|
||||
fmt.Println(string(yamlified))
|
||||
err = os.WriteFile("argo.yml", []byte(yamlified), 0660)
|
||||
if err != nil {
|
||||
if err != nil {
|
||||
logs.Error("Could not write the yaml file")
|
||||
return false
|
||||
}
|
||||
@@ -61,7 +79,8 @@ func (b *ArgoBuilder) createTemplates() {
|
||||
|
||||
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)
|
||||
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-- {
|
||||
current_link := b.graph.Links[branch[i]]
|
||||
@@ -196,4 +225,37 @@ func getComputingEnvironmentName(user_input []string) (list_names []string){
|
||||
}
|
||||
|
||||
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))
|
||||
}
|
||||
Reference in New Issue
Block a user