Skip to content

Commit

Permalink
Create env vars to override the full worker image ref
Browse files Browse the repository at this point in the history
This will allow advanced users more flexability in how
the worker images are specified. Specifically this allows
changing the image name itself and also allows for digest-based
identifiers (rather than using only tags)

Applies to ManageIQ/manageiq-pods#557
  • Loading branch information
carbonin committed Jun 19, 2020
1 parent 531cc04 commit 3b51664
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 1 deletion.
4 changes: 4 additions & 0 deletions app/models/miq_ui_worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,8 @@ def container_port
def container_image_name
"manageiq-ui-worker"
end

def container_image
ENV["UI_WORKER_IMAGE"] || default_image
end
end
10 changes: 9 additions & 1 deletion app/models/miq_worker/container_common.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def configure_worker_deployment(definition, replicas = 0)
container[:imagePullPolicy] = "IfNotPresent"
end

container[:image] = "#{container_image_namespace}/#{container_image_name}:#{container_image_tag}"
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(",")}
end
Expand All @@ -32,6 +32,14 @@ def zone_selector
{"#{Vmdb::Appliance.PRODUCT_NAME.downcase}/zone-#{MiqServer.my_zone}" => "true"}
end

def container_image
ENV["BASE_WORKER_IMAGE"] || default_image
end

def default_image
"#{container_image_namespace}/#{container_image_name}:#{container_image_tag}"
end

def container_image_namespace
ENV["CONTAINER_IMAGE_NAMESPACE"]
end
Expand Down
4 changes: 4 additions & 0 deletions app/models/miq_worker/service_worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,9 @@ def container_port
def container_image_name
"manageiq-webserver-worker"
end

def container_image
ENV["WEBSERVER_WORKER_IMAGE"] || default_image
end
end
end
41 changes: 41 additions & 0 deletions spec/models/miq_worker/container_common_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,4 +92,45 @@ def deployment_name_for(name)
worker.scale_deployment
end
end

describe "#container_image" do
let(:generic_worker) { MiqGenericWorker.new }
let(:ui_worker) { MiqUiWorker.new }
let(:api_worker) { MiqWebServiceWorker.new }

it "uses the BASE_WORKER_IMAGE value for a generic worker" do
image_ref = "registry.example.com/manageiq/manageiq-test@sha256:2997e41a1195df90d8daf9714b619c9ae0c053f3d79e39bd8ed2d18b3c8da52a"
stub_const("ENV", ENV.to_h.merge("BASE_WORKER_IMAGE" => image_ref))
expect(generic_worker.container_image).to eq(image_ref)
end

it "uses the UI_WORKER_IMAGE value for a UI worker" do
image_ref = "registry.example.com/manageiq/manageiq-ui-test@sha256:2997e41a1195df90d8daf9714b619c9ae0c053f3d79e39bd8ed2d18b3c8da52a"
stub_const("ENV", ENV.to_h.merge("UI_WORKER_IMAGE" => image_ref))
expect(ui_worker.container_image).to eq(image_ref)
end

it "uses the WEBSERVER_WORKER_IMAGE value for an API worker" do
image_ref = "registry.example.com/manageiq/manageiq-web-test@sha256:2997e41a1195df90d8daf9714b619c9ae0c053f3d79e39bd8ed2d18b3c8da52a"
stub_const("ENV", ENV.to_h.merge("WEBSERVER_WORKER_IMAGE" => image_ref))
expect(api_worker.container_image).to eq(image_ref)
end

context "when CONTAINER_IMAGE_NAMESPACE is set" do
before { stub_const("ENV", ENV.to_h.merge("CONTAINER_IMAGE_NAMESPACE" => "registry.example.com/manageiq")) }

it "uses the correct default value" do
expect(generic_worker.container_image).to eq("registry.example.com/manageiq/manageiq-base-worker:latest")
expect(ui_worker.container_image).to eq("registry.example.com/manageiq/manageiq-ui-worker:latest")
expect(api_worker.container_image).to eq("registry.example.com/manageiq/manageiq-webserver-worker:latest")
end

it "allows tag overrides" do
stub_const("ENV", ENV.to_h.merge("CONTAINER_IMAGE_TAG" => "jansa-1"))
expect(generic_worker.container_image).to eq("registry.example.com/manageiq/manageiq-base-worker:jansa-1")
expect(ui_worker.container_image).to eq("registry.example.com/manageiq/manageiq-ui-worker:jansa-1")
expect(api_worker.container_image).to eq("registry.example.com/manageiq/manageiq-webserver-worker:jansa-1")
end
end
end
end

0 comments on commit 3b51664

Please sign in to comment.