-
Notifications
You must be signed in to change notification settings - Fork 40.1k
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
Allow kubectl get to fetch multiple resource types by label #3004
Allow kubectl get to fetch multiple resource types by label #3004
Conversation
f20c2f2
to
3bd6717
Compare
@smarterclayton What exactly would you like feedback on at this point? I think the capability makes a lot of sense, and the example syntax looks fine (modulo the issue that I'd also like to be able to get all kinds of objects within a namespace matching a label selector, though that would require resolving #2057. |
And #991. We could handle that with storing config locally for all the endpoints and resources we know about. ----- Original Message -----
|
Have it now so that you can do:
and get
which you can then pipe to enscope or to something that would strip specifics. |
3bd6717
to
eb5d3b6
Compare
eb5d3b6
to
c3c7ca8
Compare
53ce361
to
b026f9e
Compare
Only the last commit is belongs to this pull, the others are part of #3152 |
Barring changes to the predecessor pull based on API design, this roughly reflects the desired functionality. |
c2a9ac3
to
7e471f8
Compare
7e471f8
to
c845d09
Compare
c845d09
to
f0d805c
Compare
Cool. Looks reasonable to me. We definitely need this functionality. Will wait for merge of #3152 before merging. |
976928c
to
1fb7fcd
Compare
This is now ready for merge, as are the commits above it (except maybe delete, Tim needs to ack the change). |
w, err := restHelper.Watch(namespace, rv, labelSelector, labels.Everything()) | ||
checkErr(err) | ||
// use the default printer for each object | ||
err = b.Do().Visit(func(r *resource.Info) error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FYI: I'd eventually like it to be possible to invoke all of the business logic of kubectl via library call, not just through the command line. That will facilitate programmatic use of Kubernetes, such as to manage dataflow pipelines, CI pipelines, background worker pools, sophisticated rollouts, etc.
Command-line processing obviously has to be coupled to cobra and the kubectl command. Input/output should be less coupled. All the actual processing and client calls should be completely independently callable.
This particular batch of PRs don't need to be changed, but please keep this in mind as we evolve kubectl functionality.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, builder has two types of arguments *Arg/*Param
which indicates it comes from a command line argument (so different failure rules apply), and programmatic "*" calls. The error messages on Do() and Visit() should eventually distinguish between those cases, so you get a different error message when you specify FilenameParam(...)
vs ResourceTypeOrArgs
vs URL
or Stream
.
LGTM. Reassigned to Tim for a look. |
return nil, err | ||
} | ||
if ok { | ||
printer = kubectl.NewVersionedPrinter(printer, mapping.ObjectConvertor, outputVersion(cmd)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@lavalamp note I moved versioning to a wrapped printer so that I could precisely control versioning here. You may want to take a look at the watch behavior and see whether it still makes sense.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry I didn't see this mention of me. This breaks the template uses in cluster/kube-validate.sh. I'm still trying to figure out what happened here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Which ones?
On Jan 13, 2015, at 5:47 PM, Daniel Smith notifications@github.com wrote:
In pkg/kubectl/cmd/get.go:
- templateFile := GetFlagString(cmd, "template")
- if len(outputFormat) == 0 && len(templateFile) != 0 {
outputFormat = "template"
- }
- return kubectl.GetPrinter(outputFormat, templateFile)
+}
+// printerForMapping returns a printer suitable for displaying the provided resource type.
+func printerForMapping(f *Factory, cmd *cobra.Command, mapping *meta.RESTMapping) (kubectl.ResourcePrinter, error) {
- printer, ok, err := printerForCommand(cmd)
- if err != nil {
return nil, err
- }
- if ok {
Sorry I didn't see this mention of me. This breaks the template uses in cluster/kube-validate.sh. I'm still trying to figure out what happened here.printer = kubectl.NewVersionedPrinter(printer, mapping.ObjectConvertor, outputVersion(cmd))
—
Reply to this email directly or view it on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At least the first one. It's giving either internal structs or v1beta3 structs, not sure yet
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will be back at my desk in a few minutes
On Jan 13, 2015, at 5:51 PM, Daniel Smith notifications@github.com wrote:
In pkg/kubectl/cmd/get.go:
- templateFile := GetFlagString(cmd, "template")
- if len(outputFormat) == 0 && len(templateFile) != 0 {
outputFormat = "template"
- }
- return kubectl.GetPrinter(outputFormat, templateFile)
+}
+// printerForMapping returns a printer suitable for displaying the provided resource type.
+func printerForMapping(f *Factory, cmd *cobra.Command, mapping *meta.RESTMapping) (kubectl.ResourcePrinter, error) {
- printer, ok, err := printerForCommand(cmd)
- if err != nil {
return nil, err
- }
- if ok {
At least the first one. It's giving either internal structs or v1beta3 structs, not sure yetprinter = kubectl.NewVersionedPrinter(printer, mapping.ObjectConvertor, outputVersion(cmd))
—
Reply to this email directly or view it on GitHub.
Like Delete, which can now run over multiple types: kubectl delete pods,services -l name=foo Get should be able to span items for label selection kubectl get pods,services -l name=foo
1fb7fcd
to
2151afe
Compare
Rerunning Travis. Will merge after it passes, assuming this doesn't need to be rebased. |
Green across the board |
Allow kubectl get to fetch multiple resource types by label
|
||
// VersionedPrinter takes runtime objects and ensures they are converted to a given API version | ||
// prior to being passed to a nested printer. | ||
type VersionedPrinter struct { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I maintain that it shouldn't be possible to make a non-versioned printer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All the regular printers are not versioned
On Jan 13, 2015, at 5:50 PM, Daniel Smith notifications@github.com wrote:
In pkg/kubectl/resource_printer.go:
-// JSONPrinter is an implementation of ResourcePrinter which outputs an object as JSON.
-// The input object is assumed to be in the internal version of an API and is converted
-// to the given version first.
-type JSONPrinter struct {
- version string
+// ResourcePrinterFunc is a function that can print objects
+type ResourcePrinterFunc func(runtime.Object, io.Writer) error
+// PrintObj implements ResourcePrinter
+func (fn ResourcePrinterFunc) PrintObj(obj runtime.Object, w io.Writer) error {
- return fn(obj, w)
+}
+// VersionedPrinter takes runtime objects and ensures they are converted to a given API version
+// prior to being passed to a nested printer.
+type VersionedPrinter struct {
I maintain that it shouldn't be possible to make a non-versioned printer.—
Reply to this email directly or view it on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They were when I last touched this code! In fact the last thing I did to this code was to fix this very problem...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should put that example into test-cmd.sh then. :)
-o json should be outputting a minionlist - is it?
On Jan 13, 2015, at 5:56 PM, Daniel Smith notifications@github.com wrote:
In pkg/kubectl/resource_printer.go:
-// JSONPrinter is an implementation of ResourcePrinter which outputs an object as JSON.
-// The input object is assumed to be in the internal version of an API and is converted
-// to the given version first.
-type JSONPrinter struct {
- version string
+// ResourcePrinterFunc is a function that can print objects
+type ResourcePrinterFunc func(runtime.Object, io.Writer) error
+// PrintObj implements ResourcePrinter
+func (fn ResourcePrinterFunc) PrintObj(obj runtime.Object, w io.Writer) error {
- return fn(obj, w)
+}
+// VersionedPrinter takes runtime objects and ensures they are converted to a given API version
+// prior to being passed to a nested printer.
+type VersionedPrinter struct {
They were when I last touched this code! In fact the last thing I did to this code was to fix this very problem...—
Reply to this email directly or view it on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
VersionedPrinter may be getting empty string?
On Jan 13, 2015, at 5:56 PM, Daniel Smith notifications@github.com wrote:
In pkg/kubectl/resource_printer.go:
-// JSONPrinter is an implementation of ResourcePrinter which outputs an object as JSON.
-// The input object is assumed to be in the internal version of an API and is converted
-// to the given version first.
-type JSONPrinter struct {
- version string
+// ResourcePrinterFunc is a function that can print objects
+type ResourcePrinterFunc func(runtime.Object, io.Writer) error
+// PrintObj implements ResourcePrinter
+func (fn ResourcePrinterFunc) PrintObj(obj runtime.Object, w io.Writer) error {
- return fn(obj, w)
+}
+// VersionedPrinter takes runtime objects and ensures they are converted to a given API version
+// prior to being passed to a nested printer.
+type VersionedPrinter struct {
They were when I last touched this code! In fact the last thing I did to this code was to fix this very problem...—
Reply to this email directly or view it on GitHub.
Like Delete, which can now run over multiple types:
Get should be able to span items for label selection
Not yet complete, want feedback from @bgrant0607.
Follow up to #2751