ruby-kubernetes-controller 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.circleci/config.yml +131 -0
- data/.circleci/setup-rubygems.sh +5 -0
- data/.gitignore +12 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Documentation/DOCUMENTATION.md +1606 -0
- data/Documentation/serviceaccount.png +0 -0
- data/Documentation/serviceaccount.yaml +18 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +54 -0
- data/Rakefile +10 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/ruby-kubernetes-controller.rb +6 -0
- data/lib/ruby-kubernetes-controller/client.rb +62 -0
- data/lib/ruby-kubernetes-controller/configmaps.rb +180 -0
- data/lib/ruby-kubernetes-controller/deployments.rb +181 -0
- data/lib/ruby-kubernetes-controller/endpoints.rb +182 -0
- data/lib/ruby-kubernetes-controller/generic.rb +70 -0
- data/lib/ruby-kubernetes-controller/ingresses.rb +180 -0
- data/lib/ruby-kubernetes-controller/namespaces.rb +142 -0
- data/lib/ruby-kubernetes-controller/nodes.rb +34 -0
- data/lib/ruby-kubernetes-controller/persistentvolumeclaims.rb +181 -0
- data/lib/ruby-kubernetes-controller/persistentvolumes.rb +160 -0
- data/lib/ruby-kubernetes-controller/pods.rb +182 -0
- data/lib/ruby-kubernetes-controller/replicasets.rb +181 -0
- data/lib/ruby-kubernetes-controller/services.rb +176 -0
- data/lib/ruby-kubernetes-controller/version.rb +4 -0
- data/ruby-kubernetes-controller.gemspec +53 -0
- metadata +146 -0
Binary file
|
@@ -0,0 +1,18 @@
|
|
1
|
+
apiVersion: v1
|
2
|
+
kind: ServiceAccount
|
3
|
+
metadata:
|
4
|
+
name: admin-user
|
5
|
+
namespace: kube-system
|
6
|
+
---
|
7
|
+
apiVersion: rbac.authorization.k8s.io/v1
|
8
|
+
kind: ClusterRoleBinding
|
9
|
+
metadata:
|
10
|
+
name: admin-user
|
11
|
+
roleRef:
|
12
|
+
apiGroup: rbac.authorization.k8s.io
|
13
|
+
kind: ClusterRole
|
14
|
+
name: cluster-admin
|
15
|
+
subjects:
|
16
|
+
- kind: ServiceAccount
|
17
|
+
name: admin-user
|
18
|
+
namespace: kube-system
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2019 Shivansh Vij
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
# Ruby Kubernetes Controller
|
2
|
+
|
3
|
+
Current Build: [![CircleCI](https://circleci.com/gh/IBM/ruby-kubernetes-controller.svg?style=svg)](https://circleci.com/gh/IBM/ruby-kubernetes-controller)
|
4
|
+
|
5
|
+
`Ruby Kubernetes Controller` is a Client-Side library which allows users to
|
6
|
+
interact with core Kubernetes APIs natively from within their
|
7
|
+
Ruby applications. This library is compatible with all leading Kubernetes
|
8
|
+
Instances, including OpenShift Kubernetes, Azure Kubernetes Service,
|
9
|
+
Amazon EKS, Google Kubernetes Service, IBM Kubernetes Service, and Rancher
|
10
|
+
Orchestrated Kubernetes. This library also supports yaml ingestion
|
11
|
+
for creating, patching, updating, or deleting existing Kubernetes
|
12
|
+
types, including Pods, Services, Deployments, Endpoints, and Ingresses.
|
13
|
+
Our documentation also contains complete examples for all operation types.
|
14
|
+
|
15
|
+
## Installation
|
16
|
+
|
17
|
+
Add this line to your application's Gemfile:
|
18
|
+
|
19
|
+
```ruby
|
20
|
+
gem 'ruby-kubernetes-controller'
|
21
|
+
```
|
22
|
+
|
23
|
+
And then execute:
|
24
|
+
|
25
|
+
$ bundle
|
26
|
+
|
27
|
+
Or install it yourself as:
|
28
|
+
|
29
|
+
$ gem install ruby-kubernetes-controller
|
30
|
+
|
31
|
+
## Usage
|
32
|
+
|
33
|
+
#### For usage instructions please see our [Documentation][DOCUMENTATION]
|
34
|
+
|
35
|
+
## Development
|
36
|
+
|
37
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
38
|
+
|
39
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
40
|
+
|
41
|
+
## Contributing
|
42
|
+
|
43
|
+
Bug reports and pull requests are welcome on GitHub at [https://github.com/IBM/ruby-kubernetes-controller][HOMEPAGE]. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
44
|
+
|
45
|
+
## License
|
46
|
+
|
47
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
48
|
+
|
49
|
+
## Code of Conduct
|
50
|
+
|
51
|
+
Everyone interacting in the Ruby Kubernetes Controller project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/rubykubernetescontroller/blob/master/CODE_OF_CONDUCT.md).
|
52
|
+
|
53
|
+
[HOMEPAGE]: https://github.com/IBM/ruby-kubernetes-controller
|
54
|
+
[DOCUMENTATION]: https://github.com/IBM/ruby-kubernetes-controller/blob/master/Documentation/DOCUMENTATION.md
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "ruby-kubernetes-controller"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,62 @@
|
|
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
|
+
|
19
|
+
# Part of the RubyKubernetesController module
|
20
|
+
module RubyKubernetesController
|
21
|
+
|
22
|
+
# Client Class
|
23
|
+
class Client
|
24
|
+
|
25
|
+
include Generic
|
26
|
+
include Namespaces
|
27
|
+
include Ingresses
|
28
|
+
include Nodes
|
29
|
+
include Endpoints
|
30
|
+
include Pods
|
31
|
+
include Services
|
32
|
+
include Deployments
|
33
|
+
include ReplicaSets
|
34
|
+
include ConfigMaps
|
35
|
+
include PersistentVolumes
|
36
|
+
include PersistentVolumeClaims
|
37
|
+
|
38
|
+
# Constructor
|
39
|
+
def initialize(endpoint, bearer_token, ssl = true, yaml = false)
|
40
|
+
# Instantiating client variables
|
41
|
+
@endpoint = endpoint
|
42
|
+
@bearer_token = bearer_token
|
43
|
+
@ssl = ssl
|
44
|
+
@yaml = yaml
|
45
|
+
end
|
46
|
+
|
47
|
+
# Return endpoint
|
48
|
+
def getEndpoint
|
49
|
+
@endpoint
|
50
|
+
end
|
51
|
+
|
52
|
+
# Return Bearer Token
|
53
|
+
def getBearer
|
54
|
+
@bearer_token
|
55
|
+
end
|
56
|
+
|
57
|
+
# Return SSL choice
|
58
|
+
def getSSL
|
59
|
+
@ssl
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,180 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
require 'uri'
|
3
|
+
require 'openssl'
|
4
|
+
require 'json'
|
5
|
+
|
6
|
+
require_relative 'generic'
|
7
|
+
|
8
|
+
module ConfigMaps
|
9
|
+
include Generic
|
10
|
+
|
11
|
+
# Create new ConfigMap
|
12
|
+
def create_new_configmap(namespace, config)
|
13
|
+
extension = "/api/v1/namespaces/#{namespace}/configmaps"
|
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 ConfigMaps
|
40
|
+
def get_all_configmaps
|
41
|
+
extension = "/api/v1/configmaps"
|
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 ConfigMaps in a Namespace
|
61
|
+
def get_all_namespaced_configmaps(namespace)
|
62
|
+
extension = "/api/v1/namespaces/#{namespace}/configmaps"
|
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 a single ConfigMap from a Namespace
|
82
|
+
def get_single_namespaced_configmap(namespace, configmap_name)
|
83
|
+
extension = "/api/v1/namespaces/#{namespace}/configmaps/#{configmap_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 ConfigMap in Namespace
|
102
|
+
def update_configmap(namespace, configmap_name, update)
|
103
|
+
extension = "/api/v1/namespaces/#{namespace}/configmaps/#{configmap_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
|
+
end
|
128
|
+
|
129
|
+
# Patch existing ConfigMap in Namespace
|
130
|
+
def patch_configmap(namespace, configmap_name, patch)
|
131
|
+
extension = "/api/v1/namespaces/#{namespace}/configmaps/#{configmap_name}"
|
132
|
+
|
133
|
+
uri = prepareURI(@endpoint, extension)
|
134
|
+
|
135
|
+
request = prepareGenericRequest(uri, @bearer_token, "PATCH")
|
136
|
+
request.content_type = "application/json-patch+json"
|
137
|
+
|
138
|
+
request.body = patch
|
139
|
+
|
140
|
+
req_options = prepareGenericRequestOptions(@ssl, uri)
|
141
|
+
|
142
|
+
begin
|
143
|
+
response = Net::HTTP.start(uri.hostname, uri.port, req_options) do |http|
|
144
|
+
http.request(request)
|
145
|
+
end
|
146
|
+
return response.body
|
147
|
+
rescue Errno::ECONNREFUSED
|
148
|
+
raise "Connection for host #{uri.hostname} refused"
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
152
|
+
# Delete existing ConfigMap in Namespace
|
153
|
+
def delete_configmap(namespace, configmap_name, options = '')
|
154
|
+
extension = "/api/v1/namespaces/#{namespace}/configmaps/#{configmap_name}"
|
155
|
+
|
156
|
+
uri = prepareURI(@endpoint, extension)
|
157
|
+
|
158
|
+
request = prepareGenericRequest(uri, @bearer_token, "DELETE")
|
159
|
+
request.content_type = "application/json"
|
160
|
+
|
161
|
+
if @yaml
|
162
|
+
request.body = yaml_file_to_json(options)
|
163
|
+
else
|
164
|
+
request.body = options
|
165
|
+
end
|
166
|
+
|
167
|
+
req_options = prepareGenericRequestOptions(@ssl, uri)
|
168
|
+
|
169
|
+
begin
|
170
|
+
response = Net::HTTP.start(uri.hostname, uri.port, req_options) do |http|
|
171
|
+
http.request(request)
|
172
|
+
end
|
173
|
+
return response.body
|
174
|
+
|
175
|
+
rescue Errno::ECONNREFUSED
|
176
|
+
raise "Connection for host #{uri.hostname} refused"
|
177
|
+
end
|
178
|
+
end
|
179
|
+
|
180
|
+
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 Deployments
|
9
|
+
include Generic
|
10
|
+
|
11
|
+
# Create new Deployment
|
12
|
+
def create_new_deployment(namespace, config)
|
13
|
+
extension = "/apis/apps/v1beta1/namespaces/#{namespace}/deployments"
|
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 Deployments
|
40
|
+
def get_all_deployments
|
41
|
+
extension = "/apis/apps/v1beta1/deployments"
|
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 Deployments in Namespace
|
61
|
+
def get_all_namespaced_deployments(namespace)
|
62
|
+
extension = "/apis/apps/v1beta1/namespaces/#{namespace}/deployments"
|
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 Deployment in Namespace
|
82
|
+
def get_single_namespaced_deployment(namespace, deployment_name)
|
83
|
+
extension = "/apis/apps/v1beta1/namespaces/#{namespace}/deployments/#{deployment_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 Deployment in Namespace
|
102
|
+
def update_namespaced_deployment(namespace, deployment_name, update)
|
103
|
+
extension = "/apis/apps/v1beta1/namespaces/#{namespace}/deployments/#{deployment_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 Deployment in Namespace
|
131
|
+
def patch_deployment(namespace, deployment_name, patch)
|
132
|
+
extension = "/apis/apps/v1beta1/namespaces/#{namespace}/deployments/#{deployment_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 Deployment in Namespace
|
154
|
+
def delete_deployment(namespace, deployment_name, options = '')
|
155
|
+
extension = "/apis/apps/v1beta1/namespaces/#{namespace}/deployments/#{deployment_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
|