44 lines
1.2 KiB
Go
44 lines
1.2 KiB
Go
package models
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
|
|
"cloud.o-forge.io/core/oc-lib/models/resources"
|
|
)
|
|
|
|
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"`
|
|
}
|
|
|
|
type VolumeMount struct {
|
|
Name string `yaml:"name"`
|
|
MountPath string `yaml:"mountPath"`
|
|
Storage *resources.StorageResource `yaml:"-"`
|
|
}
|
|
|
|
func (v *VolumeMount) BindToArgo(workflow *Workflow) { // TODO : one think about remote volume but TG
|
|
index := 0
|
|
if v.Storage.SelectedInstanceIndex != nil && (*v.Storage.SelectedInstanceIndex) >= 0 {
|
|
index = *v.Storage.SelectedInstanceIndex
|
|
}
|
|
storage := v.Storage.Instances[index]
|
|
new_volume := VolumeClaimTemplate{}
|
|
new_volume.Metadata.Name = strings.ReplaceAll(strings.ToLower(v.Name), " ", "-")
|
|
new_volume.Spec.AccessModes = []string{"ReadWriteOnce"}
|
|
new_volume.Spec.Resources.Requests.Storage = fmt.Sprintf("%v", storage.SizeGB) + storage.SizeType.ToArgo()
|
|
workflow.Spec.Volumes = append(workflow.Spec.Volumes, new_volume)
|
|
}
|