Skip to content

Commit 1788a00

Browse files
author
Kimmo Lehto
authored
Drop dry-* dependencies (#147)
* Step 1, Unaltered config spec passes * Step 2: slightly altered specs pass without dry * Update yardocs * Backport Hash#transform_keys for 2.4 * Fix transport config + specs * Yardoc fixes * Call to_h on Config.new param * Remove the .to_sym / .tr trickery in Resource * Normalize to_hash to to_h
1 parent eb86f62 commit 1788a00

25 files changed

+166
-445
lines changed

README.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ require 'k8s/json_parser/yajl'
5555
### Overview
5656
The top-level `K8s::Client` provides access to separate `APIClient` instances for each Kubernetes API Group (`v1`, `apps/v1`, etc.), which in turns provides access to separate `ResourceClient` instances for each API resource type (`nodes`, `pods`, `deployments`, etc.).
5757

58-
Individual resources are returned as `K8s::Resource` instances, which are `RecursiveOpenStruct` instances providing attribute access (`resource.metadata.name`). The resource instances are returned by methods such as `client.api('v1').resource('nodes').get('foo')`, and passed as arguments for `client.api('v1').resource('nodes').create_resource(res)`. Resources can also be loaded from disk using `K8s::Resource.from_files(path)`, and passed to the top-level methods such as `client.create_resource(res)`, which lookup the correct API/Resource client from the resource `apiVersion` and `kind`.
58+
Individual resources are returned as `K8s::Resource` instances, which provide attribute access (`resource.metadata.name`). The resource instances are returned by methods such as `client.api('v1').resource('nodes').get('foo')`, and passed as arguments for `client.api('v1').resource('nodes').create_resource(res)`. Resources can also be loaded from disk using `K8s::Resource.from_files(path)`, and passed to the top-level methods such as `client.create_resource(res)`, which lookup the correct API/Resource client from the resource `apiVersion` and `kind`.
5959

6060
The different `K8s::Error::API` subclasses represent different HTTP response codes, such as `K8s::Error::NotFound` or `K8s::Error::Conflict`.
6161

@@ -134,9 +134,9 @@ K8s::Transport.verbose!
134134

135135
```
136136
I, [2018-08-09T14:19:50.404739 #1] INFO -- K8s::Transport: Using config with server=https://167.99.39.233:6443
137-
I, [2018-08-09T14:19:50.629521 #1] INFO -- K8s::Transport<https://167.99.39.233:6443>: GET /version => HTTP 200: <K8s::API::Version> in 0.224s
138-
I, [2018-08-09T14:19:50.681367 #1] INFO -- K8s::Transport<https://167.99.39.233:6443>: GET /api/v1 => HTTP 200: <K8s::API::MetaV1::APIResourceList> in 0.046s
139-
I, [2018-08-09T14:19:51.018740 #1] INFO -- K8s::Transport<https://167.99.39.233:6443>: GET /api/v1/pods => HTTP 200: <K8s::API::MetaV1::List> in 0.316s
137+
I, [2018-08-09T14:19:50.629521 #1] INFO -- K8s::Transport<https://167.99.39.233:6443>: GET /version => HTTP 200: <K8s::Resource> in 0.224s
138+
I, [2018-08-09T14:19:50.681367 #1] INFO -- K8s::Transport<https://167.99.39.233:6443>: GET /api/v1 => HTTP 200: <K8s::Resource> in 0.046s
139+
I, [2018-08-09T14:19:51.018740 #1] INFO -- K8s::Transport<https://167.99.39.233:6443>: GET /api/v1/pods => HTTP 200: <K8s::Resource> in 0.316s
140140
```
141141

142142
Using `K8s::Transport.debug!` will also log request/response bodies. The `EXCON_DEBUG=true` env will log all request/response attributes, including headers.

k8s-client.gemspec

-2
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@ Gem::Specification.new do |spec|
2424
spec.required_ruby_version = '~> 2.4'
2525

2626
spec.add_runtime_dependency "excon", "~> 0.66"
27-
spec.add_runtime_dependency "dry-struct", "~> 0.5.0"
28-
spec.add_runtime_dependency "dry-types", "~> 0.13.0"
2927
spec.add_runtime_dependency "recursive-open-struct", "~> 1.1.0"
3028
spec.add_runtime_dependency 'hashdiff', '~> 1.0.0'
3129
spec.add_runtime_dependency 'jsonpath', '~> 0.9.5'

lib/k8s/api.rb

-31
This file was deleted.

lib/k8s/api/metav1.rb

-26
This file was deleted.

lib/k8s/api/metav1/api_group.rb

-26
This file was deleted.

lib/k8s/api/metav1/api_resource.rb

-26
This file was deleted.

lib/k8s/api/metav1/list.rb

-20
This file was deleted.

lib/k8s/api/metav1/object.rb

-53
This file was deleted.

lib/k8s/api/metav1/status.rb

-34
This file was deleted.

lib/k8s/api/metav1/watch_event.rb

-20
This file was deleted.

lib/k8s/api/version.rb

-17
This file was deleted.

lib/k8s/api_client.rb

+5-6
Original file line numberDiff line numberDiff line change
@@ -36,27 +36,26 @@ def api_resources?
3636
!!@api_resources
3737
end
3838

39-
# @param api_resources [Array<K8s::API::MetaV1::APIResource>]
39+
# @param api_resources [Array<K8s::Resource>]
4040
attr_writer :api_resources
4141

4242
# Force-update APIResources
4343
#
44-
# @return [Array<K8s::API::MetaV1::APIResource>]
44+
# @return [Array<K8s::Resource>]
4545
def api_resources!
46-
@api_resources = @transport.get(path,
47-
response_class: K8s::API::MetaV1::APIResourceList).resources
46+
@api_resources = @transport.get(path).resources
4847
end
4948

5049
# Cached APIResources
5150
#
52-
# @return [Array<K8s::API::MetaV1::APIResource>]
51+
# @return [Array<K8s::Resource>]
5352
def api_resources
5453
@api_resources || api_resources!
5554
end
5655

5756
# @param resource_name [String]
5857
# @raise [K8s::Error::UndefinedResource]
59-
# @return [K8s::API::MetaV1::APIResource]
58+
# @return [K8s::Resource]
6059
def find_api_resource(resource_name)
6160
found_resource = api_resources.find{ |api_resource| api_resource.name == resource_name }
6261
found_resource ||= api_resources!.find{ |api_resource| api_resource.name == resource_name }

lib/k8s/client.rb

+3-5
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99
require 'k8s/json_parser'
1010
require 'k8s/util'
1111

12-
require 'k8s/api/metav1'
13-
require 'k8s/api/version'
1412
require 'k8s/config'
1513
require 'k8s/logging'
1614
require 'k8s/api_client'
@@ -115,7 +113,7 @@ def initialize(transport, namespace: nil)
115113
end
116114

117115
# @raise [K8s::Error]
118-
# @return [K8s::API::Version]
116+
# @return [K8s::Resource]
119117
def version
120118
@version ||= @transport.version
121119
end
@@ -134,7 +132,7 @@ def api_groups!
134132
synchronize do
135133
@api_groups = @transport.get(
136134
'/apis',
137-
response_class: K8s::API::MetaV1::APIGroupList
135+
response_class: K8s::Resource
138136
).groups.flat_map{ |api_group| api_group.versions.map(&:groupVersion) }
139137

140138
@api_clients.clear
@@ -165,7 +163,7 @@ def apis(api_versions = nil, prefetch_resources: false, skip_missing: false)
165163

166164
# load into APIClient.api_resources=
167165
begin
168-
@transport.gets(*api_paths, response_class: K8s::API::MetaV1::APIResourceList, skip_missing: skip_missing).each do |api_resource_list|
166+
@transport.gets(*api_paths, skip_missing: skip_missing).each do |api_resource_list|
169167
api(api_resource_list.groupVersion).api_resources = api_resource_list.resources if api_resource_list
170168
end
171169
rescue K8s::Error::NotFound, K8s::Error::ServiceUnavailable # rubocop:disable Lint/HandleExceptions

0 commit comments

Comments
 (0)