Skip to content

Commit

Permalink
Differentiate being in a container vs running in OpenShift/k8s
Browse files Browse the repository at this point in the history
Before this change we would try to start worker containers in the
monolithic image, which we don't want to be doing.
  • Loading branch information
carbonin committed Feb 19, 2018
1 parent 36f79ab commit 0735aec
Show file tree
Hide file tree
Showing 10 changed files with 17 additions and 12 deletions.
2 changes: 1 addition & 1 deletion app/models/authenticator/httpd.rb
Expand Up @@ -124,7 +124,7 @@ def user_details_from_headers(username, request)
end

def user_attrs_from_external_directory(username)
if MiqEnvironment::Command.is_container?
if MiqEnvironment::Command.is_podified?
user_attrs_from_external_directory_via_dbus_api_service(username)
else
user_attrs_from_external_directory_via_dbus(username)
Expand Down
2 changes: 1 addition & 1 deletion app/models/embedded_ansible_worker/runner.rb
Expand Up @@ -74,7 +74,7 @@ def provider_url
end

def provider_uri_hash
if MiqEnvironment::Command.is_container?
if MiqEnvironment::Command.is_podified?
{:scheme => "https", :host => ContainerEmbeddedAnsible::ANSIBLE_SERVICE_NAME, :path => "/api/v1"}
elsif Rails.env.development?
{:scheme => "http", :host => "localhost", :path => "/api/v1", :port => 54321}
Expand Down
2 changes: 1 addition & 1 deletion app/models/miq_group.rb
Expand Up @@ -135,7 +135,7 @@ def self.get_ldap_groups_by_user(user, bind_dn, bind_pwd)
end

def self.get_httpd_groups_by_user(user)
if MiqEnvironment::Command.is_container?
if MiqEnvironment::Command.is_podified?
get_httpd_groups_by_user_via_dbus_api_service(user)
else
get_httpd_groups_by_user_via_dbus(user)
Expand Down
2 changes: 1 addition & 1 deletion app/models/miq_server/worker_management/monitor.rb
Expand Up @@ -92,7 +92,7 @@ def check_pending_stop(class_name = nil)
end

def check_not_responding(class_name = nil)
return [] if MiqEnvironment::Command.is_container?
return [] if MiqEnvironment::Command.is_podified?
processed_workers = []
miq_workers.each do |w|
next unless class_name.nil? || (w.type == class_name)
Expand Down
Expand Up @@ -9,13 +9,13 @@ module MiqServer::WorkerManagement::Monitor::SystemLimits
}

def kill_workers_due_to_resources_exhausted?
return false if MiqEnvironment::Command.is_container?
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_container?
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
Expand Up @@ -2,7 +2,7 @@ module MiqServer::WorkerManagement::Monitor::Validation
extend ActiveSupport::Concern

def validate_worker(w)
return true if MiqEnvironment::Command.is_container?
return true if MiqEnvironment::Command.is_podified?
time_threshold = get_time_threshold(w)
restart_interval = get_restart_interval(w)
memory_threshold = get_memory_threshold(w)
Expand Down
2 changes: 1 addition & 1 deletion app/models/miq_ui_worker/runner.rb
Expand Up @@ -3,6 +3,6 @@ class MiqUiWorker::Runner < MiqWorker::Runner

def prepare
super
MiqApache::Control.start if MiqEnvironment::Command.is_container?
MiqApache::Control.start if MiqEnvironment::Command.is_podified?
end
end
4 changes: 2 additions & 2 deletions app/models/miq_worker.rb
Expand Up @@ -370,7 +370,7 @@ def self.supports_container?
end

def self.containerized_worker?
MiqEnvironment::Command.is_container? && supports_container?
MiqEnvironment::Command.is_podified? && supports_container?
end

def containerized_worker?
Expand Down Expand Up @@ -525,7 +525,7 @@ def log_destroy_of_worker_messages
end

def status_update
return if MiqEnvironment::Command.is_container?
return if MiqEnvironment::Command.is_podified?

begin
pinfo = MiqProcess.processInfo(pid)
Expand Down
7 changes: 6 additions & 1 deletion lib/miq_environment.rb
Expand Up @@ -6,7 +6,7 @@ class Command

def self.supports_memcached?
return @supports_memcached unless @supports_memcached.nil?
@supports_memcached = is_linux? && is_appliance? && !is_container? && supports_command?('memcached') && supports_command?('memcached-tool') && supports_command?('service')
@supports_memcached = is_linux? && is_appliance? && !is_podified? && supports_command?('memcached') && supports_command?('memcached-tool') && supports_command?('service')
end

def self.supports_apache?
Expand All @@ -24,6 +24,11 @@ def self.is_container?
@is_container = ENV["CONTAINER"] == "true"
end

def self.is_podified?
return @is_podified unless @is_podified.nil?
@is_podified = is_container? && ContainerOrchestrator.available?
end

def self.is_appliance?
return @is_appliance unless @is_appliance.nil?
@is_appliance = self.is_linux? && File.exist?('/var/www/miq/vmdb')
Expand Down
2 changes: 1 addition & 1 deletion spec/models/embedded_ansible_worker/runner_spec.rb
Expand Up @@ -103,7 +103,7 @@

context "in a container" do
before do
expect(MiqEnvironment::Command).to receive(:is_container?).and_return(true)
expect(MiqEnvironment::Command).to receive(:is_podified?).and_return(true)
end

it "creates the provider with the service name for the URL" do
Expand Down

0 comments on commit 0735aec

Please sign in to comment.