-
Notifications
You must be signed in to change notification settings - Fork 900
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15884 from carbonin/container_workers
[REARCH] Container workers
- Loading branch information
Showing
23 changed files
with
297 additions
and
6 deletions.
There are no files selected for viewing
6 changes: 6 additions & 0 deletions
6
app/models/manageiq/providers/base_manager/metrics_collector_worker.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,12 @@ | ||
class MiqEventHandler < MiqQueueWorkerBase | ||
include MiqWorker::ReplicaPerWorker | ||
|
||
require_nested :Runner | ||
|
||
self.required_roles = ["event"] | ||
self.default_queue_name = "ems" | ||
|
||
def self.supports_container? | ||
true | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,13 @@ | ||
class MiqGenericWorker < MiqQueueWorkerBase | ||
include MiqWorker::ReplicaPerWorker | ||
|
||
require_nested :Runner | ||
|
||
self.default_queue_name = "generic" | ||
self.check_for_minimal_role = false | ||
self.workers = -> { MiqServer.minimal_env? ? 1 : worker_settings[:count] } | ||
|
||
def self.supports_container? | ||
true | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,15 @@ | ||
class MiqPriorityWorker < MiqQueueWorkerBase | ||
include MiqWorker::ReplicaPerWorker | ||
|
||
require_nested :Runner | ||
|
||
self.default_queue_name = "generic" | ||
|
||
def self.queue_priority | ||
MiqQueue::HIGH_PRIORITY | ||
end | ||
|
||
def self.supports_container? | ||
true | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,12 @@ | ||
class MiqReportingWorker < MiqQueueWorkerBase | ||
include MiqWorker::ReplicaPerWorker | ||
|
||
require_nested :Runner | ||
|
||
self.required_roles = ["reporting"] | ||
self.default_queue_name = "reporting" | ||
|
||
def self.supports_container? | ||
true | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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_container? | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
require 'kubeclient' | ||
|
||
class MiqWorker | ||
module ContainerCommon | ||
extend ActiveSupport::Concern | ||
|
||
def configure_worker_deployment(definition, replicas = 0) | ||
definition[:spec][:replicas] = replicas | ||
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[: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? | ||
end | ||
|
||
def container_image_name | ||
"manageiq/manageiq-base-worker" | ||
end | ||
|
||
def container_image_tag | ||
"latest" | ||
end | ||
|
||
def worker_deployment_name | ||
@worker_deployment_name ||= begin | ||
deployment_name = abbreviated_class_name.dup.chomp("Worker").sub("Manager", "").sub(/^Miq/, "") | ||
deployment_name << "-#{Array(ems_id).map { |id| ApplicationRecord.split_id(id).last }.join("-")}" if respond_to?(:ems_id) | ||
deployment_name.underscore.dasherize.tr("/", "-") | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
class MiqWorker | ||
module DeploymentPerWorker | ||
extend ActiveSupport::Concern | ||
|
||
def create_container_objects | ||
ContainerOrchestrator.new.create_deployment_config(worker_deployment_name) do |definition| | ||
configure_worker_deployment(definition, 1) | ||
definition[:spec][:template][:spec][:containers].first[:env] << {:name => "EMS_IDS", :value => Array.wrap(self.class.ems_id_from_queue_name(queue_name)).join(",")} | ||
end | ||
end | ||
|
||
def delete_container_objects | ||
ContainerOrchestrator.new.delete_deployment_config(worker_deployment_name) | ||
end | ||
|
||
def stop_container | ||
delete_container_objects | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
class MiqWorker | ||
module ReplicaPerWorker | ||
extend ActiveSupport::Concern | ||
|
||
def create_container_objects | ||
ContainerOrchestrator.new.create_deployment_config(worker_deployment_name) do |definition| | ||
configure_worker_deployment(definition) | ||
end | ||
scale_deployment | ||
end | ||
|
||
def delete_container_objects | ||
ContainerOrchestrator.new.delete_deployment_config(worker_deployment_name) | ||
end | ||
|
||
def stop_container | ||
scale_deployment | ||
end | ||
end | ||
end |
Oops, something went wrong.