Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
agrare committed Jul 29, 2024
1 parent bf069d8 commit f1548c8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ group :cisco_intersight, :manageiq_default do
end

group :embedded_terraform, :manageiq_default do
gem "manageiq-providers-embedded_terraform", :git => "https://github.com/agrare/manageiq-providers-embedded_terraform", :branch => "always_create_worker_record"
manageiq_plugin "manageiq-providers-embedded_terraform"
end

Expand Down
15 changes: 13 additions & 2 deletions app/models/miq_server/worker_management/kubernetes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,10 @@ def sync_starting_workers
# If the current worker doesn't have a system_uid assigned then find the first
# pod available for our worker type and link them up.
if worker.system_uid.nil?
_log.info("AG: found a worker without a system_uid: Class [#{worker.class.name}] Id [#{worker.id}]")
system_uid = pods_without_workers.detect { |pod_name| pod_name.start_with?(worker.worker_deployment_name) }
if system_uid
_log.info("AG: found a pod #{system_uid} assigning to worker #{worker.class.name} #{worker.id}")
pods_without_workers.delete(system_uid)
worker.update!(:system_uid => system_uid)
end
Expand All @@ -38,8 +40,10 @@ def sync_starting_workers
worker_pod = current_pods[worker.system_uid]
next if worker_pod.nil?

container_status = worker_pod.status.containerStatuses.find { |container| container.name == worker.worker_deployment_name }
if worker_pod.status.phase == "Running" && container_status.ready && container_status.started
_log.info("AG: worker_pod [#{worker_pod.inspect}]")
container_status = worker_pod.dig(:status, :container_statuses).find { |container| container[:name] == worker.worker_deployment_name }

if worker_pod.dig(:status, :phase) == "Running" && container_status[:ready] && container_status[:started]
worker.update!(:status => "started")
end
end
Expand Down Expand Up @@ -200,8 +204,11 @@ def monitor_deployments(monitor_started)
current_deployments.clear
resource_version = collect_initial(:deployments)

_log.info("AG: waiting......")
sleep(5)
monitor_started.set

_log.info("AG: waiting......Complete")
watch_for_events(:deployments, resource_version)
end
end
Expand All @@ -211,8 +218,11 @@ def monitor_pods(monitor_started)
current_pods.clear
resource_version = collect_initial(:pods)

_log.info("AG: waiting......")
sleep(5)
monitor_started.set

_log.info("AG: waiting......Complete")
# watch_for_events doesn't return unless an error caused us to break out of it, so we'll start over again
watch_for_events(:pods, resource_version)
end
Expand Down Expand Up @@ -266,6 +276,7 @@ def save_pod(pod)
ch[:label_name] = pod.metadata.labels.name
ch[:last_state_terminated] = pod.status.containerStatuses.any? { |cs| cs.lastState.terminated }
ch[:container_restarts] = pod.status.containerStatuses.sum { |cs| cs.restartCount.to_i }
ch[:status] = pod.to_h[:status]

name = pod.metadata.name
current_pods[name] ||= ch
Expand Down

0 comments on commit f1548c8

Please sign in to comment.