class CommandError
Raised when a kubectl command fails.
begin resource.patch rescue Kube::CommandError => e e.subcommand # => "patch" e.stderr # => "Error from server (NotFound): ..." e.exit_code # => 1 e.reason # => "NotFound" (parsed from stderr, or nil) end
Definitions
def parse_reason(stderr)
Attempts to extract the reason from kubectl stderr. kubectl errors typically look like: Error from server (NotFound): deployments.apps "foo" not found Error from server (Forbidden): ... error: the server doesn't have a resource type "foo"
Implementation
def parse_reason(stderr)
return nil if stderr.nil? || stderr.empty?
if stderr =~ /\((\w+)\)/
$1
end
end