Skip to content

Commit

Permalink
Merge pull request #20268 from carbonin/conditionally_add_messaging_env
Browse files Browse the repository at this point in the history
Conditionally add the messaging environment vars to worker containers
  • Loading branch information
bdunne authored Jun 10, 2020
2 parents cc688dd + b2e5683 commit 2a9cfb3
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 3 deletions.
13 changes: 10 additions & 3 deletions lib/container_orchestrator/object_definition.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,6 @@ def default_environment
{:name => "GUID", :value => MiqServer.my_guid},
{:name => "MEMCACHED_SERVER", :value => ENV["MEMCACHED_SERVER"]},
{:name => "MEMCACHED_SERVICE_NAME", :value => ENV["MEMCACHED_SERVICE_NAME"]},
{:name => "MESSAGING_PORT", :value => ENV["MESSAGING_PORT"]},
{:name => "MESSAGING_TYPE", :value => ENV["MESSAGING_TYPE"]},
{:name => "WORKER_HEARTBEAT_FILE", :value => Rails.root.join("tmp", "worker.hb").to_s},
{:name => "WORKER_HEARTBEAT_METHOD", :value => "file"},
{:name => "DATABASE_HOSTNAME",
Expand All @@ -77,7 +75,16 @@ def default_environment
{:name => "DATABASE_USER",
:valueFrom => {:secretKeyRef=>{:name => "postgresql-secrets", :key => "username"}}},
{:name => "ENCRYPTION_KEY",
:valueFrom => {:secretKeyRef=>{:name => "app-secrets", :key => "encryption-key"}}},
:valueFrom => {:secretKeyRef=>{:name => "app-secrets", :key => "encryption-key"}}}
] + messaging_environment
end

def messaging_environment
return [] unless ENV["MESSAGING_TYPE"].present?

[
{:name => "MESSAGING_PORT", :value => ENV["MESSAGING_PORT"]},
{:name => "MESSAGING_TYPE", :value => ENV["MESSAGING_TYPE"]},
{:name => "MESSAGING_HOSTNAME",
:valueFrom => {:secretKeyRef=>{:name => "kafka-secrets", :key => "hostname"}}},
{:name => "MESSAGING_PASSWORD",
Expand Down
28 changes: 28 additions & 0 deletions spec/lib/container_orchestrator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,34 @@
end
end

describe "#default_environment (private)" do
it "doesn't include messaging env vars when MESSAGING_TYPE is not set" do
env = subject.send(:default_environment)
expect(env).not_to include(hash_including(:name => "MESSAGING_TYPE"))
expect(env).not_to include(hash_including(:name => "MESSAGING_PORT"))
expect(env).not_to include(hash_including(:name => "MESSAGING_HOSTNAME"))
expect(env).not_to include(hash_including(:name => "MESSAGING_PASSWORD"))
expect(env).not_to include(hash_including(:name => "MESSAGING_USERNAME"))
end

context "when MESSAGING_TYPE is set" do
before { stub_const("ENV", ENV.to_h.merge("MESSAGING_TYPE" => "kafka", "MESSAGING_PORT" => "9092")) }

it "sets the messaging env vars" do
expect(subject.send(:default_environment)).to include(
{:name => "MESSAGING_PORT", :value => "9092"},
{:name => "MESSAGING_TYPE", :value => "kafka"},
{:name => "MESSAGING_HOSTNAME",
:valueFrom => {:secretKeyRef=>{:name => "kafka-secrets", :key => "hostname"}}},
{:name => "MESSAGING_PASSWORD",
:valueFrom => {:secretKeyRef=>{:name => "kafka-secrets", :key => "password"}}},
{:name => "MESSAGING_USERNAME",
:valueFrom => {:secretKeyRef=>{:name => "kafka-secrets", :key => "username"}}}
)
end
end
end

context "with stub connections" do
let(:apps_connection_stub) { double("AppsConnection") }
let(:kube_connection_stub) { double("KubeConnection") }
Expand Down

0 comments on commit 2a9cfb3

Please sign in to comment.