› kube_cluster › Source › Kube › Errors › CommandError

class CommandError

Raised when a kubectl command fails.

Example.

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

Signature

Definitions

def parse_reason(stderr)

Extracts the reason from kubectl stderr.

Example.

Error from server (NotFound): deployments.apps "foo" not found
Error from server (Forbidden): ...
error: the server doesn't have a resource type "foo"

Signature

Implementation

def parse_reason(stderr)
  if stderr.nil? || stderr.empty?
    nil
  else
    if stderr =~ /\((\w+)\)/
      $1
    end
  end
end