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

Update min cpln version #226

Merged
merged 6 commits into from
Aug 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ _Please add entries here for your pull requests that have not yet been released.
- Fixed issue where common options are not forwarded to other commands. [PR 207](https://github.com/shakacode/control-plane-flow/pull/207) by [Rafael Gomes](https://github.com/rafaelgomesxyz).
- Fixed BYOK endpoint. [PR 209](https://github.com/shakacode/control-plane-flow/pull/209) by [Sergey Tarasov](https://github.com/dzirtusss).
- Fixed issue where `generate` command fails if no project config exists. [PR 219](https://github.com/shakacode/control-plane-flow/pull/219) by [Zakir Dzhamaliddinov](https://github.com/zzaakiirr).
- Bumped min `cpln` version to `3.1.0` and fixed `cpln workload exec` calls. [PR 226](https://github.com/shakacode/control-plane-flow/pull/226) by [Rafael Gomes](https://github.com/rafaelgomesxyz).

## [3.0.1] - 2024-06-26

Expand Down
4 changes: 2 additions & 2 deletions lib/command/run.rb
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ def update_runner_workload # rubocop:disable Metrics/CyclomaticComplexity, Metri

step("Updating runner workload '#{runner_workload}'") do
# Update runner workload
@expected_deployed_version = cp.cron_workload_deployed_version(runner_workload) + 1
@expected_deployed_version = (cp.cron_workload_deployed_version(runner_workload) || 0) + 1
cp.apply_hash("kind" => "workload", "name" => runner_workload, "spec" => spec)
end
end
Expand All @@ -256,7 +256,7 @@ def wait_for_runner_workload_deploy

def wait_for_runner_workload_update
step("Waiting for runner workload '#{runner_workload}' to be updated", retry_on_failure: true) do
cp.cron_workload_deployed_version(runner_workload) >= expected_deployed_version
(cp.cron_workload_deployed_version(runner_workload) || 0) >= expected_deployed_version
end
end

Expand Down
2 changes: 1 addition & 1 deletion lib/core/controlplane.rb
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ def workload_connect(workload, location:, container: nil, shell: nil)
end

def workload_exec(workload, replica, location:, container: nil, command: nil)
cmd = "cpln workload exec #{workload} #{gvc_org} --replica #{replica} --location #{location}"
cmd = "cpln workload exec #{workload} #{gvc_org} --replica #{replica} --location #{location} -it"
cmd += " --container #{container}" if container
cmd += " -- #{command}"
perform!(cmd, output_mode: :all)
Expand Down
2 changes: 1 addition & 1 deletion lib/cpflow/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@

module Cpflow
VERSION = "3.0.1"
MIN_CPLN_VERSION = "2.0.1"
MIN_CPLN_VERSION = "3.1.0"
end
56 changes: 14 additions & 42 deletions spec/command/delete_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,16 +70,9 @@
run_cpflow_command!("build-image", "-a", app)
end

after do
run_cpflow_command!("delete", "-a", app, "--yes")
end

it "deletes app with volumesets and images", :slow do
allow(Shell).to receive(:confirm).with(include(app)).and_return(true)

result = run_cpflow_command("delete", "-a", app)
result = run_cpflow_command("delete", "-a", app, "--yes")

expect(Shell).to have_received(:confirm).once
expect(result[:status]).to eq(0)
expect(result[:stderr]).to match(/Deleting volumeset 'detached-volume' from app '#{app}'[.]+? done!/)
expect(result[:stderr]).to match(/Deleting volumeset 'postgres-volume' from app '#{app}'[.]+? done!/)
Expand Down Expand Up @@ -157,11 +150,8 @@
end

it "does not unbind identity from policy" do
allow(Shell).to receive(:confirm).with(include(app)).and_return(true)

result = run_cpflow_command("delete", "-a", app)
result = run_cpflow_command("delete", "-a", app, "--yes")

expect(Shell).to have_received(:confirm).once
expect(result[:status]).to eq(0)
expect(result[:stderr]).to match(/Deleting app '#{app}'[.]+? done!/)
expect(result[:stderr]).not_to include("Unbinding identity from policy")
Expand All @@ -176,11 +166,8 @@
end

it "does not unbind identity from policy" do
allow(Shell).to receive(:confirm).with(include(app)).and_return(true)

result = run_cpflow_command("delete", "-a", app)
result = run_cpflow_command("delete", "-a", app, "--yes")

expect(Shell).to have_received(:confirm).once
expect(result[:status]).to eq(0)
expect(result[:stderr]).to match(/Deleting app '#{app}'[.]+? done!/)
expect(result[:stderr]).not_to include("Unbinding identity from policy")
Expand All @@ -195,11 +182,8 @@
end

it "does not unbind identity from policy" do
allow(Shell).to receive(:confirm).with(include(app)).and_return(true)

result = run_cpflow_command("delete", "-a", app)
result = run_cpflow_command("delete", "-a", app, "--yes")

expect(Shell).to have_received(:confirm).once
expect(result[:status]).to eq(0)
expect(result[:stderr]).to match(/Deleting app '#{app}'[.]+? done!/)
expect(result[:stderr]).not_to include("Unbinding identity from policy")
Expand All @@ -214,11 +198,8 @@
end

it "unbinds identity from policy" do
allow(Shell).to receive(:confirm).with(include(app)).and_return(true)

result = run_cpflow_command("delete", "-a", app)
result = run_cpflow_command("delete", "-a", app, "--yes")

expect(Shell).to have_received(:confirm).once
expect(result[:status]).to eq(0)
expect(result[:stderr]).to match(/Deleting app '#{app}'[.]+? done!/)
expect(result[:stderr]).to match(/Unbinding identity from policy for app '#{app}'[.]+? done!/)
Expand All @@ -238,14 +219,11 @@
end

it "fails to run hook", :slow do
result = nil

spawn_cpflow_command("delete", "-a", app, "--yes") do |it|
result = it.read_full_output
end
result = run_cpflow_command("delete", "-a", app, "--yes")

expect(result).to include("Running pre-deletion hook")
expect(result).to include("Failed to run pre-deletion hook")
expect(result[:status]).not_to eq(0)
expect(result[:stderr]).to include("Running pre-deletion hook")
expect(result[:stderr]).to include("Failed to run pre-deletion hook")
end
end

Expand All @@ -258,14 +236,11 @@
end

it "successfully runs hook", :slow do
result = nil

spawn_cpflow_command("delete", "-a", app, "--yes") do |it|
result = it.read_full_output
end
result = run_cpflow_command("delete", "-a", app, "--yes")

expect(result).to include("Running pre-deletion hook")
expect(result).to include("Finished running pre-deletion hook")
expect(result[:status]).to eq(0)
expect(result[:stderr]).to include("Running pre-deletion hook")
expect(result[:stderr]).to include("Finished running pre-deletion hook")
end
end

Expand All @@ -277,11 +252,8 @@
end

it "does not run hook" do
allow(Shell).to receive(:confirm).with(include(app)).and_return(true)
result = run_cpflow_command("delete", "-a", app, "--yes", "--skip-pre-deletion-hook")

result = run_cpflow_command("delete", "-a", app, "--skip-pre-deletion-hook")

expect(Shell).to have_received(:confirm).once
expect(result[:status]).to eq(0)
expect(result[:stderr]).not_to include("Running pre-deletion hook")
end
Expand Down
41 changes: 25 additions & 16 deletions spec/command/deploy_image_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,12 @@
end

it "fails to run release script and fails to deploy image", :slow do
result = nil

spawn_cpflow_command("deploy-image", "-a", app, "--run-release-phase") do |it|
result = it.read_full_output
end
result = run_cpflow_command("deploy-image", "-a", app, "--run-release-phase")

expect(result).to include("Running release script")
expect(result).to include("Failed to run release script")
expect(result).not_to include("- rails:")
expect(result[:status]).not_to eq(0)
expect(result[:stderr]).to include("Running release script")
expect(result[:stderr]).to include("Failed to run release script")
expect(result[:stderr]).not_to include("- rails:")
end
end

Expand All @@ -100,16 +97,28 @@
end

it "runs release script and deploys image", :slow do
result = nil
result = run_cpflow_command("deploy-image", "-a", app, "--run-release-phase")

spawn_cpflow_command("deploy-image", "-a", app, "--run-release-phase") do |it|
result = it.read_full_output
end
expect(result[:status]).to eq(0)
expect(result[:stderr]).to include("Running release script")
expect(result[:stderr]).to include("Finished running release script")
expect(result[:stderr]).to match(%r{- rails: https://rails-.+?.cpln.app})
expect(result[:stderr]).not_to include("- rails-with-non-app-image:")
end
end

expect(result).to include("Running release script")
expect(result).to include("Finished running release script")
expect(result).to match(%r{- rails: https://rails-.+?.cpln.app})
expect(result).not_to include("- rails-with-non-app-image:")
context "when workload uses BYOK location" do
let!(:app) { dummy_test_app("rails-non-app-image", create_if_not_exists: true) }

before do
allow(Resolv).to receive(:getaddress).and_raise(Resolv::ResolvError)
end

it "lists correct endpoint", :slow do
result = run_cpflow_command("deploy-image", "-a", app)

expect(result[:status]).to eq(0)
expect(result[:stderr]).to match(%r{- rails: https://rails-.+?.controlplane.us})
end
end
end
47 changes: 28 additions & 19 deletions spec/command/logs_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,56 +70,65 @@
end

context "when using different limit on number of entries" do
let!(:workload) do
cmd = "'for i in {1..10}; do echo \"Line $i\"; done; while true; do sleep 1; done'"
let!(:cmd_args) do
cmd = 'for i in {0..9}; do echo "Line $i"; done; while true; do sleep 1; done'
create_run_workload(cmd)
end

before do
Kernel.sleep(30)
end

after do
run_cpflow_command!(*cmd_args[:ps_stop])
end

it "displays correct number of entries", :slow do
result = nil
expected_regex = /Line \d+/

spawn_cpflow_command("logs", "-a", app, "--workload", workload, "--limit", "5") do |it|
result = it.wait_for(expected_regex)
spawn_cpflow_command(*cmd_args[:logs], "--limit", "5") do |it|
result = it.wait_for(/Line 9/)
it.kill
end

expect(result).to include("Line 6")
expect(result).not_to match(/Line [0-4]/)
expect(result).to match(/Line [5-9]/)
end
end

context "when using different loopback window" do
let!(:workload) do
cmd = "'echo \"Line 1\"; sleep 30; echo \"Line 2\"; while true; do sleep 1; done'"
let!(:cmd_args) do
cmd = 'echo "Line 1"; sleep 30; while true; do echo "Line 2"; sleep 1; done'
create_run_workload(cmd)
end

before do
Kernel.sleep(30)
end

after do
run_cpflow_command!(*cmd_args[:ps_stop])
end

it "displays entries from correct duration", :slow do
result = nil
expected_regex = /Line \d+/

spawn_cpflow_command("logs", "-a", app, "--workload", workload, "--since", "30s") do |it|
result = it.wait_for(expected_regex)
spawn_cpflow_command(*cmd_args[:logs], "--since", "30s") do |it|
result = it.wait_for(/Line 2/)
it.kill
end

expect(result).not_to include("Line 1")
expect(result).to include("Line 2")
end
end

def create_run_workload(cmd)
runner_workload = nil

runner_workload_regex = /runner workload '(.+?)'/
spawn_cpflow_command("run", "-a", app, "--detached", "--", cmd) do |it|
runner_workload_result = it.wait_for(runner_workload_regex)
runner_workload = runner_workload_result.match(runner_workload_regex)[1]
end
result = run_cpflow_command("run", "-a", app, "--detached", "--", cmd)

runner_workload
{
logs: result[:stderr].match(/`cpflow (logs .+?)`/)[1].split,
ps_stop: result[:stderr].match(/`cpflow (ps:stop .+?)`/)[1].split
}
end
end
34 changes: 14 additions & 20 deletions spec/command/promote_app_from_upstream_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,17 +57,14 @@
end

it "copies latest image from upstream, fails to run release script and fails to deploy image", :slow do
result = nil

spawn_cpflow_command("promote-app-from-upstream", "-a", app, "--upstream-token", token) do |it|
result = it.read_full_output
end
result = run_cpflow_command("promote-app-from-upstream", "-a", app, "--upstream-token", token)

expect(result).to match(%r{Pulling image from '.+?/#{upstream_app}:1'})
expect(result).to match(%r{Pushing image to '.+?/#{app}:1'})
expect(result).to include("Running release script")
expect(result).to include("Failed to run release script")
expect(result).not_to match(%r{rails: https://rails-.+?.cpln.app})
expect(result[:status]).not_to eq(0)
expect(result[:stderr]).to match(%r{Pulling image from '.+?/#{upstream_app}:1'})
expect(result[:stderr]).to match(%r{Pushing image to '.+?/#{app}:1'})
expect(result[:stderr]).to include("Running release script")
expect(result[:stderr]).to include("Failed to run release script")
expect(result[:stderr]).not_to match(%r{rails: https://rails-.+?.cpln.app})
end
end

Expand All @@ -94,17 +91,14 @@
end

it "copies latest image from upstream, runs release script and deploys image", :slow do
result = nil

spawn_cpflow_command("promote-app-from-upstream", "-a", app, "--upstream-token", token) do |it|
result = it.read_full_output
end
result = run_cpflow_command("promote-app-from-upstream", "-a", app, "--upstream-token", token)

expect(result).to match(%r{Pulling image from '.+?/#{upstream_app}:1'})
expect(result).to match(%r{Pushing image to '.+?/#{app}:1'})
expect(result).to include("Running release script")
expect(result).to include("Finished running release script")
expect(result).to match(%r{rails: https://rails-.+?.cpln.app})
expect(result[:status]).to eq(0)
expect(result[:stderr]).to match(%r{Pulling image from '.+?/#{upstream_app}:1'})
expect(result[:stderr]).to match(%r{Pushing image to '.+?/#{app}:1'})
expect(result[:stderr]).to include("Running release script")
expect(result[:stderr]).to include("Finished running release script")
expect(result[:stderr]).to match(%r{rails: https://rails-.+?.cpln.app})
end
end
end
Loading
Loading