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 kubectl to decouple command framework from business logic #7311

Closed
bgrant0607 opened this issue Apr 24, 2015 · 18 comments
Closed

Refactor kubectl to decouple command framework from business logic #7311

bgrant0607 opened this issue Apr 24, 2015 · 18 comments
Assignees
Labels
area/client-libraries area/kubectl kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. lifecycle/frozen Indicates that an issue or PR should not be auto-closed due to staleness. priority/important-longterm Important over the long term, but may not be staffed and/or may need multiple releases to complete. sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. sig/cli Categorizes an issue or PR as relevant to SIG CLI. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.

Comments

@bgrant0607
Copy link
Member

Too much kubectl business logic resides in pkg/kubectl/cmd. I'd like essentially all of kubectl to be callable as a library, and functionality like run-container and rolling-update should be configurable declaratively, as well.

Some of the logic (stop #1535, resize #1629, rolling-update #1743) belongs on the server side, too, but that's a separate issue.

An example that's close:
https://github.com/GoogleCloudPlatform/kubernetes/blob/master/pkg/kubectl/run.go
No mention of cobra, no flags, no reading files/URLs/etc.

Additional changes I'd like to run.go include accepting its config as an object and/or json (rather than the simple array), and moved to a more generic client directory/package. For generators specifically, we need some sort of plugin mechanism and/or should just make them into simple services (#5280).

Examples that don't obey this principle:

Additionally, for declarative updates (#1702), it needs to be possible to specify the update policy in json, accompanying the objects to be updated.

At a glance, pkg/client/clientcmd looks like it respects the separation that we should strive for.

Related: Clients shouldn't be using the internal rep. #3955 #4874 -- only apiserver and kubelet should be using it. Even our controllers should only be using the latest stable API version.

Internally our command-line tool grew more and more functionality, and it became very hard to tease apart. Applications were linking in essentially the whole tool (flags and all) just to use specific bits of it, such as to take a list of objects and send them to the API.

Of course, these principles should be documented somewhere. (Related, but not identical to #6797)

@smarterclayton @lavalamp @ghodss @jlowdermilk @deads2k @ironcladlou @brendandburns @thockin @erictune

@bgrant0607 bgrant0607 added area/client-libraries area/kubectl priority/awaiting-more-evidence Lowest priority. Possibly useful, but not yet enough support to actually get it done. sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. labels Apr 24, 2015
@ghodss
Copy link
Contributor

ghodss commented Apr 24, 2015

Would one possible approach be to migrate a lot of the logic from kubectl into self-sufficient modules in something like pkg/client/tools?

@bgrant0607
Copy link
Member Author

@ghodss That's along the lines of what I was thinking, yes.

@smarterclayton
Copy link
Contributor

The commands should take interfaces directly for their type specific behavior (Reaper, etc) when specific code is required per type. Those interfaces should be provided by the factory to the cobra initializers, but the Run behavior should take generic options.

An example from Openshift: https://github.com/openshift/origin/blob/master/pkg/cmd/cli/cmd/request_project.go - flag and argument handling is distinct from execution.

On Apr 24, 2015, at 5:35 PM, Brian Grant notifications@github.com wrote:

Too much kubectl business logic resides in pkg/kubectl/cmd. I'd like essentially all of kubectl to be callable as a library, and functionality like run-container and rolling-update should be configurable declaratively, as well.

Some of the logic (stop #1535, resize #1629, rolling-update #1743) belongs on the server side, too, but that's a separate issue.

An example that's close:
https://github.com/GoogleCloudPlatform/kubernetes/blob/master/pkg/kubectl/run.go
No mention of cobra, no flags, no reading files/URLs/etc.

Additional changes I'd like to run.go include accepting its config as an object and/or json (rather than the simple array), and moved to a more generic client directory/package. For generators specifically, we need some sort of plugin mechanism and/or should just make them into simple services (#5280).

Examples that don't obey this principle:

updateWithPatch: https://github.com/GoogleCloudPlatform/kubernetes/blob/master/pkg/kubectl/cmd/update.go#L122
RunRollingUpdate: https://github.com/GoogleCloudPlatform/kubernetes/blob/master/pkg/kubectl/cmd/rollingupdate.go#L67
Additionally, for declarative updates (#1702), it needs to be possible to specify the update policy in json, accompanying the objects to be updated.

At a glance, pkg/client/clientcmd looks like it respects the separation that we should strive for.

Related: Clients shouldn't be using the internal rep. #3955 #4874 -- only apiserver and kubelet should be using it. Even our controllers should only be using the latest stable API version.

Internally our command-line tool grew more and more functionality, and it became very hard to tease apart. Applications were linking in essentially the whole tool (flags and all) just to use specific bits of it, such as to take a list of objects and send them to the API.

Of course, these principles should be documented somewhere. (Related, but not identical to #6797)

@smarterclayton @lavalamp @ghodss @jlowdermilk @deads2k @ironcladlou @brendandburns @thockin @erictune


Reply to this email directly or view it on GitHub.

@bgrant0607
Copy link
Member Author

See also #12143 re. functionality that should move server-side.

@bgrant0607 bgrant0607 added help-wanted kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. labels Aug 28, 2015
@bgrant0607 bgrant0607 added this to the v1.2-candidate milestone Sep 12, 2015
@bgrant0607 bgrant0607 added priority/backlog Higher priority than priority/awaiting-more-evidence. and removed priority/awaiting-more-evidence Lowest priority. Possibly useful, but not yet enough support to actually get it done. labels Sep 16, 2015
@bgrant0607 bgrant0607 removed this from the v1.2-candidate milestone Jan 29, 2016
@pwittrock pwittrock added this to the UX Backlog - Stack Ranked milestone Aug 22, 2016
@adohe-zz
Copy link

@bryk ok, get it.

@deads2k
Copy link
Contributor

deads2k commented Aug 25, 2016

@jwforres how do you feel about this? I'm thinking new-app and a few
specific flows. How might you use this in Openshift console?

I thought this issue was about creating composeable command objects for clean re-use (our complete, validate, run methods) and #12143 was about moving the client-side logic server-side.

@bgrant0607
Copy link
Member Author

We are probably also going to want to split generic API functionality from Kubernetes-specific API resource types, as we try to make the API machinery more generic and reusable.

@fejta-bot
Copy link

Issues go stale after 90d of inactivity.
Mark the issue as fresh with /remove-lifecycle stale.
Stale issues rot after an additional 30d of inactivity and eventually close.

Prevent issues from auto-closing with an /lifecycle frozen comment.

If this issue is safe to close now please do so with /close.

Send feedback to sig-testing, kubernetes/test-infra and/or @fejta.
/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 3, 2018
@bgrant0607
Copy link
Member Author

/remove-lifecycle stale
/lifecycle frozen

@k8s-ci-robot k8s-ci-robot added lifecycle/frozen Indicates that an issue or PR should not be auto-closed due to staleness. and removed lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. labels Jan 23, 2018
@liggitt liggitt added priority/important-longterm Important over the long term, but may not be staffed and/or may need multiple releases to complete. and removed priority/important-soon Must be staffed and worked on either currently, or very soon, ideally in time for the next release. labels Oct 7, 2019
@bgrant0607 bgrant0607 assigned monopole, mortent and seans3 and unassigned adohe-zz Jan 8, 2020
@helayoty helayoty added this to SIG CLI Oct 2, 2023
@github-project-automation github-project-automation bot moved this to Needs Triage in SIG CLI Oct 2, 2023
@ardaguclu
Copy link
Member

I think, we have run a long way to achieve this decoupling and it is time to close this issue. If there is any, we can track the work in a new issue.

/close

@k8s-ci-robot
Copy link
Contributor

@ardaguclu: Closing this issue.

In response to this:

I think, we have run a long way to achieve this decoupling and it is time to close this issue. If there is any, we can track the work in a new issue.

/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-sigs/prow repository.

@github-project-automation github-project-automation bot moved this from Needs Triage to Closed in SIG CLI May 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/client-libraries area/kubectl kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. lifecycle/frozen Indicates that an issue or PR should not be auto-closed due to staleness. priority/important-longterm Important over the long term, but may not be staffed and/or may need multiple releases to complete. sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. sig/cli Categorizes an issue or PR as relevant to SIG CLI. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
Archived in project
Development

No branches or pull requests