-
Notifications
You must be signed in to change notification settings - Fork 266
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
Fix error when output is set to name #775
Conversation
|
||
} | ||
|
||
func toUnstructured(obj runtime.Object) (*unstructured.Unstructured, 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.
see if you can reuse https://github.com/knative/pkg/blob/master/apis/duck/unstructured.go#L32
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.
Thanks for the information.
I checked pkg/apis/duck, and noticed it only accepts an interface duck.OneOfOurs
. Unfortunately, neither servingv1.ServiceList
nor servingv1.Service
, runtime.Object
cannot satisfy that interface. So I cannot leverage it.
218d894
to
f96692f
Compare
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.
See feedback
pkg/kn/commands/service/list.go
Outdated
if err != nil { | ||
return err | ||
if serviceListFlags.GenericPrintFlags.OutputFlagSpecified() { | ||
unstructedList, err := util.ToUnstructuredList(serviceList) |
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.
s/unstructedList/unstructuredList/
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.
changed in the new version.
|
||
// ToUnstructuredList is to converts an object to unstructured.UnstructuredList. | ||
// If the object is not a list type, it will convert to a single item UnstructuredList. | ||
func ToUnstructuredList(obj runtime.Object) (*unstructured.UnstructuredList, 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.
Where is the unit test for this ToUnstructuredList
exported function?
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.
see TestToUnstructuredList
in pkg/util/unstructured_test.go
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 can solve this and also improve the list printing for all command groups.
If we pull the following check earlier in pkg/kn/commands/flags/listprint.go
if serviceListFlags.GenericPrintFlags.OutputFlagSpecified() {
unstructedList, err := util.ToUnstructuredList(serviceList)
and add another method Print
to ListPrintFlags
taking care of finding correct printer and above check+conversion,
we solve this for other list commands too.
I tried doing ^^ on your PR and replaced the print call for revision list
(can be done in similar way for route.. etc)
➜ client git:(f5a4863b) ✗ git --no-pager diff .
diff --git a/pkg/kn/commands/flags/listprint.go b/pkg/kn/commands/flags/listprint.go
index a19cca49..2ec1c81d 100644
--- a/pkg/kn/commands/flags/listprint.go
+++ b/pkg/kn/commands/flags/listprint.go
@@ -15,11 +15,15 @@
package flags
import (
+ "io"
+
"github.com/spf13/cobra"
+ "k8s.io/apimachinery/pkg/runtime"
"k8s.io/cli-runtime/pkg/genericclioptions"
"knative.dev/client/pkg/kn/commands"
hprinters "knative.dev/client/pkg/printers"
+ "knative.dev/client/pkg/util"
)
// ListFlags composes common printer flag structs
@@ -56,6 +60,23 @@ func (f *ListPrintFlags) ToPrinter() (hprinters.ResourcePrinter, error) {
return p, nil
}
+func (f *ListPrintFlags) Print(obj runtime.Object, w io.Writer) error {
+ printer, err := f.ToPrinter()
+ if err != nil {
+ return err
+ }
+
+ if f.GenericPrintFlags.OutputFlagSpecified() {
+ unstructedList, err := util.ToUnstructuredList(obj)
+ if err != nil {
+ return err
+ }
+ return printer.PrintObj(unstructedList, w)
+ }
+
+ return printer.PrintObj(obj, w)
+}
+
// AddFlags receives a *cobra.Command reference and binds
// flags related to humanreadable and template printing.
func (f *ListPrintFlags) AddFlags(cmd *cobra.Command) {
diff --git a/pkg/kn/commands/revision/list.go b/pkg/kn/commands/revision/list.go
index 88f733f5..3821d76e 100644
--- a/pkg/kn/commands/revision/list.go
+++ b/pkg/kn/commands/revision/list.go
@@ -102,13 +102,7 @@ func NewRevisionListCommand(p *commands.KnParams) *cobra.Command {
// Sort revisions by namespace, service, generation (in this order)
sortRevisions(revisionList)
- // Print out infos via printer framework
- printer, err := revisionListFlags.ToPrinter()
- if err != nil {
- return err
- }
-
- return printer.PrintObj(revisionList, cmd.OutOrStdout())
+ return revisionListFlags.Print(revisionList, cmd.OutOrStdout())
},
}
commands.AddNamespaceFlags(revisionListCommand.Flags(), true)
diff --git a/pkg/kn/commands/service/list.go b/pkg/kn/commands/service/list.go
index 974db353..10a3308c 100644
--- a/pkg/kn/commands/service/list.go
+++ b/pkg/kn/commands/service/list.go
@@ -24,7 +24,6 @@ import (
"knative.dev/client/pkg/kn/commands"
"knative.dev/client/pkg/kn/commands/flags"
clientservingv1 "knative.dev/client/pkg/serving/v1"
- "knative.dev/client/pkg/util"
)
// NewServiceListCommand represents 'kn service list' command
@@ -66,11 +65,6 @@ func NewServiceListCommand(p *commands.KnParams) *cobra.Command {
serviceListFlags.EnsureWithNamespace()
}
- printer, err := serviceListFlags.ToPrinter()
- if err != nil {
- return err
- }
-
// Sort serviceList by namespace and name (in this order)
sort.SliceStable(serviceList.Items, func(i, j int) bool {
a := serviceList.Items[i]
@@ -82,15 +76,7 @@ func NewServiceListCommand(p *commands.KnParams) *cobra.Command {
return a.ObjectMeta.Name < b.ObjectMeta.Name
})
- if serviceListFlags.GenericPrintFlags.OutputFlagSpecified() {
- unstructedList, err := util.ToUnstructuredList(serviceList)
- if err != nil {
- return err
- }
- return printer.PrintObj(unstructedList, cmd.OutOrStdout())
- }
-
- return printer.PrintObj(serviceList, cmd.OutOrStdout())
+ return serviceListFlags.Print(serviceList, cmd.OutOrStdout())
},
}
commands.AddNamespaceFlags(serviceListCommand.Flags(), true)
here is the output:
➜ client git:(f5a4863b) ✗ ./kn revision list -oname
revision.serving.knative.dev/svc-tgzvv-1
➜ client git:(f5a4863b) ✗ ./kn service list -oname
service.serving.knative.dev/svc
db58f4c
to
ab7e2f1
Compare
/retest |
e66b3de
to
3c0884d
Compare
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.
@daisy-ycguo needs rebase and changes in e2e as e2e refactor PR is in now
test/e2e/basic_workflow_test.go:52:19: not enough arguments in call to serviceListOutput
have (*test.KnRunResultCollector, string)
want (*test.KnRunResultCollector, *test.KnRunResultCollector, string)
The following is the coverage report on the affected files.
|
@navidshaikh This PR is ready for review. |
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.
/lgtm
/approve
Thanks Daisy!
unstructuredList.Items = append(unstructuredList.Items, *ud) | ||
} | ||
return unstructuredList, nil | ||
|
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.
@@ -0,0 +1,86 @@ | |||
// Copyright © 2019 The Knative Authors |
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.
// Copyright © 2019 The Knative Authors | |
// Copyright © 2020 The Knative Authors |
"metadata": map[string]interface{}{ | ||
"namespace": "default", | ||
"name": name, | ||
"creationTimestamp": nil, |
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.
does it require to set creationTimeStamp
field ?
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: daisy-ycguo, maximilien, navidshaikh The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
* fix error when output is set to name * add e2e test * change to flags/listprint.go Signed-off-by: Roland Huß <roland@ro14nd.de> # Conflicts: # test/e2e/basic_workflow_test.go
* (refactor) address the e2e extract / refactor of issue #763 (#765) * (refactor) address the e2e extract / refactor of issue #763 * various updates to address reviewers feedback * renamed lib/test/integration to lib/test and package to test Signed-off-by: Roland Huß <roland@ro14nd.de> # Conflicts: # CHANGELOG.adoc # test/e2e/service_export_import_apply_test.go # test/e2e/trigger_test.go * fix(plugin): Fix plugin lookup with file ext on Windows (#774) * fix(plugin): Fix plugin lookup with file ext on Windows * chore: Update changelog * fix: Reflect review feedback * fix: Reflect review feedback and add future todo Signed-off-by: Roland Huß <roland@ro14nd.de> # Conflicts: # CHANGELOG.adoc * fix(issue #762): correct error message when updating service (#778) * fix(issue #762): correct error message when updating service * correct message when updating service and passing many names * fix issue with TestServiceUpdateWithMultipleImages running create vs update * * added TestServiceDescribeWithMultipleNames * added TestServiceCreateWithMultipleNames * fix error message for service delete since many names can be passed * Use vendored deps while running e2e locally (#783) Also set GO111MODULE=on unconditionally * Update sink binding create usage string (#785) * Add "--target-utilization" to manage "autoscaling.knative.dev/targetUtilizationPercentage" annotation (#788) * Support setting "autoscaling.knative.dev/targetUtilizationPercentage" annotation. Signed-off-by: Roland Huß <roland@ro14nd.de> # Conflicts: # test/e2e/service_options_test.go * Remove the delete propagation flag (#770) * Remove the delete propagation flag In it's current state it now takes me about 25 seconds for the `kn delete` to complete. Before #682 it used to be almost immediate. This is because we now pass in the `DeletePropagationBackground` flag. I believe this is a mistake, not only because of the 20+ seconds of additional time to delete things, but IMO the CLI should talk to the server in the same way regardless of the --wait flag. That flag should just be a CLI thing to indicate if the user wants the CLI to wait for the server to complete but not HOW the server should do the delete. Signed-off-by: Doug Davis <dug@us.ibm.com> * try just tweaking the --no-wait flag Signed-off-by: Doug Davis <dug@us.ibm.com> * Fix error when output is set to name (#775) * fix error when output is set to name * add e2e test * change to flags/listprint.go Signed-off-by: Roland Huß <roland@ro14nd.de> # Conflicts: # test/e2e/basic_workflow_test.go * Show all revisions when run `service describe -v` (#790) * The `kn service describe -v` command shows repetitive revisions, because the revision would be covered by next one. * Fix resource listing with -oname flag (#799) * Fix resource listing with -oname flag * add e2e tests Signed-off-by: Roland Huß <roland@ro14nd.de> # Conflicts: # test/e2e/ping_test.go # test/e2e/revision_test.go # test/e2e/route_test.go # test/e2e/source_apiserver_test.go # test/e2e/source_binding_test.go # test/e2e/trigger_test.go * Make wait, no-wait and async flags per bool var CLI convention (#802) * Make wait, no-wait and async flags per bool var CLI convention Fixes #800 - Deprecated bool vars can be supported for CLI convention - Bind --async flag value to --no-wait - Only one flag among [wait, no-wait, async] can be provided, else raise an error * Simplify conditionals * Add unit tests for deprecated flag async * Fix a typo * e2e: Foreground delete for revisions and services in e2e (#794) * e2e: Foreground delete for revisions and services in e2e to avoid any race conditions and flakes * Use --wait instead of --no-wait=false Signed-off-by: Roland Huß <roland@ro14nd.de> # Conflicts: # test/e2e/basic_workflow_test.go # test/e2e/revision_test.go * e2e: Run tekton e2e against pipeline v0.11.1 (#803) * Use buildah task from master branch and paramterize FORMAT * Configure pipeline v0.11.1 * DNM: Run tekton e2e in this PR * Revert "DNM: Run tekton e2e in this PR" This reverts commit 903f5be. * Update CHANGELOG for v0.13.2 (#804) * Pin serving to v0.13.2 and update version command (#797) * Pin serving v0.13.2 dep to v0.13.2 * Update version command now points to serving v0.13.2 and eventing v0.13.6 * Copy go.sum as generated in CI Signed-off-by: Roland Huß <roland@ro14nd.de> # Conflicts: # go.mod # go.sum # vendor/modules.txt * add missing vendored files * fixed error reporting for traffics tests * Updated test * fix formatting * e2e for service export (#739) * e2e for service export * e2e for service export * e2e for service export * e2e for service export * e2e for service export Signed-off-by: Roland Huß <roland@ro14nd.de> # Conflicts: # test/e2e/service_export_import_apply_test.go Co-authored-by: dr.max <maxim@us.ibm.com> Co-authored-by: David Simansky <dsimansk@redhat.com> Co-authored-by: Navid Shaikh <nshaikh@redhat.com> Co-authored-by: Lv Jiawei <lvjiawei@cmss.chinamobile.com> Co-authored-by: Doug Davis <dug@us.ibm.com> Co-authored-by: Ying Chun Guo <guoyingc@cn.ibm.com> Co-authored-by: Murugappan Chetty <itsmurugappan@gmail.com>
Describe
Fix the error when calling
kn service list -o name
. Because the default name printer only supportsunstructured.UnstructuredList
, we have to convertservingv1.ServiceList
tounstructured.UnstructuredList
when output flag is set.Changes
kn service list -o name
Reference
Fixes #754