From 2cc0538d3b5c3fcccda413a8c789862d03af5b30 Mon Sep 17 00:00:00 2001 From: Brandon Dunne Date: Wed, 28 Jul 2021 18:15:21 -0400 Subject: [PATCH 1/2] Add volume mounts for httpd configuration --- app/models/miq_worker/service_worker.rb | 7 +++++++ .../models/miq_worker/container_common_spec.rb | 18 ++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/app/models/miq_worker/service_worker.rb b/app/models/miq_worker/service_worker.rb index 58935b00564..5e11097ceba 100644 --- a/app/models/miq_worker/service_worker.rb +++ b/app/models/miq_worker/service_worker.rb @@ -17,6 +17,13 @@ def create_container_objects 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 end scale_deployment diff --git a/spec/models/miq_worker/container_common_spec.rb b/spec/models/miq_worker/container_common_spec.rb index b9247c1cb38..15f4367049f 100644 --- a/spec/models/miq_worker/container_common_spec.rb +++ b/spec/models/miq_worker/container_common_spec.rb @@ -43,6 +43,24 @@ def deployment_name_for(name) expect(test_deployment.dig(:spec, :template, :spec).keys).not_to include(:nodeSelector) end + + it "MiqUiWorker adds the ui_httpd_configs volume mount" do + container_orchestrator = ContainerOrchestrator.new + kubeclient = double("Kubeclient::Client") + + expect(ContainerOrchestrator).to receive(:new).and_return(container_orchestrator) + expect(container_orchestrator).to receive(:my_namespace).and_return("my-namespace") + expect(container_orchestrator).to receive(:raw_connect).and_return(kubeclient) + + expect(kubeclient).to receive(:create_deployment) do |deployment| + expect(deployment.fetch_path(:spec, :template, :spec, :containers, 0, :volumeMounts)).to match_array([{:name => "ui-httpd-configs", :mountPath => "/etc/httpd/conf.d"}]) + expect(deployment.fetch_path(:spec, :template, :spec, :volumes)).to match_array([{:name=>"ui-httpd-configs", :configMap=>{:name=>"ui-httpd-configs", :defaultMode=>420}}]) + end + + ui_worker = MiqUiWorker.new + expect(ui_worker).to receive(:scale_deployment) + ui_worker.create_container_objects + end end describe "#zone_selector" do From e1d2df1a812739352b878cc13fde9f2836b4fdd4 Mon Sep 17 00:00:00 2001 From: Brandon Dunne Date: Mon, 23 Aug 2021 14:45:44 -0400 Subject: [PATCH 2/2] Move service worker configuration into a method --- app/models/miq_ui_worker.rb | 7 +++++++ app/models/miq_worker/service_worker.rb | 27 ++++++++++++------------- 2 files changed, 20 insertions(+), 14 deletions(-) diff --git a/app/models/miq_ui_worker.rb b/app/models/miq_ui_worker.rb index 520f1069d37..2b24ebc9f4b 100644 --- a/app/models/miq_ui_worker.rb +++ b/app/models/miq_ui_worker.rb @@ -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 diff --git a/app/models/miq_worker/service_worker.rb b/app/models/miq_worker/service_worker.rb index 5e11097ceba..3a82721c76d 100644 --- a/app/models/miq_worker/service_worker.rb +++ b/app/models/miq_worker/service_worker.rb @@ -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 @@ -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