Skip to content

Commit

Permalink
Move service worker configuration into a method
Browse files Browse the repository at this point in the history
  • Loading branch information
bdunne committed Aug 23, 2021
1 parent 2cc0538 commit e1d2df1
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 14 deletions.
7 changes: 7 additions & 0 deletions app/models/miq_ui_worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,11 @@ def container_image_name
def container_image
ENV["UI_WORKER_IMAGE"] || default_image
end

def configure_service_worker_deployment(definition)
super

definition[:spec][:template][:spec][:containers].first[:volumeMounts] << {:name => "ui-httpd-configs", :mountPath => "/etc/httpd/conf.d"}
definition[:spec][:template][:spec][:volumes] << {:name=>"ui-httpd-configs", :configMap=>{:name=>"ui-httpd-configs", :defaultMode=>420}}
end
end
27 changes: 13 additions & 14 deletions app/models/miq_worker/service_worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,9 @@ def create_container_objects

orchestrator.create_deployment(worker_deployment_name) do |definition|
configure_worker_deployment(definition)
configure_service_worker_deployment(definition)

definition[:spec][:template][:metadata][:labels].merge!(service_label)

container = definition[:spec][:template][:spec][:containers].first
container[:ports] = [{:containerPort => SERVICE_PORT}]
container[:env] << {:name => "PORT", :value => container_port.to_s}
container[:env] << {:name => "BINDING_ADDRESS", :value => "0.0.0.0"}
add_readiness_probe(container)
container[:volumeMounts] ||= []
definition[:spec][:template][:spec][:volumes] ||= []

if kind_of?(MiqUiWorker)
container[:volumeMounts] << {:name => "ui-httpd-configs", :mountPath => "/etc/httpd/conf.d"}
definition[:spec][:template][:spec][:volumes] << {:name=>"ui-httpd-configs", :configMap=>{:name=>"ui-httpd-configs", :defaultMode=>420}}
end
add_readiness_probe(definition[:spec][:template][:spec][:containers].first)
end

scale_deployment
Expand All @@ -46,6 +34,17 @@ def add_readiness_probe(container_definition)
}
end

def configure_service_worker_deployment(definition)
definition[:spec][:template][:metadata][:labels].merge!(service_label)

container = definition[:spec][:template][:spec][:containers].first
container[:ports] = [{:containerPort => SERVICE_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

def service_label
{:service => worker_deployment_name.delete_prefix(deployment_prefix)}
end
Expand Down

0 comments on commit e1d2df1

Please sign in to comment.