kube-dsl icon indicating copy to clipboard operation
kube-dsl copied to clipboard

Add Namespace Validator object

Open denys-medynskyi opened this issue 4 years ago • 3 comments

NOT FINAL PR

I need help me out how are the "attributes" are set in the DSL.

For example we have KubeDSL::DSL::V1::Namespace

  1. How to set valid object into metadata?
  2. How to set invalid object into metadata?

Please add a comment in the PR and point me to the JSON you showed in the call :)

Any feedback is appreciated 🙏

denys-medynskyi avatar Jun 03 '20 15:06 denys-medynskyi

Hey @deny7ko, looks like a good start. You can set attributes by calling methods with the same name as the attributes, for example:

KubeDSL.namespace do
  metadata do
    name 'foobar'
  end
end

This is equivalent to:

KubeDSL::DSL::V1::Namespace.new do
  metadata do
    name 'foobar'
  end
end

If you already have an instance of Namespace

ns = KubeDSL::DSL::V1::Namespace.new
ns.instance_eval do
  metadata do
    name  'foobar'
  end
end

Does that help?

camertron avatar Jun 03 '20 21:06 camertron

@camertron hey, yes, but I also want to understand when the value is invalid? I remember you showed me some *.json file which contains the type: So we have a definition:

module KubeDSL::DSL::V1
  class Namespace < ::KubeDSL::DSLObject
    object_field(:metadata) { KubeDSL::DSL::Meta::V1::ObjectMeta.new }

Questions:

  1. What makes metadata field invalid? How should I identify that?

  2. Maybe you want me to start with testing this file - https://github.com/getkuby/kube-dsl/blob/master/lib/kube-dsl/dsl/v1/namespace_spec.rb#L3 ?

  3. Please provide me with json file you showed me in the call

  4. Please give me the link to your example app so I could play around to understand how all of these gems work together

denys-medynskyi avatar Jun 05 '20 12:06 denys-medynskyi

@deny7ko ah ok I understand now :)

  1. Here's a link to the schema for Namespace.
  2. I think ObjectMeta is probably the right place to start. ObjectMeta is used by almost all other objects, including Namespace, Service, Deployment, etc. Here's a link to the schema. You can see that name is one of the fields, and has type string. The name field would be invalid if it contained a number, for example, instead of a string.
  3. See above
  4. Ah yes, sorry for the delay. The app can be found here. Follow the README to get everything set up (all the gems are included as submodules).

camertron avatar Jun 05 '20 21:06 camertron