Method: KubernetesCLI#get_object
- Defined in:
- lib/kubernetes-cli.rb
permalink #get_object(type, namespace, name) ⇒ Object
T::Sig::WithoutRuntime.sig
params(
type: String,
namespace: String,
name: String
).returns(
T::Hash[String, T.untyped]
)
208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 |
# File 'lib/kubernetes-cli.rb', line 208 def get_object(type, namespace, name) cmd = [executable, '--kubeconfig', kubeconfig_path] cmd += ['-n', namespace] if namespace cmd += ['get', type, name] cmd += ['-o', 'json'] result = backticks(cmd) on_last_status_failure do |last_status| raise GetResourceError, "couldn't get resource of type '#{type}' named '#{name}' "\ "in namespace #{namespace}: kubectl exited with status code #{last_status.exitstatus}" end begin JSON.parse(result) rescue JSON::ParserError raise GetResourceError, "json parsing error" end end |