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

refactor: move discovery and util under package app/customresource to make packages highly cohesive #2104

Conversation

CatherineF-dev
Copy link
Contributor

What this PR does / why we need it:

How does this change affect the cardinality of KSM: (increases, decreases or does not change cardinality)

Which issue(s) this PR fixes (optional, in fixes #<issue number>(, fixes #<issue_number>, ...) format, will close the issue(s) when PR gets merged):
Fixes #2103

@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. labels Jun 27, 2023
@k8s-ci-robot k8s-ci-robot added the size/S Denotes a PR that changes 10-29 lines, ignoring generated files. label Jun 27, 2023
@CatherineF-dev CatherineF-dev changed the title Move discovery and util under package customresourcestate to make package higly cohesive [WIP] Move discovery and util under package customresourcestate to make package higly cohesive Jun 27, 2023
@k8s-ci-robot k8s-ci-robot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jun 27, 2023
@CatherineF-dev CatherineF-dev changed the title [WIP] Move discovery and util under package customresourcestate to make package higly cohesive [WIP] Move discovery and util under package customresourcestate to make packages higly cohesive Jun 27, 2023
@CatherineF-dev CatherineF-dev changed the title [WIP] Move discovery and util under package customresourcestate to make packages higly cohesive [WIP] Move discovery and util under package customresourcestate to make packages highly cohesive Jun 27, 2023
@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Jun 27, 2023
@CatherineF-dev CatherineF-dev changed the title [WIP] Move discovery and util under package customresourcestate to make packages highly cohesive Move discovery and util under package customresourcestate/customresource to make packages highly cohesive Jun 27, 2023
@k8s-ci-robot k8s-ci-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jun 27, 2023
@CatherineF-dev CatherineF-dev changed the title Move discovery and util under package customresourcestate/customresource to make packages highly cohesive refactor: move discovery and util under package customresourcestate/customresource to make packages highly cohesive Jun 27, 2023
@CatherineF-dev CatherineF-dev force-pushed the refactor-to-be-high-cohension branch 2 times, most recently from 5450836 to 18f03c1 Compare June 27, 2023 21:29
@CatherineF-dev
Copy link
Contributor Author

Ready for reviewing~

pkg/app/server.go Outdated Show resolved Hide resolved
pkg/app/server.go Outdated Show resolved Hide resolved
)

var config *rest.Config
var currentKubeClient clientset.Interface
var currentDiscoveryClient *discovery.DiscoveryClient
var currentDynamicClient *dynamic.DynamicClient

// CreateKubeClient creates a Kubernetes clientset and a custom resource clientset.
func CreateKubeClient(apiserver string, kubeconfig string) (clientset.Interface, error) {
Copy link
Member

@rexagod rexagod Jun 27, 2023

Choose a reason for hiding this comment

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

I'm not quite sure why this was moved out?

Copy link
Contributor Author

@CatherineF-dev CatherineF-dev Jun 27, 2023

Choose a reason for hiding this comment

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

Remove this dependency
v2/pkg/util
└──v2/pkg/customresource

#2103

util should be independent with customresource.

@CatherineF-dev
Copy link
Contributor Author

/hold

I find it still has these newly added dependencies. Will try to remove these as well.

v2/pkg/customresourcestate
├──v2/pkg/metricshandler
├──v2/pkg/options
├──v2/internal/store

@k8s-ci-robot k8s-ci-robot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Jun 28, 2023
@CatherineF-dev CatherineF-dev force-pushed the refactor-to-be-high-cohension branch 3 times, most recently from e6a46fe to ab98c78 Compare June 28, 2023 12:10
@CatherineF-dev CatherineF-dev changed the title refactor: move discovery and util under package customresourcestate/customresource to make packages highly cohesive refactor: move discovery and util under package app/customresource to make packages highly cohesive Jun 28, 2023
@CatherineF-dev
Copy link
Contributor Author

CatherineF-dev commented Jun 28, 2023

/unhold

Current godepgraph is

v2/pkg/builder/types
├──v2/pkg/metric_generator
├──v2/pkg/options
├──v2/pkg/metrics_store
└──v2/pkg/customresource
v2/pkg/metric_generator
└──v2/pkg/metric
v2/pkg/options
v2/tests/e2e/framework
v2/pkg/builder
├──v2/pkg/builder/types
├──v2/pkg/metric_generator
├──v2/internal/store
├──v2/pkg/customresource
├──v2/pkg/metrics_store
└──v2/pkg/options
v2/pkg/customresource
└──v2/pkg/metric_generator
v2/pkg/customresourcestate
├──v2/pkg/metric
├──v2/pkg/metric_generator
├──v2/internal/discovery
├──v2/pkg/customresource
└──v2/internal/store
v2/pkg/watch
v2/pkg/sharding
v2/pkg/util/proc
v2/internal
├──v2/pkg/options
└──v2/pkg/app
v2/internal/store
├──v2/pkg/metrics_store
├──v2/pkg/sharding
├──v2/pkg/watch
├──v2/pkg/metric_generator
├──v2/pkg/builder/types
├──v2/pkg/constant
├──v2/pkg/customresource
├──v2/pkg/metric
└──v2/pkg/options
v2/pkg/allow
v2/pkg/allowdenylist
└──v2/pkg/metric_generator
v2/pkg/metricshandler
├──v2/pkg/options
├──v2/pkg/metrics_store
└──v2/pkg/builder/types
v2/pkg/optin
└──v2/pkg/metric_generator
v2
├──v2/internal
└──v2/pkg/options
v2/internal/discovery
v2/pkg/app
├──v2/pkg/optin
├──v2/pkg/customresource
├──v2/pkg/allowdenylist
├──v2/pkg/util/proc
├──v2/pkg/customresourcestate
├──v2/pkg/options
├──v2/pkg/metric_generator
├──v2/internal/store
├──v2/internal/discovery
└──v2/pkg/metricshandler
v2/pkg/metric
v2/pkg/metrics_store/metricsstore
└──v2/pkg/metric
v2/tools

Before: #2103

@k8s-ci-robot k8s-ci-robot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Jun 28, 2023
@dgrisonnet
Copy link
Member

/triage accepted
/assign @rexagod @mrueg

@k8s-ci-robot k8s-ci-robot added the triage/accepted Indicates an issue or PR is ready to be actively worked on. label Jun 29, 2023
@k8s-ci-robot k8s-ci-robot removed the needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. label Jun 29, 2023
@CatherineF-dev
Copy link
Contributor Author

Ping ~ @rexagod @mrueg

@rexagod
Copy link
Member

rexagod commented Jul 7, 2023

Sorry for the delay here, I got caught up, will review before end of the day. 🙂

@@ -15,93 +15,22 @@ package discovery

Copy link
Member

Choose a reason for hiding this comment

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

Can we move the entire discovery package (what's left of it in internal/discovery under pkg/app as well)? It would make sense to have the types for discovery in the same place as the logic.

Copy link
Member

Choose a reason for hiding this comment

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

This would also help clean up the same import from app/discovery.go and app/discovery_test.go.

Copy link
Contributor Author

@CatherineF-dev CatherineF-dev Jul 9, 2023

Choose a reason for hiding this comment

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

If moving entire discovery package, v2/pkg/customresourcestate will depend on all packages where internal/discovery depends on.

This is shown in #2103

Copy link
Member

@rexagod rexagod Jul 9, 2023

Choose a reason for hiding this comment

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

ACK, can we move the discovery types inside pkg/app to it's own package (could be types, which would contain all such exported types for the app package, since discovery comes under that now)?

EDIT: It seems moving them under pkg would make more sense, since these are used in areas other than just pkg/app.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

discovery.go and internal/discovery/types.go should be in different packages. Because customresourcestate depends on internal/discovery/types.go and discovery.go depends on many other pkgs.

Does can we move the discovery types inside pkg/app to it's own package mean moving internal/discovery/types.go under types and discovery.go under app?

Copy link
Member

Choose a reason for hiding this comment

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

My bad, it seems the discovery types are not used in internal, so moving these types within a types package in pkg is a valid alternative, in case we do not want to have a root-level types package.

Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure if it's worth reorganizing when we want to change the way customresource metrics are created at the same time, so I don't have a strong opinion here.

Copy link
Member

Choose a reason for hiding this comment

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

ACK. In that case I think we can proceed with a types package within pkg that encapsulates all types used throughout pkg, instead of a root-level types package. This would ensure relevant types live close to their logic, while providing a degree of desired isolation away from the package the logic is present under.

@CatherineF-dev Does this sound good?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

QQ: what's the package name for types.go? pkg or types.

Copy link
Member

@rexagod rexagod Feb 25, 2024

Choose a reason for hiding this comment

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

types should suffice I believe.

pkg/app/server.go Outdated Show resolved Hide resolved
pkg/app/discovery.go Show resolved Hide resolved
pkg/customresourcestate/config.go Outdated Show resolved Hide resolved
internal/discovery/types.go Outdated Show resolved Hide resolved
internal/discovery/types.go Outdated Show resolved Hide resolved
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: CatherineF-dev
Once this PR has been reviewed and has the lgtm label, please ask for approval from mrueg. For more information see the Kubernetes Code Review Process.

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Aug 28, 2023
CatherineF-dev and others added 2 commits September 26, 2023 17:20
use interface to decouple customresourcestate and CRDiscoverer
Update pkg/app/discovery.go

Co-authored-by: Pranshu Srivastava <prasriva@redhat.com>

Update internal/discovery/types.go

Co-authored-by: Pranshu Srivastava <prasriva@redhat.com>

Update internal/discovery/types.go

Co-authored-by: Pranshu Srivastava <prasriva@redhat.com>

Update pkg/customresourcestate/config.go

Co-authored-by: Pranshu Srivastava <prasriva@redhat.com>

Update pkg/customresourcestate/config.go

Co-authored-by: Pranshu Srivastava <prasriva@redhat.com>
@k8s-ci-robot k8s-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Sep 26, 2023
@k8s-triage-robot
Copy link

The Kubernetes project currently lacks enough contributors to adequately respond to all PRs.

This bot triages PRs according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the PR is closed

You can:

  • Mark this PR as fresh with /remove-lifecycle stale
  • Close this PR with /close
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/lifecycle stale

@k8s-ci-robot k8s-ci-robot added the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Jan 21, 2024
@k8s-triage-robot
Copy link

The Kubernetes project currently lacks enough active contributors to adequately respond to all PRs.

This bot triages PRs according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the PR is closed

You can:

  • Mark this PR as fresh with /remove-lifecycle rotten
  • Close this PR with /close
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/lifecycle rotten

@k8s-ci-robot k8s-ci-robot added lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed. and removed lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. labels Feb 20, 2024
@k8s-triage-robot
Copy link

The Kubernetes project currently lacks enough active contributors to adequately respond to all issues and PRs.

This bot triages PRs according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the PR is closed

You can:

  • Reopen this PR with /reopen
  • Mark this PR as fresh with /remove-lifecycle rotten
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/close

@k8s-ci-robot
Copy link
Contributor

@k8s-triage-robot: Closed this PR.

In response to this:

The Kubernetes project currently lacks enough active contributors to adequately respond to all issues and PRs.

This bot triages PRs according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the PR is closed

You can:

  • Reopen this PR with /reopen
  • Mark this PR as fresh with /remove-lifecycle rotten
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/close

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. triage/accepted Indicates an issue or PR is ready to be actively worked on.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Potential cyclic imports
7 participants