mirror of https://github.com/knative/client.git
machinerealable output for trigger (#1121)
Signed-off-by: Arghya Sadhu <arghya88@gmail.com>
This commit is contained in:
parent
ccb5abb4ee
commit
0411239e37
|
|
@ -20,16 +20,18 @@
|
||||||
| 🐛
|
| 🐛
|
||||||
| Embed the namespace in request body while creating channels
|
| Embed the namespace in request body while creating channels
|
||||||
| https://github.com/knative/client/pull/1117[#1117]
|
| https://github.com/knative/client/pull/1117[#1117]
|
||||||
|===
|
|
||||||
|
|
||||||
| 🎁
|
| 🎁
|
||||||
| Add "url" output format to return broker url in broker describe and channel url in channel describe
|
| Add "url" output format to return broker url in broker describe and channel url in channel describe
|
||||||
| https://github.com/knative/client/pull/1118[#1118]
|
| https://github.com/knative/client/pull/1118[#1118]
|
||||||
|===
|
|
||||||
|
|
||||||
| 🎁
|
| 🎁
|
||||||
| Add machine readable output (-o flag) to kn broker describe
|
| Add machine readable output (-o flag) to kn broker describe
|
||||||
| https://github.com/knative/client/pull/1124[#1124]
|
| https://github.com/knative/client/pull/1124[#1124]
|
||||||
|
|
||||||
|
| 🎁
|
||||||
|
| Add machine readable output (-o flag) to kn trigger describe
|
||||||
|
| https://github.com/knative/client/pull/1121[#1121]
|
||||||
|===
|
|===
|
||||||
|
|
||||||
### v0.19.0 (2020-11-11)
|
### v0.19.0 (2020-11-11)
|
||||||
|
|
|
||||||
|
|
@ -16,13 +16,19 @@ kn trigger describe NAME
|
||||||
|
|
||||||
# Describe a trigger with name 'my-trigger'
|
# Describe a trigger with name 'my-trigger'
|
||||||
kn trigger describe my-trigger
|
kn trigger describe my-trigger
|
||||||
|
|
||||||
|
# Describe a trigger 'my-trigger' in YAML format
|
||||||
|
kn trigger describe my-trigger -o yaml
|
||||||
```
|
```
|
||||||
|
|
||||||
### Options
|
### Options
|
||||||
|
|
||||||
```
|
```
|
||||||
|
--allow-missing-template-keys If true, ignore any errors in templates when a field or map key is missing in the template. Only applies to golang and jsonpath output formats. (default true)
|
||||||
-h, --help help for describe
|
-h, --help help for describe
|
||||||
-n, --namespace string Specify the namespace to operate in.
|
-n, --namespace string Specify the namespace to operate in.
|
||||||
|
-o, --output string Output format. One of: json|yaml|name|go-template|go-template-file|template|templatefile|jsonpath|jsonpath-file.
|
||||||
|
--template string Template string or path to template file to use when -o=go-template, -o=go-template-file. The template format is golang templates [http://golang.org/pkg/text/template/#pkg-overview].
|
||||||
-v, --verbose More output.
|
-v, --verbose More output.
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -97,6 +97,10 @@ func (c *knEventingClient) GetTrigger(name string) (*v1beta1.Trigger, error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, kn_errors.GetError(err)
|
return nil, kn_errors.GetError(err)
|
||||||
}
|
}
|
||||||
|
err = updateEventingGVK(trigger)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
return trigger, nil
|
return trigger, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,10 @@ package trigger
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"k8s.io/cli-runtime/pkg/genericclioptions"
|
||||||
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
|
||||||
|
|
@ -26,15 +30,23 @@ import (
|
||||||
"knative.dev/client/pkg/printers"
|
"knative.dev/client/pkg/printers"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var describeExample = `
|
||||||
|
# Describe a trigger with name 'my-trigger'
|
||||||
|
kn trigger describe my-trigger
|
||||||
|
|
||||||
|
# Describe a trigger 'my-trigger' in YAML format
|
||||||
|
kn trigger describe my-trigger -o yaml`
|
||||||
|
|
||||||
// NewTriggerDescribeCommand returns a new command for describe a trigger
|
// NewTriggerDescribeCommand returns a new command for describe a trigger
|
||||||
func NewTriggerDescribeCommand(p *commands.KnParams) *cobra.Command {
|
func NewTriggerDescribeCommand(p *commands.KnParams) *cobra.Command {
|
||||||
|
|
||||||
triggerDescribe := &cobra.Command{
|
// For machine readable output
|
||||||
|
machineReadablePrintFlags := genericclioptions.NewPrintFlags("")
|
||||||
|
|
||||||
|
command := &cobra.Command{
|
||||||
Use: "describe NAME",
|
Use: "describe NAME",
|
||||||
Short: "Show details of a trigger",
|
Short: "Show details of a trigger",
|
||||||
Example: `
|
Example: describeExample,
|
||||||
# Describe a trigger with name 'my-trigger'
|
|
||||||
kn trigger describe my-trigger`,
|
|
||||||
RunE: func(cmd *cobra.Command, args []string) error {
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
if len(args) != 1 {
|
if len(args) != 1 {
|
||||||
return errors.New("'kn trigger describe' requires name of the trigger as single argument")
|
return errors.New("'kn trigger describe' requires name of the trigger as single argument")
|
||||||
|
|
@ -59,6 +71,16 @@ func NewTriggerDescribeCommand(p *commands.KnParams) *cobra.Command {
|
||||||
}
|
}
|
||||||
|
|
||||||
out := cmd.OutOrStdout()
|
out := cmd.OutOrStdout()
|
||||||
|
|
||||||
|
// Print out machine readable output if requested
|
||||||
|
if machineReadablePrintFlags.OutputFlagSpecified() {
|
||||||
|
printer, err := machineReadablePrintFlags.ToPrinter()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return printer.PrintObj(trigger, out)
|
||||||
|
}
|
||||||
|
|
||||||
dw := printers.NewPrefixWriter(out)
|
dw := printers.NewPrefixWriter(out)
|
||||||
|
|
||||||
printDetails, err := cmd.Flags().GetBool("verbose")
|
printDetails, err := cmd.Flags().GetBool("verbose")
|
||||||
|
|
@ -88,11 +110,12 @@ func NewTriggerDescribeCommand(p *commands.KnParams) *cobra.Command {
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
flags := triggerDescribe.Flags()
|
flags := command.Flags()
|
||||||
commands.AddNamespaceFlags(flags, false)
|
commands.AddNamespaceFlags(flags, false)
|
||||||
flags.BoolP("verbose", "v", false, "More output.")
|
flags.BoolP("verbose", "v", false, "More output.")
|
||||||
|
machineReadablePrintFlags.AddFlags(command)
|
||||||
return triggerDescribe
|
command.Flag("output").Usage = fmt.Sprintf("Output format. One of: %s.", strings.Join(machineReadablePrintFlags.AllowedFormats(), "|"))
|
||||||
|
return command
|
||||||
}
|
}
|
||||||
|
|
||||||
func writeTrigger(dw printers.PrefixWriter, trigger *v1beta1.Trigger, printDetails bool) {
|
func writeTrigger(dw printers.PrefixWriter, trigger *v1beta1.Trigger, printDetails bool) {
|
||||||
|
|
|
||||||
|
|
@ -81,9 +81,26 @@ func TestDescribeTriggerWithSinkURI(t *testing.T) {
|
||||||
recorder.Validate()
|
recorder.Validate()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestDescribeTriggerMachineReadable(t *testing.T) {
|
||||||
|
client := clientv1beta1.NewMockKnEventingClient(t, "mynamespace")
|
||||||
|
|
||||||
|
recorder := client.Recorder()
|
||||||
|
recorder.GetTrigger("testtrigger", getTriggerSinkRef(), nil)
|
||||||
|
|
||||||
|
output, err := executeTriggerCommand(client, nil, "describe", "testtrigger", "-o", "yaml")
|
||||||
|
assert.NilError(t, err)
|
||||||
|
assert.Assert(t, util.ContainsAll(output, "kind: Trigger", "spec:", "status:", "metadata:"))
|
||||||
|
|
||||||
|
// Validate that all recorded API methods have been called
|
||||||
|
recorder.Validate()
|
||||||
|
}
|
||||||
|
|
||||||
func getTriggerSinkRef() *v1beta1.Trigger {
|
func getTriggerSinkRef() *v1beta1.Trigger {
|
||||||
return &v1beta1.Trigger{
|
return &v1beta1.Trigger{
|
||||||
TypeMeta: v1.TypeMeta{},
|
TypeMeta: v1.TypeMeta{
|
||||||
|
Kind: "Trigger",
|
||||||
|
APIVersion: "eventing.knative.dev/v1beta1",
|
||||||
|
},
|
||||||
ObjectMeta: metav1.ObjectMeta{
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
Name: "testtrigger",
|
Name: "testtrigger",
|
||||||
Namespace: "default",
|
Namespace: "default",
|
||||||
|
|
@ -110,7 +127,10 @@ func getTriggerSinkRef() *v1beta1.Trigger {
|
||||||
|
|
||||||
func getTriggerSinkURI() *v1beta1.Trigger {
|
func getTriggerSinkURI() *v1beta1.Trigger {
|
||||||
return &v1beta1.Trigger{
|
return &v1beta1.Trigger{
|
||||||
TypeMeta: v1.TypeMeta{},
|
TypeMeta: v1.TypeMeta{
|
||||||
|
Kind: "Trigger",
|
||||||
|
APIVersion: "eventing.knative.dev/v1beta1",
|
||||||
|
},
|
||||||
ObjectMeta: metav1.ObjectMeta{
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
Name: "testtrigger",
|
Name: "testtrigger",
|
||||||
Namespace: "default",
|
Namespace: "default",
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue