kontena / k8s-client

Ruby Kubernetes API client
Apache License 2.0
76 stars 26 forks source link

Replace Dry and RecursiveOpenStruct with K8s::HashStruct + K8s::Type #129

Closed kke closed 5 years ago

kke commented 5 years ago

Closes #128 (included, merging that will simplify this diff) Closes #125 (included, merging that will simplify this diff) Closes #112 Closes #123

Related to #121

Replace RecursiveOpenStruct, Dry::Struct and Dry::Types with a simple K8s::HashStruct and K8s::Type, thus dropping the dependencies.

kke commented 5 years ago

wip: Specs pass, but I'm a bit skeptical if it actually really works.

kke commented 5 years ago

Surprisingly pharos up passes with this (if you add the recursive-open-struct dependency to pharos),

kke commented 5 years ago

The Type stuff is not needed if the api/metav1 -stuff is treated like any random resource and the predefined structs are removed, but that will require changing a lot of the specs.

pre commented 5 years ago

I tested and found that there are issues with this branch.

With the following example code,

I checked with debugger and resources.meta_list seems to have other attributes in place, expect for resources.meta_list.metadata which is nil:

# simplified copy-paste from production code
# throws `undefined method 'resourceVersion' for nil:NilClass (NoMethodError)
resources = K8s::Client.in_cluster_config
  .api('my_api')
  .resource('lolcats', namespace: 'copypasted')

checkpoint = resources.meta_list.metadata.resourceVersion
resources.watch(timeout: 900, resourceVersion: checkpoint) do |event|
  # ... 
end

Same code with k8s-client 0.10.1 works / has been working for months with older versions.

kke commented 5 years ago

Starting to thing the K8s::HashStruct and K8s::Type add too much complication, maybe better to just use the RecursiveOpenStruct for everything eventhough it is mutable. (the metav1-stuff do need the attribute from dry / k8s::type)

kke commented 5 years ago

Replaced by #147

kke commented 5 years ago

@pre You can try with #147