module Dapp::Dimg::Dapp::Command::CleanupRepo
Public Instance Methods
cleanup_repo()
click to toggle source
# File lib/dapp/dimg/dapp/command/cleanup_repo.rb, line 6 def cleanup_repo git_repo_option = git_own_repo_exist? ? JSON.dump(git_own_repo.get_ruby2go_state_hash) : nil ruby2go_cleanup_command(:gc, ruby2go_cleanup_gc_options_dump, local_repo: git_repo_option) end
cronjob_images(client)
click to toggle source
cronjob items[] spec jobTemplate spec template spec containers[] image
# File lib/dapp/dimg/dapp/command/cleanup_repo.rb, line 82 def cronjob_images(client) client.cronjob_list['items'].map do |item| images_from_pod_spec(item['spec']['jobTemplate']['spec']['template']) end end
daemonset_images(client)
click to toggle source
daemonsets items[] spec template spec containers[] image
# File lib/dapp/dimg/dapp/command/cleanup_repo.rb, line 89 def daemonset_images(client) client.daemonset_list['items'].map do |item| images_from_pod_spec(item['spec']['template']) end end
deployed_docker_images()
click to toggle source
# File lib/dapp/dimg/dapp/command/cleanup_repo.rb, line 22 def deployed_docker_images @deployed_docker_images ||= search_deployed_docker_images end
deployment_images(client)
click to toggle source
deployment items[] spec template spec containers[] image
# File lib/dapp/dimg/dapp/command/cleanup_repo.rb, line 96 def deployment_images(client) client.deployment_list['items'].map do |item| images_from_pod_spec(item['spec']['template']) end end
images_from_pod_spec(pod_spec)
click to toggle source
# File lib/dapp/dimg/dapp/command/cleanup_repo.rb, line 130 def images_from_pod_spec(pod_spec) containers = Array(pod_spec['spec']['containers']) initContainers = Array(pod_spec['spec']['initContainers']) (containers + initContainers).map { |cont| cont['image'] } end
job_images(client)
click to toggle source
job items[] spec template spec containers[] image
# File lib/dapp/dimg/dapp/command/cleanup_repo.rb, line 103 def job_images(client) client.job_list['items'].map do |item| images_from_pod_spec(item['spec']['template']) end end
pod_images(client)
click to toggle source
pod items[] spec containers[] image
# File lib/dapp/dimg/dapp/command/cleanup_repo.rb, line 75 def pod_images(client) client.pod_list['items'].map do |item| images_from_pod_spec(item) end end
replicaset_images(client)
click to toggle source
replicasets items[] spec template spec containers[] image
# File lib/dapp/dimg/dapp/command/cleanup_repo.rb, line 110 def replicaset_images(client) client.replicaset_list['items'].map do |item| images_from_pod_spec(item['spec']['template']) end end
replicationcontroller_images(client)
click to toggle source
replicationcontroller items[] spec template spec containers[] image
# File lib/dapp/dimg/dapp/command/cleanup_repo.rb, line 124 def replicationcontroller_images(client) client.replicationcontroller_list['items'].map do |item| images_from_pod_spec(item['spec']['template']) end end
ruby2go_cleanup_gc_options_dump()
click to toggle source
# File lib/dapp/dimg/dapp/command/cleanup_repo.rb, line 11 def ruby2go_cleanup_gc_options_dump ruby2go_cleanup_common_repo_options.merge( mode: { with_stages: with_stages? }, deployed_docker_images: deployed_docker_images ).tap do |data| break JSON.dump(data) end end
search_deployed_docker_images()
click to toggle source
# File lib/dapp/dimg/dapp/command/cleanup_repo.rb, line 26 def search_deployed_docker_images return [] if without_kube? config = ::Dapp::Kube::Kubernetes::Config.new_auto_if_available return [] if config.nil? config.context_names. map {|context_name| client = ::Dapp::Kube::Kubernetes::Client.new( config, context_name, "default", timeout: options[:kubernetes_timeout], ) search_deployed_docker_images_from_kube(client) }.flatten.sort.uniq end
search_deployed_docker_images_from_kube(client)
click to toggle source
# File lib/dapp/dimg/dapp/command/cleanup_repo.rb, line 44 def search_deployed_docker_images_from_kube(client) namespaces = [] # check connectivity for 2 seconds begin namespaces = client.namespace_list(excon_parameters: {:connect_timeout => 30}) rescue Excon::Error::Timeout raise ::Dapp::Error::Default, code: :kube_connect_timeout end # get images from containers from pods from all namespaces. namespaces['items'].map do |item| item['metadata']['name'] end.map do |ns| [].tap do |arr| client.with_namespace(ns) do arr << pod_images(client) arr << deployment_images(client) arr << replicaset_images(client) arr << statefulset_images(client) arr << daemonset_images(client) arr << job_images(client) arr << cronjob_images(client) arr << replicationcontroller_images(client) end end end.flatten.select do |img| img.start_with? option_repo end.sort.uniq end
statefulset_images(client)
click to toggle source
replicasets items[] spec template spec containers[] image
# File lib/dapp/dimg/dapp/command/cleanup_repo.rb, line 117 def statefulset_images(client) client.statefulset_list['items'].map do |item| images_from_pod_spec(item['spec']['template']) end end
without_kube?()
click to toggle source
# File lib/dapp/dimg/dapp/command/cleanup_repo.rb, line 136 def without_kube? !!options[:without_kube] end