k8s-client 0.3.1 → 0.3.2

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: 767ebc980b6e01f66e4739cc341aa7518245287d88273068460358b88f8b110f
4
- data.tar.gz: 73a21392fdf0ad9e56060571aced26e0b53983f6f2c1b727280a16d72dbaa8a1
3
+ metadata.gz: 0c52ed78175ae8e13a19fdc6a8e0140bd638f49e7120c7b8227bbfb23086487a
4
+ data.tar.gz: 43224378fdcb6d08636e346d8c79090e572957cf298d72b2fb6be1bb4a13c948
5
5
  SHA512:
6
- metadata.gz: a2943973befbad7b7f24b6f9aa9aa186a20ca5e970259bcb2a354e8161511af4a42d29aeceb75ab26f9031c414f56d0f7f7cc606723e4f585c637427d4e59e6d
7
- data.tar.gz: a8161a1c2b74a027395a33ee3ff39ea4b87554615d861933a5a0c04cac4525086bc84ca91234ab7c62b308b067ec441b7b396c7fb9e3e08493141814a3acf0b2
6
+ metadata.gz: fb131b63d5a7ea82c0afbb0a32543ee60b13156c13f13f62b23ff9260491c26561e863c76495600f2db1ccf1cd51a956f9acc195d494a97f9e7e66b1764209cc
7
+ data.tar.gz: 71d19732db165ac68306d031981f95b4d1dda404ada3e6a2dca146b42c2b7bb427432e74c2192d673010d92668eefb046efd22782c9ba7f9e460cd685c4c2e9a
data/bin/k8s-client CHANGED
@@ -10,6 +10,7 @@ Options = Struct.new(
10
10
  :server,
11
11
  :insecure_skip_tls_verify,
12
12
  :prefetch_resources,
13
+ :list_resource_kinds,
13
14
  :namespace,
14
15
  :all_namespaces,
15
16
  :label_selector,
@@ -76,6 +77,9 @@ parser = OptionParser.new do |parser|
76
77
  parser.on('--prefetch-resources', TrueClass) do |bool|
77
78
  options.prefetch_resources = bool
78
79
  end
80
+ parser.on('--list-resource-kinds', TrueClass) do |bool|
81
+ options.list_resource_kinds = true
82
+ end
79
83
  parser.on('-n', '--namespace=NAMESPACE') do |namespace|
80
84
  options.namespace = namespace
81
85
  end
@@ -171,6 +175,14 @@ if options.prefetch_resources
171
175
  client.apis(prefetch_resources: true)
172
176
  end
173
177
 
178
+ if options.list_resource_kinds
179
+ client.resources.sort_by{|r| r.kind}.each do |resource_client|
180
+ next if resource_client.subresource?
181
+
182
+ puts "#{resource_client.kind} => #{resource_client.api_version} #{resource_client.name}"
183
+ end
184
+ end
185
+
174
186
  if options.all_namespaces
175
187
  namespace = nil # all
176
188
  elsif options.namespace
@@ -57,7 +57,7 @@ module K8s
57
57
  # @return [K8s::ResourceClient]
58
58
  def resource(resource_name, namespace: nil)
59
59
  unless api_resource = api_resources.find{ |api_resource| api_resource.name == resource_name }
60
- raise K8s::Error, "Unknown resource #{resource_name} for #{@api_version}"
60
+ raise K8s::Error::UndefinedResource, "Unknown resource #{resource_name} for #{@api_version}"
61
61
  end
62
62
 
63
63
  ResourceClient.new(@transport, self, api_resource,
@@ -67,15 +67,16 @@ module K8s
67
67
 
68
68
  # @param resource [K8s::Resource]
69
69
  # @param namespace [String, nil] default if resource is missing namespace
70
- # @raise [K8s::Error] unknown resource
70
+ # @raise [K8s::Error::NotFound] API Group does not exist
71
+ # @raise [K8s::Error::UndefinedResource]
71
72
  # @return [K8s::ResourceClient]
72
73
  def client_for_resource(resource, namespace: nil)
73
74
  unless @api_version == resource.apiVersion
74
- raise K8s::Error, "Invalid apiVersion=#{resource.apiVersion} for #{@api_version} client"
75
+ raise K8s::Error::UndefinedResource, "Invalid apiVersion=#{resource.apiVersion} for #{@api_version} client"
75
76
  end
76
77
 
77
78
  unless api_resource = api_resources.find{ |api_resource| api_resource.kind == resource.kind }
78
- raise K8s::Error, "Unknown resource kind=#{api_resource.kind} for #{@api_version}"
79
+ raise K8s::Error::UndefinedResource, "Unknown resource kind=#{resource.kind} for #{@api_version}"
79
80
  end
80
81
 
81
82
  ResourceClient.new(@transport, self, api_resource,
data/lib/k8s/client.rb CHANGED
@@ -48,7 +48,7 @@ module K8s
48
48
  def api_groups!
49
49
  @api_groups = @transport.get('/apis',
50
50
  response_class: K8s::API::MetaV1::APIGroupList,
51
- ).groups.map{|api_group| api_group.preferredVersion.groupVersion }
51
+ ).groups.map{|api_group| api_group.versions.map{|api_version| api_version.groupVersion} }.flatten
52
52
  end
53
53
 
54
54
  # Cached /apis preferred group apiVersions
@@ -101,7 +101,8 @@ module K8s
101
101
 
102
102
  # @param resource [K8s::Resource]
103
103
  # @param namespace [String, nil] default if resource is missing namespace
104
- # @raise [K8s::Error] unknown resource
104
+ # @raise [K8s::Error::NotFound] API Group does not exist
105
+ # @raise [K8s::Error::UndefinedResource]
105
106
  # @return [K8s::ResourceClient]
106
107
  def client_for_resource(resource, namespace: nil)
107
108
  api(resource.apiVersion).client_for_resource(resource, namespace: namespace)
@@ -1,5 +1,5 @@
1
1
  module K8s
2
2
  class Client
3
- VERSION = "0.3.1"
3
+ VERSION = "0.3.2"
4
4
  end
5
5
  end
data/lib/k8s/error.rb CHANGED
@@ -44,5 +44,9 @@ module K8s
44
44
  define_status_error 500, :InternalError
45
45
  define_status_error 503, :ServiceUnavailable
46
46
  define_status_error 504, :ServerTimeout
47
+
48
+ class UndefinedResource < Error
49
+
50
+ end
47
51
  end
48
52
  end
@@ -94,6 +94,11 @@ module K8s
94
94
  @resource
95
95
  end
96
96
 
97
+ # @return [Boolean]
98
+ def subresource?
99
+ !!@subresource
100
+ end
101
+
97
102
  # @return [String, nil]
98
103
  def subresource
99
104
  @subresource
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: k8s-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kontena, Inc.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-08-13 00:00:00.000000000 Z
11
+ date: 2018-08-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: excon