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

Cleaned up some of the logic in main #16

Merged
merged 3 commits into from
Aug 5, 2020

Conversation

ghost
Copy link

@ghost ghost commented Jul 30, 2020

By introducing a function which gets the collectors interface, I wanted to know if there would ever be a case when there would be more than one collector?

IE:

NewClusterCollector
NewHelmV2Collector
NewHelmV3Collector

or is it always just one of these?

@ghost ghost requested a review from stepanstipl July 30, 2020 11:56
@ghost ghost force-pushed the feature/refactorTwoCollections branch from b127d1e to 9d0de37 Compare July 30, 2020 11:58
@ghost
Copy link
Author

ghost commented Jul 30, 2020

Additionally, I wanted to know what action to take when inputs are empty? @stepanstipl Should we throw or...?

@ghost ghost force-pushed the feature/refactorTwoCollections branch from 9d0de37 to 8b5dced Compare July 30, 2020 12:03
@ghost ghost assigned ghost and stepanstipl Jul 30, 2020
@stepanstipl
Copy link
Contributor

if there would ever be a case when there would be more than one collector?

@david-doit-intl yes, multiple collectors at once should be allowed, ie. typical scenario is that workloads in the cluster are deployed both directly (Cluster collector) and via Helm, and we want to scan all of those.

what action to take when inputs are empty?

Empty inputs are fine too, we print how many resources we have retrieved from individual collectors if there is none - no issue.

TL;DR: The ides of default use case is: Just run kubent, without any additional config, and it tries to detect as many problematic resources as we can.

@stepanstipl
Copy link
Contributor

I think that moving the logic to individual functions, away from the main "spaghetti" is a nice improvement. 👍

But I would prefer to keep the actual retrieval of the resources collector.Get() to happen after all the collectors are initialized. Rationale: resource retrieval can take a while on large clusters/slow connections, and it's good for the user to fail fast & early if some preconditions are not met (like the collector failed to init because of bad kubeconfig, or the file for file collector does not exist).

Perhaps moving just the collection logic/loop to a separate function, smth. like processCollectors(collectors []collector.Collector) []interface{} (please come up with better name 😄 )?

@ghost
Copy link
Author

ghost commented Jul 31, 2020

I think that moving the logic to individual functions, away from the main "spaghetti" is a nice improvement.

But I would prefer to keep the actual retrieval of the resources collector.Get() to happen after all the collectors are initialized. Rationale: resource retrieval can take a while on large clusters/slow connections, and it's good for the user to fail fast & early if some preconditions are not met (like the collector failed to init because of bad kubeconfig, or the file for file collector does not exist).

Perhaps moving just the collection logic/loop to a separate function, smth. like processCollectors(collectors []collector.Collector) []interface{} (please come up with better name )?

Yes, we can do a defer as well, but ok will change!

@ghost
Copy link
Author

ghost commented Jul 31, 2020

@stepanstipl maybe also the collection.Get(), should be async then, if that is the case? https://gobyexample.com/goroutines

So we can run the get or the resource retrival all at once if they exist.

@ghost
Copy link
Author

ghost commented Jul 31, 2020

defer -> https://tour.golang.org/flowcontrol/12,

something like this so the Get collection can happen after!

@stepanstipl
Copy link
Contributor

defer

Not sure how that would look like - .Get() would still have to be taken out of storeCollector, I think... Typically I've seen defer used more for closing connections and cleaning up.

maybe also the collection.Get(), should be async then

Hm, that is a good point and would say yes, but :)... because most of the collectors talk to the cluster, I'm not sure if hitting it with 3 connections, all at once, wouldn't degrade the resulting performance/cause issues with the network. But definitely a good point to think about... maybe worth running some tests....

@ghost
Copy link
Author

ghost commented Jul 31, 2020

let me show you the defer first and then we can have a look at async stuff if needed

@ghost ghost force-pushed the feature/refactorTwoCollections branch 2 times, most recently from 7f48239 to 2b422d4 Compare August 4, 2020 14:58
Signed-off-by: david-doit-intl <david@doit-intl.com>
@ghost ghost force-pushed the feature/refactorTwoCollections branch from 2b422d4 to f3f7ca6 Compare August 4, 2020 14:59
@ghost
Copy link
Author

ghost commented Aug 4, 2020

@stepanstipl have updated this code :)

@ghost ghost force-pushed the feature/refactorTwoCollections branch from 79c4dbe to 855a115 Compare August 4, 2020 15:15
Copy link
Contributor

@stepanstipl stepanstipl left a comment

Choose a reason for hiding this comment

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

@david-doit-intl I think it looks good 🚀 Do you plan to add tests for the new funcs? (I'm happy to merge as it is)

@ghost
Copy link
Author

ghost commented Aug 5, 2020

@stepanstipl adding tests now :)

@stepanstipl stepanstipl merged commit 4d5a306 into master Aug 5, 2020
@stepanstipl stepanstipl deleted the feature/refactorTwoCollections branch August 5, 2020 12:15
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.

None yet

1 participant