Class: Kubeclient::Client
- Inherits:
-
Common::Client
- Object
- Common::Client
- Kubeclient::Client
- Defined in:
- lib/kubeclient.rb
Overview
Kubernetes Client
Constant Summary collapse
- ENTITY_TYPES =
Dynamically creating classes definitions (class Pod, class Service, etc.), The classes are extending RecursiveOpenStruct. This cancels the need to define the classes manually on every new entity addition, and especially since currently the class body is empty
%w(Pod Service ReplicationController Node Event Endpoint Namespace).map do |et| clazz = Class.new(RecursiveOpenStruct) do def initialize(hash = nil, args = {}) args.merge!(recurse_over_arrays: true) super(hash, args) end end [Kubeclient.const_set(et, clazz), et] end
Instance Attribute Summary collapse
-
#api_endpoint ⇒ Object
readonly
Returns the value of attribute api_endpoint.
Instance Method Summary collapse
- #all_entities ⇒ Object
- #api ⇒ Object
- #api_valid? ⇒ Boolean
-
#initialize(uri, version = 'v1beta3') ⇒ Client
constructor
A new instance of Client.
Constructor Details
#initialize(uri, version = 'v1beta3') ⇒ Client
Returns a new instance of Client.
32 33 34 35 36 |
# File 'lib/kubeclient.rb', line 32 def initialize(uri, version = 'v1beta3') handle_uri(uri, '/api') @api_version = version end |
Instance Attribute Details
#api_endpoint ⇒ Object (readonly)
Returns the value of attribute api_endpoint.
14 15 16 |
# File 'lib/kubeclient.rb', line 14 def api_endpoint @api_endpoint end |
Instance Method Details
#all_entities ⇒ Object
38 39 40 |
# File 'lib/kubeclient.rb', line 38 def all_entities retrieve_all_entities(ENTITY_TYPES) end |
#api ⇒ Object
42 43 44 45 46 47 |
# File 'lib/kubeclient.rb', line 42 def api response = handle_exception do RestClient::Resource.new(@api_endpoint.to_s).get end JSON.parse(response) end |
#api_valid? ⇒ Boolean
49 50 51 52 |
# File 'lib/kubeclient.rb', line 49 def api_valid? result = api result.is_a?(Hash) && result['versions'].is_a?(Array) end |