@@ -39,29 +39,12 @@ func New(ctx context.Context, cloud common.Cloud, identifier common.Identifier,
3939 return nil , err
4040 }
4141
42- persistentVolumeClaimStorageClass := ""
43- persistentVolumeClaimSize := task .Size .Storage
44- persistentVolumeDirectory := task .Environment .Directory
45-
46- match := regexp .MustCompile (`^([^:]+):(?:(\d+):)?(.+)$` ).FindStringSubmatch (task .Environment .Directory )
47- if match != nil {
48- persistentVolumeClaimStorageClass = match [1 ]
49- if match [2 ] != "" {
50- number , err := strconv .Atoi (match [2 ])
51- if err != nil {
52- return nil , err
53- }
54- persistentVolumeClaimSize = int (number )
55- }
56- persistentVolumeDirectory = match [3 ]
57- }
58-
5942 t := new (Task )
6043 t .Client = client
6144 t .Identifier = identifier
6245 t .Attributes .Task = task
63- t .Attributes .Directory = persistentVolumeDirectory
64- t .Attributes .DirectoryOut = persistentVolumeDirectory
46+ t .Attributes .Directory = task . Environment . Directory
47+ t .Attributes .DirectoryOut = task . Environment . Directory
6548 if task .Environment .DirectoryOut != "" {
6649 t .Attributes .DirectoryOut = task .Environment .DirectoryOut
6750 }
@@ -75,17 +58,43 @@ func New(ctx context.Context, cloud common.Cloud, identifier common.Identifier,
7558 t .Identifier ,
7659 map [string ]string {"script" : t .Attributes .Task .Environment .Script },
7760 )
78- t .Resources .PersistentVolumeClaim = resources .NewPersistentVolumeClaim (
79- t .Client ,
80- t .Identifier ,
81- persistentVolumeClaimStorageClass ,
82- persistentVolumeClaimSize ,
83- t .Attributes .Task .Parallelism > 1 ,
84- )
61+ var pvc resources.VolumeInfoProvider
62+ if task .RemoteStorage != nil {
63+ t .DataSources .ExistingPersistentVolumeClaim = resources .NewExistingPersistentVolumeClaim (
64+ t .Client , * task .RemoteStorage )
65+ pvc = t .DataSources .ExistingPersistentVolumeClaim
66+ } else {
67+ var persistentVolumeDirectory string
68+ var persistentVolumeClaimStorageClass string
69+ persistentVolumeClaimSize := task .Size .Storage
70+
71+ match := regexp .MustCompile (`^([^:]+):(?:(\d+):)?(.+)$` ).FindStringSubmatch (task .Environment .Directory )
72+ if match != nil {
73+ persistentVolumeClaimStorageClass = match [1 ]
74+ if match [2 ] != "" {
75+ number , err := strconv .Atoi (match [2 ])
76+ if err != nil {
77+ return nil , err
78+ }
79+ persistentVolumeClaimSize = int (number )
80+ }
81+ persistentVolumeDirectory = match [3 ]
82+ t .Attributes .Directory = persistentVolumeDirectory
83+ }
84+
85+ t .Resources .PersistentVolumeClaim = resources .NewPersistentVolumeClaim (
86+ t .Client ,
87+ t .Identifier ,
88+ persistentVolumeClaimStorageClass ,
89+ persistentVolumeClaimSize ,
90+ t .Attributes .Task .Parallelism > 1 ,
91+ )
92+ pvc = t .Resources .PersistentVolumeClaim
93+ }
8594 t .Resources .Job = resources .NewJob (
8695 t .Client ,
8796 t .Identifier ,
88- t . Resources . PersistentVolumeClaim ,
97+ pvc ,
8998 t .Resources .ConfigMap ,
9099 t .DataSources .PermissionSet ,
91100 t .Attributes .Task ,
@@ -102,12 +111,13 @@ type Task struct {
102111 DirectoryOut string
103112 }
104113 DataSources struct {
105- * resources.PermissionSet
114+ PermissionSet * resources.PermissionSet
115+ ExistingPersistentVolumeClaim * resources.ExistingPersistentVolumeClaim
106116 }
107117 Resources struct {
108- * resources.ConfigMap
109- * resources.PersistentVolumeClaim
110- * resources.Job
118+ ConfigMap * resources.ConfigMap
119+ PersistentVolumeClaim * resources.PersistentVolumeClaim
120+ Job * resources.Job
111121 }
112122}
113123
@@ -119,10 +129,13 @@ func (t *Task) Create(ctx context.Context) error {
119129 }, {
120130 Description : "Creating ConfigMap..." ,
121131 Action : t .Resources .ConfigMap .Create ,
122- }, {
123- Description : "Creating PersistentVolumeClaim..." ,
124- Action : t .Resources .PersistentVolumeClaim .Create ,
125132 }}
133+ if t .Resources .PersistentVolumeClaim != nil {
134+ steps = append (steps , common.Step {
135+ Description : "Creating PersistentVolumeClaim..." ,
136+ Action : t .Resources .PersistentVolumeClaim .Create ,
137+ })
138+ }
126139
127140 if t .Attributes .Directory != "" {
128141 env := map [string ]string {
@@ -166,7 +179,14 @@ func (t *Task) Read(ctx context.Context) error {
166179 Action : t .Resources .ConfigMap .Read ,
167180 }, {
168181 Description : "Reading PersistentVolumeClaim..." ,
169- Action : t .Resources .PersistentVolumeClaim .Read ,
182+ Action : func (ctx context.Context ) error {
183+ if t .Resources .PersistentVolumeClaim != nil {
184+ return t .Resources .PersistentVolumeClaim .Read (ctx )
185+ } else if t .DataSources .ExistingPersistentVolumeClaim != nil {
186+ return t .DataSources .ExistingPersistentVolumeClaim .Read (ctx )
187+ }
188+ return fmt .Errorf ("misconfigured storage" )
189+ },
170190 }, {
171191 Description : "Reading Job..." ,
172192 Action : t .Resources .Job .Read ,
@@ -211,13 +231,17 @@ func (t *Task) Delete(ctx context.Context) error {
211231 steps = append (steps , []common.Step {{
212232 Description : "Deleting Job..." ,
213233 Action : t .Resources .Job .Delete ,
214- }, {
215- Description : "Deleting PersistentVolumeClaim..." ,
216- Action : t .Resources .PersistentVolumeClaim .Delete ,
217234 }, {
218235 Description : "Deleting ConfigMap..." ,
219236 Action : t .Resources .ConfigMap .Delete ,
220237 }}... )
238+ if t .Resources .PersistentVolumeClaim != nil {
239+ steps = append (steps , common.Step {
240+ Description : "Deleting PersistentVolumeClaim..." ,
241+ Action : t .Resources .PersistentVolumeClaim .Delete ,
242+ })
243+ }
244+
221245 if err := common .RunSteps (ctx , steps ); err != nil {
222246 return err
223247 }
0 commit comments