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

Feat/crd argo rollouts #375

Closed

Conversation

oliveiraxavier
Copy link

@oliveiraxavier oliveiraxavier commented Oct 30, 2024

This PR allow get some unused Argo rollouts

PR Checklist

  • This PR adds K8s exceptions (false positives)
  • This PR adds new code
  • This PR includes tests for new/existing code
  • This PR adds docs

Notes for your reviewers

This PR adds support for get unused Argo Rollout, Cluster Analysis templates and Analysis templates.

For this pr, some code refactoring was necessary.

@codecov-commenter
Copy link

codecov-commenter commented Oct 30, 2024

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

Attention: Patch coverage is 42.85714% with 212 lines in your changes missing coverage. Please review.

Project coverage is 44.25%. Comparing base (9cd0aba) to head (e85e81e).
Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
pkg/clusterconfig/connection.go 11.68% 64 Missing and 4 partials ⚠️
pkg/kor/argorollouts.go 56.16% 48 Missing and 16 partials ⚠️
pkg/kor/all.go 46.87% 16 Missing and 1 partial ⚠️
pkg/filters/options.go 0.00% 12 Missing ⚠️
pkg/kor/exporter.go 0.00% 7 Missing ⚠️
cmd/kor/root.go 0.00% 6 Missing ⚠️
cmd/kor/all.go 0.00% 5 Missing ⚠️
cmd/kor/exporter.go 0.00% 5 Missing ⚠️
pkg/kor/formatter.go 33.33% 3 Missing and 1 partial ⚠️
cmd/kor/crds.go 0.00% 2 Missing ⚠️
... and 21 more

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #375      +/-   ##
==========================================
+ Coverage   43.38%   44.25%   +0.87%     
==========================================
  Files          63       65       +2     
  Lines        4020     4291     +271     
==========================================
+ Hits         1744     1899     +155     
- Misses       2030     2128      +98     
- Partials      246      264      +18     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@yonahd
Copy link
Owner

yonahd commented Oct 30, 2024

@oliveiraxavier Please rebase so we can properly review the code

@oliveiraxavier
Copy link
Author

@yonahd The main branch has been merged with the feat branch.

@yonahd
Copy link
Owner

yonahd commented Oct 31, 2024

@yonahd The main branch has been merged with the feat branch.

Did you sync your fork?

@oliveiraxavier
Copy link
Author

@yonahd The main branch has been merged with the feat branch.

Did you sync your fork?

Yes, synced

@oliveiraxavier oliveiraxavier force-pushed the feat/crd-argo-rollouts branch 2 times, most recently from 1e937ad to e85e81e Compare November 3, 2024 00:31
@yonahd
Copy link
Owner

yonahd commented Nov 5, 2024

@oliveiraxavier I'm working on the review. Any chance you can split this into 2 separate PRs
One for the Argo rollout and a second for moving the create client logic into a separate folder?

@oliveiraxavier
Copy link
Author

@oliveiraxavier I'm working on the review. Any chance you can split this into 2 separate PRs One for the Argo rollout and a second for moving the create client logic into a separate folder?

In my previous PR (#363), the logic was separated but the resource search files (deployments for example) were extremely tied to the connection logic, I separated them with that in mind. Refactoring this would almost be a reopening of the previous pr and would require some more refactoring of everything I developed, I can't see how I can split this PR into two without breaking the functioning of everything.

@yonahd
Copy link
Owner

yonahd commented Nov 6, 2024

@oliveiraxavier I'm working on the review. Any chance you can split this into 2 separate PRs One for the Argo rollout and a second for moving the create client logic into a separate folder?

In my previous PR (#363), the logic was separated but the resource search files (deployments for example) were extremely tied to the connection logic, I separated them with that in mind. Refactoring this would almost be a reopening of the previous pr and would require some more refactoring of everything I developed, I can't see how I can split this PR into two without breaking the functioning of everything.

Maybe I'm missing something but it seems most of the connection logic is just moving the logic from kor.go
If it's too much to separate I'll review it as it is (mainly wanted the separation to help with my adhd)

@oliveiraxavier
Copy link
Author

Talvez eu esteja esquecendo de algo, mas parece que a maior parte da lógica de conexão está apenas movendo a lógica do kor.go. Se for muita coisa para separar, revisarei como está (queria principalmente a separação para ajudar com meu TDAH)

I won't be able to work on it at the moment

@yonahd
Copy link
Owner

yonahd commented Nov 6, 2024

Talvez eu esteja esquecendo de algo, mas parece que a maior parte da lógica de conexão está apenas movendo a lógica do kor.go. Se for muita coisa para separar, revisarei como está (queria principalmente a separação para ajudar com meu TDAH)

I won't be able to work on it at the moment

No worries. I'll review it as is.
It'll just take me a bit longer

Copy link
Owner

@yonahd yonahd left a comment

Choose a reason for hiding this comment

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

Logic looks right for the finding unused argorollouts
There are some structure issues and minor fixes.
I suggest you also look through https://github.com/yonahd/kor/blob/main/CONTRIBUTING.md which will help structuring the PR.
Also we need to think of how we give the permissions in the helm chart

@@ -253,6 +269,45 @@ Unused resources in namespace: "test"
+---+----------------+----------------------------------------------+--------------------------------------------------------+
```

```sh
kor all --include-third-party-crds argo-rollouts,argo-rollouts-analysis-templates,argo-rollouts-cluster-analysis-templates --show-reason --show-reason
Copy link
Owner

Choose a reason for hiding this comment

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

No need for this additional example

@@ -85,4 +87,5 @@ func addFilterOptionsFlag(cmd *cobra.Command, opts *filters.Options) {
cmd.PersistentFlags().StringVar(&opts.IncludeLabels, "include-labels", opts.IncludeLabels, "Selector to filter in, Example: --include-labels key1=value1.(currently supports one label)")
cmd.PersistentFlags().StringSliceVarP(&opts.ExcludeNamespaces, "exclude-namespaces", "e", opts.ExcludeNamespaces, "Namespaces to be excluded, split by commas. Example: --exclude-namespaces ns1,ns2,ns3. If --include-namespaces is set, --exclude-namespaces will be ignored.")
cmd.PersistentFlags().StringSliceVarP(&opts.IncludeNamespaces, "include-namespaces", "n", opts.IncludeNamespaces, "Namespaces to run on, split by commas. Example: --include-namespaces ns1,ns2,ns3. If set, non-namespaced resources will be ignored.")
rootCmd.PersistentFlags().StringSliceVar(&opts.IncludeThirdPartyCrds, "include-third-party-crds", opts.IncludeThirdPartyCrds, "Custom resources defintions to search, split by commas. Example: --include-crds argo-rollouts. If set, the chosen crd will be returned (in addition to the other resources, of course)")
Copy link
Owner

Choose a reason for hiding this comment

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

We can allow the user to select specific ones without a flag using the multi functionality.
I think the flag should exist in case the user chooses kor all and wants to choose either only native resources or also crds (a boolean flag)

Copy link
Owner

Choose a reason for hiding this comment

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

Please change the folder structure to pkg/kor/crds

Copy link
Author

Choose a reason for hiding this comment

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

This should cause circular import error

Copy link
Owner

Choose a reason for hiding this comment

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

Create a separate file create_test_crd_resources.go for crd test resources

Copy link
Owner

Choose a reason for hiding this comment

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

Please move this into utils

@@ -235,3 +235,12 @@ func FormatOutputAll(namespace string, allDiffs []ResourceDiff, opts common.Opts
table.Render()
return fmt.Sprintf("Unused resources in namespace: %q\n%s\n", namespace, buf.String())
}

func SkipIfContainsValue(data []ResourceInfo, key string, value interface{}) bool {
Copy link
Owner

Choose a reason for hiding this comment

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

This Should not be in formatter.go

"github.com/yonahd/kor/pkg/filters"
)

func GetUnusedArgoRollouts(clientsetinterface clusterconfig.ClientInterface, namespace string, filterOpts *filters.Options) ResourceDiff {
Copy link
Owner

Choose a reason for hiding this comment

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

We need to create cmd/kor/argorollouts.go so users can select this one specifically
Also missing pkg/kor/multi.go - allow finding your new resource in a comma-separated query along other resources.

"github.com/yonahd/kor/pkg/clusterconfig"
"github.com/yonahd/kor/pkg/filters"
)

Copy link
Owner

Choose a reason for hiding this comment

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

nit: move the get unused functions to the bottom to match convention

Copy link
Owner

Choose a reason for hiding this comment

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

What is this needed for?

@oliveiraxavier
Copy link
Author

I'm closing this pr.
My time is short and until I finish these changes there will be many conflicts.

@oliveiraxavier
Copy link
Author

Thank's for your review

@yonahd
Copy link
Owner

yonahd commented Nov 10, 2024

I'm closing this pr. My time is short and until I finish these changes there will be many conflicts.

Are you planning on completing this?

@oliveiraxavier
Copy link
Author

I'm closing this pr. My time is short and until I finish these changes there will be many conflicts.

Are you planning on completing this?

Maybe in two or three months I can set aside some time to get back to it. If someone follows the idea, no problem.

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.

3 participants