ruby-kubernetes-controller 0.1.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e1d7bfdc1de0725fb1f2d4cad6780c71f58bc8dd619836d80514f81f80c706ac
4
- data.tar.gz: 4650e322ec9b9ef297e782e17f0b245f16e05d8432aecb8ef1c02d6b6896e054
3
+ metadata.gz: 2062f2405d0d36ad772ace7721366404fb71507d9abfb27a34ca8b73315ee1e8
4
+ data.tar.gz: f82fbed50886984db3ee1a1ddc89684462cd7382ee4568d6a34b1807bb429e1c
5
5
  SHA512:
6
- metadata.gz: b6637290fee0b38a28187a4f4f9ca100eef89de7476ebe7feacda2b23e97697111532ceb9a66358b3f0b389def34ce5fedbf77b3229366cc5ad6279cc676dc4d
7
- data.tar.gz: dc1339715316475a8600ab9d5d5eeec4259a2554a42dd95e2fcf9579e250095093cc48324249174e1de407176b5b564cf32de9512bd1ab368932790a3c5f39c5
6
+ metadata.gz: 800feff4f19a022aa143c59b112ed785c3011143488d8f654320f652711504b347e0b7c2e20aae2083af89dfd1e454a71f23d1f5cce8491309d60696cb9a4c64
7
+ data.tar.gz: ab448d9edccdffcc4e78a481a40aeaa711bedac579fa597bdfb4e973b26ea3788759513e020897bca372bbc3f0b07c8e2aec9e4e49b838b21890410464c46350
@@ -2,7 +2,9 @@
2
2
 
3
3
  ## Pre-requisites
4
4
  Before beginning, you must generate a bearer token for the Ruby Kubernetes Controller to use:
5
-
5
+ If you want to read the bearer token that is in the pod instead of generating one to use,
6
+ pass in an empty string to bearer_token when calling
7
+ `::RubyKubernetesController::Client.new(endpoint, bearer_token, ssl)`
6
8
 
7
9
  1. Save the following as `serviceaccount.yaml` (file available [here][SERVICEACCOUNT])
8
10
  <p align="center"><img width=100% src="./serviceaccount.png"></p>
@@ -169,7 +171,7 @@ Before beginning, you must generate a bearer token for the Ruby Kubernetes Contr
169
171
  json_config =
170
172
  '{
171
173
  "kind": "Ingress",
172
- "apiVersion": "extensions/v1beta1",
174
+ "apiVersion": "networking.k8s.io/v1beta1",
173
175
  ...
174
176
  }'
175
177
 
@@ -247,7 +249,7 @@ Before beginning, you must generate a bearer token for the Ruby Kubernetes Contr
247
249
  json_update =
248
250
  '{
249
251
  "kind": "Ingress",
250
- "apiVersion": "extensions/v1beta1",
252
+ "apiVersion": "networking.k8s.io/v1beta1",
251
253
  ...
252
254
  }'
253
255
 
@@ -303,7 +305,7 @@ Before beginning, you must generate a bearer token for the Ruby Kubernetes Contr
303
305
  json_options =
304
306
  '{
305
307
  "kind": "Ingress",
306
- "apiVersion": "extensions/v1beta1",
308
+ "apiVersion": "networking.k8s.io/v1beta1",
307
309
  ...
308
310
  }'
309
311
 
@@ -543,6 +545,38 @@ Before beginning, you must generate a bearer token for the Ruby Kubernetes Contr
543
545
  puts client.get_all_namespaced_pods(namespace) # Returns JSON
544
546
  ```
545
547
 
548
+ #### Get Namespaced Pods With Field Selector
549
+ * List all existing Pods in Namespace that have a specific field selector
550
+ ```ruby
551
+ require 'ruby-kubernetes-controller'
552
+
553
+ pod = "localhost"
554
+ bearer_token = "token"
555
+ ssl = false
556
+
557
+ client = ::RubyKubernetesController::Client.new(pod, bearer_token, ssl)
558
+
559
+ namespace = "default"
560
+
561
+ puts client.get_all_namespaced_pods_with_field_selector(namespace, field_selector) # Returns JSON
562
+ ```
563
+
564
+ #### Get Namespaced Pods With Label Selector
565
+ * List all existing Pods in Namespace that have a specific label selector
566
+ ```ruby
567
+ require 'ruby-kubernetes-controller'
568
+
569
+ pod = "localhost"
570
+ bearer_token = "token"
571
+ ssl = false
572
+
573
+ client = ::RubyKubernetesController::Client.new(pod, bearer_token, ssl)
574
+
575
+ namespace = "default"
576
+
577
+ puts client.get_all_namespaced_pods_with_label_selector(namespace, label_selector) # Returns JSON
578
+ ```
579
+
546
580
  #### Get Single Namespaced Pod
547
581
  * Get details for single Pod in Namespace
548
582
  ```ruby
@@ -814,7 +848,7 @@ Before beginning, you must generate a bearer token for the Ruby Kubernetes Contr
814
848
  json_config =
815
849
  '{
816
850
  "kind": "Deployment",
817
- "apiVersion": "extensions/v1beta1",
851
+ "apiVersion": "extensions/v1",
818
852
  ...
819
853
  }'
820
854
 
@@ -828,8 +862,8 @@ Before beginning, you must generate a bearer token for the Ruby Kubernetes Contr
828
862
  puts yaml_client.create_new_deployment(namespace, yaml_file_path) # Returns JSON
829
863
  ```
830
864
 
831
- #### Get Deploymentes
832
- * List all Deploymentes
865
+ #### Get Deployments
866
+ * List all Deployments
833
867
  ```ruby
834
868
  require 'ruby-kubernetes-controller'
835
869
 
@@ -839,11 +873,11 @@ Before beginning, you must generate a bearer token for the Ruby Kubernetes Contr
839
873
 
840
874
  client = ::RubyKubernetesController::Client.new(endpoint, bearer_token, ssl)
841
875
 
842
- puts client.get_all_deploymentes # Returns JSON
876
+ puts client.get_all_deployments # Returns JSON
843
877
  ```
844
878
 
845
- #### Get Namespaced Deploymentes
846
- * List all existing Deploymentes in Namespace
879
+ #### Get Namespaced Deployments
880
+ * List all existing Deployments in Namespace
847
881
  ```ruby
848
882
  require 'ruby-kubernetes-controller'
849
883
 
@@ -855,7 +889,7 @@ Before beginning, you must generate a bearer token for the Ruby Kubernetes Contr
855
889
 
856
890
  namespace = "default"
857
891
 
858
- puts client.get_all_namespaced_deploymentes(namespace) # Returns JSON
892
+ puts client.get_all_namespaced_deployments(namespace) # Returns JSON
859
893
  ```
860
894
 
861
895
  #### Get Single Namespaced Deployment
@@ -892,7 +926,7 @@ Before beginning, you must generate a bearer token for the Ruby Kubernetes Contr
892
926
  json_update =
893
927
  '{
894
928
  "kind": "Deployment",
895
- "apiVersion": "extensions/v1beta1",
929
+ "apiVersion": "extensions/v1",
896
930
  ...
897
931
  }'
898
932
 
@@ -948,7 +982,7 @@ Before beginning, you must generate a bearer token for the Ruby Kubernetes Contr
948
982
  json_options =
949
983
  '{
950
984
  "kind": "Deployment",
951
- "apiVersion": "extensions/v1beta1",
985
+ "apiVersion": "extensions/v1",
952
986
  ...
953
987
  }'
954
988
 
@@ -979,7 +1013,7 @@ Before beginning, you must generate a bearer token for the Ruby Kubernetes Contr
979
1013
  json_config =
980
1014
  '{
981
1015
  "kind": "Replicaset",
982
- "apiVersion": "extensions/v1beta1",
1016
+ "apiVersion": "apps/v1",
983
1017
  ...
984
1018
  }'
985
1019
 
@@ -1057,7 +1091,7 @@ Before beginning, you must generate a bearer token for the Ruby Kubernetes Contr
1057
1091
  json_update =
1058
1092
  '{
1059
1093
  "kind": "Replicaset",
1060
- "apiVersion": "extensions/v1beta1",
1094
+ "apiVersion": "apps/v1",
1061
1095
  ...
1062
1096
  }'
1063
1097
 
@@ -1113,7 +1147,7 @@ Before beginning, you must generate a bearer token for the Ruby Kubernetes Contr
1113
1147
  json_options =
1114
1148
  '{
1115
1149
  "kind": "Replicaset",
1116
- "apiVersion": "extensions/v1beta1",
1150
+ "apiVersion": "apps/v1",
1117
1151
  ...
1118
1152
  }'
1119
1153
 
@@ -1603,4 +1637,349 @@ Before beginning, you must generate a bearer token for the Ruby Kubernetes Contr
1603
1637
  puts yaml_client.delete_persistentvolumeclaim(namespace, persistentvolumeclaim_name, yaml_file_path) # Returns JSON
1604
1638
  ```
1605
1639
 
1640
+
1641
+ #### Create Job
1642
+ * Create new Job
1643
+ ```ruby
1644
+ require 'ruby-kubernetes-controller'
1645
+
1646
+ endpoint = "localhost"
1647
+ bearer_token = "token"
1648
+ ssl = false
1649
+
1650
+ # With JSON
1651
+ json_client = ::RubyKubernetesController::Client.new(endpoint, bearer_token, ssl, yaml = false)
1652
+ namespace = "default"
1653
+ json_config =
1654
+ '{
1655
+ "kind": "Job",
1656
+ "apiVersion": "batch/v1",
1657
+ ...
1658
+ }'
1659
+
1660
+ puts json_client.create_new_job(namespace, json_config) # Returns JSON
1661
+
1662
+ # With YAML
1663
+ yaml_client = ::RubyKubernetesController::Client.new(endpoint, bearer_token, ssl, yaml = true)
1664
+ namespace = "default"
1665
+ yaml_file_path = 'path/to/file.yaml'
1666
+
1667
+ puts yaml_client.create_new_job(namespace, yaml_file_path) # Returns JSON
1668
+ ```
1669
+
1670
+ #### Get Jobs
1671
+ * List all Jobs
1672
+ ```ruby
1673
+ require 'ruby-kubernetes-controller'
1674
+
1675
+ endpoint = "localhost"
1676
+ bearer_token = "token"
1677
+ ssl = false
1678
+
1679
+ client = ::RubyKubernetesController::Client.new(endpoint, bearer_token, ssl)
1680
+
1681
+ puts client.get_all_jobs # Returns JSON
1682
+ ```
1683
+
1684
+ #### Get Namespaced Jobs
1685
+ * List all existing Jobs in Namespace
1686
+ ```ruby
1687
+ require 'ruby-kubernetes-controller'
1688
+
1689
+ endpoint = "localhost"
1690
+ bearer_token = "token"
1691
+ ssl = false
1692
+
1693
+ client = ::RubyKubernetesController::Client.new(endpoint, bearer_token, ssl)
1694
+
1695
+ namespace = "default"
1696
+
1697
+ puts client.get_all_namespaced_jobs(namespace) # Returns JSON
1698
+ ```
1699
+
1700
+ #### Get Single Namespaced Job
1701
+ * Get details for single Job in Namespace
1702
+ ```ruby
1703
+ require 'ruby-kubernetes-controller'
1704
+
1705
+ endpoint = "localhost"
1706
+ bearer_token = "token"
1707
+ ssl = false
1708
+
1709
+ client = ::RubyKubernetesController::Client.new(endpoint, bearer_token, ssl)
1710
+
1711
+ namespace = "default"
1712
+ job_name = "job"
1713
+
1714
+ puts client.get_single_namespaced_job(namespace, job_name) # Returns JSON
1715
+ ```
1716
+
1717
+ #### Update Job
1718
+ * Update existing Job in Namespace
1719
+ ```ruby
1720
+ require 'ruby-kubernetes-controller'
1721
+
1722
+ endpoint = "localhost"
1723
+ bearer_token = "token"
1724
+ ssl = false
1725
+
1726
+ # With JSON
1727
+ json_client = ::RubyKubernetesController::Client.new(endpoint, bearer_token, ssl, yaml = false)
1728
+ namespace = "default"
1729
+ job_name = "job"
1730
+ json_update =
1731
+ '{
1732
+ "kind": "Job",
1733
+ "apiVersion": "batch/v1",
1734
+ ...
1735
+ }'
1736
+
1737
+ puts json_client.update_namespaced_job(namespace, job_name, json_update) # Returns JSON
1738
+
1739
+ # With YAML
1740
+ yaml_client = ::RubyKubernetesController::Client.new(endpoint, bearer_token, ssl, yaml = true)
1741
+ namespace = "default"
1742
+ job_name = "job"
1743
+ yaml_file_path = 'path/to/file.yaml'
1744
+
1745
+ puts yaml_client.update_namespaced_job(namespace, job_name, yaml_file_path) # Returns JSON
1746
+ ```
1747
+
1748
+ #### Patch Job
1749
+ * Patch existing Job
1750
+ * Patch Format documentation available at: http://jsonpatch.com/
1751
+ ```ruby
1752
+ require 'ruby-kubernetes-controller'
1753
+
1754
+ endpoint = "localhost"
1755
+ bearer_token = "token"
1756
+ ssl = false
1757
+
1758
+ client = ::RubyKubernetesController::Client.new(endpoint, bearer_token, ssl)
1759
+
1760
+ namespace = "default"
1761
+ job_name = "job"
1762
+ patch =
1763
+ '[
1764
+ { "op": "replace", "path": "/baz", "value": "boo" },
1765
+ { "op": "add", "path": "/hello", "value": ["world"] },
1766
+ { "op": "remove", "path": "/foo" }
1767
+ ]'
1768
+
1769
+ puts client.patch_job(namespace, job_name, patch) # Returns JSON
1770
+ ```
1771
+
1772
+ #### Delete Job
1773
+ * Delete existing Job
1774
+ * Delete options documentation available at: https://kubernetes.io/docs/reference/federation/v1/definitions/#_v1_deleteoptions
1775
+ ```ruby
1776
+ require 'ruby-kubernetes-controller'
1777
+
1778
+ endpoint = "localhost"
1779
+ bearer_token = "token"
1780
+ ssl = false
1781
+
1782
+ # With JSON
1783
+ json_client = ::RubyKubernetesController::Client.new(endpoint, bearer_token, ssl, yaml = false)
1784
+ namespace = "default"
1785
+ job_name = "job"
1786
+ json_options =
1787
+ '{
1788
+ "kind": "Job",
1789
+ "apiVersion": "batch/v1",
1790
+ ...
1791
+ }'
1792
+
1793
+ puts json_client.delete_job(namespace, job_name, json_options) # Returns JSON
1794
+
1795
+ # With YAML
1796
+ yaml_client = ::RubyKubernetesController::Client.new(endpoint, bearer_token, ssl, yaml = true)
1797
+ namespace = "default"
1798
+ job_name = "job"
1799
+ yaml_file_path = 'path/to/file.yaml'
1800
+
1801
+ puts yaml_client.delete_job(namespace, job_name, yaml_file_path) # Returns JSON
1802
+ ```
1803
+
1804
+ #### Create cronjob
1805
+ * Create new cronjob
1806
+ ```ruby
1807
+ require 'ruby-kubernetes-controller'
1808
+
1809
+ endpoint = "localhost"
1810
+ bearer_token = "token"
1811
+ ssl = false
1812
+
1813
+ # With JSON
1814
+ json_client = ::RubyKubernetesController::Client.new(endpoint, bearer_token, ssl, yaml = false)
1815
+ namespace = "default"
1816
+ json_config =
1817
+ '{
1818
+ "kind": "CronJob",
1819
+ "apiVersion": "batch/v1beta1",
1820
+ ...
1821
+ }'
1822
+
1823
+ puts json_client.create_new_cronjob(namespace, json_config) # Returns JSON
1824
+
1825
+ # With YAML
1826
+ yaml_client = ::RubyKubernetesController::Client.new(endpoint, bearer_token, ssl, yaml = true)
1827
+ namespace = "default"
1828
+ yaml_file_path = 'path/to/file.yaml'
1829
+
1830
+ puts yaml_client.create_new_cronjob(namespace, yaml_file_path) # Returns JSON
1831
+ ```
1832
+
1833
+ #### Get cronjobs
1834
+ * List all cronjobs
1835
+ ```ruby
1836
+ require 'ruby-kubernetes-controller'
1837
+
1838
+ endpoint = "localhost"
1839
+ bearer_token = "token"
1840
+ ssl = false
1841
+
1842
+ client = ::RubyKubernetesController::Client.new(endpoint, bearer_token, ssl)
1843
+
1844
+ puts client.get_all_cronjobs # Returns JSON
1845
+ ```
1846
+
1847
+ #### Get Namespaced cronjobs
1848
+ * List all existing cronjobs in Namespace
1849
+ ```ruby
1850
+ require 'ruby-kubernetes-controller'
1851
+
1852
+ endpoint = "localhost"
1853
+ bearer_token = "token"
1854
+ ssl = false
1855
+
1856
+ client = ::RubyKubernetesController::Client.new(endpoint, bearer_token, ssl)
1857
+
1858
+ namespace = "default"
1859
+
1860
+ puts client.get_all_namespaced_cronjobs(namespace) # Returns JSON
1861
+ ```
1862
+
1863
+ #### Get Single Namespaced cronjob
1864
+ * Get details for single cronjob in Namespace
1865
+ ```ruby
1866
+ require 'ruby-kubernetes-controller'
1867
+
1868
+ endpoint = "localhost"
1869
+ bearer_token = "token"
1870
+ ssl = false
1871
+
1872
+ client = ::RubyKubernetesController::Client.new(endpoint, bearer_token, ssl)
1873
+
1874
+ namespace = "default"
1875
+ cronjob_name = "cronjob"
1876
+
1877
+ puts client.get_single_namespaced_cronjob(namespace, cronjob_name) # Returns JSON
1878
+ ```
1879
+
1880
+ #### Update cronjob
1881
+ * Update existing cronjob in Namespace
1882
+ ```ruby
1883
+ require 'ruby-kubernetes-controller'
1884
+
1885
+ endpoint = "localhost"
1886
+ bearer_token = "token"
1887
+ ssl = false
1888
+
1889
+ # With JSON
1890
+ json_client = ::RubyKubernetesController::Client.new(endpoint, bearer_token, ssl, yaml = false)
1891
+ namespace = "default"
1892
+ cronjob_name = "cronjob"
1893
+ json_update =
1894
+ '{
1895
+ "kind": "CronJob",
1896
+ "apiVersion": "batch/v1beta1",
1897
+ ...
1898
+ }'
1899
+
1900
+ puts json_client.update_namespaced_cronjob(namespace, cronjob_name, json_update) # Returns JSON
1901
+
1902
+ # With YAML
1903
+ yaml_client = ::RubyKubernetesController::Client.new(endpoint, bearer_token, ssl, yaml = true)
1904
+ namespace = "default"
1905
+ cronjob_name = "cronjob"
1906
+ yaml_file_path = 'path/to/file.yaml'
1907
+
1908
+ puts yaml_client.update_namespaced_cronjob(namespace, cronjob_name, yaml_file_path) # Returns JSON
1909
+ ```
1910
+
1911
+ #### Patch cronjob
1912
+ * Patch existing cronjob
1913
+ * Patch Format documentation available at: http://jsonpatch.com/
1914
+ ```ruby
1915
+ require 'ruby-kubernetes-controller'
1916
+
1917
+ endpoint = "localhost"
1918
+ bearer_token = "token"
1919
+ ssl = false
1920
+
1921
+ client = ::RubyKubernetesController::Client.new(endpoint, bearer_token, ssl)
1922
+
1923
+ namespace = "default"
1924
+ cronjob_name = "cronjob"
1925
+ patch =
1926
+ '[
1927
+ { "op": "replace", "path": "/baz", "value": "boo" },
1928
+ { "op": "add", "path": "/hello", "value": ["world"] },
1929
+ { "op": "remove", "path": "/foo" }
1930
+ ]'
1931
+
1932
+ puts client.patch_cronjob(namespace, cronjob_name, patch) # Returns JSON
1933
+ ```
1934
+
1935
+ #### Delete cronjob
1936
+ * Delete existing cronjob
1937
+ * Delete options documentation available at: https://kubernetes.io/docs/reference/federation/v1/definitions/#_v1_deleteoptions
1938
+ ```ruby
1939
+ require 'ruby-kubernetes-controller'
1940
+
1941
+ endpoint = "localhost"
1942
+ bearer_token = "token"
1943
+ ssl = false
1944
+
1945
+ # With JSON
1946
+ json_client = ::RubyKubernetesController::Client.new(endpoint, bearer_token, ssl, yaml = false)
1947
+ namespace = "default"
1948
+ cronjob_name = "cronjob"
1949
+ json_options =
1950
+ '{
1951
+ "kind": "CronJob",
1952
+ "apiVersion": "batch/v1beta1",
1953
+ ...
1954
+ }'
1955
+
1956
+ puts json_client.delete_cronjob(namespace, cronjob_name, json_options) # Returns JSON
1957
+
1958
+ # With YAML
1959
+ yaml_client = ::RubyKubernetesController::Client.new(endpoint, bearer_token, ssl, yaml = true)
1960
+ namespace = "default"
1961
+ cronjob_name = "cronjob"
1962
+ yaml_file_path = 'path/to/file.yaml'
1963
+
1964
+ puts yaml_client.delete_cronjob(namespace, cronjob_name, yaml_file_path) # Returns JSON
1965
+ ```
1966
+
1967
+ #### Triggering a cronjob
1968
+ * Trigger an existing cronjob in Namespace
1969
+ ```ruby
1970
+ require 'ruby-kubernetes-controller'
1971
+
1972
+ endpoint = "localhost"
1973
+ bearer_token = "token"
1974
+ ssl = false
1975
+
1976
+ # With JSON
1977
+ json_client = ::RubyKubernetesController::Client.new(endpoint, bearer_token, ssl, yaml = false)
1978
+ namespace = "default"
1979
+ cronjob_name = "cronjob"
1980
+ restart_policy = "Never"
1981
+
1982
+ puts json_client.trigger_cronjob(namespace, cronjob_name, restart_policy) # Returns JSON
1983
+ ```
1984
+
1606
1985
  [SERVICEACCOUNT]: https://github.com/IBM/ruby-kubernetes-controller/blob/master/Documentation/serviceaccount.yaml
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Ruby Kubernetes Controller
2
2
 
3
- Current Build: [![CircleCI](https://circleci.com/gh/IBM/ruby-kubernetes-controller.svg?style=svg)](https://circleci.com/gh/IBM/ruby-kubernetes-controller)
3
+ [![CircleCI](https://circleci.com/gh/IBM/ruby-kubernetes-controller.svg?style=svg)](https://circleci.com/gh/IBM/ruby-kubernetes-controller) [![Gem Version](https://badge.fury.io/rb/ruby-kubernetes-controller.svg)](https://badge.fury.io/rb/ruby-kubernetes-controller) [![RubyGems](https://img.shields.io/gem/dt/ruby-kubernetes-controller.svg?color=FF502A&label=gem%20downloads&style=popout)](https://rubygems.org/gems/ruby-kubernetes-controller) [![License](https://img.shields.io/github/license/ibm/ruby-kubernetes-controller.svg)](https://github.com/IBM/ruby-kubernetes-controller/blob/master/LICENSE.txt)
4
4
 
5
5
  `Ruby Kubernetes Controller` is a Client-Side library which allows users to
6
6
  interact with core Kubernetes APIs natively from within their
@@ -15,6 +15,9 @@ require_relative 'replicasets'
15
15
  require_relative 'configmaps'
16
16
  require_relative 'persistentvolumes'
17
17
  require_relative 'persistentvolumeclaims'
18
+ require_relative 'jobs'
19
+ require_relative 'cronjob'
20
+ require_relative 'utilities'
18
21
 
19
22
  # Part of the RubyKubernetesController module
20
23
  module RubyKubernetesController
@@ -34,12 +37,16 @@ module RubyKubernetesController
34
37
  include ConfigMaps
35
38
  include PersistentVolumes
36
39
  include PersistentVolumeClaims
40
+ include Jobs
41
+ include CronJobs
42
+ include Utilities
37
43
 
38
44
  # Constructor
39
45
  def initialize(endpoint, bearer_token, ssl = true, yaml = false)
40
46
  # Instantiating client variables
41
47
  @endpoint = endpoint
42
48
  @bearer_token = bearer_token
49
+ @bearer_token = default_serviceaccount_token if bearer_token.empty?
43
50
  @ssl = ssl
44
51
  @yaml = yaml
45
52
  end
@@ -58,5 +65,14 @@ module RubyKubernetesController
58
65
  def getSSL
59
66
  @ssl
60
67
  end
68
+
69
+ # Reads the Bearer Token from the pod
70
+ private
71
+
72
+ def default_serviceaccount_token
73
+ return "" unless File.exist?("/var/run/secrets/kubernetes.io/serviceaccount/token")
74
+
75
+ File.read("/var/run/secrets/kubernetes.io/serviceaccount/token")
76
+ end
61
77
  end
62
- end
78
+ end
@@ -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
@@ -10,7 +10,7 @@ module Deployments
10
10
 
11
11
  # Create new Deployment
12
12
  def create_new_deployment(namespace, config)
13
- extension = "/apis/apps/v1beta1/namespaces/#{namespace}/deployments"
13
+ extension = "/apis/apps/v1/namespaces/#{namespace}/deployments"
14
14
 
15
15
  uri = prepareURI(@endpoint, extension)
16
16
 
@@ -38,7 +38,7 @@ module Deployments
38
38
 
39
39
  # Get all Deployments
40
40
  def get_all_deployments
41
- extension = "/apis/apps/v1beta1/deployments"
41
+ extension = "/apis/apps/v1/deployments"
42
42
 
43
43
  uri = prepareURI(@endpoint, extension)
44
44
 
@@ -59,7 +59,7 @@ module Deployments
59
59
 
60
60
  # Get all existing Deployments in Namespace
61
61
  def get_all_namespaced_deployments(namespace)
62
- extension = "/apis/apps/v1beta1/namespaces/#{namespace}/deployments"
62
+ extension = "/apis/apps/v1/namespaces/#{namespace}/deployments"
63
63
 
64
64
  uri = prepareURI(@endpoint, extension)
65
65
 
@@ -80,7 +80,7 @@ module Deployments
80
80
 
81
81
  # Get single Deployment in Namespace
82
82
  def get_single_namespaced_deployment(namespace, deployment_name)
83
- extension = "/apis/apps/v1beta1/namespaces/#{namespace}/deployments/#{deployment_name}"
83
+ extension = "/apis/apps/v1/namespaces/#{namespace}/deployments/#{deployment_name}"
84
84
 
85
85
  uri = prepareURI(@endpoint, extension)
86
86
 
@@ -100,7 +100,7 @@ module Deployments
100
100
 
101
101
  # Update existing Deployment in Namespace
102
102
  def update_namespaced_deployment(namespace, deployment_name, update)
103
- extension = "/apis/apps/v1beta1/namespaces/#{namespace}/deployments/#{deployment_name}"
103
+ extension = "/apis/apps/v1/namespaces/#{namespace}/deployments/#{deployment_name}"
104
104
 
105
105
  uri = prepareURI(@endpoint, extension)
106
106
 
@@ -129,7 +129,7 @@ module Deployments
129
129
 
130
130
  # Patch existing Deployment in Namespace
131
131
  def patch_deployment(namespace, deployment_name, patch)
132
- extension = "/apis/apps/v1beta1/namespaces/#{namespace}/deployments/#{deployment_name}"
132
+ extension = "/apis/apps/v1/namespaces/#{namespace}/deployments/#{deployment_name}"
133
133
 
134
134
  uri = prepareURI(@endpoint, extension)
135
135
 
@@ -152,7 +152,7 @@ module Deployments
152
152
 
153
153
  # Delete existing Deployment in Namespace
154
154
  def delete_deployment(namespace, deployment_name, options = '')
155
- extension = "/apis/apps/v1beta1/namespaces/#{namespace}/deployments/#{deployment_name}"
155
+ extension = "/apis/apps/v1/namespaces/#{namespace}/deployments/#{deployment_name}"
156
156
 
157
157
  uri = prepareURI(@endpoint, extension)
158
158
 
@@ -11,6 +11,14 @@ module Generic
11
11
  URI.parse("https://#{endpoint}#{extension}")
12
12
  end
13
13
 
14
+ # Create a URI Object with params
15
+ def prepareURIWithParams(endpoint, extension, params)
16
+ uri = URI.parse("https://#{endpoint}#{extension}")
17
+ uri.query = URI.encode_www_form(params)
18
+
19
+ uri
20
+ end
21
+
14
22
  # Prepare a Generic Request Object
15
23
  def prepareGenericRequest(uri, bearer_token, type)
16
24
  if type == "GET"
@@ -10,7 +10,7 @@ module Ingresses
10
10
 
11
11
  # Create new Ingress
12
12
  def create_new_ingress(namespace, config)
13
- extension = "/apis/extensions/v1beta1/namespaces/#{namespace}/ingresses"
13
+ extension = "/apis/networking.k8s.io/v1beta1/namespaces/#{namespace}/ingresses"
14
14
 
15
15
  uri = prepareURI(@endpoint, extension)
16
16
 
@@ -38,7 +38,7 @@ module Ingresses
38
38
 
39
39
  # Get all Ingresses
40
40
  def get_all_ingresses
41
- extension = "/apis/extensions/v1beta1/ingresses"
41
+ extension = "/apis/networking.k8s.io/v1beta1/ingresses"
42
42
 
43
43
  uri = prepareURI(@endpoint, extension)
44
44
 
@@ -59,7 +59,7 @@ module Ingresses
59
59
 
60
60
  # Get all existing Ingresses in Namespace
61
61
  def get_all_namespaced_ingresses(namespace)
62
- extension = "/apis/extensions/v1beta1/namespaces/#{namespace}/ingresses"
62
+ extension = "/apis/networking.k8s.io/v1beta1/namespaces/#{namespace}/ingresses"
63
63
 
64
64
  uri = prepareURI(@endpoint, extension)
65
65
 
@@ -80,7 +80,7 @@ module Ingresses
80
80
 
81
81
  # Get single Ingress in Namespace
82
82
  def get_single_namespaced_ingress(namespace, ingress_name)
83
- extension = "/apis/extensions/v1beta1/namespaces/#{namespace}/ingresses/#{ingress_name}"
83
+ extension = "/apis/networking.k8s.io/v1beta1/namespaces/#{namespace}/ingresses/#{ingress_name}"
84
84
 
85
85
  uri = prepareURI(@endpoint, extension)
86
86
 
@@ -100,7 +100,7 @@ module Ingresses
100
100
 
101
101
  # Update existing Ingress in Namespace
102
102
  def update_namespaced_ingress(namespace, ingress_name, update)
103
- extension = "/apis/extensions/v1beta1/namespaces/#{namespace}/ingresses/#{ingress_name}"
103
+ extension = "/apis/networking.k8s.io/v1beta1/namespaces/#{namespace}/ingresses/#{ingress_name}"
104
104
 
105
105
  uri = prepareURI(@endpoint, extension)
106
106
 
@@ -128,7 +128,7 @@ module Ingresses
128
128
 
129
129
  # Patch existing Ingress
130
130
  def patch_ingress(namespace, ingress_name, patch)
131
- extension = "/apis/extensions/v1beta1/namespaces/#{namespace}/ingresses/#{ingress_name}"
131
+ extension = "/apis/networking.k8s.io/v1beta1/namespaces/#{namespace}/ingresses/#{ingress_name}"
132
132
 
133
133
  uri = prepareURI(@endpoint, extension)
134
134
 
@@ -151,7 +151,7 @@ module Ingresses
151
151
 
152
152
  # Delete existing Namespace
153
153
  def delete_ingress(namespace, ingress_name, options = '')
154
- extension = "/apis/extensions/v1beta1/namespaces/#{namespace}/ingresses/#{ingress_name}"
154
+ extension = "/apis/networking.k8s.io/v1beta1/namespaces/#{namespace}/ingresses/#{ingress_name}"
155
155
 
156
156
  uri = prepareURI(@endpoint, extension)
157
157
 
@@ -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 Jobs
9
+ include Generic
10
+
11
+ # Create new Job
12
+ def create_new_job(namespace, config)
13
+ extension = "/apis/batch/v1/namespaces/#{namespace}/jobs"
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 Jobs
40
+ def get_all_jobs
41
+ extension = "/apis/batch/v1/jobs"
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 Jobs in Namespace
61
+ def get_all_namespaced_jobs(namespace)
62
+ extension = "/apis/batch/v1/namespaces/#{namespace}/jobs"
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 Job in Namespace
82
+ def get_single_namespaced_job(namespace, job_name)
83
+ extension = "/apis/batch/v1/namespaces/#{namespace}/jobs/#{job_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 Job in Namespace
102
+ def update_namespaced_job(namespace, job_name, update)
103
+ extension = "/apis/batch/v1/namespaces/#{namespace}/jobs/#{job_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 Job in Namespace
131
+ def patch_job(namespace, job_name, patch)
132
+ extension = "/apis/batch/v1/namespaces/#{namespace}/jobs/#{job_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_job(namespace, job_name, options = '')
155
+ extension = "/apis/batch/v1/namespaces/#{namespace}/jobs/#{job_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
@@ -78,6 +78,54 @@ module Pods
78
78
  end
79
79
  end
80
80
 
81
+ # Get all existing Pods in Namespace with field selector
82
+ def get_all_namespaced_pods_with_field_selector(namespace, selector)
83
+ extension = "/api/v1/namespaces/#{namespace}/pods"
84
+
85
+ params = { :fieldSelector => "#{selector}" }
86
+
87
+ uri = prepareURIWithParams(@endpoint, extension, params)
88
+
89
+ puts(uri)
90
+
91
+ request = prepareGenericRequest(uri, @bearer_token, "GET")
92
+
93
+ req_options = prepareGenericRequestOptions(@ssl, uri)
94
+
95
+ begin
96
+ response = Net::HTTP.start(uri.hostname, uri.port, req_options) do |http|
97
+ http.request(request)
98
+ end
99
+ return response.body
100
+
101
+ rescue Errno::ECONNREFUSED
102
+ raise "Connection for host #{uri.hostname} refused"
103
+ end
104
+ end
105
+
106
+ # Get all existing Pods in Namespace with label selector
107
+ def get_all_namespaced_pods_with_label_selector(namespace, selector)
108
+ extension = "/api/v1/namespaces/#{namespace}/pods"
109
+
110
+ params = { :labelSelector => "#{selector}" }
111
+
112
+ uri = prepareURIWithParams(@endpoint, extension, params)
113
+
114
+ request = prepareGenericRequest(uri, @bearer_token, "GET")
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
+ end
128
+
81
129
  # Get single Pod in Namespace
82
130
  def get_single_namespaced_pod(namespace, pod_name)
83
131
  extension = "/api/v1/namespaces/#{namespace}/pods/#{pod_name}"
@@ -11,7 +11,7 @@ module ReplicaSets
11
11
 
12
12
  # Create new ReplicaSet
13
13
  def create_new_replicaset(namespace, config)
14
- extension = "/apis/extensions/v1beta1/namespaces/#{namespace}/replicasets"
14
+ extension = "/apis/apps/v1/namespaces/#{namespace}/replicasets"
15
15
 
16
16
  uri = prepareURI(@endpoint, extension)
17
17
 
@@ -39,7 +39,7 @@ module ReplicaSets
39
39
 
40
40
  # Get all ReplicaSets
41
41
  def get_all_replicasets
42
- extension = "/apis/extensions/v1beta1/replicasets"
42
+ extension = "/apis/apps/v1/replicasets"
43
43
 
44
44
  uri = prepareURI(@endpoint, extension)
45
45
 
@@ -60,7 +60,7 @@ module ReplicaSets
60
60
 
61
61
  # Get all existing ReplicaSets in Namespace
62
62
  def get_all_namespaced_replicasets(namespace)
63
- extension = "/apis/extensions/v1beta1/namespaces/#{namespace}/replicasets"
63
+ extension = "/apis/apps/v1/namespaces/#{namespace}/replicasets"
64
64
 
65
65
  uri = prepareURI(@endpoint, extension)
66
66
 
@@ -81,7 +81,7 @@ module ReplicaSets
81
81
 
82
82
  # Get single ReplicaSet in Namespace
83
83
  def get_single_namespaced_replicaset(namespace, replicaset_name)
84
- extension = "/apis/extensions/v1beta1/namespaces/#{namespace}/replicasets/#{replicaset_name}"
84
+ extension = "/apis/apps/v1/namespaces/#{namespace}/replicasets/#{replicaset_name}"
85
85
 
86
86
  uri = prepareURI(@endpoint, extension)
87
87
 
@@ -101,7 +101,7 @@ module ReplicaSets
101
101
 
102
102
  # Update existing ReplicaSet in Namespace
103
103
  def update_namespaced_replicaset(namespace, replicaset_name, update)
104
- extension = "/apis/extensions/v1beta1/namespaces/#{namespace}/replicasets/#{replicaset_name}"
104
+ extension = "/apis/apps/v1/namespaces/#{namespace}/replicasets/#{replicaset_name}"
105
105
 
106
106
  uri = prepareURI(@endpoint, extension)
107
107
 
@@ -129,7 +129,7 @@ module ReplicaSets
129
129
 
130
130
  # Patch existing ReplicaSet
131
131
  def patch_replicaset(namespace, replicaset_name, patch)
132
- extension = "/apis/extensions/v1beta1/namespaces/#{namespace}/replicasets/#{replicaset_name}"
132
+ extension = "/apis/apps/v1/namespaces/#{namespace}/replicasets/#{replicaset_name}"
133
133
 
134
134
  uri = prepareURI(@endpoint, extension)
135
135
 
@@ -152,7 +152,7 @@ module ReplicaSets
152
152
 
153
153
  # Delete existing Namespace
154
154
  def delete_replicaset(namespace, replicaset_name, options = '')
155
- extension = "/apis/extensions/v1beta1/namespaces/#{namespace}/replicasets/#{replicaset_name}"
155
+ extension = "/apis/apps/v1/namespaces/#{namespace}/replicasets/#{replicaset_name}"
156
156
 
157
157
  uri = prepareURI(@endpoint, extension)
158
158
 
@@ -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
@@ -1,4 +1,4 @@
1
1
  # Part of the RubyKubernetesController module
2
2
  module RubyKubernetesController
3
- VERSION = "0.1.0"
3
+ VERSION = "0.3.0"
4
4
  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.1.0
4
+ version: 0.3.0
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: 2019-06-10 00:00:00.000000000 Z
13
+ date: 2020-10-22 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: bundler
@@ -101,10 +101,12 @@ 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
107
108
  - lib/ruby-kubernetes-controller/ingresses.rb
109
+ - lib/ruby-kubernetes-controller/jobs.rb
108
110
  - lib/ruby-kubernetes-controller/namespaces.rb
109
111
  - lib/ruby-kubernetes-controller/nodes.rb
110
112
  - lib/ruby-kubernetes-controller/persistentvolumeclaims.rb
@@ -112,6 +114,7 @@ files:
112
114
  - lib/ruby-kubernetes-controller/pods.rb
113
115
  - lib/ruby-kubernetes-controller/replicasets.rb
114
116
  - lib/ruby-kubernetes-controller/services.rb
117
+ - lib/ruby-kubernetes-controller/utilities.rb
115
118
  - lib/ruby-kubernetes-controller/version.rb
116
119
  - ruby-kubernetes-controller.gemspec
117
120
  homepage: https://github.com/IBM/ruby-kubernetes-controller/