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

Proposal: Refactoring of KnParameters to an interface #888

Open
Tracked by #1582
rhuss opened this issue Jun 16, 2020 · 11 comments
Open
Tracked by #1582

Proposal: Refactoring of KnParameters to an interface #888

rhuss opened this issue Jun 16, 2020 · 11 comments
Assignees
Labels
triage/accepted Issues which should be fixed (post-triage)

Comments

@rhuss
Copy link
Contributor

rhuss commented Jun 16, 2020

Curently we are using a struct KnParams as the context that we pass down into specific commands so that they can access the various services:

type KnParams struct {
	Output            io.Writer
	KubeCfgPath       string
	ClientConfig      clientcmd.ClientConfig
	NewServingClient  func(namespace string) (clientservingv1.KnServingClient, error)
	NewSourcesClient  func(namespace string) (v1alpha2.KnSourcesClient, error)
	NewEventingClient func(namespace string) (clienteventingv1beta1.KnEventingClient, error)
	NewDynamicClient  func(namespace string) (clientdynamic.KnDynamicClient, error)

	// General global options
	LogHTTP bool

	// Set this if you want to nail down the namespace
	fixedCurrentNamespace string
}

This struct was mainly added in this form for allowing injection of fake clients for unit testing. However, this construct has some drawbacks:

  • It leaks testing concerns into the business logic
  • Anytime something you need for testing is added here (see fixedCurrentNamespace or also the Output writer which should be used from the command itself.
  • Test initialization is done lazy with a side-effect in Initialize() which is hard to understand why that call is needed from business logic PoV
  • KnParameters is a poor name because it does not reflect its purpose (i.e. the services included are not parameters, but part of the environment/context for which a command is created).

The suggested refactoring is:

  • Move to a KnContext interface with direct access to the services needed.
  • Provide an implementation KnDefaultContext, KnFakeContext (for fake based testing) and KnMockContext (for mock based testing)
  • Consider to also move the output streams out & error to the context, too, so that any output goes over that streams. Test implementations KnFakeContext and KnMockContext the can use a buffer for these streams.
  • The context remains the single constructor parameter for a command.

Please vote for this refactoring here with 👍 / 👎 , preferably with some comment to reason about your vote.

@rhuss rhuss self-assigned this Jun 16, 2020
@rhuss rhuss changed the title Proposal: Refactoring of KnParameters to an interface Proposal: Refactoring of KnParameters to an interface Jun 16, 2020
@rhuss
Copy link
Contributor Author

rhuss commented Jun 26, 2020

ballot is over, let's tackle that refactoring. Thanks !

/assign rhuss

@github-actions
Copy link

This issue is stale because it has been open for 90 days with no
activity. It will automatically close after 30 more days of
inactivity. Reopen the issue with /reopen. Mark the issue as
fresh by adding the comment /remove-lifecycle stale.

@github-actions github-actions bot added the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Oct 15, 2020
@rhuss
Copy link
Contributor Author

rhuss commented Nov 10, 2020

/remove-lifecycle-stale

@rhuss
Copy link
Contributor Author

rhuss commented Nov 10, 2020

/remove-lifecycle stale

@knative-prow-robot knative-prow-robot removed the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Nov 10, 2020
@github-actions
Copy link

github-actions bot commented Feb 9, 2021

This issue is stale because it has been open for 90 days with no
activity. It will automatically close after 30 more days of
inactivity. Reopen the issue with /reopen. Mark the issue as
fresh by adding the comment /remove-lifecycle stale.

@github-actions github-actions bot added the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Feb 9, 2021
@rhuss
Copy link
Contributor Author

rhuss commented Feb 15, 2021

/remove-lifecycle stale

@knative-prow-robot knative-prow-robot removed the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Feb 15, 2021
@rhuss
Copy link
Contributor Author

rhuss commented Feb 15, 2021

This is refactoring should be considered to be implemented along with the extraction of the shared code #1039

@github-actions
Copy link

This issue is stale because it has been open for 90 days with no
activity. It will automatically close after 30 more days of
inactivity. Reopen the issue with /reopen. Mark the issue as
fresh by adding the comment /remove-lifecycle stale.

@github-actions github-actions bot added the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label May 17, 2021
@rhuss
Copy link
Contributor Author

rhuss commented Jun 1, 2021

/remove-lifecycle stale

@dsimansk Not sure if we can do it within the current scope of extracting shared code or whether we should consider this story for a second step refactoring.

@knative-prow-robot knative-prow-robot removed the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Jun 1, 2021
@github-actions
Copy link

This issue is stale because it has been open for 90 days with no
activity. It will automatically close after 30 more days of
inactivity. Reopen the issue with /reopen. Mark the issue as
fresh by adding the comment /remove-lifecycle stale.

@github-actions github-actions bot added the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Aug 31, 2021
@rhuss rhuss added the triage/accepted Issues which should be fixed (post-triage) label Sep 1, 2021
@rhuss
Copy link
Contributor Author

rhuss commented Sep 1, 2021

/remove-lifecycle stale

@knative-prow-robot knative-prow-robot removed the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Sep 1, 2021
dsimansk pushed a commit to dsimansk/client that referenced this issue Dec 7, 2021
Co-authored-by: Markus Thömmes <markusthoemmes@me.com>
@rhuss rhuss mentioned this issue Jan 27, 2022
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
triage/accepted Issues which should be fixed (post-triage)
Projects
Status: In Design
Development

No branches or pull requests

2 participants