k8s-client 0.4.2 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +4 -0
- data/.rubocop.relaxed.yml +176 -0
- data/.rubocop.yml +57 -0
- data/Rakefile +11 -1
- data/bin/k8s-client +32 -36
- data/k8s-client.gemspec +2 -0
- data/lib/k8s-client.rb +2 -16
- data/lib/k8s/api.rb +3 -1
- data/lib/k8s/api/metav1.rb +2 -0
- data/lib/k8s/api/metav1/api_group.rb +2 -0
- data/lib/k8s/api/metav1/api_resource.rb +2 -0
- data/lib/k8s/api/metav1/list.rb +2 -0
- data/lib/k8s/api/metav1/object.rb +2 -0
- data/lib/k8s/api/metav1/status.rb +2 -0
- data/lib/k8s/api/version.rb +2 -0
- data/lib/k8s/api_client.rb +25 -28
- data/lib/k8s/client.rb +34 -15
- data/lib/k8s/client/version.rb +3 -1
- data/lib/k8s/config.rb +14 -7
- data/lib/k8s/error.rb +27 -26
- data/lib/k8s/logging.rb +4 -2
- data/lib/k8s/resource.rb +9 -7
- data/lib/k8s/resource_client.rb +39 -45
- data/lib/k8s/stack.rb +22 -14
- data/lib/k8s/transport.rb +59 -50
- data/lib/k8s/util.rb +10 -9
- metadata +32 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2f06cad5e9cbad737bd7a94f169f56c71f6a323d06f3cfc68dd01ba1733abc95
|
4
|
+
data.tar.gz: 694b1835b27534c3c86841a5d58763b6494331f7078e89115d8c6f6bc50f6260
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d7f1cb6a943da7f7d9e1ecbf396d50f1c7bd481425ed68232b8a99340c20ec5fd7304d89a56c312c1eabf078d7989a37bd22353c7c9a88806ee8c13029d586c5
|
7
|
+
data.tar.gz: aa6b067859e0838f7b1240d282cf6bdb5d2dc1187ead8247409a45c29b0bc9fa2c827fe844323ab7e664a3910716b6646d65e862c4d3c596bd7f95ab10a548ff
|
data/.gitignore
CHANGED
@@ -0,0 +1,176 @@
|
|
1
|
+
# Relaxed.Ruby.Style
|
2
|
+
## Version 2.2
|
3
|
+
|
4
|
+
Style/Alias:
|
5
|
+
Enabled: false
|
6
|
+
StyleGuide: http://relaxed.ruby.style/#stylealias
|
7
|
+
|
8
|
+
Style/AsciiComments:
|
9
|
+
Enabled: false
|
10
|
+
StyleGuide: http://relaxed.ruby.style/#styleasciicomments
|
11
|
+
|
12
|
+
Style/BeginBlock:
|
13
|
+
Enabled: false
|
14
|
+
StyleGuide: http://relaxed.ruby.style/#stylebeginblock
|
15
|
+
|
16
|
+
Style/BlockDelimiters:
|
17
|
+
Enabled: false
|
18
|
+
StyleGuide: http://relaxed.ruby.style/#styleblockdelimiters
|
19
|
+
|
20
|
+
Style/CommentAnnotation:
|
21
|
+
Enabled: false
|
22
|
+
StyleGuide: http://relaxed.ruby.style/#stylecommentannotation
|
23
|
+
|
24
|
+
Style/Documentation:
|
25
|
+
Enabled: false
|
26
|
+
StyleGuide: http://relaxed.ruby.style/#styledocumentation
|
27
|
+
|
28
|
+
Layout/DotPosition:
|
29
|
+
Enabled: false
|
30
|
+
StyleGuide: http://relaxed.ruby.style/#layoutdotposition
|
31
|
+
|
32
|
+
Style/DoubleNegation:
|
33
|
+
Enabled: false
|
34
|
+
StyleGuide: http://relaxed.ruby.style/#styledoublenegation
|
35
|
+
|
36
|
+
Style/EndBlock:
|
37
|
+
Enabled: false
|
38
|
+
StyleGuide: http://relaxed.ruby.style/#styleendblock
|
39
|
+
|
40
|
+
Style/FormatString:
|
41
|
+
Enabled: false
|
42
|
+
StyleGuide: http://relaxed.ruby.style/#styleformatstring
|
43
|
+
|
44
|
+
Style/IfUnlessModifier:
|
45
|
+
Enabled: false
|
46
|
+
StyleGuide: http://relaxed.ruby.style/#styleifunlessmodifier
|
47
|
+
|
48
|
+
Style/Lambda:
|
49
|
+
Enabled: false
|
50
|
+
StyleGuide: http://relaxed.ruby.style/#stylelambda
|
51
|
+
|
52
|
+
Style/ModuleFunction:
|
53
|
+
Enabled: false
|
54
|
+
StyleGuide: http://relaxed.ruby.style/#stylemodulefunction
|
55
|
+
|
56
|
+
Style/MultilineBlockChain:
|
57
|
+
Enabled: false
|
58
|
+
StyleGuide: http://relaxed.ruby.style/#stylemultilineblockchain
|
59
|
+
|
60
|
+
Style/NegatedIf:
|
61
|
+
Enabled: false
|
62
|
+
StyleGuide: http://relaxed.ruby.style/#stylenegatedif
|
63
|
+
|
64
|
+
Style/NegatedWhile:
|
65
|
+
Enabled: false
|
66
|
+
StyleGuide: http://relaxed.ruby.style/#stylenegatedwhile
|
67
|
+
|
68
|
+
Style/ParallelAssignment:
|
69
|
+
Enabled: false
|
70
|
+
StyleGuide: http://relaxed.ruby.style/#styleparallelassignment
|
71
|
+
|
72
|
+
Style/PercentLiteralDelimiters:
|
73
|
+
Enabled: false
|
74
|
+
StyleGuide: http://relaxed.ruby.style/#stylepercentliteraldelimiters
|
75
|
+
|
76
|
+
Style/PerlBackrefs:
|
77
|
+
Enabled: false
|
78
|
+
StyleGuide: http://relaxed.ruby.style/#styleperlbackrefs
|
79
|
+
|
80
|
+
Style/Semicolon:
|
81
|
+
Enabled: false
|
82
|
+
StyleGuide: http://relaxed.ruby.style/#stylesemicolon
|
83
|
+
|
84
|
+
Style/SignalException:
|
85
|
+
Enabled: false
|
86
|
+
StyleGuide: http://relaxed.ruby.style/#stylesignalexception
|
87
|
+
|
88
|
+
Style/SingleLineBlockParams:
|
89
|
+
Enabled: false
|
90
|
+
StyleGuide: http://relaxed.ruby.style/#stylesinglelineblockparams
|
91
|
+
|
92
|
+
Style/SingleLineMethods:
|
93
|
+
Enabled: false
|
94
|
+
StyleGuide: http://relaxed.ruby.style/#stylesinglelinemethods
|
95
|
+
|
96
|
+
Layout/SpaceBeforeBlockBraces:
|
97
|
+
Enabled: false
|
98
|
+
StyleGuide: http://relaxed.ruby.style/#layoutspacebeforeblockbraces
|
99
|
+
|
100
|
+
Layout/SpaceInsideParens:
|
101
|
+
Enabled: false
|
102
|
+
StyleGuide: http://relaxed.ruby.style/#layoutspaceinsideparens
|
103
|
+
|
104
|
+
Style/SpecialGlobalVars:
|
105
|
+
Enabled: false
|
106
|
+
StyleGuide: http://relaxed.ruby.style/#stylespecialglobalvars
|
107
|
+
|
108
|
+
Style/StringLiterals:
|
109
|
+
Enabled: false
|
110
|
+
StyleGuide: http://relaxed.ruby.style/#stylestringliterals
|
111
|
+
|
112
|
+
# Style/TrailingCommaInArguments:
|
113
|
+
# Enabled: false
|
114
|
+
# StyleGuide: http://relaxed.ruby.style/#styletrailingcommainarguments
|
115
|
+
#
|
116
|
+
# Style/TrailingCommaInArrayLiteral:
|
117
|
+
# Enabled: false
|
118
|
+
# StyleGuide: http://relaxed.ruby.style/#styletrailingcommainarrayliteral
|
119
|
+
#
|
120
|
+
# Style/TrailingCommaInHashLiteral:
|
121
|
+
# Enabled: false
|
122
|
+
# StyleGuide: http://relaxed.ruby.style/#styletrailingcommainhashliteral
|
123
|
+
|
124
|
+
Style/WhileUntilModifier:
|
125
|
+
Enabled: false
|
126
|
+
StyleGuide: http://relaxed.ruby.style/#stylewhileuntilmodifier
|
127
|
+
|
128
|
+
Style/WordArray:
|
129
|
+
Enabled: false
|
130
|
+
StyleGuide: http://relaxed.ruby.style/#stylewordarray
|
131
|
+
|
132
|
+
Lint/AmbiguousRegexpLiteral:
|
133
|
+
Enabled: false
|
134
|
+
StyleGuide: http://relaxed.ruby.style/#lintambiguousregexpliteral
|
135
|
+
|
136
|
+
Lint/AssignmentInCondition:
|
137
|
+
Enabled: false
|
138
|
+
StyleGuide: http://relaxed.ruby.style/#lintassignmentincondition
|
139
|
+
|
140
|
+
Metrics/AbcSize:
|
141
|
+
Enabled: false
|
142
|
+
|
143
|
+
Metrics/BlockNesting:
|
144
|
+
Enabled: false
|
145
|
+
|
146
|
+
Metrics/ClassLength:
|
147
|
+
Enabled: false
|
148
|
+
|
149
|
+
Metrics/ModuleLength:
|
150
|
+
Enabled: false
|
151
|
+
|
152
|
+
Metrics/CyclomaticComplexity:
|
153
|
+
Enabled: false
|
154
|
+
|
155
|
+
Metrics/LineLength:
|
156
|
+
Enabled: false
|
157
|
+
|
158
|
+
Metrics/MethodLength:
|
159
|
+
Enabled: false
|
160
|
+
|
161
|
+
Metrics/ParameterLists:
|
162
|
+
Enabled: false
|
163
|
+
|
164
|
+
Metrics/PerceivedComplexity:
|
165
|
+
Enabled: false
|
166
|
+
|
167
|
+
Naming/VariableName: # disabled because camelCased params are used in kube api/yamls
|
168
|
+
Enabled: false
|
169
|
+
|
170
|
+
Naming/UncommunicativeMethodParamName: # disabled because camelCased params are used in kube api/yamls
|
171
|
+
Enabled: false
|
172
|
+
|
173
|
+
Naming/FileName:
|
174
|
+
Enabled: true
|
175
|
+
Exclude:
|
176
|
+
- lib/k8s-client.rb # ignored because gem name is k8s-client, so 'require k8s-client' and gem 'k8s-client' in Gemfile work
|
data/.rubocop.yml
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
inherit_from: .rubocop.relaxed.yml
|
2
|
+
|
3
|
+
AllCops:
|
4
|
+
Exclude:
|
5
|
+
- spec/**/*
|
6
|
+
- Gemfile
|
7
|
+
- "*.gemspec"
|
8
|
+
- bundler/**/*
|
9
|
+
TargetRubyVersion: 2.4
|
10
|
+
|
11
|
+
Style/PercentLiteralDelimiters:
|
12
|
+
PreferredDelimiters:
|
13
|
+
default: ()
|
14
|
+
'%i': '()'
|
15
|
+
'%I': '()'
|
16
|
+
'%r': '{}'
|
17
|
+
'%w': '()'
|
18
|
+
'%W': '()'
|
19
|
+
|
20
|
+
Style/FormatString:
|
21
|
+
EnforcedStyle: percent
|
22
|
+
|
23
|
+
Style/FrozenStringLiteralComment:
|
24
|
+
EnforcedStyle: always
|
25
|
+
|
26
|
+
Style/WordArray:
|
27
|
+
Enabled: true
|
28
|
+
MinSize: 3
|
29
|
+
|
30
|
+
Style/SymbolArray:
|
31
|
+
Enabled: true
|
32
|
+
MinSize: 3
|
33
|
+
|
34
|
+
Gemspec/OrderedDependencies:
|
35
|
+
Enabled: false
|
36
|
+
|
37
|
+
Style/PerlBackrefs:
|
38
|
+
Enabled: true
|
39
|
+
|
40
|
+
Layout/SpaceInsideParens:
|
41
|
+
Enabled: true
|
42
|
+
|
43
|
+
Style/SpecialGlobalVars:
|
44
|
+
Enabled: true
|
45
|
+
|
46
|
+
Style/Alias:
|
47
|
+
Enabled: true
|
48
|
+
|
49
|
+
Style/BeginBlock:
|
50
|
+
Enabled: true
|
51
|
+
|
52
|
+
Naming/UncommunicativeMethodParamName:
|
53
|
+
AllowedNames:
|
54
|
+
- cn
|
55
|
+
|
56
|
+
Metrics/BlockLength:
|
57
|
+
Enabled: false
|
data/Rakefile
CHANGED
@@ -1,6 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "bundler/gem_tasks"
|
2
4
|
require "rspec/core/rake_task"
|
5
|
+
require 'rubocop/rake_task'
|
3
6
|
|
4
7
|
RSpec::Core::RakeTask.new(:spec)
|
5
8
|
|
6
|
-
|
9
|
+
RuboCop::RakeTask.new(:rubocop).tap do |task|
|
10
|
+
task.options = %w(--fail-level A -S --format c)
|
11
|
+
if RUBY_ENGINE == 'ruby' && RbConfig::CONFIG['host_os'] !~ /mswin|msys|mingw|cygwin|bccwin|wince|emc/
|
12
|
+
task.options << '--parallel'
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
task default: [:spec, :rubocop]
|
data/bin/k8s-client
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
2
3
|
|
3
4
|
require 'optparse'
|
4
5
|
require 'uri'
|
@@ -35,17 +36,17 @@ Options = Struct.new(
|
|
35
36
|
:api,
|
36
37
|
:list_api_resources,
|
37
38
|
:patch_deployment,
|
38
|
-
:replicas
|
39
|
+
:replicas
|
39
40
|
)
|
40
41
|
|
41
|
-
options = Options.new
|
42
|
+
options = Options.new
|
42
43
|
options.create_resources = []
|
43
44
|
options.update_resources = []
|
44
45
|
options.delete_resources = []
|
45
46
|
|
46
47
|
logger = Logger.new(STDERR)
|
47
48
|
|
48
|
-
|
49
|
+
opt_parser = OptionParser.new do |parser|
|
49
50
|
parser.on('--debug-api') do
|
50
51
|
K8s::Logging.debug!
|
51
52
|
K8s::Transport.debug!
|
@@ -77,7 +78,7 @@ parser = OptionParser.new do |parser|
|
|
77
78
|
parser.on('--prefetch-resources', TrueClass) do |bool|
|
78
79
|
options.prefetch_resources = bool
|
79
80
|
end
|
80
|
-
parser.on('--list-resource-kinds', TrueClass) do |
|
81
|
+
parser.on('--list-resource-kinds', TrueClass) do |_bool|
|
81
82
|
options.list_resource_kinds = true
|
82
83
|
end
|
83
84
|
parser.on('-n', '--namespace=NAMESPACE') do |namespace|
|
@@ -157,22 +158,20 @@ parser = OptionParser.new do |parser|
|
|
157
158
|
end
|
158
159
|
end
|
159
160
|
|
160
|
-
|
161
|
+
opt_parser.parse!
|
161
162
|
|
162
163
|
if options.config
|
163
164
|
overrides = {}
|
164
165
|
overrides[:ssl_verify_peer] = false if options.insecure_skip_tls_verify
|
165
166
|
|
166
167
|
client = K8s::Client.config(options.config,
|
167
|
-
|
168
|
-
|
169
|
-
)
|
168
|
+
server: options.server,
|
169
|
+
**overrides)
|
170
170
|
elsif options.in_cluster_config
|
171
171
|
client = K8s::Client.in_cluster_config
|
172
172
|
else
|
173
173
|
client = K8s.client(options.server,
|
174
|
-
|
175
|
-
)
|
174
|
+
ssl_verify_peer: !options.insecure_skip_tls_verify)
|
176
175
|
end
|
177
176
|
|
178
177
|
logger.info "Kube server version: #{client.version.gitVersion}"
|
@@ -182,22 +181,20 @@ if options.prefetch_resources
|
|
182
181
|
end
|
183
182
|
|
184
183
|
if options.list_resource_kinds
|
185
|
-
client.resources.sort_by
|
184
|
+
client.resources.sort_by(&:kind).each do |resource_client|
|
186
185
|
next if resource_client.subresource?
|
187
186
|
|
188
187
|
puts "#{resource_client.kind} => #{resource_client.api_version} #{resource_client.name}"
|
189
188
|
end
|
190
189
|
end
|
191
190
|
|
192
|
-
if options.all_namespaces
|
193
|
-
|
194
|
-
elsif options.namespace
|
195
|
-
|
196
|
-
elsif options.config && ns = options.config.context.namespace
|
197
|
-
|
198
|
-
|
199
|
-
namespace = nil # all
|
200
|
-
end
|
191
|
+
namespace = if options.all_namespaces
|
192
|
+
nil # all
|
193
|
+
elsif options.namespace
|
194
|
+
options.namespace
|
195
|
+
elsif options.config && ns = options.config.context.namespace
|
196
|
+
ns
|
197
|
+
end
|
201
198
|
|
202
199
|
if options.list_api_resources
|
203
200
|
logger.info "List resource types for api=#{options.list_api_resources}..."
|
@@ -216,7 +213,7 @@ elsif options.list_resources
|
|
216
213
|
client.apis(prefetch_resources: true).each do |api|
|
217
214
|
logger.info "api=#{api.api_version}"
|
218
215
|
|
219
|
-
resources = api.resources.select
|
216
|
+
resources = api.resources.select(&:list?)
|
220
217
|
|
221
218
|
resources.each do |resource|
|
222
219
|
logger.info "api=#{api.api_version} resource=#{resource.name}"
|
@@ -262,8 +259,8 @@ if options.delete_pods
|
|
262
259
|
|
263
260
|
pods = client.api('v1').resource('pods', namespace: namespace).delete_collection(labelSelector: options.label_selector)
|
264
261
|
|
265
|
-
pods.each do |
|
266
|
-
logger.info "Deleted pod=#{
|
262
|
+
pods.each do |pod_instance|
|
263
|
+
logger.info "Deleted pod=#{pod_instance.metadata.name} in namespace=#{pod_instance.metadata.namespace} on node=#{pod_instance.spec.nodeName}"
|
267
264
|
end
|
268
265
|
end
|
269
266
|
|
@@ -273,15 +270,15 @@ if options.create_service
|
|
273
270
|
kind: 'Service',
|
274
271
|
metadata: {
|
275
272
|
namespace: namespace,
|
276
|
-
name: options.create_service
|
273
|
+
name: options.create_service
|
277
274
|
},
|
278
275
|
spec: {
|
279
276
|
type: options.service_type,
|
280
277
|
ports: [
|
281
|
-
{ port: options.service_port }
|
278
|
+
{ port: options.service_port }
|
282
279
|
],
|
283
|
-
selector: Hash[options.label_selector.split('=', 2)]
|
284
|
-
}
|
280
|
+
selector: Hash[options.label_selector.split('=', 2)]
|
281
|
+
}
|
285
282
|
)
|
286
283
|
|
287
284
|
logger.info "Create service=#{service.metadata.name} in namespace=#{service.metadata.namespace}"
|
@@ -291,19 +288,19 @@ if options.create_service
|
|
291
288
|
logger.debug { service }
|
292
289
|
end
|
293
290
|
|
294
|
-
|
291
|
+
options.create_resources.each do |resource|
|
295
292
|
resource = client.create_resource(resource)
|
296
293
|
|
297
294
|
logger.info "Created #{resource.apiVersion} resource #{resource.kind} #{resource.metadata.name} in namespace #{resource.metadata.namespace}:\n#{JSON.pretty_generate(resource)}"
|
298
295
|
end
|
299
296
|
|
300
|
-
|
297
|
+
options.update_resources.each do |resource|
|
301
298
|
resource = client.update_resource(resource)
|
302
299
|
|
303
300
|
logger.info "Updated #{resource.apiVersion} resource #{resource.kind} #{resource.metadata.name} in namespace #{resource.metadata.namespace}:\n#{JSON.pretty_generate(resource)}"
|
304
301
|
end
|
305
302
|
|
306
|
-
|
303
|
+
options.delete_resources.each do |resource|
|
307
304
|
begin
|
308
305
|
resource = client.delete_resource(resource)
|
309
306
|
|
@@ -321,13 +318,12 @@ if stack = options.delete_stack
|
|
321
318
|
elsif options.stack
|
322
319
|
logger.info "Apply stack #{options.stack.name}..."
|
323
320
|
|
324
|
-
options.stack.apply(client,
|
325
|
-
prune: options.prune_stack,
|
326
|
-
)
|
321
|
+
options.stack.apply(client, prune: options.prune_stack)
|
327
322
|
end
|
328
323
|
|
329
324
|
if name = options.patch_deployment
|
330
|
-
client.api('apps/v1').resource('deployments', namespace: namespace).merge_patch(
|
331
|
-
|
332
|
-
|
325
|
+
client.api('apps/v1').resource('deployments', namespace: namespace).merge_patch(
|
326
|
+
name,
|
327
|
+
spec: { replicas: options.replicas }
|
328
|
+
)
|
333
329
|
end
|