Class: Kubernetes::Client
- Inherits:
-
Object
- Object
- Kubernetes::Client
- Defined in:
- lib/kubernetes/client.rb
Constant Summary collapse
- DEFAULT_NAMESPACE =
"default".freeze
Instance Method Summary collapse
- #create_namespace(namespace) ⇒ Object
- #create_pod(pod) ⇒ Object
- #create_replication_controller(rc) ⇒ Object
- #delete_namespace(name) ⇒ Object
- #delete_pod(name) ⇒ Object
- #get_pod(name) ⇒ Object
- #get_pods ⇒ Object
- #get_replication_controller(name) ⇒ Object
- #get_replication_controllers ⇒ Object
-
#initialize(namespace: DEFAULT_NAMESPACE, options: {}) ⇒ Client
constructor
A new instance of Client.
- #logs(pod_name) ⇒ Object
- #watch_pods(name = nil) ⇒ Object
Constructor Details
#initialize(namespace: DEFAULT_NAMESPACE, options: {}) ⇒ Client
Returns a new instance of Client.
24 25 26 27 |
# File 'lib/kubernetes/client.rb', line 24 def initialize(namespace: DEFAULT_NAMESPACE, options: {}) = [:connection] || {} @connection = Connection.new(namespace: namespace, options: ) end |
Instance Method Details
#create_namespace(namespace) ⇒ Object
73 74 75 |
# File 'lib/kubernetes/client.rb', line 73 def create_namespace(namespace) post("namespaces", prefix: nil, body: namespace.to_json) end |
#create_pod(pod) ⇒ Object
29 30 31 32 |
# File 'lib/kubernetes/client.rb', line 29 def create_pod(pod) data = post("pods", body: pod.to_json) Pod.new(data) end |
#create_replication_controller(rc) ⇒ Object
57 58 59 60 |
# File 'lib/kubernetes/client.rb', line 57 def create_replication_controller(rc) data = post("replicationcontrollers", body: rc.to_json) ReplicationController.new(data) end |
#delete_namespace(name) ⇒ Object
77 78 79 |
# File 'lib/kubernetes/client.rb', line 77 def delete_namespace(name) delete("namespaces/#{name}", prefix: nil) end |
#delete_pod(name) ⇒ Object
34 35 36 |
# File 'lib/kubernetes/client.rb', line 34 def delete_pod(name) delete("pods/#{name}") end |
#get_pod(name) ⇒ Object
38 39 40 41 |
# File 'lib/kubernetes/client.rb', line 38 def get_pod(name) data = get("pods/#{name}") Pod.new(data) end |
#get_pods ⇒ Object
43 44 45 46 47 |
# File 'lib/kubernetes/client.rb', line 43 def get_pods get("pods"). fetch("items"). map {|item| Pod.new(item) } end |
#get_replication_controller(name) ⇒ Object
62 63 64 65 |
# File 'lib/kubernetes/client.rb', line 62 def get_replication_controller(name) data = get("replicationcontrollers/#{name}") ReplicationController.new(data) end |
#get_replication_controllers ⇒ Object
67 68 69 70 71 |
# File 'lib/kubernetes/client.rb', line 67 def get_replication_controllers get("replicationcontrollers"). fetch("items"). map {|item| ReplicationController.new(item) } end |
#logs(pod_name) ⇒ Object
81 82 83 |
# File 'lib/kubernetes/client.rb', line 81 def logs(pod_name) get("pods/#{pod_name}/log") end |
#watch_pods(name = nil) ⇒ Object
49 50 51 52 53 54 55 |
# File 'lib/kubernetes/client.rb', line 49 def watch_pods(name = nil) stream = Stream.new(@connection) stream.each("watch/#{namespace_prefix}/pods/#{name}") do |line| yield WatchEvent.new(JSON.parse(line)) end end |