diff --git a/app/models/miq_server/worker_management/kubernetes.rb b/app/models/miq_server/worker_management/kubernetes.rb index 3f949b6018a0..7771672e374d 100644 --- a/app/models/miq_server/worker_management/kubernetes.rb +++ b/app/models/miq_server/worker_management/kubernetes.rb @@ -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) @@ -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 diff --git a/app/models/miq_server/worker_management/monitor.rb b/app/models/miq_server/worker_management/monitor.rb index eb1a90eb62c0..23720726fff5 100644 --- a/app/models/miq_server/worker_management/monitor.rb +++ b/app/models/miq_server/worker_management/monitor.rb @@ -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 diff --git a/spec/models/miq_server/worker_management/kubernetes_spec.rb b/spec/models/miq_server/worker_management/kubernetes_spec.rb index ac619d08f9d3..36133ddbc6db 100644 --- a/spec/models/miq_server/worker_management/kubernetes_spec.rb +++ b/spec/models/miq_server/worker_management/kubernetes_spec.rb @@ -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' } @@ -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