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

Container Template: convert params to hashes #15587

Closed
wants to merge 1 commit into from

Conversation

zakiva
Copy link
Contributor

@zakiva zakiva commented Jul 18, 2017

Converts the Container Template Parameters that are passed to instantiate method to hashes before passing them to openshift for template processing. The new hashes include only relevant attributes for instantiation.

@zakiva
Copy link
Contributor Author

zakiva commented Jul 18, 2017

@miq-bot add_label providers/containers, enhancement

@zakiva
Copy link
Contributor Author

zakiva commented Jul 18, 2017

@simon3z @lfu @cben Please review

Copy link
Contributor

@cben cben left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍
A bit of context: previously it was passing ActiveRecord objects to kubeclient (which somehow managed to turn it into json, but we shouldn't rely on this),
sending to openshift fields like id or created_on (which it seemed to ignore but we shouldn't rely on this).

create_objects(processed_template['objects'], project)
@created_objects.each { |obj| obj[:miq_class] = MIQ_ENTITY_MAPPING[obj[:kind]] }
end

def params_to_hashes(params)
params.to_a.collect do |param|
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is .to_a necessary? If params is a single container template parameter, the call would fail. If it is an array, no need to call it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed it, please note that caller anyway needs to pass an array or ActiveRecord collection (just template.container_template_parameters)

@zakiva zakiva force-pushed the convert_params_to_hashes branch from 81f4395 to 7b8e70e Compare July 18, 2017 14:25
@miq-bot
Copy link
Member

miq-bot commented Jul 18, 2017

Checked commit zakiva@7b8e70e with ruby 2.2.6, rubocop 0.47.1, and haml-lint 0.20.0
1 file checked, 0 offenses detected
Everything looks fine. 👍

@zakiva
Copy link
Contributor Author

zakiva commented Jul 26, 2017

@gmcculloug Please review

}
end
end

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a helper method, and should be added to the bottom of the file under a private so it doesn't get used publicly.

There's some duplication here, you could slice attributes to maintain a single list of the ones you want doing something like...

def params_to_hashes(params)
  keys = %w(name value generate from required)

  params.each_with_object([]) do |param, collection|
    collection << param.attributes.slice(*keys) 
  end
end

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The method params_to_hashes returns an array? 😕

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's what :parameters is expecting, yeah. Doesn't seem like the worst name; the more annoying part (that's beyond the scope of this change) is overloading the term params (used everywhere in a Rails app as a hash of parameters) with an array of ContainerTemplateParameters :)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hashes (plural!) is widely used in refresh to mean array of hashes. Though yes, in ems_inv_to_hashes it means hash of arrays of hashes :-|

How about template_params_to_hashes ?

Why each_with_object([]), won't

params.collect do |param|
  .param.attributes.slice("name", "value", "generate", "from", "required")
end

work?

@zakiva note this slice returns string keys and you had symbols.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cben Yes; I was going somewhere else in my brain before I realized params aren't just hashes themselves and are AR objects.

Prefer map over collect ;)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you convince our rubocop to not prefer collect? ;-)
Hey, did https://github.com/ManageIQ/ruby-style-guide evaporate ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ugh I'm too lazy to start that battle again, nevermind.

Yes, we torched it.

@miq-bot
Copy link
Member

miq-bot commented Aug 2, 2017

This pull request is not mergeable. Please rebase and repush.

@zakiva
Copy link
Contributor Author

zakiva commented Aug 21, 2017

Closing in favor of ManageIQ/manageiq-providers-kubernetes#97

@zakiva zakiva closed this Aug 21, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants