@@ -39,28 +39,28 @@ module AirGap
39
39
tar_dir = info[:tar_dir ]
40
40
tar_name = info[:tar_name ]
41
41
42
- TarClient .modify_tar!(tar_name) do |directory |
42
+ TarClient .modify_tar!(tar_name) do |directory |
43
43
template_files = Find .find(directory, " *.yaml*" , " 100" )
44
44
template_files.map{|x | AirGap .image_pull_policy(x)}
45
45
end
46
46
TarClient .append(output_file, " /tmp" , " #{ repo_path } " )
47
47
ensure
48
48
FileUtils .rm_rf(" /tmp/#{ repo_path } " )
49
49
end
50
-
50
+
51
51
def self.tar_manifest (url, output_file : String = " ./airgapped.tar.gz" , prefix= " " )
52
- manifest_path = " manifests/"
52
+ manifest_path = " manifests/"
53
53
FileUtils .rm_rf(" /tmp/#{ manifest_path } " )
54
54
FileUtils .mkdir_p(" /tmp/" + manifest_path)
55
- manifest_name = prefix + url.split(" /" ).last
56
- manifest_full_path = manifest_path + manifest_name
55
+ manifest_name = prefix + url.split(" /" ).last
56
+ manifest_full_path = manifest_path + manifest_name
57
57
Log .info { " manifest_name: #{ manifest_name } " }
58
58
Log .info { " manifest_full_path: #{ manifest_full_path } " }
59
59
download_path = " /tmp/" + manifest_full_path
60
60
HttpHelper .download(" #{ url } " , " #{ download_path } " )
61
61
62
- # Halite.get("#{url}") do |response|
63
- # File.open("/tmp/" + manifest_full_path, "w") do |file|
62
+ # Halite.get("#{url}") do |response|
63
+ # File.open("/tmp/" + manifest_full_path, "w") do |file|
64
64
# IO.copy(response.body_io, file)
65
65
# end
66
66
# end
@@ -92,10 +92,10 @@ module AirGap
92
92
unless kind_name
93
93
AirGap .bootstrap_cluster()
94
94
end
95
- # TODO Potentially remove this.
95
+ # TODO Potentially remove this.
96
96
if ENV [" CRYSTAL_ENV" ]? == " TEST"
97
97
# todo change chaos-mesh tar to something more generic
98
- image_files = [" #{ TAR_BOOTSTRAP_IMAGES_DIR } /kubectl.tar" ,
98
+ image_files = [" #{ TAR_BOOTSTRAP_IMAGES_DIR } /kubectl.tar" ,
99
99
" #{ TAR_BOOTSTRAP_IMAGES_DIR } /chaos-mesh.tar" ]
100
100
tar_image_files = Find .find(" #{ TarClient ::TAR_IMAGES_DIR } " , " *.tar*" )
101
101
image_files = image_files + tar_image_files + Find .find(" #{ TarClient ::TAR_IMAGES_DIR } " , " *.tgz*" )
@@ -120,7 +120,7 @@ module AirGap
120
120
Log .info { " TAR POD: #{ pods } " }
121
121
tar_pod_name = pods[0 ].dig?(" metadata" , " name" ) if pods[0 ]?
122
122
Log .info { " TAR POD NAME: #{ tar_pod_name } " }
123
- unless tar_pod_name
123
+ unless tar_pod_name
124
124
Log .info { " NO TAR POD, CHECKING FOR PODS WITH SHELL" }
125
125
pods = AirGap .pods_with_sh()
126
126
no_tar = true
@@ -140,9 +140,9 @@ module AirGap
140
140
if no_tar
141
141
Log .info { " NO TAR POD, COPYING TAR FROM HOST" }
142
142
tar_path = AirGap .check_tar(cri_tools_pod_name, namespace: " default" , pod: false )
143
- pods.map do |pod |
144
- KubectlClient .exec(" #{ pod.dig?(" metadata" , " name" ) } -ti - - cp #{ tar_path } /usr/local/bin/" )
145
- status = KubectlClient .exec(" #{ pod.dig?(" metadata" , " name" ) } -ti - - /usr/local/bin/tar --version" )
143
+ pods.map do |pod |
144
+ KubectlClient .exec(" #{ pod.dig?(" metadata" , " name" ) } -- cp #{ tar_path } /usr/local/bin/" )
145
+ status = KubectlClient .exec(" #{ pod.dig?(" metadata" , " name" ) } -- /usr/local/bin/tar --version" )
146
146
unless status[:status ].success?
147
147
raise " No images with Tar or Shell found. Please deploy a Pod with Tar or Shell to your cluster."
148
148
end
@@ -155,20 +155,20 @@ module AirGap
155
155
unless kind_name
156
156
pods = KubectlClient ::Get .pods_by_nodes(KubectlClient ::Get .schedulable_nodes_list)
157
157
pods = KubectlClient ::Get .pods_by_label(pods, " name" , " cri-tools" )
158
- pods.map do |pod |
158
+ pods.map do |pod |
159
159
pod_name = pod.dig?(" metadata" , " name" )
160
160
KubectlClient .cp(" #{ tarball } #{ pod_name } :/tmp/#{ tarball.split(" /" )[-1 ] } " )
161
161
end
162
- pods.map do |pod |
162
+ pods.map do |pod |
163
163
pod_name = pod.dig?(" metadata" , " name" )
164
- resp = KubectlClient .exec(" -ti #{ pod_name } -- ctr -n=k8s.io image import /tmp/#{ tarball.split(" /" )[-1 ] } " )
164
+ resp = KubectlClient .exec(" #{ pod_name } -- ctr -n=k8s.io image import /tmp/#{ tarball.split(" /" )[-1 ] } " )
165
165
Log .debug { " Resp: #{ resp } " }
166
166
resp
167
167
end
168
168
else
169
169
DockerClient .cp(" #{ tarball } #{ kind_name } :/#{ tarball.split(" /" )[-1 ] } " )
170
- # DockerClient.exec("-ti #{kind_name} ctr -n=k8s.io image import /#{tarball.split("/")[-1]}")
171
- ` docker exec -ti #{ kind_name } ctr -n=k8s.io image import /#{ tarball.split(" /" )[-1 ] } `
170
+ # DockerClient.exec("#{kind_name} ctr -n=k8s.io image import /#{tarball.split("/")[-1]}")
171
+ ` docker exec #{ kind_name } ctr -n=k8s.io image import /#{ tarball.split(" /" )[-1 ] } `
172
172
end
173
173
end
174
174
@@ -190,7 +190,7 @@ module AirGap
190
190
end
191
191
192
192
def self.pod_images (pods )
193
- # todo change into a reduce, loop through all containers and append image
193
+ # todo change into a reduce, loop through all containers and append image
194
194
# into final array of images
195
195
pods.map do |pod |
196
196
containers = pod.dig(" spec" ," containers" ).as_a
@@ -211,19 +211,19 @@ module AirGap
211
211
212
212
def self.check_sh (pod_name, namespace= " default" )
213
213
# --namespace=${POD[1]}
214
- sh = KubectlClient .exec(" --namespace=#{ namespace } -ti #{ pod_name } -- cat /bin/sh > /dev/null" )
214
+ sh = KubectlClient .exec(" --namespace=#{ namespace } #{ pod_name } -- cat /bin/sh > /dev/null" )
215
215
sh[:status ].success?
216
216
end
217
217
218
218
def self.check_tar (pod_name, namespace= " default" , pod= true )
219
219
if pod
220
- bin_tar = KubectlClient .exec(" --namespace=#{ namespace } -ti #{ pod_name } -- cat /bin/tar > /dev/null" )
221
- usr_bin_tar = KubectlClient .exec(" --namespace=#{ namespace } -ti #{ pod_name } -- cat /usr/bin/tar > /dev/null" )
222
- usr_local_bin_tar = KubectlClient .exec(" --namespace=#{ namespace } -ti #{ pod_name } -- cat /usr/local/bin/tar > /dev/null" )
220
+ bin_tar = KubectlClient .exec(" --namespace=#{ namespace } #{ pod_name } -- cat /bin/tar > /dev/null" )
221
+ usr_bin_tar = KubectlClient .exec(" --namespace=#{ namespace } #{ pod_name } -- cat /usr/bin/tar > /dev/null" )
222
+ usr_local_bin_tar = KubectlClient .exec(" --namespace=#{ namespace } #{ pod_name } -- cat /usr/local/bin/tar > /dev/null" )
223
223
else
224
- bin_tar = KubectlClient .exec(" --namespace=#{ namespace } -ti #{ pod_name } -- cat /tmp/bin/tar > /dev/null" )
225
- usr_bin_tar = KubectlClient .exec(" --namespace=#{ namespace } -ti #{ pod_name } -- cat /tmp/usr/bin/tar > /dev/null" )
226
- usr_local_bin_tar = KubectlClient .exec(" --namespace=#{ namespace } -ti #{ pod_name } -- cat /tmp/usr/local/bin/tar > /dev/null" )
224
+ bin_tar = KubectlClient .exec(" --namespace=#{ namespace } #{ pod_name } -- cat /tmp/bin/tar > /dev/null" )
225
+ usr_bin_tar = KubectlClient .exec(" --namespace=#{ namespace } #{ pod_name } -- cat /tmp/usr/bin/tar > /dev/null" )
226
+ usr_local_bin_tar = KubectlClient .exec(" --namespace=#{ namespace } #{ pod_name } -- cat /tmp/usr/local/bin/tar > /dev/null" )
227
227
end
228
228
if pod
229
229
(bin_tar[:status ].success? && " /bin/tar" ) || (usr_bin_tar.[:status ].success? && " /usr/bin/tar" ) || (usr_local_bin_tar[:status ].success? && " /usr/local/bin/tar" )
@@ -263,7 +263,7 @@ module AirGap
263
263
pods = KubectlClient ::Get .pods_by_nodes(KubectlClient ::Get .schedulable_nodes_list).select do |pod |
264
264
pod_name = pod.dig?(" metadata" , " name" )
265
265
namespace = pod.dig?(" metadata" , " namespace" )
266
- if check_sh(pod_name, namespace)
266
+ if check_sh(pod_name, namespace)
267
267
Log .debug { " Found sh Pod: #{ pod_name } " }
268
268
true
269
269
else
@@ -281,7 +281,7 @@ module AirGap
281
281
file_list = Helm ::Manifest .manifest_file_list(config_src, silent= false )
282
282
yml = Helm ::Manifest .manifest_ymls_from_file_list(file_list)
283
283
when Helm ::InstallMethod ::HelmChart , Helm ::InstallMethod ::HelmDirectory
284
- Helm .template(release_name, config_src, output_file= " cnfs/temp_template.yml" )
284
+ Helm .template(release_name, config_src, output_file= " cnfs/temp_template.yml" )
285
285
yml = Helm ::Manifest .parse_manifest_as_ymls(template_file_name= " cnfs/temp_template.yml" )
286
286
else
287
287
raise " config source error: #{ install_method } "
@@ -296,7 +296,7 @@ module AirGap
296
296
mc.as_a? if mc
297
297
}.flatten.compact
298
298
Log .debug { " containers : #{ containers } " }
299
- found_all = true
299
+ found_all = true
300
300
containers.flatten.map do |x |
301
301
Log .debug { " container x: #{ x } " }
302
302
ipp = x.dig?(" imagePullPolicy" )
@@ -310,23 +310,23 @@ module AirGap
310
310
if ipp == nil && (parsed_image && parsed_image[" tag" ] == " latest" )
311
311
Log .info { " ipp or tag not found with ipp: #{ ipp } and parsed_image: #{ parsed_image } " }
312
312
found_all = false
313
- end
313
+ end
314
314
end
315
315
Log .info { " found_all: #{ found_all } " }
316
316
found_all
317
317
end
318
318
319
319
320
320
def self.image_pull_policy (file, output_file= " " )
321
- input_content = File .read(file)
321
+ input_content = File .read(file)
322
322
output_content = input_content.gsub(/(.*imagePullPolicy:)(.*.) / ," \\ 1 Never" )
323
323
324
324
# LOGGING.debug "pull policy found?: #{input_content =~ /(.*imagePullPolicy:)(.*)/}"
325
325
# LOGGING.debug "output_content: #{output_content}"
326
326
if output_file.empty?
327
- input_content = File .write(file, output_content)
327
+ input_content = File .write(file, output_content)
328
328
else
329
- input_content = File .write(output_file, output_content)
329
+ input_content = File .write(output_file, output_content)
330
330
end
331
331
#
332
332
# TODO find out why this doesn't work
@@ -352,7 +352,7 @@ module AirGap
352
352
repo = config_src.split(" " )[0 ]
353
353
repo_dir = repo.gsub(" /" , " _" )
354
354
chart_name = repo.split(" /" )[-1 ]
355
- repo_path = " repositories/#{ repo_dir } "
355
+ repo_path = " repositories/#{ repo_dir } "
356
356
tar_dir = " /tmp/#{ repo_path } "
357
357
tar_info = {repo: repo, repo_dir: repo_dir, chart_name: chart_name,
358
358
repo_path: repo_path, tar_dir: tar_dir, tar_name: tar_name_by_helm_chart(config_src)}
@@ -367,7 +367,7 @@ module AirGap
367
367
repo = config_src.split(" " )[0 ]
368
368
repo_dir = repo.gsub(" /" , " _" )
369
369
chart_name = repo.split(" /" )[-1 ]
370
- repo_path = " repositories/#{ repo_dir } "
370
+ repo_path = " repositories/#{ repo_dir } "
371
371
tar_dir = " /tmp/#{ repo_path } "
372
372
Log .info { " helm_tar_dir: #{ tar_dir } " }
373
373
tar_dir
0 commit comments