Git Product home page Git Product logo

Comments (10)

moolitayer avatar moolitayer commented on July 17, 2024 1

@motymichaely I'm good with a Readme change.
I think the best we can do is to consistently advocate the usage of the generic Kubeclient::resource class post #185 throughout the Readme as well as all the tests.
There are just too many ways being used in our example code now and that is confusing as well as the problem described in this issue.

In your example:

client.create_namespace(Kubeclient::Resource.new(YAML.load(namespace_str)))

@abonas @simon3z agree/disagree?

from kubeclient.

grosser avatar grosser commented on July 17, 2024 1

would prefer telling the user what they do wrong instead of doing work behind their back
-> call .to_h on what they give in and check if first key is a symbol, otherwise ArgumentError

from kubeclient.

simon3z avatar simon3z commented on July 17, 2024

cc @moolitayer

from kubeclient.

moolitayer avatar moolitayer commented on July 17, 2024

RecursiveOpenStruct symbolizes keys for us:
"Also, by default it will turn all hash keys into symbols internally:"

pod = {
  'metadata' => 
...
client.create_pod(pod) # will not work
client.create_pod(Kubeclient::Pod.new(pod)) # will not work
client.create_pod(Kubeclient::Pod.new(POD)) # will work

We should not re implement rails' deep_symbolize_keys

from kubeclient.

motymichaely avatar motymichaely commented on July 17, 2024

@moolitayer Great. So I would suggest adding some info on this to the documentation.

For example:

namespace_str = <<-EOF
apiVersion: v1
kind: Namespace
metadata:
  name: "my-namespace"
  labels:
    name: "my-namespace"
EOF
client.create_namespace(YAML.load(namespace_yaml_str))

Produces this error:

NoMethodError: undefined method `[]' for nil:NilClass
    from /Users/moty/.rbenv/versions/2.0.0-p481/lib/ruby/gems/2.0.0/gems/kubeclient-1.2.0/lib/kubeclient/common.rb:229:in `create_entity'
    from /Users/moty/.rbenv/versions/2.0.0-p481/lib/ruby/gems/2.0.0/gems/kubeclient-1.2.0/lib/kubeclient/common.rb:116:in `block (2 levels) in define_entity_methods'

Based on your suggestion, this works:

client.create_namespace(Kubeclient::Namespace.new(YAML.load(namespace_str)))

from kubeclient.

abonas avatar abonas commented on July 17, 2024

@moolitayer 👍

from kubeclient.

moolitayer avatar moolitayer commented on July 17, 2024

@motymichaely interested in submitting a pr as per the above comment ?

from kubeclient.

grosser avatar grosser commented on July 17, 2024

FYI Decided to go with .deep_symbolize_keys (rails) in our project... easier to debug and no more ObjectStruct bugs/overhead ...

from kubeclient.

cben avatar cben commented on July 17, 2024

Now that we have as: :parsed_symbolized and as: :parsed (#306), kubeclient get_foo may give you data that isn't a Kubeclient::Resource, and in the latter case that you can't write back with create_foo/update_foo.
Also, now that we use a single Kubeclient::Resource class everywhere, there's less value in forcing users to wrap everything in it...

=> I don't have bandwidth to work on this but would welcome a PR. @moolitayer are you still against?

from kubeclient.

cben avatar cben commented on July 17, 2024

hmm, good idea.

from kubeclient.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.