Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Namespace Validator object #1

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

denys-medynskyi
Copy link

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 🙏

@camertron
Copy link
Member

camertron commented Jun 3, 2020

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?

@denys-medynskyi
Copy link
Author

@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

@camertron
Copy link
Member

camertron commented Jun 5, 2020

@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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants