18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
# File 'lib/dapp/kube/kubernetes/manager/job.rb', line 18
def watch_till_done!
wait_till_exists!
job = Kubernetes::Client::Resource::Job.new(dapp.kubernetes.job(name))
loop do
process_pod = dapp.kubernetes.pod_list.fetch('items', [])
.select do |pod_spec|
pod_spec.fetch('metadata', {}).fetch('labels', {})['controller-uid'] == job.uid
end
.reject do |pod_spec|
@processed_pods_names.include? pod_spec.fetch('metadata', {})['name']
end
.sort_by do |pod_spec|
Time.parse(pod_spec.fetch('metadata', {})['creationTimestamp'])
end
.map {|pod_spec| Kubernetes::Client::Resource::Pod.new(pod_spec)}
.first
if process_pod.nil?
job = Kubernetes::Client::Resource::Job.new(dapp.kubernetes.job(name))
if job.succeeded?
break
elsif job.failed?
dapp.log_warning "Job '#{name}' has been failed: #{job.spec['status']}"
break
end
sleep 0.1
next
end
pod_manager = Kubernetes::Manager::Pod.new(dapp, process_pod.name)
begin
pod_manager.watch_till_done!
rescue Kubernetes::Client::Error::Pod::NotFound => err
dapp.log_warning "Pod '#{pod_manager.name}' has been deleted"
ensure
@processed_pods_names << process_pod.name
end
end
end
|