Skip to content

Commit

Permalink
Merge pull request cnti-testcatalog#1984 from collivier/remove_ti_option
Browse files Browse the repository at this point in the history
Remove -ti in docker and kubectl calls
  • Loading branch information
HashNuke authored Apr 21, 2024
2 parents eb4eb12 + f310a73 commit 675c9de
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 51 deletions.
2 changes: 1 addition & 1 deletion src/tasks/platform/resilience.cr
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ namespace "platform" do

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

#Watch for Node Failure.
pod_ready = ""
Expand Down
2 changes: 1 addition & 1 deletion src/tasks/utils/image_prepull.cr
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def self.image_pull(yml, offline)
pods = KubectlClient::Get.pods_by_nodes(KubectlClient::Get.schedulable_nodes_list)
pods = KubectlClient::Get.pods_by_label(pods, "name", "cri-tools")
pods.map do |pod|
KubectlClient.exec("-ti #{pod.dig?("metadata", "name")} -- crictl pull #{image}")
KubectlClient.exec("#{pod.dig?("metadata", "name")} -- crictl pull #{image}")
end
end
end
2 changes: 1 addition & 1 deletion src/tasks/utils/k8s_instrumentation.cr
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ module K8sInstrumentation
cluster_tools = pod_status.split(",")[0]
Log.info { "k8s_instrumentation_debug Pod status: #{pod_status.inspect}" }
result = ShellCmd.run("kubectl get all -A", "k8s_instrumentation_debug", force_output: true)
resp = KubectlClient.exec("#{cluster_tools} -ti -- /bin/bash -c 'sysbench fileio prepare && sysbench fileio --file-test-mode=rndrw run'", namespace: TESTSUITE_NAMESPACE)
resp = KubectlClient.exec("#{cluster_tools} -- /bin/bash -c 'sysbench fileio prepare && sysbench fileio --file-test-mode=rndrw run'", namespace: TESTSUITE_NAMESPACE)
parse_sysbench(resp[:output].to_s)
end

Expand Down
6 changes: 3 additions & 3 deletions tools/ephemeral_env/ephemeral_env.cr
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ elsif ARGV[0]? && ARGV[0] == "create_env"
puts "Required argument missing [-n, --name]"
else
puts "Creating ENV For: \n Name: #{env_name} \n Kubeconfig: #{kubeconfig}"
`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`
`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`
puts `docker ps -f name=#{env_name}`
end

Expand Down Expand Up @@ -204,10 +204,10 @@ elsif ARGV[0]? && ARGV[0] == "command"
# cyrstal src/cnf-testsuite.cr all
# cyrstal ./cnf-testsuite all
if binary == true
system "docker exec -ti #{ENV["CRYSTAL_DEV_ENV"]} ./cnf-testsuite #{execute_command}"
system "docker exec #{ENV["CRYSTAL_DEV_ENV"]} ./cnf-testsuite #{execute_command}"
exit $?.exit_code
else
system "docker exec -ti #{ENV["CRYSTAL_DEV_ENV"]} crystal #{execute_command}"
system "docker exec #{ENV["CRYSTAL_DEV_ENV"]} crystal #{execute_command}"
exit $?.exit_code
end
else
Expand Down
70 changes: 35 additions & 35 deletions utils/airgap/airgap.cr
Original file line number Diff line number Diff line change
Expand Up @@ -39,28 +39,28 @@ module AirGap
tar_dir = info[:tar_dir]
tar_name = info[:tar_name]

TarClient.modify_tar!(tar_name) do |directory|
TarClient.modify_tar!(tar_name) do |directory|
template_files = Find.find(directory, "*.yaml*", "100")
template_files.map{|x| AirGap.image_pull_policy(x)}
end
TarClient.append(output_file, "/tmp", "#{repo_path}")
ensure
FileUtils.rm_rf("/tmp/#{repo_path}")
end

def self.tar_manifest(url, output_file : String = "./airgapped.tar.gz", prefix="")
manifest_path = "manifests/"
manifest_path = "manifests/"
FileUtils.rm_rf("/tmp/#{manifest_path}")
FileUtils.mkdir_p("/tmp/" + manifest_path)
manifest_name = prefix + url.split("/").last
manifest_full_path = manifest_path + manifest_name
manifest_name = prefix + url.split("/").last
manifest_full_path = manifest_path + manifest_name
Log.info { "manifest_name: #{manifest_name}" }
Log.info { "manifest_full_path: #{manifest_full_path}" }
download_path = "/tmp/" + manifest_full_path
HttpHelper.download("#{url}", "#{download_path}")

# Halite.get("#{url}") do |response|
# File.open("/tmp/" + manifest_full_path, "w") do |file|
# Halite.get("#{url}") do |response|
# File.open("/tmp/" + manifest_full_path, "w") do |file|
# IO.copy(response.body_io, file)
# end
# end
Expand Down Expand Up @@ -92,10 +92,10 @@ module AirGap
unless kind_name
AirGap.bootstrap_cluster()
end
#TODO Potentially remove this.
#TODO Potentially remove this.
if ENV["CRYSTAL_ENV"]? == "TEST"
# todo change chaos-mesh tar to something more generic
image_files = ["#{TAR_BOOTSTRAP_IMAGES_DIR}/kubectl.tar",
image_files = ["#{TAR_BOOTSTRAP_IMAGES_DIR}/kubectl.tar",
"#{TAR_BOOTSTRAP_IMAGES_DIR}/chaos-mesh.tar"]
tar_image_files = Find.find("#{TarClient::TAR_IMAGES_DIR}", "*.tar*")
image_files = image_files + tar_image_files + Find.find("#{TarClient::TAR_IMAGES_DIR}", "*.tgz*")
Expand All @@ -120,7 +120,7 @@ module AirGap
Log.info { "TAR POD: #{pods}" }
tar_pod_name = pods[0].dig?("metadata", "name") if pods[0]?
Log.info { "TAR POD NAME: #{tar_pod_name}" }
unless tar_pod_name
unless tar_pod_name
Log.info { "NO TAR POD, CHECKING FOR PODS WITH SHELL" }
pods = AirGap.pods_with_sh()
no_tar = true
Expand All @@ -140,9 +140,9 @@ module AirGap
if no_tar
Log.info { "NO TAR POD, COPYING TAR FROM HOST" }
tar_path = AirGap.check_tar(cri_tools_pod_name, namespace: "default", pod: false)
pods.map do |pod|
KubectlClient.exec("#{pod.dig?("metadata", "name")} -ti -- cp #{tar_path} /usr/local/bin/")
status = KubectlClient.exec("#{pod.dig?("metadata", "name")} -ti -- /usr/local/bin/tar --version")
pods.map do |pod|
KubectlClient.exec("#{pod.dig?("metadata", "name")} -- cp #{tar_path} /usr/local/bin/")
status = KubectlClient.exec("#{pod.dig?("metadata", "name")} -- /usr/local/bin/tar --version")
unless status[:status].success?
raise "No images with Tar or Shell found. Please deploy a Pod with Tar or Shell to your cluster."
end
Expand All @@ -155,20 +155,20 @@ module AirGap
unless kind_name
pods = KubectlClient::Get.pods_by_nodes(KubectlClient::Get.schedulable_nodes_list)
pods = KubectlClient::Get.pods_by_label(pods, "name", "cri-tools")
pods.map do |pod|
pods.map do |pod|
pod_name = pod.dig?("metadata", "name")
KubectlClient.cp("#{tarball} #{pod_name}:/tmp/#{tarball.split("/")[-1]}")
end
pods.map do |pod|
pods.map do |pod|
pod_name = pod.dig?("metadata", "name")
resp = KubectlClient.exec("-ti #{pod_name} -- ctr -n=k8s.io image import /tmp/#{tarball.split("/")[-1]}")
resp = KubectlClient.exec("#{pod_name} -- ctr -n=k8s.io image import /tmp/#{tarball.split("/")[-1]}")
Log.debug { "Resp: #{resp}" }
resp
end
else
DockerClient.cp("#{tarball} #{kind_name}:/#{tarball.split("/")[-1]}")
#DockerClient.exec("-ti #{kind_name} ctr -n=k8s.io image import /#{tarball.split("/")[-1]}")
`docker exec -ti #{kind_name} ctr -n=k8s.io image import /#{tarball.split("/")[-1]}`
#DockerClient.exec("#{kind_name} ctr -n=k8s.io image import /#{tarball.split("/")[-1]}")
`docker exec #{kind_name} ctr -n=k8s.io image import /#{tarball.split("/")[-1]}`
end
end

Expand All @@ -190,7 +190,7 @@ module AirGap
end

def self.pod_images(pods)
# todo change into a reduce, loop through all containers and append image
# todo change into a reduce, loop through all containers and append image
# into final array of images
pods.map do |pod|
containers = pod.dig("spec","containers").as_a
Expand All @@ -211,19 +211,19 @@ module AirGap

def self.check_sh(pod_name, namespace="default")
# --namespace=${POD[1]}
sh = KubectlClient.exec("--namespace=#{namespace} -ti #{pod_name} -- cat /bin/sh > /dev/null")
sh = KubectlClient.exec("--namespace=#{namespace} #{pod_name} -- cat /bin/sh > /dev/null")
sh[:status].success?
end

def self.check_tar(pod_name, namespace="default", pod=true)
if pod
bin_tar = KubectlClient.exec("--namespace=#{namespace} -ti #{pod_name} -- cat /bin/tar > /dev/null")
usr_bin_tar = KubectlClient.exec("--namespace=#{namespace} -ti #{pod_name} -- cat /usr/bin/tar > /dev/null")
usr_local_bin_tar = KubectlClient.exec("--namespace=#{namespace} -ti #{pod_name} -- cat /usr/local/bin/tar > /dev/null")
bin_tar = KubectlClient.exec("--namespace=#{namespace} #{pod_name} -- cat /bin/tar > /dev/null")
usr_bin_tar = KubectlClient.exec("--namespace=#{namespace} #{pod_name} -- cat /usr/bin/tar > /dev/null")
usr_local_bin_tar = KubectlClient.exec("--namespace=#{namespace} #{pod_name} -- cat /usr/local/bin/tar > /dev/null")
else
bin_tar = KubectlClient.exec("--namespace=#{namespace} -ti #{pod_name} -- cat /tmp/bin/tar > /dev/null")
usr_bin_tar = KubectlClient.exec("--namespace=#{namespace} -ti #{pod_name} -- cat /tmp/usr/bin/tar > /dev/null")
usr_local_bin_tar = KubectlClient.exec("--namespace=#{namespace} -ti #{pod_name} -- cat /tmp/usr/local/bin/tar > /dev/null")
bin_tar = KubectlClient.exec("--namespace=#{namespace} #{pod_name} -- cat /tmp/bin/tar > /dev/null")
usr_bin_tar = KubectlClient.exec("--namespace=#{namespace} #{pod_name} -- cat /tmp/usr/bin/tar > /dev/null")
usr_local_bin_tar = KubectlClient.exec("--namespace=#{namespace} #{pod_name} -- cat /tmp/usr/local/bin/tar > /dev/null")
end
if pod
(bin_tar[:status].success? && "/bin/tar") || (usr_bin_tar.[:status].success? && "/usr/bin/tar") || (usr_local_bin_tar[:status].success? && "/usr/local/bin/tar")
Expand Down Expand Up @@ -263,7 +263,7 @@ module AirGap
pods = KubectlClient::Get.pods_by_nodes(KubectlClient::Get.schedulable_nodes_list).select do |pod|
pod_name = pod.dig?("metadata", "name")
namespace = pod.dig?("metadata", "namespace")
if check_sh(pod_name, namespace)
if check_sh(pod_name, namespace)
Log.debug { "Found sh Pod: #{pod_name}" }
true
else
Expand All @@ -281,7 +281,7 @@ module AirGap
file_list = Helm::Manifest.manifest_file_list(config_src, silent=false)
yml = Helm::Manifest.manifest_ymls_from_file_list(file_list)
when Helm::InstallMethod::HelmChart, Helm::InstallMethod::HelmDirectory
Helm.template(release_name, config_src, output_file="cnfs/temp_template.yml")
Helm.template(release_name, config_src, output_file="cnfs/temp_template.yml")
yml = Helm::Manifest.parse_manifest_as_ymls(template_file_name="cnfs/temp_template.yml")
else
raise "config source error: #{install_method}"
Expand All @@ -296,7 +296,7 @@ module AirGap
mc.as_a? if mc
}.flatten.compact
Log.debug { "containers : #{containers}" }
found_all = true
found_all = true
containers.flatten.map do |x|
Log.debug { "container x: #{x}" }
ipp = x.dig?("imagePullPolicy")
Expand All @@ -310,23 +310,23 @@ module AirGap
if ipp == nil && (parsed_image && parsed_image["tag"] == "latest")
Log.info { "ipp or tag not found with ipp: #{ipp} and parsed_image: #{parsed_image}" }
found_all = false
end
end
end
Log.info { "found_all: #{found_all}" }
found_all
end


def self.image_pull_policy(file, output_file="")
input_content = File.read(file)
input_content = File.read(file)
output_content = input_content.gsub(/(.*imagePullPolicy:)(.*.)/,"\\1 Never")

# LOGGING.debug "pull policy found?: #{input_content =~ /(.*imagePullPolicy:)(.*)/}"
# LOGGING.debug "output_content: #{output_content}"
if output_file.empty?
input_content = File.write(file, output_content)
input_content = File.write(file, output_content)
else
input_content = File.write(output_file, output_content)
input_content = File.write(output_file, output_content)
end
#
#TODO find out why this doesn't work
Expand All @@ -352,7 +352,7 @@ module AirGap
repo = config_src.split(" ")[0]
repo_dir = repo.gsub("/", "_")
chart_name = repo.split("/")[-1]
repo_path = "repositories/#{repo_dir}"
repo_path = "repositories/#{repo_dir}"
tar_dir = "/tmp/#{repo_path}"
tar_info = {repo: repo, repo_dir: repo_dir, chart_name: chart_name,
repo_path: repo_path, tar_dir: tar_dir, tar_name: tar_name_by_helm_chart(config_src)}
Expand All @@ -367,7 +367,7 @@ module AirGap
repo = config_src.split(" ")[0]
repo_dir = repo.gsub("/", "_")
chart_name = repo.split("/")[-1]
repo_path = "repositories/#{repo_dir}"
repo_path = "repositories/#{repo_dir}"
tar_dir = "/tmp/#{repo_path}"
Log.info { "helm_tar_dir: #{tar_dir}" }
tar_dir
Expand Down
20 changes: 10 additions & 10 deletions utils/airgap/spec/airgap_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ describe "AirGap" do

AirGap.image_pull_policy("./spec/fixtures/litmus-operator-v1.13.2.yaml", "/tmp/imagetest.yml")
(File.exists?("/tmp/imagetest.yml")).should be_true
resp = File.read("/tmp/imagetest.yml")
resp = File.read("/tmp/imagetest.yml")
(resp).match(/imagePullPolicy: Always/).should be_nil
(resp).match(/imagePullPolicy: Never/).should_not be_nil
ensure
Expand Down Expand Up @@ -61,13 +61,13 @@ describe "AirGap" do
resp = AirGap.check_tar(pods.dig?("metadata", "name"))
resp.should be_false
end

it "'#AirGap.check_tar' should determine if the host has the tar binary on it", tags: ["airgap"] do
pods = KubectlClient::Get.pods_by_nodes(KubectlClient::Get.schedulable_nodes_list)
pods = KubectlClient::Get.pods_by_label(pods, "name", "cri-tools")
resp = AirGap.check_tar(pods[0].dig?("metadata", "name"), pod=false)
Log.debug { "Path to tar on the host filesystem: #{resp}" }
resp.should_not be_nil
resp.should_not be_nil
end

it "'#AirGap.check_sh' should determine if a pod has a shell on it", tags: ["airgap"] do
Expand Down Expand Up @@ -137,14 +137,14 @@ describe "AirGap" do
pods = KubectlClient::Get.pods_by_nodes(KubectlClient::Get.schedulable_nodes_list)
pods = KubectlClient::Get.pods_by_label(pods, "name", "cri-tools")
# Get the generated name of the cri-tools per node
pods.map do |pod|
pods.map do |pod|
pod_name = pod.dig?("metadata", "name")
containers = pod.dig("spec","containers").as_a
image = containers[0]? && containers[0].dig("image")
Log.info { "CRI Pod Image: #{image}" }
sh = KubectlClient.exec("-ti #{pod_name} -- cat /usr/local/bin/crictl > /dev/null")
sh = KubectlClient.exec("#{pod_name} -- cat /usr/local/bin/crictl > /dev/null")
sh[:status].success?
sh = KubectlClient.exec("-ti #{pod_name} -- cat /usr/local/bin/ctr > /dev/null")
sh = KubectlClient.exec("#{pod_name} -- cat /usr/local/bin/ctr > /dev/null")
sh[:status].success?
end
ensure
Expand All @@ -156,17 +156,17 @@ describe "AirGap" do
it "'#AirGap.bootstrap_cluster' should install the cri tools in the cluster that does not have tar in the images", tags: ["airgap-tools"] do
KubectlClient::Delete.command("daemonset cri-tools")
pods = AirGap.pods_with_tar()
# Skip the test if tar is available outside of the cri tools
# Skip the test if tar is available outside of the cri tools
if pods.empty?
AirGap.bootstrap_cluster()
pods = KubectlClient::Get.pods_by_nodes(KubectlClient::Get.schedulable_nodes_list)
pods = KubectlClient::Get.pods_by_label(pods, "name", "cri-tools")
# Get the generated name of the cri-tools per node
pods.map do |pod|
pods.map do |pod|
pod_name = pod.dig?("metadata", "name")
sh = KubectlClient.exec("-ti #{pod_name} -- cat /usr/local/bin/crictl > /dev/null")
sh = KubectlClient.exec("#{pod_name} -- cat /usr/local/bin/crictl > /dev/null")
sh[:status].success?
sh = KubectlClient.exec("-ti #{pod_name} -- cat /usr/local/bin/ctr > /dev/null")
sh = KubectlClient.exec("#{pod_name} -- cat /usr/local/bin/ctr > /dev/null")
sh[:status].success?
end
end
Expand Down

0 comments on commit 675c9de

Please sign in to comment.