Class: Kubernetes::Connection
- Inherits:
-
Object
- Object
- Kubernetes::Connection
- Defined in:
- lib/kubernetes/connection.rb
Constant Summary collapse
- KUBERNETES_HOST =
ENV.fetch("KUBERNETES_HOST", "http://localhost:8080").freeze
Instance Attribute Summary collapse
-
#namespace ⇒ Object
readonly
Returns the value of attribute namespace.
Instance Method Summary collapse
-
#initialize(host: KUBERNETES_HOST, namespace:, options: {}) ⇒ Connection
constructor
A new instance of Connection.
- #request(method, path, prefix: "/namespaces/#{namespace}", **options) ⇒ Object
- #stream(path, &block) ⇒ Object
Constructor Details
#initialize(host: KUBERNETES_HOST, namespace:, options: {}) ⇒ Connection
Returns a new instance of Connection.
9 10 11 12 |
# File 'lib/kubernetes/connection.rb', line 9 def initialize(host: KUBERNETES_HOST, namespace:, options: {}) @connection = Excon.new(host, ) @namespace = namespace end |
Instance Attribute Details
#namespace ⇒ Object (readonly)
Returns the value of attribute namespace.
7 8 9 |
# File 'lib/kubernetes/connection.rb', line 7 def namespace @namespace end |
Instance Method Details
#request(method, path, prefix: "/namespaces/#{namespace}", **options) ⇒ Object
14 15 16 17 18 |
# File 'lib/kubernetes/connection.rb', line 14 def request(method, path, prefix: "/namespaces/#{namespace}", **) qualified_path = File.join("/api/v1", prefix || "", path) @connection.request(method: method, path: qualified_path, **) end |
#stream(path, &block) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/kubernetes/connection.rb', line 20 def stream(path, &block) handler = lambda {|chunk, remaining_bytes, total_bytes| block.call(chunk) } request(:get, path, prefix: nil, response_block: handler) ensure # If the stream is stopped by the client there may be stuff still lingering # in the socket. @connection.reset end |