Skip to content

Commit

Permalink
Merge pull request #19451 from carbonin/re_rearch
Browse files Browse the repository at this point in the history
Enable workers as containers
  • Loading branch information
Fryguy authored Nov 4, 2019
2 parents 51c4282 + 469f730 commit e2f0281
Show file tree
Hide file tree
Showing 10 changed files with 29 additions and 14 deletions.
2 changes: 2 additions & 0 deletions app/models/miq_server/worker_management/monitor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ def check_pending_stop(class_name = nil)
end

def check_not_responding(class_name = nil)
return [] if MiqEnvironment::Command.is_podified?

processed_workers = []
miq_workers.each do |w|
next unless class_name.nil? || (w.type == class_name)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,15 @@ module MiqServer::WorkerManagement::Monitor::SystemLimits
}

def kill_workers_due_to_resources_exhausted?
return false if MiqEnvironment::Command.is_podified?

options = worker_monitor_settings[:kill_algorithm].merge(:type => :kill)
invoke_algorithm(options)
end

def enough_resource_to_start_worker?(worker_class)
return true if MiqEnvironment::Command.is_podified?

# HACK, sync_config is done in the server, while this method is called from miq_worker
# This method should move to the worker and the server should pass the settings.
sync_config if worker_monitor_settings.nil? || child_worker_settings.nil?
Expand Down
2 changes: 2 additions & 0 deletions app/models/miq_server/worker_management/monitor/validation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ module MiqServer::WorkerManagement::Monitor::Validation
extend ActiveSupport::Concern

def validate_worker(w)
return true if MiqEnvironment::Command.is_podified?

time_threshold = get_time_threshold(w)
memory_threshold = get_memory_threshold(w)

Expand Down
2 changes: 1 addition & 1 deletion app/models/miq_ui_worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,6 @@ def container_port
end

def container_image_name
"manageiq/manageiq-ui-worker"
"manageiq-ui-worker"
end
end
5 changes: 5 additions & 0 deletions app/models/miq_ui_worker/runner.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
class MiqUiWorker::Runner < MiqWorker::Runner
include MiqWebServerRunnerMixin

def prepare
super
MiqApache::Control.start if MiqEnvironment::Command.is_podified?
end
end
8 changes: 5 additions & 3 deletions app/models/miq_worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class << self

def self.workers
return (self.has_minimal_env_option? ? 1 : 0) if MiqServer.minimal_env? && check_for_minimal_role
return 0 unless has_required_role?
return @workers.call if @workers.kind_of?(Proc)
return @workers unless @workers.nil?
workers_configured_count
Expand Down Expand Up @@ -137,7 +138,7 @@ def self.enough_resource_to_start_worker?
def self.sync_workers
w = include_stopping_workers_on_synchronize ? find_alive : find_current_or_starting
current = w.length
desired = self.has_required_role? ? workers : 0
desired = workers
result = {:adds => [], :deletes => []}

if current != desired
Expand Down Expand Up @@ -358,8 +359,7 @@ def self.supports_container?
end

def self.containerized_worker?
# un-rearch containers until further notice
return false
MiqEnvironment::Command.is_podified? && supports_container?
end

def containerized_worker?
Expand Down Expand Up @@ -527,6 +527,8 @@ def log_destroy_of_worker_messages
end

def status_update
return if MiqEnvironment::Command.is_podified?

begin
pinfo = MiqProcess.processInfo(pid)
rescue Errno::ESRCH
Expand Down
12 changes: 8 additions & 4 deletions app/models/miq_worker/container_common.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,21 @@ def configure_worker_deployment(definition, replicas = 0)
definition[:spec][:template][:spec][:terminationGracePeriodSeconds] = self.class.worker_settings[:stopping_timeout].seconds

container = definition[:spec][:template][:spec][:containers].first
container[:image] = "#{container_image_name}:#{container_image_tag}"
container[:image] = "#{container_image_namespace}/#{container_image_name}:#{container_image_tag}"
container[:env] << {:name => "WORKER_CLASS_NAME", :value => self.class.name}
end

def scale_deployment
ContainerOrchestrator.new.scale(worker_deployment_name, self.class.workers_configured_count)
delete_container_objects if self.class.workers_configured_count.zero?
ContainerOrchestrator.new.scale(worker_deployment_name, self.class.workers)
delete_container_objects if self.class.workers.zero?
end

def container_image_namespace
ENV["CONTAINER_IMAGE_NAMESPACE"]
end

def container_image_name
"manageiq/manageiq-base-worker"
"manageiq-base-worker"
end

def container_image_tag
Expand Down
2 changes: 1 addition & 1 deletion app/models/miq_worker/service_worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def container_port

# Can be overriden by including classes
def container_image_name
"manageiq/manageiq-webserver-worker"
"manageiq-webserver-worker"
end
end
end
2 changes: 1 addition & 1 deletion app/models/mixins/miq_web_server_worker_mixin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def sync_workers

workers = find_current_or_starting
current = workers.length
desired = self.has_required_role? ? self.workers : 0
desired = self.workers
result = {:adds => [], :deletes => []}
ports = all_ports_in_use

Expand Down
4 changes: 0 additions & 4 deletions lib/container_orchestrator/object_definition.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,11 @@ def secret_definition(name, string_data)

def default_environment
[
{:name => "ARTEMIS_USER", :value => ENV["ARTEMIS_USER"]},
{:name => "DATABASE_SERVICE_NAME", :value => ENV["DATABASE_SERVICE_NAME"]},
{:name => "GUID", :value => MiqServer.my_guid},
{:name => "MEMCACHED_SERVER", :value => ENV["MEMCACHED_SERVER"]},
{:name => "MEMCACHED_SERVICE_NAME", :value => ENV["MEMCACHED_SERVICE_NAME"]},
{:name => "WORKER_HEARTBEAT_FILE", :value => Rails.root.join("tmp", "worker.hb").to_s},
{:name => "WORKER_HEARTBEAT_METHOD", :value => "file"},
{:name => "ARTEMIS_PASSWORD",
:valueFrom => {:secretKeyRef=>{:name => "#{app_name}-secrets", :key => "artemis-password"}}},
{:name => "DATABASE_URL",
:valueFrom => {:secretKeyRef=>{:name => "#{app_name}-secrets", :key => "database-url"}}},
{:name => "V2_KEY",
Expand Down

0 comments on commit e2f0281

Please sign in to comment.