Skip to content

Commit

Permalink
Merge branch 'master' into pr/update-cobra
Browse files Browse the repository at this point in the history
  • Loading branch information
rhuss committed Oct 23, 2019
2 parents 02fc0d5 + 462973c commit 43d33dd
Show file tree
Hide file tree
Showing 26 changed files with 220 additions and 223 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,5 @@ tags
# VSCode specific
.vscode

# Operating system temporary files
.DS_Store
2 changes: 1 addition & 1 deletion docs/cmd/kn_service_update.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ kn service update NAME [flags]
--tag strings Set tag (format: --tag revisionRef=tagName) where revisionRef can be a revision or '@latest' string representing latest ready revision. This flag can be specified multiple times.
--traffic strings Set traffic distribution (format: --traffic revisionRef=percent) where revisionRef can be a revision or a tag or '@latest' string representing latest ready revision. This flag can be given multiple times with percent summing up to 100%.
--untag strings Untag revision (format: --untag tagName). This flag can be spcified multiple times.
--wait-timeout int Seconds to wait before giving up on waiting for service to be ready. (default 60)
--wait-timeout int Seconds to wait before giving up on waiting for service to be ready. (default 600)
```

### Options inherited from parent commands
Expand Down
27 changes: 24 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,23 +1,44 @@
module knative.dev/client

require (
github.com/BurntSushi/toml v0.3.1 // indirect
github.com/cpuguy83/go-md2man v1.0.10 // indirect
github.com/evanphx/json-patch v4.5.0+incompatible // indirect
github.com/ghodss/yaml v1.0.0 // indirect
github.com/gogo/protobuf v1.2.1 // indirect
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b // indirect
github.com/golang/groupcache v0.0.0-20191002201903-404acd9df4cc // indirect
github.com/golang/protobuf v1.3.2 // indirect
github.com/google/btree v1.0.0 // indirect
github.com/google/go-cmp v0.3.1 // indirect
github.com/google/go-containerregistry v0.0.0-20190723205234-74f764b9c575 // indirect
github.com/google/licenseclassifier v0.0.0-20190711054124-c3068f13fcc3 // indirect
github.com/googleapis/gnostic v0.3.0 // indirect
github.com/gregjones/httpcache v0.0.0-20190611155906-901d90724c79 // indirect
github.com/hashicorp/golang-lru v0.5.3 // indirect
github.com/imdario/mergo v0.3.7 // indirect
github.com/inconshreveable/mousetrap v1.0.0 // indirect
github.com/json-iterator/go v1.1.7 // indirect
github.com/knative/client v0.2.0 // indirect
github.com/kr/pretty v0.1.0 // indirect
github.com/mattbaird/jsonpatch v0.0.0-20171005235357-81af80346b1a // indirect
github.com/mitchellh/go-homedir v1.1.0
github.com/modern-go/reflect2 v1.0.1 // indirect
github.com/peterbourgon/diskv v2.0.1+incompatible // indirect
github.com/pkg/errors v0.8.1
github.com/spf13/cobra v0.0.5
github.com/spf13/pflag v1.0.3
github.com/spf13/viper v1.3.2
github.com/stretchr/objx v0.2.0 // indirect
github.com/stretchr/testify v1.4.0 // indirect
go.uber.org/atomic v1.4.0 // indirect
go.uber.org/multierr v1.2.0 // indirect
go.uber.org/zap v1.10.0 // indirect
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2
golang.org/x/net v0.0.0-20190724013045-ca1201d0de80 // indirect
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 // indirect
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45 // indirect
golang.org/x/time v0.0.0-20190308202827-9d24e82272b4 // indirect
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/yaml.v2 v2.2.4 // indirect
gotest.tools v2.2.0+incompatible
k8s.io/api v0.0.0-20190226173710-145d52631d00
k8s.io/apimachinery v0.0.0-20190221084156-01f179d85dbc
Expand Down
67 changes: 22 additions & 45 deletions go.sum

Large diffs are not rendered by default.

6 changes: 2 additions & 4 deletions hack/build-flags.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ function build_flags() {
local base="${1}"
local now="$(date -u '+%Y-%m-%d %H:%M:%S')"
local rev="$(git rev-parse --short HEAD)"
local pkg="knative.dev/client/pkg/kn/commands"
local pkg="knative.dev/client/pkg/kn/commands/version"
local version="${TAG:-}"
# Use vYYYYMMDD-local-<hash> for the version string, if not passed.
if [[ -z "${version}" ]]; then
Expand All @@ -26,7 +26,5 @@ function build_flags() {
version="v$(date +%Y%m%d)-local-${commit}"
fi

local serving_version=$(grep 'knative.dev/serving' ${base}/go.mod | sed -e 's/.*serving \(.*\)/\1/')

echo "-X '${pkg}.BuildDate=${now}' -X ${pkg}.Version=${version} -X ${pkg}.GitRevision=${rev} -X ${pkg}.ServingVersion=${serving_version}"
echo "-X '${pkg}.BuildDate=${now}' -X ${pkg}.Version=${version} -X ${pkg}.GitRevision=${rev}"
}
1 change: 1 addition & 0 deletions hack/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ check_license() {

update_deps() {
echo "🕸️ ${S}Update"
go mod tidy
go mod vendor
}

Expand Down
2 changes: 1 addition & 1 deletion hack/verify-codegen.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,6 @@ else
git status --porcelain
echo "ERROR: Diff"
git diff
echo "ERROR: ${REPO_ROOT_DIR} is out of date. Please run ./hack/build.sh -u and commit."
echo "ERROR: ${REPO_ROOT_DIR} is out of date. Please run ./hack/build.sh -c and commit."
exit 1
fi
21 changes: 4 additions & 17 deletions pkg/kn/commands/completion.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,26 +20,13 @@ import (
"github.com/spf13/cobra"
)

type CompletionFlags struct {
Zsh bool
}

func NewCompletionCommand(p *KnParams) *cobra.Command {
var completionFlags CompletionFlags

completionCmd := &cobra.Command{
return &cobra.Command{
Use: "completion",
Short: "Output shell completion code (default Bash)",
Hidden: true, // Don't show this in help listing.
Short: "Output shell completion code (Bash)",
Hidden: true, // Don't show this in help listing
Run: func(cmd *cobra.Command, args []string) {
if completionFlags.Zsh {
cmd.Root().GenZshCompletion(os.Stdout)
} else {
cmd.Root().GenBashCompletion(os.Stdout)
}
cmd.Root().GenBashCompletion(os.Stdout)
},
}

completionCmd.Flags().BoolVar(&completionFlags.Zsh, "zsh", false, "Generates completion code for Zsh shell.")
return completionCmd
}
11 changes: 1 addition & 10 deletions pkg/kn/commands/completion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func TestCompletion(t *testing.T) {
t.Run("creates a CompletionCommand", func(t *testing.T) {
setup()
assert.Equal(t, completionCmd.Use, "completion")
assert.Equal(t, completionCmd.Short, "Output shell completion code (default Bash)")
assert.Equal(t, completionCmd.Short, "Output shell completion code (Bash)")
assert.Assert(t, completionCmd.RunE == nil)
})

Expand All @@ -50,13 +50,4 @@ func TestCompletion(t *testing.T) {
completionCmd.Run(fakeRootCmd, []string{})
assert.Assert(t, ReadStdout(t) != "")
})

t.Run("returns completion code for ZSH", func(t *testing.T) {
setup()
CaptureStdout(t)
defer ReleaseStdout(t)

completionCmd.Run(fakeRootCmd, []string{"--zsh"})
assert.Assert(t, ReadStdout(t) != "")
})
}
26 changes: 3 additions & 23 deletions pkg/kn/commands/route/human_readable_flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
package route

import (
"fmt"

metav1beta1 "k8s.io/apimachinery/pkg/apis/meta/v1beta1"
"k8s.io/apimachinery/pkg/runtime"
"knative.dev/client/pkg/kn/commands"
Expand All @@ -29,9 +27,7 @@ func RouteListHandlers(h hprinters.PrintHandler) {
kRouteColumnDefinitions := []metav1beta1.TableColumnDefinition{
{Name: "Name", Type: "string", Description: "Name of the Knative route.", Priority: 1},
{Name: "URL", Type: "string", Description: "URL of the Knative route.", Priority: 1},
{Name: "Age", Type: "string", Description: "Age of the Knative route.", Priority: 1},
{Name: "Conditions", Type: "string", Description: "Conditions describing statuses of route components.", Priority: 1},
{Name: "Traffic", Type: "integer", Description: "Traffic configured for route.", Priority: 1},
{Name: "READY", Type: "string", Description: "Ready condition status of the Knative route.", Priority: 1},
}
h.TableHandler(kRouteColumnDefinitions, printRoute)
h.TableHandler(kRouteColumnDefinitions, printKRouteList)
Expand All @@ -54,29 +50,13 @@ func printKRouteList(kRouteList *servingv1alpha1.RouteList, options hprinters.Pr
func printRoute(route *servingv1alpha1.Route, options hprinters.PrintOptions) ([]metav1beta1.TableRow, error) {
name := route.Name
url := route.Status.URL
age := commands.TranslateTimestampSince(route.CreationTimestamp)
conditions := commands.ConditionsValue(route.Status.Conditions)
traffic := calculateTraffic(route.Status.Traffic)
ready := commands.ReadyCondition(route.Status.Conditions)
row := metav1beta1.TableRow{
Object: runtime.RawExtension{Object: route},
}
row.Cells = append(row.Cells,
name,
url,
age,
conditions,
traffic)
ready)
return []metav1beta1.TableRow{row}, nil
}

func calculateTraffic(targets []servingv1alpha1.TrafficTarget) string {
var traffic string
for _, target := range targets {
if len(traffic) > 0 {
traffic = fmt.Sprintf("%s, %d%% -> %s", traffic, target.Percent, target.RevisionName)
} else {
traffic = fmt.Sprintf("%d%% -> %s", target.Percent, target.RevisionName)
}
}
return traffic
}
16 changes: 8 additions & 8 deletions pkg/kn/commands/route/list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@ func TestRouteListDefaultOutput(t *testing.T) {
} else if !action.Matches("list", "routes") {
t.Errorf("Bad action %v", action)
}
assert.Check(t, util.ContainsAll(output[0], "NAME", "URL", "AGE", "CONDITIONS", "TRAFFIC"))
assert.Check(t, util.ContainsAll(output[1], "foo", "100% -> foo-01234"))
assert.Check(t, util.ContainsAll(output[2], "bar", "100% -> bar-98765"))
assert.Check(t, util.ContainsAll(output[0], "NAME", "URL", "READY"))
assert.Check(t, util.ContainsAll(output[1], "foo"))
assert.Check(t, util.ContainsAll(output[2], "bar"))
}

func TestRouteListDefaultOutputNoHeaders(t *testing.T) {
Expand All @@ -84,9 +84,9 @@ func TestRouteListDefaultOutputNoHeaders(t *testing.T) {
t.Errorf("Bad action %v", action)
}

assert.Check(t, util.ContainsNone(output[0], "NAME", "URL", "GENERATION", "AGE", "CONDITIONS", "READY", "REASON"))
assert.Check(t, util.ContainsAll(output[0], "foo", "100% -> foo-01234"))
assert.Check(t, util.ContainsAll(output[1], "bar", "100% -> bar-98765"))
assert.Check(t, util.ContainsNone(output[0], "NAME", "URL", "READY"))
assert.Check(t, util.ContainsAll(output[0], "foo"))
assert.Check(t, util.ContainsAll(output[1], "bar"))

}

Expand All @@ -100,8 +100,8 @@ func TestRouteListWithTwoTargetsOutput(t *testing.T) {
} else if !action.Matches("list", "routes") {
t.Errorf("Bad action %v", action)
}
assert.Check(t, util.ContainsAll(output[0], "NAME", "URL", "AGE", "CONDITIONS", "TRAFFIC"))
assert.Check(t, util.ContainsAll(output[1], "foo", "20% -> foo-01234, 80% -> foo-98765"))
assert.Check(t, util.ContainsAll(output[0], "NAME", "URL", "READY"))
assert.Check(t, util.ContainsAll(output[1], "foo"))
}

func createMockRouteMeta(name string) *v1alpha1.Route {
Expand Down
4 changes: 3 additions & 1 deletion pkg/kn/commands/service/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ func NewServiceCreateCommand(p *commands.KnParams) *cobra.Command {
}
commands.AddNamespaceFlags(serviceCreateCommand.Flags(), false)
editFlags.AddCreateFlags(serviceCreateCommand)
waitFlags.AddConditionWaitFlags(serviceCreateCommand, 600, "Create", "service")
waitFlags.AddConditionWaitFlags(serviceCreateCommand, commands.WaitDefaultTimeout, "Create", "service")
return serviceCreateCommand
}

Expand Down Expand Up @@ -188,10 +188,12 @@ func prepareAndUpdateService(client serving_kn_v1alpha1.KnServingClient, service
}

func waitForServiceToGetReady(client serving_kn_v1alpha1.KnServingClient, name string, timeout int, verbDone string, out io.Writer) error {
fmt.Fprintln(out, "")
err := waitForService(client, name, out, timeout)
if err != nil {
return err
}
fmt.Fprintln(out, "")
return showUrl(client, name, "", verbDone, out)
}

Expand Down
3 changes: 1 addition & 2 deletions pkg/kn/commands/service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ func NewServiceCommand(p *commands.KnParams) *cobra.Command {
}

func waitForService(client serving_kn_v1alpha1.KnServingClient, serviceName string, out io.Writer, timeout int) error {
fmt.Println("")
err, duration := client.WaitForService(serviceName, time.Duration(timeout)*time.Second, wait.SimpleMessageCallback(out))
if err != nil {
return err
Expand All @@ -69,6 +68,6 @@ func showUrl(client serving_kn_v1alpha1.KnServingClient, serviceName string, ori
if originalRevision != "" && originalRevision == newRevision {
revisionUpdateStatus = " (unchanged)"
}
fmt.Fprintf(out, "\nService '%s' %s with latest revision '%s'%s and URL:\n%s\n", serviceName, what, newRevision, revisionUpdateStatus, url)
fmt.Fprintf(out, "Service '%s' %s with latest revision '%s'%s and URL:\n%s\n", serviceName, what, newRevision, revisionUpdateStatus, url)
return nil
}
9 changes: 5 additions & 4 deletions pkg/kn/commands/service/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func NewServiceUpdateCommand(p *commands.KnParams) *cobra.Command {
Example: update_example,
RunE: func(cmd *cobra.Command, args []string) (err error) {
if len(args) != 1 {
return errors.New("requires the service name.")
return errors.New("requires the service name")
}

namespace, err := p.GetNamespace(cmd)
Expand Down Expand Up @@ -114,15 +114,16 @@ func NewServiceUpdateCommand(p *commands.KnParams) *cobra.Command {

out := cmd.OutOrStdout()
if !waitFlags.Async {
fmt.Fprintf(cmd.OutOrStdout(), "Updating Service '%s' in namespace '%s':\n", args[0], namespace)
fmt.Fprintf(out, "Updating Service '%s' in namespace '%s':\n", args[0], namespace)
fmt.Fprintln(out, "")
err := waitForService(client, name, out, waitFlags.TimeoutInSeconds)
if err != nil {
return err
}
fmt.Fprintln(out, "")
return showUrl(client, name, latestRevisionBeforeUpdate, "updated", out)
} else {
fmt.Fprintf(out, "Service '%s' updated in namespace '%s'.\n", args[0], namespace)

}

return nil
Expand All @@ -135,7 +136,7 @@ func NewServiceUpdateCommand(p *commands.KnParams) *cobra.Command {

commands.AddNamespaceFlags(serviceUpdateCommand.Flags(), false)
editFlags.AddUpdateFlags(serviceUpdateCommand)
waitFlags.AddConditionWaitFlags(serviceUpdateCommand, 60, "Update", "service")
waitFlags.AddConditionWaitFlags(serviceUpdateCommand, commands.WaitDefaultTimeout, "Update", "service")
trafficFlags.Add(serviceUpdateCommand)
return serviceUpdateCommand
}
Expand Down
62 changes: 0 additions & 62 deletions pkg/kn/commands/version.go

This file was deleted.

Loading

0 comments on commit 43d33dd

Please sign in to comment.