Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

be more efficient by reusing the response of create and update #3448

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 2 additions & 6 deletions plugins/kubernetes/app/models/kubernetes/resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -117,23 +117,19 @@ def expire_resource_cache
remove_instance_variable(:@resource) if defined?(@resource)
end

# TODO: remove the expire_cache and assign @resource but that breaks a bunch of deploy_executor tests
def create
return if @delete_resource
restore_template do
@template[:metadata].delete(:resourceVersion)
request(:create, @template)
@resource = request(:create, @template)
end
expire_resource_cache
rescue Kubeclient::ResourceNotFoundError => e
raise_kubernetes_error(e.message)
end

# TODO: remove the expire_cache and assign @resource but that breaks a bunch of deploy_executor tests
def update
ensure_not_updating_match_labels
request(:update, template_for_update)
expire_resource_cache
@resource = request(:update, template_for_update)
end

def ensure_not_updating_match_labels
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ def worker_is_unstable

stub_request(:get, "#{deployments_url}/test-app-server").to_return(status: 404) # previous deploys ? -> none!
stub_request(:get, "#{deployments_url}/test-resque-worker").to_return(status: 404) # previous deploys ? -> none!
stub_request(:post, deployments_url).to_return(body: "{}") # creates deployment
stub_request(:post, deployments_url). # creates deployment
to_return(body: {spec: {selector: {matchLabels: {project: "some-project", role: "some-role"}}}}.to_json)
stub_request(:put, "#{deployments_url}/test-resque-worker").to_return(body: '{}') # during delete for rollback

Kubernetes::DeployExecutor.any_instance.stubs(:sleep) # not using .executor to keep it uninitialized
Expand Down Expand Up @@ -608,7 +609,7 @@ def worker_is_unstable
out.must_include rollback_indicator
out.must_include "DONE" # DONE is shown ... we got past the rollback
out.wont_include "SUCCESS"
out.wont_include "FAILED"
out.wont_include "FAILED" # rollback failed
end

it "deletes when there was no previous deployed resource" do
Expand All @@ -620,7 +621,7 @@ def worker_is_unstable
out.wont_include rollback_indicator
out.must_include "DONE" # DONE is shown ... we got past the rollback
out.wont_include "SUCCESS"
out.wont_include "FAILED"
out.wont_include "FAILED" # rollback failed
end

it "does not crash when rollback fails" do
Expand Down
4 changes: 2 additions & 2 deletions plugins/kubernetes/test/models/kubernetes/resource_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def assert_create_and_delete_requests(**args, &block)
let(:url) { "#{origin}/apis/extensions/v1beta1/namespaces/pod1/deployments/some-project" }

it "creates when missing" do
assert_request(:get, url, to_return: [{status: 404}, {body: "{}"}]) do
assert_request(:get, url, to_return: {status: 404}) do
assert_request(:post, base_url, to_return: {body: "{}"}) do
resource.deploy
end
Expand All @@ -119,7 +119,7 @@ def assert_create_and_delete_requests(**args, &block)
end

it "updates existing" do
assert_request(:get, url, to_return: {body: "{}"}, times: 2) do
assert_request(:get, url, to_return: {body: "{}"}) do
args = ->(x) { x.body.must_include '"replicas":2'; true }
assert_request(:put, url, to_return: {body: "{}"}, with: args) do
resource.deploy
Expand Down