lib/core/controlplane.rb in cpl-0.2.0 vs lib/core/controlplane.rb in cpl-0.3.0
- old
+ new
@@ -1,8 +1,8 @@
# frozen_string_literal: true
-class Controlplane
+class Controlplane # rubocop:disable Metrics/ClassLength
attr_reader :config, :api, :gvc, :org
def initialize(config)
@config = config
@api = ControlplaneApi.new
@@ -40,20 +40,34 @@
def gvc_get(a_gvc = gvc)
api.gvc_get(gvc: a_gvc, org: org)
end
+ def gvc_get_and_ensure(a_gvc = gvc)
+ gvc_data = gvc_get(a_gvc)
+ return gvc_data if gvc_data
+
+ Shell.abort("Can't find GVC '#{gvc}', please create it with 'cpl setup gvc -a #{config.app}'.")
+ end
+
def gvc_delete(a_gvc = gvc)
api.gvc_delete(gvc: a_gvc, org: org)
end
# workload
def workload_get(workload)
api.workload_get(workload: workload, gvc: gvc, org: org)
end
+ def workload_get_and_ensure(workload)
+ workload_data = workload_get(workload)
+ return workload_data if workload_data
+
+ Shell.abort("Can't find workload '#{workload}', please create it with 'cpl setup #{workload} -a #{config.app}'.")
+ end
+
def workload_get_replicas(workload, location:)
cmd = "cpln workload get-replicas #{workload} #{gvc_org} --location #{location} -o yaml"
perform_yaml(cmd)
end
@@ -62,10 +76,10 @@
cmd += " --set spec.containers.#{container}.image=/org/#{config[:cpln_org]}/image/#{image}"
perform(cmd)
end
def workload_set_suspend(workload, value)
- data = workload_get(workload)
+ data = workload_get_and_ensure(workload)
data["spec"]["defaultOptions"]["suspend"] = value
apply(data)
end
def workload_force_redeployment(workload)