Skip to content

Commit 3c482da

Browse files
Update min cpln version (#226)
1 parent ef627be commit 3c482da

File tree

12 files changed

+148
-219
lines changed

12 files changed

+148
-219
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ _Please add entries here for your pull requests that have not yet been released.
1919
- 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).
2020
- Fixed BYOK endpoint. [PR 209](https://github.com/shakacode/control-plane-flow/pull/209) by [Sergey Tarasov](https://github.com/dzirtusss).
2121
- 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).
22+
- 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).
2223

2324
## [3.0.1] - 2024-06-26
2425

lib/command/run.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ def update_runner_workload # rubocop:disable Metrics/CyclomaticComplexity, Metri
243243

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

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

lib/core/controlplane.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ def workload_connect(workload, location:, container: nil, shell: nil)
277277
end
278278

279279
def workload_exec(workload, replica, location:, container: nil, command: nil)
280-
cmd = "cpln workload exec #{workload} #{gvc_org} --replica #{replica} --location #{location}"
280+
cmd = "cpln workload exec #{workload} #{gvc_org} --replica #{replica} --location #{location} -it"
281281
cmd += " --container #{container}" if container
282282
cmd += " -- #{command}"
283283
perform!(cmd, output_mode: :all)

lib/cpflow/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22

33
module Cpflow
44
VERSION = "3.0.1"
5-
MIN_CPLN_VERSION = "2.0.1"
5+
MIN_CPLN_VERSION = "3.1.0"
66
end

spec/command/delete_spec.rb

Lines changed: 14 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -70,16 +70,9 @@
7070
run_cpflow_command!("build-image", "-a", app)
7171
end
7272

73-
after do
74-
run_cpflow_command!("delete", "-a", app, "--yes")
75-
end
76-
7773
it "deletes app with volumesets and images", :slow do
78-
allow(Shell).to receive(:confirm).with(include(app)).and_return(true)
79-
80-
result = run_cpflow_command("delete", "-a", app)
74+
result = run_cpflow_command("delete", "-a", app, "--yes")
8175

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

159152
it "does not unbind identity from policy" do
160-
allow(Shell).to receive(:confirm).with(include(app)).and_return(true)
161-
162-
result = run_cpflow_command("delete", "-a", app)
153+
result = run_cpflow_command("delete", "-a", app, "--yes")
163154

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

178168
it "does not unbind identity from policy" do
179-
allow(Shell).to receive(:confirm).with(include(app)).and_return(true)
180-
181-
result = run_cpflow_command("delete", "-a", app)
169+
result = run_cpflow_command("delete", "-a", app, "--yes")
182170

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

197184
it "does not unbind identity from policy" do
198-
allow(Shell).to receive(:confirm).with(include(app)).and_return(true)
199-
200-
result = run_cpflow_command("delete", "-a", app)
185+
result = run_cpflow_command("delete", "-a", app, "--yes")
201186

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

216200
it "unbinds identity from policy" do
217-
allow(Shell).to receive(:confirm).with(include(app)).and_return(true)
218-
219-
result = run_cpflow_command("delete", "-a", app)
201+
result = run_cpflow_command("delete", "-a", app, "--yes")
220202

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

240221
it "fails to run hook", :slow do
241-
result = nil
242-
243-
spawn_cpflow_command("delete", "-a", app, "--yes") do |it|
244-
result = it.read_full_output
245-
end
222+
result = run_cpflow_command("delete", "-a", app, "--yes")
246223

247-
expect(result).to include("Running pre-deletion hook")
248-
expect(result).to include("Failed to run pre-deletion hook")
224+
expect(result[:status]).not_to eq(0)
225+
expect(result[:stderr]).to include("Running pre-deletion hook")
226+
expect(result[:stderr]).to include("Failed to run pre-deletion hook")
249227
end
250228
end
251229

@@ -258,14 +236,11 @@
258236
end
259237

260238
it "successfully runs hook", :slow do
261-
result = nil
262-
263-
spawn_cpflow_command("delete", "-a", app, "--yes") do |it|
264-
result = it.read_full_output
265-
end
239+
result = run_cpflow_command("delete", "-a", app, "--yes")
266240

267-
expect(result).to include("Running pre-deletion hook")
268-
expect(result).to include("Finished running pre-deletion hook")
241+
expect(result[:status]).to eq(0)
242+
expect(result[:stderr]).to include("Running pre-deletion hook")
243+
expect(result[:stderr]).to include("Finished running pre-deletion hook")
269244
end
270245
end
271246

@@ -277,11 +252,8 @@
277252
end
278253

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

282-
result = run_cpflow_command("delete", "-a", app, "--skip-pre-deletion-hook")
283-
284-
expect(Shell).to have_received(:confirm).once
285257
expect(result[:status]).to eq(0)
286258
expect(result[:stderr]).not_to include("Running pre-deletion hook")
287259
end

spec/command/deploy_image_spec.rb

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -76,15 +76,12 @@
7676
end
7777

7878
it "fails to run release script and fails to deploy image", :slow do
79-
result = nil
80-
81-
spawn_cpflow_command("deploy-image", "-a", app, "--run-release-phase") do |it|
82-
result = it.read_full_output
83-
end
79+
result = run_cpflow_command("deploy-image", "-a", app, "--run-release-phase")
8480

85-
expect(result).to include("Running release script")
86-
expect(result).to include("Failed to run release script")
87-
expect(result).not_to include("- rails:")
81+
expect(result[:status]).not_to eq(0)
82+
expect(result[:stderr]).to include("Running release script")
83+
expect(result[:stderr]).to include("Failed to run release script")
84+
expect(result[:stderr]).not_to include("- rails:")
8885
end
8986
end
9087

@@ -100,16 +97,28 @@
10097
end
10198

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

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

109-
expect(result).to include("Running release script")
110-
expect(result).to include("Finished running release script")
111-
expect(result).to match(%r{- rails: https://rails-.+?.cpln.app})
112-
expect(result).not_to include("- rails-with-non-app-image:")
110+
context "when workload uses BYOK location" do
111+
let!(:app) { dummy_test_app("rails-non-app-image", create_if_not_exists: true) }
112+
113+
before do
114+
allow(Resolv).to receive(:getaddress).and_raise(Resolv::ResolvError)
115+
end
116+
117+
it "lists correct endpoint", :slow do
118+
result = run_cpflow_command("deploy-image", "-a", app)
119+
120+
expect(result[:status]).to eq(0)
121+
expect(result[:stderr]).to match(%r{- rails: https://rails-.+?.controlplane.us})
113122
end
114123
end
115124
end

spec/command/logs_spec.rb

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -70,56 +70,65 @@
7070
end
7171

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

78+
before do
79+
Kernel.sleep(30)
80+
end
81+
82+
after do
83+
run_cpflow_command!(*cmd_args[:ps_stop])
84+
end
85+
7886
it "displays correct number of entries", :slow do
7987
result = nil
80-
expected_regex = /Line \d+/
8188

82-
spawn_cpflow_command("logs", "-a", app, "--workload", workload, "--limit", "5") do |it|
83-
result = it.wait_for(expected_regex)
89+
spawn_cpflow_command(*cmd_args[:logs], "--limit", "5") do |it|
90+
result = it.wait_for(/Line 9/)
8491
it.kill
8592
end
8693

87-
expect(result).to include("Line 6")
94+
expect(result).not_to match(/Line [0-4]/)
95+
expect(result).to match(/Line [5-9]/)
8896
end
8997
end
9098

9199
context "when using different loopback window" do
92-
let!(:workload) do
93-
cmd = "'echo \"Line 1\"; sleep 30; echo \"Line 2\"; while true; do sleep 1; done'"
100+
let!(:cmd_args) do
101+
cmd = 'echo "Line 1"; sleep 30; while true; do echo "Line 2"; sleep 1; done'
94102
create_run_workload(cmd)
95103
end
96104

97105
before do
98106
Kernel.sleep(30)
99107
end
100108

109+
after do
110+
run_cpflow_command!(*cmd_args[:ps_stop])
111+
end
112+
101113
it "displays entries from correct duration", :slow do
102114
result = nil
103-
expected_regex = /Line \d+/
104115

105-
spawn_cpflow_command("logs", "-a", app, "--workload", workload, "--since", "30s") do |it|
106-
result = it.wait_for(expected_regex)
116+
spawn_cpflow_command(*cmd_args[:logs], "--since", "30s") do |it|
117+
result = it.wait_for(/Line 2/)
107118
it.kill
108119
end
109120

121+
expect(result).not_to include("Line 1")
110122
expect(result).to include("Line 2")
111123
end
112124
end
113125

114126
def create_run_workload(cmd)
115-
runner_workload = nil
116-
117-
runner_workload_regex = /runner workload '(.+?)'/
118-
spawn_cpflow_command("run", "-a", app, "--detached", "--", cmd) do |it|
119-
runner_workload_result = it.wait_for(runner_workload_regex)
120-
runner_workload = runner_workload_result.match(runner_workload_regex)[1]
121-
end
127+
result = run_cpflow_command("run", "-a", app, "--detached", "--", cmd)
122128

123-
runner_workload
129+
{
130+
logs: result[:stderr].match(/`cpflow (logs .+?)`/)[1].split,
131+
ps_stop: result[:stderr].match(/`cpflow (ps:stop .+?)`/)[1].split
132+
}
124133
end
125134
end

spec/command/promote_app_from_upstream_spec.rb

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -57,17 +57,14 @@
5757
end
5858

5959
it "copies latest image from upstream, fails to run release script and fails to deploy image", :slow do
60-
result = nil
61-
62-
spawn_cpflow_command("promote-app-from-upstream", "-a", app, "--upstream-token", token) do |it|
63-
result = it.read_full_output
64-
end
60+
result = run_cpflow_command("promote-app-from-upstream", "-a", app, "--upstream-token", token)
6561

66-
expect(result).to match(%r{Pulling image from '.+?/#{upstream_app}:1'})
67-
expect(result).to match(%r{Pushing image to '.+?/#{app}:1'})
68-
expect(result).to include("Running release script")
69-
expect(result).to include("Failed to run release script")
70-
expect(result).not_to match(%r{rails: https://rails-.+?.cpln.app})
62+
expect(result[:status]).not_to eq(0)
63+
expect(result[:stderr]).to match(%r{Pulling image from '.+?/#{upstream_app}:1'})
64+
expect(result[:stderr]).to match(%r{Pushing image to '.+?/#{app}:1'})
65+
expect(result[:stderr]).to include("Running release script")
66+
expect(result[:stderr]).to include("Failed to run release script")
67+
expect(result[:stderr]).not_to match(%r{rails: https://rails-.+?.cpln.app})
7168
end
7269
end
7370

@@ -94,17 +91,14 @@
9491
end
9592

9693
it "copies latest image from upstream, runs release script and deploys image", :slow do
97-
result = nil
98-
99-
spawn_cpflow_command("promote-app-from-upstream", "-a", app, "--upstream-token", token) do |it|
100-
result = it.read_full_output
101-
end
94+
result = run_cpflow_command("promote-app-from-upstream", "-a", app, "--upstream-token", token)
10295

103-
expect(result).to match(%r{Pulling image from '.+?/#{upstream_app}:1'})
104-
expect(result).to match(%r{Pushing image to '.+?/#{app}:1'})
105-
expect(result).to include("Running release script")
106-
expect(result).to include("Finished running release script")
107-
expect(result).to match(%r{rails: https://rails-.+?.cpln.app})
96+
expect(result[:status]).to eq(0)
97+
expect(result[:stderr]).to match(%r{Pulling image from '.+?/#{upstream_app}:1'})
98+
expect(result[:stderr]).to match(%r{Pushing image to '.+?/#{app}:1'})
99+
expect(result[:stderr]).to include("Running release script")
100+
expect(result[:stderr]).to include("Finished running release script")
101+
expect(result[:stderr]).to match(%r{rails: https://rails-.+?.cpln.app})
108102
end
109103
end
110104
end

0 commit comments

Comments
 (0)