diff --git a/app/models/automation_worker.rb b/app/models/automation_worker.rb index 40ce38cecd36..5783ac285e7a 100644 --- a/app/models/automation_worker.rb +++ b/app/models/automation_worker.rb @@ -10,4 +10,10 @@ class AutomationWorker < MiqQueueWorkerBase def self.kill_priority MiqWorkerType::KILL_PRIORITY_GENERIC_WORKERS end + + def configure_worker_deployment(definition, replicas = 0) + super + + definition[:spec][:template][:spec][:serviceAccountName] = "manageiq-automation" + end end diff --git a/spec/models/automation_worker_spec.rb b/spec/models/automation_worker_spec.rb new file mode 100644 index 000000000000..80f5009d0709 --- /dev/null +++ b/spec/models/automation_worker_spec.rb @@ -0,0 +1,35 @@ +RSpec.describe AutomationWorker do + describe "kubernetes worker deployment" do + let(:test_deployment) do + { + :metadata => { + :name => "test", + :labels => {:app => "manageiq"}, + :namespace => "manageiq", + }, + :spec => { + :selector => {:matchLabels => {:name => "test"}}, + :template => { + :metadata => {:name => "test", :labels => {:name => "test", :app => "manageiq"}}, + :spec => { + :containers => [{ + :name => "test", + :env => [] + }] + } + } + } + } + end + + it "#configure_worker_deplyoment adds a node selector based on the zone name" do + EvmSpecHelper.local_miq_server + + worker = described_class.new + worker.configure_worker_deployment(test_deployment) + + expect(test_deployment.dig(:spec, :template, :spec, :nodeSelector)).to eq("manageiq/zone-#{MiqServer.my_zone}".gsub(" ", "-") => "true") + expect(test_deployment.dig(:spec, :template, :spec, :serviceAccountName)).to eq("manageiq-automation") + end + end +end