@@ -132,7 +132,7 @@ func showBackupInfo(name string) {
132132 if ShowPVC {
133133 //print pvc information for all jobs
134134 for key , _ := range pvcMap {
135- displayPVC ( name , key )
135+ PrintPVCListing ( key )
136136 }
137137 }
138138}
@@ -298,121 +298,3 @@ type PodTemplateFields struct {
298298 BACKUP_ROOT string
299299 PVC_NAME string
300300}
301-
302- func displayPVC (name string , pvcName string ) {
303- var POD_PATH = viper .GetString ("PGO.LSPVC_TEMPLATE" )
304- var PodTemplate * template.Template
305- var err error
306- var buf []byte
307- var doc2 bytes.Buffer
308- var podName = "lspvc-" + name
309-
310- fmt .Println ("PVC " + pvcName + " contains..." )
311-
312- //delete lspvc pod if it was not deleted for any reason prior
313- _ , err = Clientset .Core ().Pods (Namespace ).Get (podName )
314- if errors .IsNotFound (err ) {
315- //
316- } else if err != nil {
317- log .Error (err .Error ())
318- } else {
319- log .Debug ("deleting prior pod " + podName )
320- err = Clientset .Core ().Pods (Namespace ).Delete (podName ,
321- & v1.DeleteOptions {})
322- if err != nil {
323- log .Error ("delete pod error " + err .Error ()) //TODO this is debug info
324- }
325- //sleep a bit for the pod to be deleted
326- time .Sleep (2000 * time .Millisecond )
327- }
328-
329- buf , err = ioutil .ReadFile (POD_PATH )
330- if err != nil {
331- log .Error ("error reading lspvc_template file" )
332- log .Error ("make sure it is specified in your .pgo.yaml config" )
333- log .Error (err .Error ())
334- return
335- }
336- PodTemplate = template .Must (template .New ("pod template" ).Parse (string (buf )))
337-
338- podFields := PodTemplateFields {
339- Name : podName ,
340- CO_IMAGE_TAG : viper .GetString ("PGO.CO_IMAGE_TAG" ),
341- BACKUP_ROOT : name + "-backups" ,
342- PVC_NAME : pvcName ,
343- }
344-
345- err = PodTemplate .Execute (& doc2 , podFields )
346- if err != nil {
347- log .Error (err .Error ())
348- return
349- }
350- podDocString := doc2 .String ()
351- log .Debug (podDocString )
352-
353- //template name is lspvc-pod.json
354- //create lspvc pod
355- newpod := v1.Pod {}
356- err = json .Unmarshal (doc2 .Bytes (), & newpod )
357- if err != nil {
358- log .Error ("error unmarshalling json into Pod " )
359- log .Error (err .Error ())
360- return
361- }
362- var resultPod * v1.Pod
363- resultPod , err = Clientset .Core ().Pods (Namespace ).Create (& newpod )
364- if err != nil {
365- log .Error ("error creating lspvc Pod " )
366- log .Error (err .Error ())
367- return
368- }
369- log .Debug ("created pod " + resultPod .Name )
370-
371- //sleep a bit for the pod to finish, replace later with watch or better
372- time .Sleep (3000 * time .Millisecond )
373-
374- //get lspvc pod output
375- logOptions := v1.PodLogOptions {}
376- req := Clientset .Core ().Pods (Namespace ).GetLogs (podName , & logOptions )
377- if req == nil {
378- log .Debug ("error in get logs for " + podName )
379- } else {
380- log .Debug ("got the logs for " + podName )
381- }
382-
383- readCloser , err := req .Stream ()
384- if err != nil {
385- log .Error (err .Error ())
386- return
387- }
388-
389- defer readCloser .Close ()
390- var buf2 bytes.Buffer
391- _ , err = io .Copy (& buf2 , readCloser )
392- log .Debugf ("backups are... \n %s" , buf2 .String ())
393-
394- log .Debug ("pvc=" + pvcName )
395- lines := strings .Split (buf2 .String (), "\n " )
396-
397- //chop off last line since its only a newline
398- last := len (lines ) - 1
399- newlines := make ([]string , last )
400- copy (newlines , lines [:last ])
401-
402- for k , v := range newlines {
403- if k == len (newlines )- 1 {
404- fmt .Printf ("%s%s\n " , TREE_TRUNK , name + "-backups/" + v )
405- } else {
406- fmt .Printf ("%s%s\n " , TREE_BRANCH , name + "-backups/" + v )
407- }
408- }
409-
410- //delete lspvc pod
411- err = Clientset .Core ().Pods (Namespace ).Delete (podName ,
412- & v1.DeleteOptions {})
413- if err != nil {
414- log .Error (err .Error ())
415- log .Error ("error deleting lspvc pod " + podName )
416- }
417-
418- }
0 commit comments