Skip to content

Commit

Permalink
Only run kube_monitor threads on master MiqServer
Browse files Browse the repository at this point in the history
On podified there are multiple miq_server instances but only one
"master".  All miq_servers run on the same kubernetes cluster and thus
only have to run one set of monitor_pods/monitor_deployments threads to
update the global current_pods/current_deployments hashes.
  • Loading branch information
agrare committed Nov 1, 2021
1 parent a58761c commit 70789e1
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
19 changes: 17 additions & 2 deletions app/models/miq_server/worker_management/kubernetes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,28 @@ def sync_monitor
end

def sync_from_system
# All miq_server instances have to reside on the same Kubernetes cluster, so
# we only have to sync the list of pods and deployments once
return unless my_server.is_master?

ensure_kube_monitors_started
cleanup_orphaned_worker_rows
sync_deployment_settings
end

def enough_resource_to_start_worker?(_worker_class)
true
end

def sync_workers
# Before syncing the workers check for any orphaned worker rows that don't have
# a current pod and delete them
cleanup_orphaned_worker_rows

# Update worker deployments with updated settings such as cpu/memory limits
sync_deployment_settings

super
end

def cleanup_orphaned_worker_rows
unless current_pods.empty?
orphaned_rows = podified_miq_workers.where.not(:system_uid => current_pods.keys)
Expand Down Expand Up @@ -131,6 +144,8 @@ def ensure_kube_monitors_started
end

def delete_failed_deployments
return unless my_server.is_master?

failed_deployments.each do |failed|
orchestrator.delete_deployment(failed)
end
Expand Down
4 changes: 4 additions & 0 deletions app/models/miq_server/worker_management/monitor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,10 @@ def do_system_limit_exceeded
end
end

def sync_from_system
raise NotImplementedError, "Must be implemented in a subclass"
end

def sync_monitor
@last_sync ||= Time.now.utc
sync_interval = @worker_monitor_settings[:sync_interval] || 30.minutes
Expand Down
3 changes: 1 addition & 2 deletions spec/models/miq_server/worker_management/kubernetes_spec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require 'recursive-open-struct'

RSpec.describe MiqServer::WorkerManagement::Kubernetes do
let(:server) { EvmSpecHelper.create_guid_miq_server_zone.second }
let(:server) { EvmSpecHelper.local_miq_server(:is_master => true) }
let(:orchestrator) { double("ContainerOrchestrator") }
let(:deployment_name) { '1-generic-79bb8b8bb5-8ggbg' }
let(:pod_label) { '1-generic' }
Expand Down Expand Up @@ -111,7 +111,6 @@
context "#ensure_kube_monitors_started" do
it "podified, ensures pod monitor started and orphaned rows are removed" do
expect(server.worker_manager).to receive(:ensure_kube_monitors_started)
expect(server.worker_manager).to receive(:cleanup_orphaned_worker_rows)
server.worker_manager.sync_from_system
end
end
Expand Down

0 comments on commit 70789e1

Please sign in to comment.