Skip to content

Commit 6b3b7e8

Browse files
committed
Remove -ti in docker and kubectl calls
It avoids passing stdin to the container when useless. Please note it removes a comple of issues higlighted by [1] in airgap specs. It also removes all useless blank chars in the files modified by this change. [1] lfn-cnti#1949 Signed-off-by: Cédric Ollivier <cedric.ollivier@orange.com>
1 parent 13fa681 commit 6b3b7e8

File tree

7 files changed

+54
-54
lines changed

7 files changed

+54
-54
lines changed

spec/airgap_task_spec.cr

+3-3
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,11 @@ describe "AirGap" do
4242
pods = KubectlClient::Get.pods_by_nodes(KubectlClient::Get.schedulable_nodes_list)
4343
pods = KubectlClient::Get.pods_by_label(pods, "name", "cri-tools")
4444
# Get the generated name of the cri-tools per node
45-
pods.map do |pod|
45+
pods.map do |pod|
4646
pod_name = pod.dig?("metadata", "name")
47-
sh = KubectlClient.exec("-ti #{pod_name} -- cat /usr/local/bin/crictl > /dev/null")
47+
sh = KubectlClient.exec("#{pod_name} -- cat /usr/local/bin/crictl > /dev/null")
4848
sh[:status].success?
49-
sh = KubectlClient.exec("-ti #{pod_name} -- cat /usr/local/bin/ctr > /dev/null")
49+
sh = KubectlClient.exec("#{pod_name} -- cat /usr/local/bin/ctr > /dev/null")
5050
sh[:status].success?
5151
end
5252
(/All prerequisites found./ =~ response_s).should_not be_nil

src/tasks/platform/resilience.cr

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ namespace "platform" do
5050

5151
# Find Reboot Daemon name
5252
reboot_daemon_pod = KubectlClient::Get.pod_status("reboot", "--field-selector spec.nodeName=#{worker_node}").split(",")[0]
53-
start_reboot = KubectlClient.exec("-ti #{reboot_daemon_pod} touch /tmp/reboot")
53+
start_reboot = KubectlClient.exec("#{reboot_daemon_pod} touch /tmp/reboot")
5454

5555
#Watch for Node Failure.
5656
pod_ready = ""

src/tasks/utils/image_prepull.cr

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def self.image_pull(yml, offline)
3030
pods = KubectlClient::Get.pods_by_nodes(KubectlClient::Get.schedulable_nodes_list)
3131
pods = KubectlClient::Get.pods_by_label(pods, "name", "cri-tools")
3232
pods.map do |pod|
33-
KubectlClient.exec("-ti #{pod.dig?("metadata", "name")} -- crictl pull #{image}")
33+
KubectlClient.exec("#{pod.dig?("metadata", "name")} -- crictl pull #{image}")
3434
end
3535
end
3636
end

src/tasks/utils/k8s_instrumentation.cr

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ module K8sInstrumentation
1010
cluster_tools = pod_status.split(",")[0]
1111
Log.info { "k8s_instrumentation_debug Pod status: #{pod_status.inspect}" }
1212
result = ShellCmd.run("kubectl get all -A", "k8s_instrumentation_debug", force_output: true)
13-
resp = KubectlClient.exec("#{cluster_tools} -ti -- /bin/bash -c 'sysbench fileio prepare && sysbench fileio --file-test-mode=rndrw run'", namespace: TESTSUITE_NAMESPACE)
13+
resp = KubectlClient.exec("#{cluster_tools} -- /bin/bash -c 'sysbench fileio prepare && sysbench fileio --file-test-mode=rndrw run'", namespace: TESTSUITE_NAMESPACE)
1414
parse_sysbench(resp[:output].to_s)
1515
end
1616

tools/ephemeral_env/ephemeral_env.cr

+3-3
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ elsif ARGV[0]? && ARGV[0] == "create_env"
123123
puts "Required argument missing [-n, --name]"
124124
else
125125
puts "Creating ENV For: \n Name: #{env_name} \n Kubeconfig: #{kubeconfig}"
126-
`docker run --name #{env_name} --network host -d -e GITHUB_USER=$GITHUB_USER -e GITHUB_TOKEN=$GITHUB_TOKEN -e DOCKERHUB_USERNAME=$DOCKERHUB_USERNAME -e DOCKERHUB_PASSWORD=$DOCKERHUB_PASSWORD -v $(pwd):/cnf-testsuite -v #{kubeconfig}:/root/.kube/config -ti cnf-test /bin/sleep infinity`
126+
`docker run --name #{env_name} --network host -d -e GITHUB_USER=$GITHUB_USER -e GITHUB_TOKEN=$GITHUB_TOKEN -e DOCKERHUB_USERNAME=$DOCKERHUB_USERNAME -e DOCKERHUB_PASSWORD=$DOCKERHUB_PASSWORD -v $(pwd):/cnf-testsuite -v #{kubeconfig}:/root/.kube/config cnf-test /bin/sleep infinity`
127127
puts `docker ps -f name=#{env_name}`
128128
end
129129

@@ -204,10 +204,10 @@ elsif ARGV[0]? && ARGV[0] == "command"
204204
# cyrstal src/cnf-testsuite.cr all
205205
# cyrstal ./cnf-testsuite all
206206
if binary == true
207-
system "docker exec -ti #{ENV["CRYSTAL_DEV_ENV"]} ./cnf-testsuite #{execute_command}"
207+
system "docker exec #{ENV["CRYSTAL_DEV_ENV"]} ./cnf-testsuite #{execute_command}"
208208
exit $?.exit_code
209209
else
210-
system "docker exec -ti #{ENV["CRYSTAL_DEV_ENV"]} crystal #{execute_command}"
210+
system "docker exec #{ENV["CRYSTAL_DEV_ENV"]} crystal #{execute_command}"
211211
exit $?.exit_code
212212
end
213213
else

utils/airgap/airgap.cr

+35-35
Original file line numberDiff line numberDiff line change
@@ -39,28 +39,28 @@ module AirGap
3939
tar_dir = info[:tar_dir]
4040
tar_name = info[:tar_name]
4141

42-
TarClient.modify_tar!(tar_name) do |directory|
42+
TarClient.modify_tar!(tar_name) do |directory|
4343
template_files = Find.find(directory, "*.yaml*", "100")
4444
template_files.map{|x| AirGap.image_pull_policy(x)}
4545
end
4646
TarClient.append(output_file, "/tmp", "#{repo_path}")
4747
ensure
4848
FileUtils.rm_rf("/tmp/#{repo_path}")
4949
end
50-
50+
5151
def self.tar_manifest(url, output_file : String = "./airgapped.tar.gz", prefix="")
52-
manifest_path = "manifests/"
52+
manifest_path = "manifests/"
5353
FileUtils.rm_rf("/tmp/#{manifest_path}")
5454
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
5757
Log.info { "manifest_name: #{manifest_name}" }
5858
Log.info { "manifest_full_path: #{manifest_full_path}" }
5959
download_path = "/tmp/" + manifest_full_path
6060
HttpHelper.download("#{url}", "#{download_path}")
6161

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|
6464
# IO.copy(response.body_io, file)
6565
# end
6666
# end
@@ -92,10 +92,10 @@ module AirGap
9292
unless kind_name
9393
AirGap.bootstrap_cluster()
9494
end
95-
#TODO Potentially remove this.
95+
#TODO Potentially remove this.
9696
if ENV["CRYSTAL_ENV"]? == "TEST"
9797
# 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",
9999
"#{TAR_BOOTSTRAP_IMAGES_DIR}/chaos-mesh.tar"]
100100
tar_image_files = Find.find("#{TarClient::TAR_IMAGES_DIR}", "*.tar*")
101101
image_files = image_files + tar_image_files + Find.find("#{TarClient::TAR_IMAGES_DIR}", "*.tgz*")
@@ -120,7 +120,7 @@ module AirGap
120120
Log.info { "TAR POD: #{pods}" }
121121
tar_pod_name = pods[0].dig?("metadata", "name") if pods[0]?
122122
Log.info { "TAR POD NAME: #{tar_pod_name}" }
123-
unless tar_pod_name
123+
unless tar_pod_name
124124
Log.info { "NO TAR POD, CHECKING FOR PODS WITH SHELL" }
125125
pods = AirGap.pods_with_sh()
126126
no_tar = true
@@ -140,9 +140,9 @@ module AirGap
140140
if no_tar
141141
Log.info { "NO TAR POD, COPYING TAR FROM HOST" }
142142
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")
146146
unless status[:status].success?
147147
raise "No images with Tar or Shell found. Please deploy a Pod with Tar or Shell to your cluster."
148148
end
@@ -155,20 +155,20 @@ module AirGap
155155
unless kind_name
156156
pods = KubectlClient::Get.pods_by_nodes(KubectlClient::Get.schedulable_nodes_list)
157157
pods = KubectlClient::Get.pods_by_label(pods, "name", "cri-tools")
158-
pods.map do |pod|
158+
pods.map do |pod|
159159
pod_name = pod.dig?("metadata", "name")
160160
KubectlClient.cp("#{tarball} #{pod_name}:/tmp/#{tarball.split("/")[-1]}")
161161
end
162-
pods.map do |pod|
162+
pods.map do |pod|
163163
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]}")
165165
Log.debug { "Resp: #{resp}" }
166166
resp
167167
end
168168
else
169169
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]}`
172172
end
173173
end
174174

@@ -190,7 +190,7 @@ module AirGap
190190
end
191191

192192
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
194194
# into final array of images
195195
pods.map do |pod|
196196
containers = pod.dig("spec","containers").as_a
@@ -211,19 +211,19 @@ module AirGap
211211

212212
def self.check_sh(pod_name, namespace="default")
213213
# --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")
215215
sh[:status].success?
216216
end
217217

218218
def self.check_tar(pod_name, namespace="default", pod=true)
219219
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")
223223
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")
227227
end
228228
if pod
229229
(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
263263
pods = KubectlClient::Get.pods_by_nodes(KubectlClient::Get.schedulable_nodes_list).select do |pod|
264264
pod_name = pod.dig?("metadata", "name")
265265
namespace = pod.dig?("metadata", "namespace")
266-
if check_sh(pod_name, namespace)
266+
if check_sh(pod_name, namespace)
267267
Log.debug { "Found sh Pod: #{pod_name}" }
268268
true
269269
else
@@ -281,7 +281,7 @@ module AirGap
281281
file_list = Helm::Manifest.manifest_file_list(config_src, silent=false)
282282
yml = Helm::Manifest.manifest_ymls_from_file_list(file_list)
283283
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")
285285
yml = Helm::Manifest.parse_manifest_as_ymls(template_file_name="cnfs/temp_template.yml")
286286
else
287287
raise "config source error: #{install_method}"
@@ -296,7 +296,7 @@ module AirGap
296296
mc.as_a? if mc
297297
}.flatten.compact
298298
Log.debug { "containers : #{containers}" }
299-
found_all = true
299+
found_all = true
300300
containers.flatten.map do |x|
301301
Log.debug { "container x: #{x}" }
302302
ipp = x.dig?("imagePullPolicy")
@@ -310,23 +310,23 @@ module AirGap
310310
if ipp == nil && (parsed_image && parsed_image["tag"] == "latest")
311311
Log.info { "ipp or tag not found with ipp: #{ipp} and parsed_image: #{parsed_image}" }
312312
found_all = false
313-
end
313+
end
314314
end
315315
Log.info { "found_all: #{found_all}" }
316316
found_all
317317
end
318318

319319

320320
def self.image_pull_policy(file, output_file="")
321-
input_content = File.read(file)
321+
input_content = File.read(file)
322322
output_content = input_content.gsub(/(.*imagePullPolicy:)(.*.)/,"\\1 Never")
323323

324324
# LOGGING.debug "pull policy found?: #{input_content =~ /(.*imagePullPolicy:)(.*)/}"
325325
# LOGGING.debug "output_content: #{output_content}"
326326
if output_file.empty?
327-
input_content = File.write(file, output_content)
327+
input_content = File.write(file, output_content)
328328
else
329-
input_content = File.write(output_file, output_content)
329+
input_content = File.write(output_file, output_content)
330330
end
331331
#
332332
#TODO find out why this doesn't work
@@ -352,7 +352,7 @@ module AirGap
352352
repo = config_src.split(" ")[0]
353353
repo_dir = repo.gsub("/", "_")
354354
chart_name = repo.split("/")[-1]
355-
repo_path = "repositories/#{repo_dir}"
355+
repo_path = "repositories/#{repo_dir}"
356356
tar_dir = "/tmp/#{repo_path}"
357357
tar_info = {repo: repo, repo_dir: repo_dir, chart_name: chart_name,
358358
repo_path: repo_path, tar_dir: tar_dir, tar_name: tar_name_by_helm_chart(config_src)}
@@ -367,7 +367,7 @@ module AirGap
367367
repo = config_src.split(" ")[0]
368368
repo_dir = repo.gsub("/", "_")
369369
chart_name = repo.split("/")[-1]
370-
repo_path = "repositories/#{repo_dir}"
370+
repo_path = "repositories/#{repo_dir}"
371371
tar_dir = "/tmp/#{repo_path}"
372372
Log.info { "helm_tar_dir: #{tar_dir}" }
373373
tar_dir

utils/airgap/spec/airgap_spec.cr

+10-10
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ describe "AirGap" do
99

1010
AirGap.image_pull_policy("./spec/fixtures/litmus-operator-v1.13.2.yaml", "/tmp/imagetest.yml")
1111
(File.exists?("/tmp/imagetest.yml")).should be_true
12-
resp = File.read("/tmp/imagetest.yml")
12+
resp = File.read("/tmp/imagetest.yml")
1313
(resp).match(/imagePullPolicy: Always/).should be_nil
1414
(resp).match(/imagePullPolicy: Never/).should_not be_nil
1515
ensure
@@ -61,13 +61,13 @@ describe "AirGap" do
6161
resp = AirGap.check_tar(pods.dig?("metadata", "name"))
6262
resp.should be_false
6363
end
64-
64+
6565
it "'#AirGap.check_tar' should determine if the host has the tar binary on it", tags: ["airgap"] do
6666
pods = KubectlClient::Get.pods_by_nodes(KubectlClient::Get.schedulable_nodes_list)
6767
pods = KubectlClient::Get.pods_by_label(pods, "name", "cri-tools")
6868
resp = AirGap.check_tar(pods[0].dig?("metadata", "name"), pod=false)
6969
Log.debug { "Path to tar on the host filesystem: #{resp}" }
70-
resp.should_not be_nil
70+
resp.should_not be_nil
7171
end
7272

7373
it "'#AirGap.check_sh' should determine if a pod has a shell on it", tags: ["airgap"] do
@@ -137,14 +137,14 @@ describe "AirGap" do
137137
pods = KubectlClient::Get.pods_by_nodes(KubectlClient::Get.schedulable_nodes_list)
138138
pods = KubectlClient::Get.pods_by_label(pods, "name", "cri-tools")
139139
# Get the generated name of the cri-tools per node
140-
pods.map do |pod|
140+
pods.map do |pod|
141141
pod_name = pod.dig?("metadata", "name")
142142
containers = pod.dig("spec","containers").as_a
143143
image = containers[0]? && containers[0].dig("image")
144144
Log.info { "CRI Pod Image: #{image}" }
145-
sh = KubectlClient.exec("-ti #{pod_name} -- cat /usr/local/bin/crictl > /dev/null")
145+
sh = KubectlClient.exec("#{pod_name} -- cat /usr/local/bin/crictl > /dev/null")
146146
sh[:status].success?
147-
sh = KubectlClient.exec("-ti #{pod_name} -- cat /usr/local/bin/ctr > /dev/null")
147+
sh = KubectlClient.exec("#{pod_name} -- cat /usr/local/bin/ctr > /dev/null")
148148
sh[:status].success?
149149
end
150150
ensure
@@ -156,17 +156,17 @@ describe "AirGap" do
156156
it "'#AirGap.bootstrap_cluster' should install the cri tools in the cluster that does not have tar in the images", tags: ["airgap-tools"] do
157157
KubectlClient::Delete.command("daemonset cri-tools")
158158
pods = AirGap.pods_with_tar()
159-
# Skip the test if tar is available outside of the cri tools
159+
# Skip the test if tar is available outside of the cri tools
160160
if pods.empty?
161161
AirGap.bootstrap_cluster()
162162
pods = KubectlClient::Get.pods_by_nodes(KubectlClient::Get.schedulable_nodes_list)
163163
pods = KubectlClient::Get.pods_by_label(pods, "name", "cri-tools")
164164
# Get the generated name of the cri-tools per node
165-
pods.map do |pod|
165+
pods.map do |pod|
166166
pod_name = pod.dig?("metadata", "name")
167-
sh = KubectlClient.exec("-ti #{pod_name} -- cat /usr/local/bin/crictl > /dev/null")
167+
sh = KubectlClient.exec("#{pod_name} -- cat /usr/local/bin/crictl > /dev/null")
168168
sh[:status].success?
169-
sh = KubectlClient.exec("-ti #{pod_name} -- cat /usr/local/bin/ctr > /dev/null")
169+
sh = KubectlClient.exec("#{pod_name} -- cat /usr/local/bin/ctr > /dev/null")
170170
sh[:status].success?
171171
end
172172
end

0 commit comments

Comments
 (0)