File tree 2 files changed +53
-0
lines changed
2 files changed +53
-0
lines changed Original file line number Diff line number Diff line change @@ -9,6 +9,7 @@ module Actions
9
9
TailLogsSingleContainer ,
10
10
TailLogsAllContainers ,
11
11
ForwardPort ,
12
+ DownloadFile ,
12
13
RestartDeployment ,
13
14
DestroyNamespace
14
15
] . freeze
Original file line number Diff line number Diff line change
1
+ # frozen_string_literal: true
2
+
3
+ module Turbulence
4
+ module GCloud
5
+ module Actions
6
+ # Access a command line / console for a container
7
+ class DownloadFile
8
+ ID = :download_file
9
+ NAME = 'Download a file from a Pod to your computer'
10
+
11
+ include ActionResources
12
+
13
+ def run
14
+ project
15
+ cluster
16
+ namespace
17
+ pod
18
+ container
19
+ remote_file_name
20
+ download_destination
21
+
22
+ PROMPT . ok ( "\n Connecting...\n " )
23
+ download && \
24
+ PROMPT . ok ( "\n The file is now in the Downloads folder of your Turbulence installation." )
25
+ end
26
+
27
+ private
28
+
29
+ def remote_file_name
30
+ return @remote_file_name if defined? ( @remote_file_name )
31
+
32
+ remote_file = PROMPT . ask ( 'Full path and filename of remote file: (e.g. /tmp/my-file)' , required : true )
33
+
34
+ @remote_file_path = File . dirname ( remote_file )
35
+ @remote_file_name = File . basename ( remote_file )
36
+ end
37
+
38
+ def download_destination
39
+ system ( '[ -d ./Downloads ] || mkdir Downloads' )
40
+ end
41
+
42
+ def command
43
+ "kubectl cp -n #{ namespace . name } -c #{ container . name } #{ pod . id } :#{ remote_file_name } ./Downloads/#{ remote_file_name } " . tap { puts _1 }
44
+ end
45
+
46
+ def download
47
+ system ( command )
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
You can’t perform that action at this time.
0 commit comments