Skip to content

Commit 3ba0049

Browse files
Fix issue that happens when trying to fetch replicas with CPLN CLI (#254)
* fix: issue that happens when trying to fetch replicas from cpln * docs: update changelog
1 parent 016357d commit 3ba0049

File tree

5 files changed

+11
-6
lines changed

5 files changed

+11
-6
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ Changes since the last non-beta release.
1414

1515
_Please add entries here for your pull requests that have not yet been released._
1616

17+
### Fixed
18+
19+
- Fixed issue where `ps`, `ps:start`, `ps:stop`, `ps:wait`, and `run` commands fail when trying to fetch replicas with CPLN CLI. [PR 254](https://github.com/shakacode/control-plane-flow/pull/254) by [Rafael Gomes](https://github.com/rafaelgomesxyz).
20+
1721
## [4.1.0] - 2024-12-17
1822

1923
### Fixed

lib/command/ps.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def call
3434
cp.fetch_workload!(workload)
3535

3636
result = cp.fetch_workload_replicas(workload, location: location)
37-
result["items"].each { |replica| puts replica }
37+
result&.dig("items")&.each { |replica| puts replica }
3838
end
3939
end
4040
end

lib/command/ps_stop.rb

+2-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,8 @@ def wait_for_replica_not_ready(workload, replica)
7575

7676
step("Waiting for replica '#{replica}' to not be ready", retry_on_failure: true) do
7777
result = cp.fetch_workload_replicas(workload, location: config.location)
78-
!result["items"].include?(replica)
78+
items = result&.dig("items")
79+
items && !items.include?(replica)
7980
end
8081
end
8182
end

lib/command/run.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ def start_job
274274
def wait_for_replica_for_job
275275
step("Waiting for replica to start, which runs job '#{job}'", retry_on_failure: true) do
276276
result = cp.fetch_workload_replicas(runner_workload, location: location)
277-
@replica = result["items"].find { |item| item.include?(job) }
277+
@replica = result&.dig("items")&.find { |item| item.include?(job) }
278278

279279
replica || false
280280
end

lib/core/controlplane.rb

+3-3
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ def query_workloads(workload, a_gvc = gvc, a_org = org, partial_workload_match:
192192
end
193193

194194
def fetch_workload_replicas(workload, location:)
195-
cmd = "cpln workload replica get #{workload} #{gvc_org} --location #{location} -o yaml"
195+
cmd = "cpln workload replica get #{workload} #{gvc_org} --location #{location} -o yaml 2> /dev/null"
196196
perform_yaml(cmd)
197197
end
198198

@@ -213,8 +213,8 @@ def workload_deployment_version_ready?(version, next_version)
213213
end
214214
end
215215

216-
def workload_deployments_ready?(workload, location:, expected_status:)
217-
deployed_replicas = fetch_workload_replicas(workload, location: location)["items"].length
216+
def workload_deployments_ready?(workload, location:, expected_status:) # rubocop:disable Metrics/CyclomaticComplexity
217+
deployed_replicas = fetch_workload_replicas(workload, location: location)&.dig("items")&.length || 0
218218
return deployed_replicas.zero? if expected_status == false
219219

220220
deployments = fetch_workload_deployments(workload)["items"]

0 commit comments

Comments
 (0)