mirror of https://github.com/knative/client.git
Add support for service url in svc describe output (#916)
* Add support for service url in svc describe output * Add changes in CHANGELOG.adoc * Update CHANGELOG.adoc Co-authored-by: Matt Moore <mattmoor@vmware.com> * Add url as output format in kn service describe --help command * Build locally and autogenerated doc * Change service describe help message for consistency Co-authored-by: Matt Moore <mattmoor@vmware.com>
This commit is contained in:
parent
1a8cf96997
commit
e6f125fd4e
|
|
@ -18,6 +18,10 @@
|
||||||
|===
|
|===
|
||||||
| | Description | PR
|
| | Description | PR
|
||||||
|
|
||||||
|
| 🎁
|
||||||
|
| Add "url" output format to return service url in service describe
|
||||||
|
| https://github.com/knative/client/pull/916[#916]
|
||||||
|
|
||||||
| 🐛
|
| 🐛
|
||||||
| Fix panic for `kn source apiserver` and `kn source binding` describe with Sink URI
|
| Fix panic for `kn source apiserver` and `kn source binding` describe with Sink URI
|
||||||
| https://github.com/knative/client/pull/901[#901]
|
| https://github.com/knative/client/pull/901[#901]
|
||||||
|
|
|
||||||
|
|
@ -10,13 +10,27 @@ Show details of a service
|
||||||
kn service describe NAME
|
kn service describe NAME
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Examples
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
# Describe service 'svc' in human friendly format
|
||||||
|
kn service describe svc
|
||||||
|
|
||||||
|
# Describe service 'svc' in YAML format
|
||||||
|
kn service describe svc -o yaml
|
||||||
|
|
||||||
|
# Print only service URL
|
||||||
|
kn service describe svc -o url
|
||||||
|
```
|
||||||
|
|
||||||
### 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)
|
--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.
|
-o, --output string Output format. One of: json|yaml|name|go-template|go-template-file|template|templatefile|jsonpath|jsonpath-file|url.
|
||||||
--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].
|
--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.
|
||||||
```
|
```
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,7 @@ import (
|
||||||
"io"
|
"io"
|
||||||
"sort"
|
"sort"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"k8s.io/apimachinery/pkg/util/sets"
|
"k8s.io/apimachinery/pkg/util/sets"
|
||||||
"k8s.io/cli-runtime/pkg/genericclioptions"
|
"k8s.io/cli-runtime/pkg/genericclioptions"
|
||||||
|
|
@ -70,6 +71,16 @@ type revisionDesc struct {
|
||||||
// As this command does not do any writes/updates, it's just a matter of fallbacks.
|
// As this command does not do any writes/updates, it's just a matter of fallbacks.
|
||||||
// [/REMOVE COMMENT WHEN MOVING TO 0.7.0]
|
// [/REMOVE COMMENT WHEN MOVING TO 0.7.0]
|
||||||
|
|
||||||
|
var describe_example = `
|
||||||
|
# Describe service 'svc' in human friendly format
|
||||||
|
kn service describe svc
|
||||||
|
|
||||||
|
# Describe service 'svc' in YAML format
|
||||||
|
kn service describe svc -o yaml
|
||||||
|
|
||||||
|
# Print only service URL
|
||||||
|
kn service describe svc -o url`
|
||||||
|
|
||||||
// NewServiceDescribeCommand returns a new command for describing a service.
|
// NewServiceDescribeCommand returns a new command for describing a service.
|
||||||
func NewServiceDescribeCommand(p *commands.KnParams) *cobra.Command {
|
func NewServiceDescribeCommand(p *commands.KnParams) *cobra.Command {
|
||||||
|
|
||||||
|
|
@ -77,8 +88,9 @@ func NewServiceDescribeCommand(p *commands.KnParams) *cobra.Command {
|
||||||
machineReadablePrintFlags := genericclioptions.NewPrintFlags("")
|
machineReadablePrintFlags := genericclioptions.NewPrintFlags("")
|
||||||
|
|
||||||
command := &cobra.Command{
|
command := &cobra.Command{
|
||||||
Use: "describe NAME",
|
Use: "describe NAME",
|
||||||
Short: "Show details of a service",
|
Short: "Show details of a service",
|
||||||
|
Example: describe_example,
|
||||||
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("'service describe' requires the service name given as single argument")
|
return errors.New("'service describe' requires the service name given as single argument")
|
||||||
|
|
@ -102,11 +114,16 @@ func NewServiceDescribeCommand(p *commands.KnParams) *cobra.Command {
|
||||||
|
|
||||||
// Print out machine readable output if requested
|
// Print out machine readable output if requested
|
||||||
if machineReadablePrintFlags.OutputFlagSpecified() {
|
if machineReadablePrintFlags.OutputFlagSpecified() {
|
||||||
|
out := cmd.OutOrStdout()
|
||||||
|
if strings.ToLower(*machineReadablePrintFlags.OutputFormat) == "url" {
|
||||||
|
fmt.Fprintf(out, "%s\n", extractURL(service))
|
||||||
|
return nil
|
||||||
|
}
|
||||||
printer, err := machineReadablePrintFlags.ToPrinter()
|
printer, err := machineReadablePrintFlags.ToPrinter()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return printer.PrintObj(service, cmd.OutOrStdout())
|
return printer.PrintObj(service, out)
|
||||||
}
|
}
|
||||||
|
|
||||||
printDetails, err = cmd.Flags().GetBool("verbose")
|
printDetails, err = cmd.Flags().GetBool("verbose")
|
||||||
|
|
@ -126,6 +143,7 @@ func NewServiceDescribeCommand(p *commands.KnParams) *cobra.Command {
|
||||||
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)
|
machineReadablePrintFlags.AddFlags(command)
|
||||||
|
command.Flag("output").Usage = fmt.Sprintf("Output format. One of: %s.", strings.Join(append(machineReadablePrintFlags.AllowedFormats(), "url"), "|"))
|
||||||
return command
|
return command
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -506,6 +506,23 @@ func TestServiceDescribeMachineReadable(t *testing.T) {
|
||||||
r.Validate()
|
r.Validate()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestServiceDescribeURL(t *testing.T) {
|
||||||
|
client := knclient.NewMockKnServiceClient(t)
|
||||||
|
|
||||||
|
// Recording:
|
||||||
|
r := client.Recorder()
|
||||||
|
|
||||||
|
// Prepare service
|
||||||
|
expectedService := createTestService("foo", []string{"rev1", "rev2"}, goodConditions())
|
||||||
|
r.GetService("foo", &expectedService, nil)
|
||||||
|
|
||||||
|
output, err := executeServiceCommand(client, "describe", "foo", "-o", "url")
|
||||||
|
assert.NilError(t, err)
|
||||||
|
assert.Assert(t, util.ContainsAll(output, "foo.default.example.com"))
|
||||||
|
|
||||||
|
r.Validate()
|
||||||
|
}
|
||||||
|
|
||||||
func validateServiceOutput(t *testing.T, service string, output string) {
|
func validateServiceOutput(t *testing.T, service string, output string) {
|
||||||
assert.Assert(t, cmp.Regexp("Name:\\s+"+service, output))
|
assert.Assert(t, cmp.Regexp("Name:\\s+"+service, output))
|
||||||
assert.Assert(t, cmp.Regexp("Namespace:\\s+default", output))
|
assert.Assert(t, cmp.Regexp("Namespace:\\s+default", output))
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue