Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unify Worker Environment Variables systemd/k8s #23197

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion app/models/automation_worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,13 @@ def self.kill_priority
MiqWorkerType::KILL_PRIORITY_GENERIC_WORKERS
end

def container_environment_variables
super.merge("AUTOMATION_JOB_SERVICE_ACCOUNT" => ENV.fetch("WORKER_SERVICE_ACCOUNT"))
end

def configure_worker_deployment(definition, replicas = 0)
super

definition[:spec][:template][:spec][:serviceAccountName] = "manageiq-automation"
definition[:spec][:template][:spec][:containers][0][:env] << {:name => "AUTOMATION_JOB_SERVICE_ACCOUNT", :value => ENV.fetch("WORKER_SERVICE_ACCOUNT")}
end
end
8 changes: 7 additions & 1 deletion app/models/miq_worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -379,9 +379,15 @@ def command_line
self.class.build_command_line(*worker_options.values_at(:guid, :ems_id))
end

def environment_variables
{
"BUNDLER_GROUPS" => self.class.bundler_groups.join(",")
}
end

def start_runner_via_spawn
pid = Kernel.spawn(
{"BUNDLER_GROUPS" => self.class.bundler_groups.join(",")},
environment_variables,
command_line,
[:out, :err] => [Rails.root.join("log/evm.log"), "a"]
)
Expand Down
18 changes: 9 additions & 9 deletions app/models/miq_worker/container_common.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,18 @@ def configure_worker_deployment(definition, replicas = 0)
definition[:spec][:template][:spec][:nodeSelector] = zone_selector
end

env = container_environment_variables.merge(environment_variables).map { |name, value| {:name => name, :value => value} }

container = definition[:spec][:template][:spec][:containers].first

if container_image_tag.include?("latest")
container[:imagePullPolicy] = "Always"
else
container[:imagePullPolicy] = "IfNotPresent"
end
container[:imagePullPolicy] = container_image_tag.include?("latest") ? "Always" : "IfNotPresent"
container[:image] = container_image
container[:resources] = resource_constraints
container[:env].concat(env)
end

container[:image] = container_image
container[:env] << {:name => "WORKER_CLASS_NAME", :value => self.class.name}
container[:env] << {:name => "BUNDLER_GROUPS", :value => self.class.bundler_groups.join(",")}
container[:resources] = resource_constraints
def container_environment_variables
{"WORKER_CLASS_NAME" => self.class.name}
end

def scale_deployment
Expand Down
1 change: 0 additions & 1 deletion app/models/miq_worker/deployment_per_worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ module DeploymentPerWorker
def create_container_objects
ContainerOrchestrator.new.create_deployment(worker_deployment_name) do |definition|
configure_worker_deployment(definition, 1)
definition[:spec][:template][:spec][:containers].first[:env] << {:name => "EMS_ID", :value => self.class.ems_id_from_queue_name(queue_name).to_s}
end
end

Expand Down
6 changes: 4 additions & 2 deletions app/models/miq_worker/service_worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@ def configure_service_worker_deployment(definition)

container = definition[:spec][:template][:spec][:containers].first
container[:ports] = [{:containerPort => SERVICE_PORT}, {:containerPort => HEALTH_PORT}]
container[:env] << {:name => "PORT", :value => container_port.to_s}
container[:env] << {:name => "BINDING_ADDRESS", :value => "0.0.0.0"}
container[:volumeMounts] ||= []
definition[:spec][:template][:spec][:volumes] ||= []
end
Expand All @@ -68,5 +66,9 @@ def container_image_name
def container_image
ENV["WEBSERVER_WORKER_IMAGE"] || default_image
end

def container_environment_variables
super.merge("PORT" => container_port.to_s, "BINDING_ADDRESS" => "0.0.0.0")
end
end
end
8 changes: 5 additions & 3 deletions app/models/miq_worker/systemd_common.rb
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,12 @@ def unit_config_file_path
end

def unit_config_file
environment = systemd_environment_variables.merge(environment_variables)

<<~UNIT_CONFIG_FILE
[Service]
#{unit_settings.compact.map { |key, value| "#{key}=#{value}" }.join("\n")}
#{unit_environment_variables.compact.map { |key, value| "Environment=#{key}=#{value}" }.join("\n")}
#{unit_settings.compact.map { |key, value| "#{key}=#{value}" }.join("\n")}
#{environment.compact.map { |key, value| "Environment=#{key}=#{value}" }.join("\n")}
UNIT_CONFIG_FILE
end

Expand All @@ -135,7 +137,7 @@ def unit_settings
end

# Override this in a child class to add environment variables
def unit_environment_variables
def systemd_environment_variables
{}
end
end
Expand Down
4 changes: 2 additions & 2 deletions app/models/mixins/per_ems_worker_mixin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ def worker_options
super.merge(:ems_id => ems_id)
end

def unit_environment_variables
super.merge("EMS_ID" => ems_id)
def environment_variables
super.merge("EMS_ID" => ems_id.to_s)
end
end
1 change: 0 additions & 1 deletion systemd/[email protected]
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ PartOf=manageiq-automation.target
WantedBy=manageiq-automation.target
[Service]
WorkingDirectory=/var/www/miq/vmdb
Environment=BUNDLER_GROUPS=manageiq_default,ui_dependencies
EnvironmentFile=/etc/default/manageiq*.properties
ExecStart=/usr/bin/ruby lib/workers/bin/run_single_worker.rb AutomationWorker --heartbeat --guid=%i
User=manageiq
Expand Down
1 change: 0 additions & 1 deletion systemd/[email protected]
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ PartOf=manageiq-ems_metrics_processor.target
WantedBy=manageiq-ems_metrics_processor.target
[Service]
WorkingDirectory=/var/www/miq/vmdb
Environment=BUNDLER_GROUPS=manageiq_default,ui_dependencies
EnvironmentFile=/etc/default/manageiq*.properties
ExecStart=/usr/bin/ruby lib/workers/bin/run_single_worker.rb MiqEmsMetricsProcessorWorker --heartbeat --guid=%i
User=manageiq
Expand Down
1 change: 0 additions & 1 deletion systemd/[email protected]
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ PartOf=manageiq-event_handler.target
WantedBy=manageiq-event_handler.target
[Service]
WorkingDirectory=/var/www/miq/vmdb
Environment=BUNDLER_GROUPS=manageiq_default,ui_dependencies
EnvironmentFile=/etc/default/manageiq*.properties
ExecStart=/usr/bin/ruby lib/workers/bin/run_single_worker.rb MiqEventHandler --heartbeat --guid=%i
User=manageiq
Expand Down
1 change: 0 additions & 1 deletion systemd/[email protected]
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ PartOf=manageiq-generic.target
WantedBy=manageiq-generic.target
[Service]
WorkingDirectory=/var/www/miq/vmdb
Environment=BUNDLER_GROUPS=manageiq_default,ui_dependencies
EnvironmentFile=/etc/default/manageiq*.properties
ExecStart=/usr/bin/ruby lib/workers/bin/run_single_worker.rb MiqGenericWorker --heartbeat --guid=%i
User=manageiq
Expand Down
1 change: 0 additions & 1 deletion systemd/[email protected]
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ PartOf=manageiq-priority.target
WantedBy=manageiq-priority.target
[Service]
WorkingDirectory=/var/www/miq/vmdb
Environment=BUNDLER_GROUPS=manageiq_default,ui_dependencies
EnvironmentFile=/etc/default/manageiq*.properties
ExecStart=/usr/bin/ruby lib/workers/bin/run_single_worker.rb MiqPriorityWorker --heartbeat --guid=%i
User=manageiq
Expand Down
1 change: 0 additions & 1 deletion systemd/[email protected]
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ Wants=httpd.service
WantedBy=manageiq-remote_console.target
[Service]
WorkingDirectory=/var/www/miq/vmdb
Environment=BUNDLER_GROUPS=manageiq_default,ui_dependencies
EnvironmentFile=/etc/default/manageiq*.properties
ExecStart=/usr/bin/ruby lib/workers/bin/run_single_worker.rb MiqRemoteConsoleWorker --heartbeat --guid=%i
User=manageiq
Expand Down
1 change: 0 additions & 1 deletion systemd/[email protected]
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ PartOf=manageiq-reporting.target
WantedBy=manageiq-reporting.target
[Service]
WorkingDirectory=/var/www/miq/vmdb
Environment=BUNDLER_GROUPS=manageiq_default,ui_dependencies
EnvironmentFile=/etc/default/manageiq*.properties
ExecStart=/usr/bin/ruby lib/workers/bin/run_single_worker.rb MiqReportingWorker --heartbeat --guid=%i
User=manageiq
Expand Down
1 change: 0 additions & 1 deletion systemd/[email protected]
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ PartOf=manageiq-schedule.target
WantedBy=manageiq-schedule.target
[Service]
WorkingDirectory=/var/www/miq/vmdb
Environment=BUNDLER_GROUPS=manageiq_default,ui_dependencies
EnvironmentFile=/etc/default/manageiq*.properties
ExecStart=/usr/bin/ruby lib/workers/bin/run_single_worker.rb MiqScheduleWorker --heartbeat --guid=%i
User=manageiq
Expand Down
1 change: 0 additions & 1 deletion systemd/[email protected]
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ PartOf=manageiq-smart_proxy.target
WantedBy=manageiq-smart_proxy.target
[Service]
WorkingDirectory=/var/www/miq/vmdb
Environment=BUNDLER_GROUPS=manageiq_default,ui_dependencies
EnvironmentFile=/etc/default/manageiq*.properties
ExecStart=/usr/bin/ruby lib/workers/bin/run_single_worker.rb MiqSmartProxyWorker --heartbeat --guid=%i
User=manageiq
Expand Down
1 change: 0 additions & 1 deletion systemd/[email protected]
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ Wants=httpd.service
WantedBy=manageiq-ui.target
[Service]
WorkingDirectory=/var/www/miq/vmdb
Environment=BUNDLER_GROUPS=manageiq_default,ui_dependencies
EnvironmentFile=/etc/default/manageiq*.properties
ExecStart=/usr/bin/ruby lib/workers/bin/run_single_worker.rb MiqUiWorker --heartbeat --guid=%i
User=manageiq
Expand Down
1 change: 0 additions & 1 deletion systemd/[email protected]
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ Wants=httpd.service
WantedBy=manageiq-web_service.target
[Service]
WorkingDirectory=/var/www/miq/vmdb
Environment=BUNDLER_GROUPS=manageiq_default,ui_dependencies
EnvironmentFile=/etc/default/manageiq*.properties
ExecStart=/usr/bin/ruby lib/workers/bin/run_single_worker.rb MiqWebServiceWorker --heartbeat --guid=%i
User=manageiq
Expand Down