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

ContainerLabelTagMapping::Mapper class, separate tag creation #16098

Closed
wants to merge 2 commits into from

Conversation

cben
Copy link
Contributor

@cben cben commented Oct 3, 2017

Overview/plan issue: ManageIQ/manageiq-providers-kubernetes#126

To be merged simultaneously with ManageIQ/manageiq-providers-kubernetes#130 & ManageIQ/manageiq-providers-amazon#316.

A refactoring and first step towards tag mapping with graph refresh.
https://bugzilla.redhat.com/show_bug.cgi?id=1470021

The functional change besides extracting code to a Mapper class is making Mapper responsible for keeping track of mapped tags, and a batch API to find/create all of them.

Currently it has just array and calls find_or_create_tag for each, but in future PR that will turn into an InventoryCollection (with some custom logic) that will be usable as part of graph refresh.

retag_entity kept outside Mapper class because it may be used later / in separate process
(soon in post refresh, possibly queued; later collector/persistor split might also require this).

@cben cben changed the title ContainerLabelTagMapping::Mapper class with cleaner interface ContainerLabelTagMapping::Mapper class, separate tag creation Oct 3, 2017
@cben
Copy link
Contributor Author

cben commented Oct 3, 2017

@miq-bot add-label enhancement, providers/containers

@cben cben changed the title ContainerLabelTagMapping::Mapper class, separate tag creation [WIP] ContainerLabelTagMapping::Mapper class, separate tag creation Oct 8, 2017
@miq-bot miq-bot added the wip label Oct 8, 2017
@cben cben force-pushed the tag-mapper branch 2 times, most recently from bb6c481 to 6e5d485 Compare October 15, 2017 13:51
@cben cben changed the title [WIP] ContainerLabelTagMapping::Mapper class, separate tag creation ContainerLabelTagMapping::Mapper class, separate tag creation Oct 15, 2017
@cben
Copy link
Contributor Author

cben commented Oct 15, 2017

@moolitayer @zgalor @djberg96 The 3 PRs are ready now, please review.

I might have to untangle them to actually get them merged, but that would just add then remove some transient ugliness, let's review the actual changes first.

The Mapper will exist during mapping, and finding/creating tags,
but not necessary for actual [un]assigning them.
The Mapper keeps track of all mapped tags.

This commit requires simultaneous changes in providers
(kubernetes, amazon) to use new API and pass a mapper to save_inventory.
Copy link
Contributor

@Ladas Ladas left a comment

Choose a reason for hiding this comment

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

Not sure about the Cloud support here. Also YARD docs would be nice. :-)

class ContainerLabelTagMapping
# Performs most of the work of ContainerLabelTagMapping - holds current mappings,
# computes applicable tags, and creates/finds Tag records - except actually [un]assigning.
class Mapper
Copy link
Contributor

Choose a reason for hiding this comment

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

@cben could you add YARD doc format, at least for the public methods? Can be theoretically done in another PR, but a new class is a nice opportunity. :-)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure 👍 Learning it now...

@@ -45,6 +45,8 @@ def save_ems_cloud_inventory(ems, hashes, target = nil, disconnect = true)
_log.debug("#{log_header} hashes:\n#{YAML.dump(hashes)}")
end

hashes[:tag_mapper].find_or_create_tags if hashes[:tag_mapper]
Copy link
Contributor

Choose a reason for hiding this comment

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

Is the if condition ok? Seems like this would never run for Cloud?

Copy link
Contributor

@Ladas Ladas Oct 16, 2017

Choose a reason for hiding this comment

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

I see, that is set in AWS repo. So jut a question, why is if hashes[:tag_mapper] here and not in SaveInventoryContainer

Copy link
Contributor Author

@cben cben Oct 16, 2017

Choose a reason for hiding this comment

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

IINM it will be set by ManageIQ/manageiq-providers-amazon#316 (but not other cloud providers, hence condition).

But I just run amazon specs assuming they prove tag mapping works — if as you say they're commented out, then I didn't really test it...

(To clarify, at this stage I only expect it to work for old save_inventory path.)

Copy link
Contributor

Choose a reason for hiding this comment

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

ok, make sense, my brain must be still rebooting after the weekend :-)

@djberg96
Copy link
Contributor

LGTM 👍

@cben
Copy link
Contributor Author

cben commented Oct 17, 2017

added docs, PTAL

Copy link
Contributor

@Ladas Ladas left a comment

Choose a reason for hiding this comment

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

Nice docs, looks great now. 👍

@miq-bot
Copy link
Member

miq-bot commented Oct 17, 2017

Checked commits cben/manageiq@480f865~...a2185b1 with ruby 2.3.3, rubocop 0.47.1, and haml-lint 0.20.0
7 files checked, 1 offense detected

app/models/container_label_tag_mapping/mapper.rb

@cben
Copy link
Contributor Author

cben commented Oct 17, 2017

Fixed 1 rubocop in docs (deliberately rejecting the elsif one).

@agrare These are ready, are you able to merge in all 3 repos?
I've rerun k8s, openshift & amazon specs locally.
(You may prefer to merge this one first, kick Travis on other 2 before merging)

@agrare
Copy link
Member

agrare commented Oct 17, 2017

@cben yes I can merge in all three, let me take a final look at them all

Copy link
Member

@agrare agrare left a comment

Choose a reason for hiding this comment

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

👍 LGTM

@agrare agrare added this to the Sprint 72 Ending Oct 30, 2017 milestone Oct 17, 2017
@agrare
Copy link
Member

agrare commented Oct 17, 2017

Weird, github isn't picking up the merge commit b0d6bb8
Closing this.

@agrare agrare closed this Oct 17, 2017
agrare added a commit that referenced this pull request Oct 17, 2017
ContainerLabelTagMapping::Mapper class, separate tag creation
@cben cben mentioned this pull request Apr 11, 2018
@djberg96
Copy link
Contributor

@cben Can we backport this to Fine/Gaprindashvili?

cben pushed a commit to cben/manageiq that referenced this pull request Apr 14, 2018
ContainerLabelTagMapping::Mapper class, separate tag creation
cben pushed a commit to cben/manageiq that referenced this pull request Apr 14, 2018
ContainerLabelTagMapping::Mapper class, separate tag creation
@cben
Copy link
Contributor Author

cben commented Apr 14, 2018

This is already in gaprindashvili.
I just tried backporting to fine, didn't apply cleanly, but I more or less managed, see cben/FINE-tag-mapper branch.
EDIT: fails 1 test

@cben
Copy link
Contributor Author

cben commented Apr 14, 2018

BTW, if you only need classic refresh mapping in Fine, another approach is skip this PR and modify backported refresh parsers to use old interface — like ManageIQ/manageiq-providers-amazon#316 in reverse.

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.

5 participants