ruby-kubernetes-controller 0.2.2 → 0.2.3
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ae9bccbe5b323b1c7319de8370b94439cd95627c785e2bda8ba359d6f27b3df0
|
4
|
+
data.tar.gz: 6a5b3923bb1f538942c4d61355957ff31ab9ea7048c379773d4df77b1a97fe26
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b82a2e8b4e416deeeeec55a9adbba752c9f555dc2c72cba9896d1af82f0ee6356ba6c38472f56b5344b4801d8dc1cc16747908eba3ec8110cdc9182ecf3f2a8c
|
7
|
+
data.tar.gz: ddee35da7ff08689047c2faa4a9b98a8b83ac75356e67216304832feffee5d3d614efb20660d293838f70019fae61f177330108c299b5764d0be08098ed9e340
|
@@ -1767,4 +1767,185 @@ Before beginning, you must generate a bearer token for the Ruby Kubernetes Contr
|
|
1767
1767
|
puts yaml_client.delete_job(namespace, job_name, yaml_file_path) # Returns JSON
|
1768
1768
|
```
|
1769
1769
|
|
1770
|
+
#### Create cronjob
|
1771
|
+
* Create new cronjob
|
1772
|
+
```ruby
|
1773
|
+
require 'ruby-kubernetes-controller'
|
1774
|
+
|
1775
|
+
endpoint = "localhost"
|
1776
|
+
bearer_token = "token"
|
1777
|
+
ssl = false
|
1778
|
+
|
1779
|
+
# With JSON
|
1780
|
+
json_client = ::RubyKubernetesController::Client.new(endpoint, bearer_token, ssl, yaml = false)
|
1781
|
+
namespace = "default"
|
1782
|
+
json_config =
|
1783
|
+
'{
|
1784
|
+
"kind": "CronJob",
|
1785
|
+
"apiVersion": "batch/v1beta1",
|
1786
|
+
...
|
1787
|
+
}'
|
1788
|
+
|
1789
|
+
puts json_client.create_new_cronjob(namespace, json_config) # Returns JSON
|
1790
|
+
|
1791
|
+
# With YAML
|
1792
|
+
yaml_client = ::RubyKubernetesController::Client.new(endpoint, bearer_token, ssl, yaml = true)
|
1793
|
+
namespace = "default"
|
1794
|
+
yaml_file_path = 'path/to/file.yaml'
|
1795
|
+
|
1796
|
+
puts yaml_client.create_new_cronjob(namespace, yaml_file_path) # Returns JSON
|
1797
|
+
```
|
1798
|
+
|
1799
|
+
#### Get cronjobs
|
1800
|
+
* List all cronjobs
|
1801
|
+
```ruby
|
1802
|
+
require 'ruby-kubernetes-controller'
|
1803
|
+
|
1804
|
+
endpoint = "localhost"
|
1805
|
+
bearer_token = "token"
|
1806
|
+
ssl = false
|
1807
|
+
|
1808
|
+
client = ::RubyKubernetesController::Client.new(endpoint, bearer_token, ssl)
|
1809
|
+
|
1810
|
+
puts client.get_all_cronjobs # Returns JSON
|
1811
|
+
```
|
1812
|
+
|
1813
|
+
#### Get Namespaced cronjobs
|
1814
|
+
* List all existing cronjobs in Namespace
|
1815
|
+
```ruby
|
1816
|
+
require 'ruby-kubernetes-controller'
|
1817
|
+
|
1818
|
+
endpoint = "localhost"
|
1819
|
+
bearer_token = "token"
|
1820
|
+
ssl = false
|
1821
|
+
|
1822
|
+
client = ::RubyKubernetesController::Client.new(endpoint, bearer_token, ssl)
|
1823
|
+
|
1824
|
+
namespace = "default"
|
1825
|
+
|
1826
|
+
puts client.get_all_namespaced_cronjobs(namespace) # Returns JSON
|
1827
|
+
```
|
1828
|
+
|
1829
|
+
#### Get Single Namespaced cronjob
|
1830
|
+
* Get details for single cronjob in Namespace
|
1831
|
+
```ruby
|
1832
|
+
require 'ruby-kubernetes-controller'
|
1833
|
+
|
1834
|
+
endpoint = "localhost"
|
1835
|
+
bearer_token = "token"
|
1836
|
+
ssl = false
|
1837
|
+
|
1838
|
+
client = ::RubyKubernetesController::Client.new(endpoint, bearer_token, ssl)
|
1839
|
+
|
1840
|
+
namespace = "default"
|
1841
|
+
cronjob_name = "cronjob"
|
1842
|
+
|
1843
|
+
puts client.get_single_namespaced_cronjob(namespace, cronjob_name) # Returns JSON
|
1844
|
+
```
|
1845
|
+
|
1846
|
+
#### Update cronjob
|
1847
|
+
* Update existing cronjob in Namespace
|
1848
|
+
```ruby
|
1849
|
+
require 'ruby-kubernetes-controller'
|
1850
|
+
|
1851
|
+
endpoint = "localhost"
|
1852
|
+
bearer_token = "token"
|
1853
|
+
ssl = false
|
1854
|
+
|
1855
|
+
# With JSON
|
1856
|
+
json_client = ::RubyKubernetesController::Client.new(endpoint, bearer_token, ssl, yaml = false)
|
1857
|
+
namespace = "default"
|
1858
|
+
cronjob_name = "cronjob"
|
1859
|
+
json_update =
|
1860
|
+
'{
|
1861
|
+
"kind": "CronJob",
|
1862
|
+
"apiVersion": "batch/v1beta1",
|
1863
|
+
...
|
1864
|
+
}'
|
1865
|
+
|
1866
|
+
puts json_client.update_namespaced_cronjob(namespace, cronjob_name, json_update) # Returns JSON
|
1867
|
+
|
1868
|
+
# With YAML
|
1869
|
+
yaml_client = ::RubyKubernetesController::Client.new(endpoint, bearer_token, ssl, yaml = true)
|
1870
|
+
namespace = "default"
|
1871
|
+
cronjob_name = "cronjob"
|
1872
|
+
yaml_file_path = 'path/to/file.yaml'
|
1873
|
+
|
1874
|
+
puts yaml_client.update_namespaced_cronjob(namespace, cronjob_name, yaml_file_path) # Returns JSON
|
1875
|
+
```
|
1876
|
+
|
1877
|
+
#### Patch cronjob
|
1878
|
+
* Patch existing cronjob
|
1879
|
+
* Patch Format documentation available at: http://jsonpatch.com/
|
1880
|
+
```ruby
|
1881
|
+
require 'ruby-kubernetes-controller'
|
1882
|
+
|
1883
|
+
endpoint = "localhost"
|
1884
|
+
bearer_token = "token"
|
1885
|
+
ssl = false
|
1886
|
+
|
1887
|
+
client = ::RubyKubernetesController::Client.new(endpoint, bearer_token, ssl)
|
1888
|
+
|
1889
|
+
namespace = "default"
|
1890
|
+
cronjob_name = "cronjob"
|
1891
|
+
patch =
|
1892
|
+
'[
|
1893
|
+
{ "op": "replace", "path": "/baz", "value": "boo" },
|
1894
|
+
{ "op": "add", "path": "/hello", "value": ["world"] },
|
1895
|
+
{ "op": "remove", "path": "/foo" }
|
1896
|
+
]'
|
1897
|
+
|
1898
|
+
puts client.patch_cronjob(namespace, cronjob_name, patch) # Returns JSON
|
1899
|
+
```
|
1900
|
+
|
1901
|
+
#### Delete cronjob
|
1902
|
+
* Delete existing cronjob
|
1903
|
+
* Delete options documentation available at: https://kubernetes.io/docs/reference/federation/v1/definitions/#_v1_deleteoptions
|
1904
|
+
```ruby
|
1905
|
+
require 'ruby-kubernetes-controller'
|
1906
|
+
|
1907
|
+
endpoint = "localhost"
|
1908
|
+
bearer_token = "token"
|
1909
|
+
ssl = false
|
1910
|
+
|
1911
|
+
# With JSON
|
1912
|
+
json_client = ::RubyKubernetesController::Client.new(endpoint, bearer_token, ssl, yaml = false)
|
1913
|
+
namespace = "default"
|
1914
|
+
cronjob_name = "cronjob"
|
1915
|
+
json_options =
|
1916
|
+
'{
|
1917
|
+
"kind": "CronJob",
|
1918
|
+
"apiVersion": "batch/v1beta1",
|
1919
|
+
...
|
1920
|
+
}'
|
1921
|
+
|
1922
|
+
puts json_client.delete_cronjob(namespace, cronjob_name, json_options) # Returns JSON
|
1923
|
+
|
1924
|
+
# With YAML
|
1925
|
+
yaml_client = ::RubyKubernetesController::Client.new(endpoint, bearer_token, ssl, yaml = true)
|
1926
|
+
namespace = "default"
|
1927
|
+
cronjob_name = "cronjob"
|
1928
|
+
yaml_file_path = 'path/to/file.yaml'
|
1929
|
+
|
1930
|
+
puts yaml_client.delete_cronjob(namespace, cronjob_name, yaml_file_path) # Returns JSON
|
1931
|
+
```
|
1932
|
+
|
1933
|
+
#### Triggering a cronjob
|
1934
|
+
* Trigger an existing cronjob in Namespace
|
1935
|
+
```ruby
|
1936
|
+
require 'ruby-kubernetes-controller'
|
1937
|
+
|
1938
|
+
endpoint = "localhost"
|
1939
|
+
bearer_token = "token"
|
1940
|
+
ssl = false
|
1941
|
+
|
1942
|
+
# With JSON
|
1943
|
+
json_client = ::RubyKubernetesController::Client.new(endpoint, bearer_token, ssl, yaml = false)
|
1944
|
+
namespace = "default"
|
1945
|
+
cronjob_name = "cronjob"
|
1946
|
+
restart_policy = "Never"
|
1947
|
+
|
1948
|
+
puts json_client.trigger_cronjob(namespace, cronjob_name, restart_policy) # Returns JSON
|
1949
|
+
```
|
1950
|
+
|
1770
1951
|
[SERVICEACCOUNT]: https://github.com/IBM/ruby-kubernetes-controller/blob/master/Documentation/serviceaccount.yaml
|
@@ -16,6 +16,8 @@ require_relative 'configmaps'
|
|
16
16
|
require_relative 'persistentvolumes'
|
17
17
|
require_relative 'persistentvolumeclaims'
|
18
18
|
require_relative 'jobs'
|
19
|
+
require_relative 'cronjob'
|
20
|
+
require_relative 'utilities'
|
19
21
|
|
20
22
|
# Part of the RubyKubernetesController module
|
21
23
|
module RubyKubernetesController
|
@@ -36,6 +38,8 @@ module RubyKubernetesController
|
|
36
38
|
include PersistentVolumes
|
37
39
|
include PersistentVolumeClaims
|
38
40
|
include Jobs
|
41
|
+
include CronJobs
|
42
|
+
include Utilities
|
39
43
|
|
40
44
|
# Constructor
|
41
45
|
def initialize(endpoint, bearer_token, ssl = true, yaml = false)
|
@@ -0,0 +1,181 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
require 'uri'
|
3
|
+
require 'openssl'
|
4
|
+
require 'json'
|
5
|
+
|
6
|
+
require_relative 'generic'
|
7
|
+
|
8
|
+
module CronJobs
|
9
|
+
include Generic
|
10
|
+
|
11
|
+
# Create new CronJob
|
12
|
+
def create_new_cronjob(namespace, config)
|
13
|
+
extension = "/apis/batch/v1beta1/namespaces/#{namespace}/cronjobs"
|
14
|
+
|
15
|
+
uri = prepareURI(@endpoint, extension)
|
16
|
+
|
17
|
+
request = prepareGenericRequest(uri, @bearer_token, "POST")
|
18
|
+
request.content_type = "application/json"
|
19
|
+
|
20
|
+
if @yaml
|
21
|
+
request.body = yaml_file_to_json(config)
|
22
|
+
else
|
23
|
+
request.body = config
|
24
|
+
end
|
25
|
+
|
26
|
+
req_options = prepareGenericRequestOptions(@ssl, uri)
|
27
|
+
|
28
|
+
begin
|
29
|
+
response = Net::HTTP.start(uri.hostname, uri.port, req_options) do |http|
|
30
|
+
http.request(request)
|
31
|
+
end
|
32
|
+
return response.body
|
33
|
+
|
34
|
+
rescue Errno::ECONNREFUSED
|
35
|
+
raise "Connection for host #{uri.hostname} refused"
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
# Get all CronJobs
|
40
|
+
def get_all_cronjobs
|
41
|
+
extension = "/apis/batch/v1beta1/cronjobs"
|
42
|
+
|
43
|
+
uri = prepareURI(@endpoint, extension)
|
44
|
+
|
45
|
+
request = prepareGenericRequest(uri, @bearer_token, "GET")
|
46
|
+
|
47
|
+
req_options = prepareGenericRequestOptions(@ssl, uri)
|
48
|
+
|
49
|
+
begin
|
50
|
+
response = Net::HTTP.start(uri.hostname, uri.port, req_options) do |http|
|
51
|
+
http.request(request)
|
52
|
+
end
|
53
|
+
return response.body
|
54
|
+
|
55
|
+
rescue Errno::ECONNREFUSED
|
56
|
+
raise "Connection for host #{uri.hostname} refused"
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
# Get all existing CronJobs in Namespace
|
61
|
+
def get_all_namespaced_cronjobs(namespace)
|
62
|
+
extension = "/apis/batch/v1beta1/namespaces/#{namespace}/cronjobs"
|
63
|
+
|
64
|
+
uri = prepareURI(@endpoint, extension)
|
65
|
+
|
66
|
+
request = prepareGenericRequest(uri, @bearer_token, "GET")
|
67
|
+
|
68
|
+
req_options = prepareGenericRequestOptions(@ssl, uri)
|
69
|
+
|
70
|
+
begin
|
71
|
+
response = Net::HTTP.start(uri.hostname, uri.port, req_options) do |http|
|
72
|
+
http.request(request)
|
73
|
+
end
|
74
|
+
return response.body
|
75
|
+
|
76
|
+
rescue Errno::ECONNREFUSED
|
77
|
+
raise "Connection for host #{uri.hostname} refused"
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
# Get single CronJob in Namespace
|
82
|
+
def get_single_namespaced_cronjob(namespace, cronjob_name)
|
83
|
+
extension = "/apis/batch/v1beta1/namespaces/#{namespace}/cronjobs/#{cronjob_name}"
|
84
|
+
|
85
|
+
uri = prepareURI(@endpoint, extension)
|
86
|
+
|
87
|
+
request = prepareGenericRequest(uri, @bearer_token, "GET")
|
88
|
+
|
89
|
+
req_options = prepareGenericRequestOptions(@ssl, uri)
|
90
|
+
|
91
|
+
begin
|
92
|
+
response = Net::HTTP.start(uri.hostname, uri.port, req_options) do |http|
|
93
|
+
http.request(request)
|
94
|
+
end
|
95
|
+
return response.body
|
96
|
+
rescue Errno::ECONNREFUSED
|
97
|
+
raise "Connection for host #{uri.hostname} refused"
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
# Update existing CronJob in Namespace
|
102
|
+
def update_namespaced_cronjob(namespace, cronjob_name, update)
|
103
|
+
extension = "/apis/batch/v1beta1/namespaces/#{namespace}/cronjobs/#{cronjob_name}"
|
104
|
+
|
105
|
+
uri = prepareURI(@endpoint, extension)
|
106
|
+
|
107
|
+
request = prepareGenericRequest(uri, @bearer_token, "PUT")
|
108
|
+
request.content_type = "application/json"
|
109
|
+
|
110
|
+
if @yaml
|
111
|
+
request.body = yaml_file_to_json(update)
|
112
|
+
else
|
113
|
+
request.body = update
|
114
|
+
end
|
115
|
+
|
116
|
+
req_options = prepareGenericRequestOptions(@ssl, uri)
|
117
|
+
|
118
|
+
begin
|
119
|
+
response = Net::HTTP.start(uri.hostname, uri.port, req_options) do |http|
|
120
|
+
http.request(request)
|
121
|
+
end
|
122
|
+
return response.body
|
123
|
+
|
124
|
+
rescue Errno::ECONNREFUSED
|
125
|
+
raise "Connection for host #{uri.hostname} refused"
|
126
|
+
end
|
127
|
+
|
128
|
+
end
|
129
|
+
|
130
|
+
# Patch existing CronJob in Namespace
|
131
|
+
def patch_cronjob(namespace, cronjob_name, patch)
|
132
|
+
extension = "/apis/batch/v1beta1/namespaces/#{namespace}/cronjobs/#{cronjob_name}"
|
133
|
+
|
134
|
+
uri = prepareURI(@endpoint, extension)
|
135
|
+
|
136
|
+
request = prepareGenericRequest(uri, @bearer_token, "PATCH")
|
137
|
+
request.content_type = "application/json-patch+json"
|
138
|
+
|
139
|
+
request.body = patch
|
140
|
+
|
141
|
+
req_options = prepareGenericRequestOptions(@ssl, uri)
|
142
|
+
|
143
|
+
begin
|
144
|
+
response = Net::HTTP.start(uri.hostname, uri.port, req_options) do |http|
|
145
|
+
http.request(request)
|
146
|
+
end
|
147
|
+
return response.body
|
148
|
+
rescue Errno::ECONNREFUSED
|
149
|
+
raise "Connection for host #{uri.hostname} refused"
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
153
|
+
# Delete existing Job in Namespace
|
154
|
+
def delete_cronjob(namespace, cronjob_name, options = '')
|
155
|
+
extension = "apis/batch/v1beta1/namespaces/#{namespace}/cronjobs/#{cronjob_name}"
|
156
|
+
|
157
|
+
uri = prepareURI(@endpoint, extension)
|
158
|
+
|
159
|
+
request = prepareGenericRequest(uri, @bearer_token, "DELETE")
|
160
|
+
request.content_type = "application/json"
|
161
|
+
|
162
|
+
if @yaml
|
163
|
+
request.body = yaml_file_to_json(options)
|
164
|
+
else
|
165
|
+
request.body = options
|
166
|
+
end
|
167
|
+
|
168
|
+
req_options = prepareGenericRequestOptions(@ssl, uri)
|
169
|
+
|
170
|
+
begin
|
171
|
+
response = Net::HTTP.start(uri.hostname, uri.port, req_options) do |http|
|
172
|
+
http.request(request)
|
173
|
+
end
|
174
|
+
return response.body
|
175
|
+
|
176
|
+
rescue Errno::ECONNREFUSED
|
177
|
+
raise "Connection for host #{uri.hostname} refused"
|
178
|
+
end
|
179
|
+
end
|
180
|
+
|
181
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
require 'uri'
|
3
|
+
require 'openssl'
|
4
|
+
require 'json'
|
5
|
+
|
6
|
+
require_relative 'generic'
|
7
|
+
require_relative 'namespaces'
|
8
|
+
require_relative 'ingresses'
|
9
|
+
require_relative 'nodes'
|
10
|
+
require_relative 'endpoints'
|
11
|
+
require_relative 'pods'
|
12
|
+
require_relative 'services'
|
13
|
+
require_relative 'deployments'
|
14
|
+
require_relative 'replicasets'
|
15
|
+
require_relative 'configmaps'
|
16
|
+
require_relative 'persistentvolumes'
|
17
|
+
require_relative 'persistentvolumeclaims'
|
18
|
+
require_relative 'jobs'
|
19
|
+
require_relative 'cronjob'
|
20
|
+
|
21
|
+
module Utilities
|
22
|
+
include Generic
|
23
|
+
include Namespaces
|
24
|
+
include Ingresses
|
25
|
+
include Nodes
|
26
|
+
include Endpoints
|
27
|
+
include Pods
|
28
|
+
include Services
|
29
|
+
include Deployments
|
30
|
+
include ReplicaSets
|
31
|
+
include ConfigMaps
|
32
|
+
include PersistentVolumes
|
33
|
+
include PersistentVolumeClaims
|
34
|
+
include Jobs
|
35
|
+
include CronJobs
|
36
|
+
|
37
|
+
# Trigger a cronjob
|
38
|
+
def trigger_cronjob(namespace, cronjob_name, restart_policy = 'Never')
|
39
|
+
cronjob_json = JSON.parse(get_single_namespaced_cronjob(namespace, cronjob_name))
|
40
|
+
cronjob_json['spec']['jobTemplate']['spec']['template']['spec']['restartPolicy'] = restart_policy
|
41
|
+
cronjob_json['metadata']['name'] += '-' + ('a'..'z').to_a.shuffle[0,8].join
|
42
|
+
json_config =
|
43
|
+
'{
|
44
|
+
"kind": "Job",
|
45
|
+
"apiVersion": "batch/v1",
|
46
|
+
"metadata": {
|
47
|
+
"name": ' + cronjob_json['metadata']['name'].to_json + '
|
48
|
+
},
|
49
|
+
"spec": {
|
50
|
+
"template": {
|
51
|
+
"spec": ' + cronjob_json['spec']['jobTemplate']['spec']['template']['spec'].to_json + '
|
52
|
+
}
|
53
|
+
}
|
54
|
+
}'
|
55
|
+
create_new_job(namespace, json_config)
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby-kubernetes-controller
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Shivansh Vij (ShivanshVij)
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: exe
|
12
12
|
cert_chain: []
|
13
|
-
date:
|
13
|
+
date: 2020-01-02 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: bundler
|
@@ -101,6 +101,7 @@ files:
|
|
101
101
|
- lib/ruby-kubernetes-controller.rb
|
102
102
|
- lib/ruby-kubernetes-controller/client.rb
|
103
103
|
- lib/ruby-kubernetes-controller/configmaps.rb
|
104
|
+
- lib/ruby-kubernetes-controller/cronjob.rb
|
104
105
|
- lib/ruby-kubernetes-controller/deployments.rb
|
105
106
|
- lib/ruby-kubernetes-controller/endpoints.rb
|
106
107
|
- lib/ruby-kubernetes-controller/generic.rb
|
@@ -113,6 +114,7 @@ files:
|
|
113
114
|
- lib/ruby-kubernetes-controller/pods.rb
|
114
115
|
- lib/ruby-kubernetes-controller/replicasets.rb
|
115
116
|
- lib/ruby-kubernetes-controller/services.rb
|
117
|
+
- lib/ruby-kubernetes-controller/utilities.rb
|
116
118
|
- lib/ruby-kubernetes-controller/version.rb
|
117
119
|
- ruby-kubernetes-controller.gemspec
|
118
120
|
homepage: https://github.com/IBM/ruby-kubernetes-controller/
|