From 47219600c290583da34f203752a0394efbcdf103 Mon Sep 17 00:00:00 2001 From: Michael Maximilien Date: Tue, 28 May 2019 15:50:43 -0700 Subject: [PATCH] Regroups code to use subpackages. Finishes issue #66 Creates four subpackages for now: 1. kn/commands - inludes types.go for common struct and other common files and misc commands 2. kn/commands/service - all 'kn service *' commands 3. kn/commands/revision - all 'kn revision *' commands 4. kn/core - contains the root.go and other top level for code and testing 5. refactors: a. split .../commons/human_readable_flags.go into three b. modifies the HumanReadableFlags.ToPrinter to get pass a function that sets the columns and fields Had to refactor all tests to avoid cycles. --- cmd/kn/main.go | 6 +- go.mod | 3 + go.sum | 9 + hack/generate-docs.go | 4 +- pkg/kn/commands/human_readable_flags.go | 61 +++++- .../human_readable_flags.go} | 66 +------ pkg/kn/commands/{ => revision}/revision.go | 5 +- .../{ => revision}/revision_describe.go | 9 +- .../{ => revision}/revision_describe_test.go | 14 +- .../commands/{ => revision}/revision_get.go | 9 +- .../commands/revision/revision_get_flags.go | 71 +++++++ .../{ => revision}/revision_get_test.go | 22 ++- .../{ => service}/configuration_edit_flags.go | 2 +- .../commands/service/human_readable_flags.go | 83 ++++++++ pkg/kn/commands/{ => service}/service.go | 5 +- .../commands/{ => service}/service_create.go | 9 +- .../{ => service}/service_create_test.go | 15 +- .../commands/{ => service}/service_delete.go | 10 +- .../{ => service}/service_describe.go | 10 +- .../{ => service}/service_describe_test.go | 14 +- pkg/kn/commands/{ => service}/service_get.go | 9 +- pkg/kn/commands/service/service_get_flags.go | 71 +++++++ .../{ => service}/service_get_test.go | 14 +- .../commands/{ => service}/service_update.go | 9 +- .../{ => service}/service_update_test.go | 15 +- pkg/kn/commands/service_get_flags.go | 182 ------------------ pkg/kn/commands/test_helper.go | 66 +++++++ pkg/kn/commands/types.go | 52 +++++ pkg/kn/commands/version.go | 1 + pkg/kn/{commands => core}/root.go | 64 ++---- vendor/modules.txt | 50 ++--- 31 files changed, 545 insertions(+), 415 deletions(-) rename pkg/kn/commands/{revision_get_flags.go => revision/human_readable_flags.go} (57%) rename pkg/kn/commands/{ => revision}/revision.go (87%) rename pkg/kn/commands/{ => revision}/revision_describe.go (87%) rename pkg/kn/commands/{ => revision}/revision_describe_test.go (84%) rename pkg/kn/commands/{ => revision}/revision_get.go (88%) create mode 100644 pkg/kn/commands/revision/revision_get_flags.go rename pkg/kn/commands/{ => revision}/revision_get_test.go (85%) rename pkg/kn/commands/{ => service}/configuration_edit_flags.go (99%) create mode 100644 pkg/kn/commands/service/human_readable_flags.go rename pkg/kn/commands/{ => service}/service.go (89%) rename pkg/kn/commands/{ => service}/service_create.go (93%) rename pkg/kn/commands/{ => service}/service_create_test.go (95%) rename pkg/kn/commands/{ => service}/service_delete.go (86%) rename pkg/kn/commands/{ => service}/service_describe.go (88%) rename pkg/kn/commands/{ => service}/service_describe_test.go (84%) rename pkg/kn/commands/{ => service}/service_get.go (88%) create mode 100644 pkg/kn/commands/service/service_get_flags.go rename pkg/kn/commands/{ => service}/service_get_test.go (87%) rename pkg/kn/commands/{ => service}/service_update.go (88%) rename pkg/kn/commands/{ => service}/service_update_test.go (95%) delete mode 100644 pkg/kn/commands/service_get_flags.go create mode 100644 pkg/kn/commands/test_helper.go create mode 100644 pkg/kn/commands/types.go rename pkg/kn/{commands => core}/root.go (65%) diff --git a/cmd/kn/main.go b/cmd/kn/main.go index 7ed049d05b..a261cdb691 100644 --- a/cmd/kn/main.go +++ b/cmd/kn/main.go @@ -18,15 +18,15 @@ import ( "fmt" "os" - "github.com/knative/client/pkg/kn/commands" + "github.com/knative/client/pkg/kn/core" ) func init() { - commands.InitializeConfig() + core.InitializeConfig() } func main() { - err := commands.NewKnCommand().Execute() + err := core.NewKnCommand().Execute() if err != nil { fmt.Fprintln(os.Stderr, err) os.Exit(1) diff --git a/go.mod b/go.mod index ecc1fa1524..3681ccd966 100644 --- a/go.mod +++ b/go.mod @@ -11,12 +11,14 @@ require ( github.com/google/go-cmp v0.3.0 // indirect github.com/google/go-containerregistry v0.0.0-20190503220729-1c6c7f61e8a5 // indirect github.com/google/gofuzz v1.0.0 // indirect + github.com/google/licenseclassifier v0.0.0-20190501212618-47b603fe1b8c // indirect github.com/googleapis/gnostic v0.2.0 // indirect github.com/gregjones/httpcache v0.0.0-20190212212710-3befbb6ad0cc // indirect github.com/hashicorp/golang-lru v0.5.1 // indirect github.com/imdario/mergo v0.3.7 // indirect github.com/inconshreveable/mousetrap v1.0.0 // indirect github.com/json-iterator/go v1.1.6 // indirect + github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024 // indirect github.com/knative/build v0.6.0 // indirect github.com/knative/pkg v0.0.0-20190518173526-34792a92cec2 github.com/knative/serving v0.6.0 @@ -28,6 +30,7 @@ require ( github.com/spf13/cobra v0.0.3 github.com/spf13/pflag v1.0.3 github.com/spf13/viper v1.3.1 + github.com/stretchr/objx v0.2.0 // indirect golang.org/x/net v0.0.0-20190514140710-3ec191127204 // indirect golang.org/x/oauth2 v0.0.0-20190517181255-950ef44c6e07 // indirect golang.org/x/time v0.0.0-20190308202827-9d24e82272b4 // indirect diff --git a/go.sum b/go.sum index 9cb00ba9c1..7e75308691 100644 --- a/go.sum +++ b/go.sum @@ -35,6 +35,7 @@ github.com/coreos/go-semver v0.2.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3Ee github.com/cpuguy83/go-md2man v1.0.10 h1:BSKMNlYxDvnunlTymqtgONjNnaRV1sTpcovwwjF22jk= github.com/cpuguy83/go-md2man v1.0.10/go.mod h1:SmD6nW6nTyfqj6ABTjUi3V3JVMnlJmwcJI5acqYI6dE= github.com/davecgh/go-spew v0.0.0-20151105211317-5215b55f46b2/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/eapache/go-resiliency v1.1.0/go.mod h1:kFI+JgMyC7bLPUVY133qvEBtVayf5mFgVsvEsIPBvNs= @@ -95,6 +96,8 @@ github.com/google/go-containerregistry v0.0.0-20190503220729-1c6c7f61e8a5/go.mod github.com/google/gofuzz v0.0.0-20161122191042-44d81051d367/go.mod h1:HP5RmnzzSNb993RKQDq4+1A4ia9nllfqcQFTQJedwGI= github.com/google/gofuzz v1.0.0 h1:A8PeW59pxE9IoFRqBp37U+mSNaQoZ46F1f0f863XSXw= github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= +github.com/google/licenseclassifier v0.0.0-20190501212618-47b603fe1b8c h1:UmyQvw1iOARMPiuZDuH5T/kkKgdQth4da/uHxNVKK2M= +github.com/google/licenseclassifier v0.0.0-20190501212618-47b603fe1b8c/go.mod h1:qsqn2hxC+vURpyBRygGUuinTO42MFRLcsmQ/P8v94+M= github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs= github.com/google/pprof v0.0.0-20181206194817-3ea8567a2e57/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc= github.com/googleapis/gax-go/v2 v2.0.4 h1:hU4mGcQI4DaAYW+IbTun+2qEZVFxK0ySjQLTbS0VQKc= @@ -125,6 +128,7 @@ github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af/go.mod h1:Nht github.com/json-iterator/go v0.0.0-20180612202835-f2b4162afba3/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU= github.com/json-iterator/go v1.1.6 h1:MrUvLMLTMxbqFJ9kzlvat/rYZqZnW3u4wkLzWTaFwKs= github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU= +github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024 h1:rBMNdlhTLzJjJSDIjNEXX1Pz3Hmwmz91v+zycvx9PJc= github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU= github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w= github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvWXihfKN4Q= @@ -216,6 +220,8 @@ github.com/rcrowley/go-metrics v0.0.0-20181016184325-3113b8401b8a/go.mod h1:bCqn github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg= github.com/russross/blackfriday v1.5.2 h1:HyvC0ARfnZBqnXwABFeSZHpKvJHJJfPz81GNueLj0oo= github.com/russross/blackfriday v1.5.2/go.mod h1:JO/DiYxRf+HjHt06OyowR9PTA263kcR/rfWxYHBV53g= +github.com/sergi/go-diff v1.0.0 h1:Kpca3qRNrduNnOQeazBd0ysaKrUJiIuISHxogkT9RPQ= +github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo= github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo= github.com/spf13/afero v1.1.2 h1:m8/z1t7/fwjysjQRYbP0RD+bUIF/8tJwPdEZsI83ACI= github.com/spf13/afero v1.1.2/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B0CQ= @@ -230,10 +236,13 @@ github.com/spf13/pflag v1.0.3 h1:zPAT6CGy6wXeQ7NtTnaTerfKOsV6V6F8agHXFiazDkg= github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4= github.com/spf13/viper v1.3.1 h1:5+8j8FTpnFV4nEImW/ofkzEt8VoOiLXxdYIDsB73T38= github.com/spf13/viper v1.3.1/go.mod h1:ZiWeW+zYFKm7srdB9IoDzzZXaJaI5eL9QjNiN/DMA2s= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/objx v0.2.0/go.mod h1:qt09Ya8vawLte6SNmTgCsAVtYtaKzEcn8ATUoHMkEqE= github.com/stretchr/testify v0.0.0-20151208002404-e3a8ff8ce365/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w= github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= +github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/ugorji/go/codec v0.0.0-20181204163529-d75b2dcb6bc8/go.mod h1:VFNgLljTbGfSG7qAOspJ7OScBnGdDN/yBr0sguwnwf0= github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q= go.opencensus.io v0.20.1/go.mod h1:6WKK9ahsWS3RSO+PY9ZHZUfv2irvY6gN279GOPZjmmk= diff --git a/hack/generate-docs.go b/hack/generate-docs.go index fa2f82bf33..10b9642d8a 100644 --- a/hack/generate-docs.go +++ b/hack/generate-docs.go @@ -18,12 +18,12 @@ import ( "fmt" "os" - "github.com/knative/client/pkg/kn/commands" + "github.com/knative/client/pkg/kn/core" "github.com/spf13/cobra/doc" ) func main() { - rootCmd := commands.NewKnCommand() + rootCmd := core.NewKnCommand() dir := "." if len(os.Args) > 1 { diff --git a/pkg/kn/commands/human_readable_flags.go b/pkg/kn/commands/human_readable_flags.go index 762dfc0a4b..516bc202d0 100644 --- a/pkg/kn/commands/human_readable_flags.go +++ b/pkg/kn/commands/human_readable_flags.go @@ -15,8 +15,15 @@ package commands import ( + "fmt" + "time" + hprinters "github.com/knative/client/pkg/printers" + "github.com/knative/pkg/apis" + duckv1beta1 "github.com/knative/pkg/apis/duck/v1beta1" "github.com/spf13/cobra" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/util/duration" ) // HumanPrintFlags provides default flags necessary for printing. @@ -34,12 +41,9 @@ func (f *HumanPrintFlags) AllowedFormats() []string { // ToPrinter receives returns a printer capable of // handling human-readable output. -func (f *HumanPrintFlags) ToPrinter() (hprinters.ResourcePrinter, error) { +func (f *HumanPrintFlags) ToPrinter(getHandlerFunc func(h hprinters.PrintHandler)) (hprinters.ResourcePrinter, error) { p := hprinters.NewTablePrinter(hprinters.PrintOptions{}) - // Add the column definitions and respective printing functions for service get command - ServiceGetHandlers(p) - // Add the column definitions and respective printing functions for revision get command - RevisionGetHandlers(p) + getHandlerFunc(p) return p, nil } @@ -54,3 +58,50 @@ func (f *HumanPrintFlags) AddFlags(c *cobra.Command) { func NewHumanPrintFlags() *HumanPrintFlags { return &HumanPrintFlags{} } + +// Private functions + +// conditionsValue returns the True conditions count among total conditions +func ConditionsValue(conditions duckv1beta1.Conditions) string { + var ok int + for _, condition := range conditions { + if condition.Status == "True" { + ok++ + } + } + return fmt.Sprintf("%d OK / %d", ok, len(conditions)) +} + +// readyCondition returns status of resource's Ready type condition +func ReadyCondition(conditions duckv1beta1.Conditions) string { + for _, condition := range conditions { + if condition.Type == apis.ConditionReady { + return string(condition.Status) + } + } + return "" +} + +func NonReadyConditionReason(conditions duckv1beta1.Conditions) string { + for _, condition := range conditions { + if condition.Type == apis.ConditionReady { + if string(condition.Status) == "True" { + return "" + } + if condition.Message != "" { + return fmt.Sprintf("%s : %s", condition.Reason, condition.Message) + } + return string(condition.Reason) + } + } + return "" +} + +// translateTimestampSince returns the elapsed time since timestamp in +// human-readable approximation. +func TranslateTimestampSince(timestamp metav1.Time) string { + if timestamp.IsZero() { + return "" + } + return duration.HumanDuration(time.Since(timestamp.Time)) +} diff --git a/pkg/kn/commands/revision_get_flags.go b/pkg/kn/commands/revision/human_readable_flags.go similarity index 57% rename from pkg/kn/commands/revision_get_flags.go rename to pkg/kn/commands/revision/human_readable_flags.go index ae7ddfab04..dd92c3a3de 100644 --- a/pkg/kn/commands/revision_get_flags.go +++ b/pkg/kn/commands/revision/human_readable_flags.go @@ -8,71 +8,21 @@ // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or im +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. -package commands +package revision import ( + "github.com/knative/client/pkg/kn/commands" hprinters "github.com/knative/client/pkg/printers" serving "github.com/knative/serving/pkg/apis/serving" servingv1alpha1 "github.com/knative/serving/pkg/apis/serving/v1alpha1" - "github.com/spf13/cobra" metav1beta1 "k8s.io/apimachinery/pkg/apis/meta/v1beta1" "k8s.io/apimachinery/pkg/runtime" - "k8s.io/cli-runtime/pkg/genericclioptions" ) -// RevisionGetFlags composes common printer flag structs -// used in the Get command. -type RevisionGetFlags struct { - GenericPrintFlags *genericclioptions.PrintFlags - HumanReadableFlags *HumanPrintFlags -} - -// AllowedFormats is the list of formats in which data can be displayed -func (f *RevisionGetFlags) AllowedFormats() []string { - formats := f.GenericPrintFlags.AllowedFormats() - formats = append(formats, f.HumanReadableFlags.AllowedFormats()...) - return formats -} - -// ToPrinter attempts to find a composed set of RevisionGetFlags suitable for -// returning a printer based on current flag values. -func (f *RevisionGetFlags) ToPrinter() (hprinters.ResourcePrinter, error) { - // if there are flags specified for generic printing - if f.GenericPrintFlags.OutputFlagSpecified() { - p, err := f.GenericPrintFlags.ToPrinter() - if err != nil { - return nil, err - } - return p, nil - } - // if no flags specified, use the table printing - p, err := f.HumanReadableFlags.ToPrinter() - if err != nil { - return nil, err - } - return p, nil -} - -// AddFlags receives a *cobra.Command reference and binds -// flags related to humanreadable and template printing. -func (f *RevisionGetFlags) AddFlags(cmd *cobra.Command) { - f.GenericPrintFlags.AddFlags(cmd) - f.HumanReadableFlags.AddFlags(cmd) -} - -// NewGetPrintFlags returns flags associated with humanreadable, -// template, and "name" printing, with default values set. -func NewRevisionGetFlags() *RevisionGetFlags { - return &RevisionGetFlags{ - GenericPrintFlags: genericclioptions.NewPrintFlags(""), - HumanReadableFlags: NewHumanPrintFlags(), - } -} - // RevisionGetHandlers adds print handlers for revision get command func RevisionGetHandlers(h hprinters.PrintHandler) { RevisionColumnDefinitions := []metav1beta1.TableColumnDefinition{ @@ -87,6 +37,8 @@ func RevisionGetHandlers(h hprinters.PrintHandler) { h.TableHandler(RevisionColumnDefinitions, printRevisionList) } +// Private functions + // printRevisionList populates the knative revision list table rows func printRevisionList(revisionList *servingv1alpha1.RevisionList, options hprinters.PrintOptions) ([]metav1beta1.TableRow, error) { rows := make([]metav1beta1.TableRow, 0, len(revisionList.Items)) @@ -104,10 +56,10 @@ func printRevisionList(revisionList *servingv1alpha1.RevisionList, options hprin func printRevision(revision *servingv1alpha1.Revision, options hprinters.PrintOptions) ([]metav1beta1.TableRow, error) { service := revision.Labels[serving.ConfigurationLabelKey] name := revision.Name - age := translateTimestampSince(revision.CreationTimestamp) - conditions := conditionsValue(revision.Status.Conditions) - ready := readyCondition(revision.Status.Conditions) - reason := nonReadyConditionReason(revision.Status.Conditions) + age := commands.TranslateTimestampSince(revision.CreationTimestamp) + conditions := commands.ConditionsValue(revision.Status.Conditions) + ready := commands.ReadyCondition(revision.Status.Conditions) + reason := commands.NonReadyConditionReason(revision.Status.Conditions) row := metav1beta1.TableRow{ Object: runtime.RawExtension{Object: revision}, } diff --git a/pkg/kn/commands/revision.go b/pkg/kn/commands/revision/revision.go similarity index 87% rename from pkg/kn/commands/revision.go rename to pkg/kn/commands/revision/revision.go index d4746165d6..0b6ae15864 100644 --- a/pkg/kn/commands/revision.go +++ b/pkg/kn/commands/revision/revision.go @@ -12,13 +12,14 @@ // See the License for the specific language governing permissions and // limitations under the License. -package commands +package revision import ( + "github.com/knative/client/pkg/kn/commands" "github.com/spf13/cobra" ) -func NewRevisionCommand(p *KnParams) *cobra.Command { +func NewRevisionCommand(p *commands.KnParams) *cobra.Command { revisionCmd := &cobra.Command{ Use: "revision", Short: "Revision command group", diff --git a/pkg/kn/commands/revision_describe.go b/pkg/kn/commands/revision/revision_describe.go similarity index 87% rename from pkg/kn/commands/revision_describe.go rename to pkg/kn/commands/revision/revision_describe.go index 68c595a0a2..2ca24eb20a 100644 --- a/pkg/kn/commands/revision_describe.go +++ b/pkg/kn/commands/revision/revision_describe.go @@ -12,18 +12,19 @@ // See the License for the specific language governing permissions and // limitations under the License. -package commands +package revision import ( "errors" + "github.com/knative/client/pkg/kn/commands" "github.com/spf13/cobra" v1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime/schema" "k8s.io/cli-runtime/pkg/genericclioptions" ) -func NewRevisionDescribeCommand(p *KnParams) *cobra.Command { +func NewRevisionDescribeCommand(p *commands.KnParams) *cobra.Command { revisionDescribePrintFlags := genericclioptions.NewPrintFlags("").WithDefaultOutput("yaml") revisionDescribeCmd := &cobra.Command{ Use: "describe NAME", @@ -38,7 +39,7 @@ func NewRevisionDescribeCommand(p *KnParams) *cobra.Command { return err } - namespace, err := GetNamespace(cmd) + namespace, err := commands.GetNamespace(cmd) if err != nil { return err } @@ -62,7 +63,7 @@ func NewRevisionDescribeCommand(p *KnParams) *cobra.Command { return nil }, } - AddNamespaceFlags(revisionDescribeCmd.Flags(), false) + commands.AddNamespaceFlags(revisionDescribeCmd.Flags(), false) revisionDescribePrintFlags.AddFlags(revisionDescribeCmd) return revisionDescribeCmd } diff --git a/pkg/kn/commands/revision_describe_test.go b/pkg/kn/commands/revision/revision_describe_test.go similarity index 84% rename from pkg/kn/commands/revision_describe_test.go rename to pkg/kn/commands/revision/revision_describe_test.go index 14aa9708d7..9c1b2af4e5 100644 --- a/pkg/kn/commands/revision_describe_test.go +++ b/pkg/kn/commands/revision/revision_describe_test.go @@ -12,16 +12,14 @@ // See the License for the specific language governing permissions and // limitations under the License. -package commands +package revision import ( - "bytes" "encoding/json" "testing" + "github.com/knative/client/pkg/kn/commands" "github.com/knative/serving/pkg/apis/serving/v1alpha1" - serving "github.com/knative/serving/pkg/client/clientset/versioned/typed/serving/v1alpha1" - "github.com/knative/serving/pkg/client/clientset/versioned/typed/serving/v1alpha1/fake" corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/api/equality" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -31,12 +29,8 @@ import ( ) func fakeRevision(args []string, response *v1alpha1.Revision) (action client_testing.Action, output string, err error) { - buf := new(bytes.Buffer) - fakeServing := &fake.FakeServingV1alpha1{&client_testing.Fake{}} - cmd := NewKnCommand(KnParams{ - Output: buf, - ServingFactory: func() (serving.ServingV1alpha1Interface, error) { return fakeServing, nil }, - }) + knParams := &commands.KnParams{} + cmd, fakeServing, buf := commands.CreateTestKnCommand(NewRevisionCommand(knParams), knParams) fakeServing.AddReactor("*", "*", func(a client_testing.Action) (bool, runtime.Object, error) { action = a diff --git a/pkg/kn/commands/revision_get.go b/pkg/kn/commands/revision/revision_get.go similarity index 88% rename from pkg/kn/commands/revision_get.go rename to pkg/kn/commands/revision/revision_get.go index 33d9f8b965..900a671321 100644 --- a/pkg/kn/commands/revision_get.go +++ b/pkg/kn/commands/revision/revision_get.go @@ -12,18 +12,19 @@ // See the License for the specific language governing permissions and // limitations under the License. -package commands +package revision import ( "fmt" + "github.com/knative/client/pkg/kn/commands" "github.com/spf13/cobra" "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime/schema" ) // NewRevisionGetCommand represents 'kn revision get' command -func NewRevisionGetCommand(p *KnParams) *cobra.Command { +func NewRevisionGetCommand(p *commands.KnParams) *cobra.Command { revisionGetFlags := NewRevisionGetFlags() revisionGetCommand := &cobra.Command{ @@ -34,7 +35,7 @@ func NewRevisionGetCommand(p *KnParams) *cobra.Command { if err != nil { return err } - namespace, err := GetNamespace(cmd) + namespace, err := commands.GetNamespace(cmd) if err != nil { return err } @@ -61,7 +62,7 @@ func NewRevisionGetCommand(p *KnParams) *cobra.Command { return nil }, } - AddNamespaceFlags(revisionGetCommand.Flags(), true) + commands.AddNamespaceFlags(revisionGetCommand.Flags(), true) revisionGetFlags.AddFlags(revisionGetCommand) return revisionGetCommand } diff --git a/pkg/kn/commands/revision/revision_get_flags.go b/pkg/kn/commands/revision/revision_get_flags.go new file mode 100644 index 0000000000..224df10cf2 --- /dev/null +++ b/pkg/kn/commands/revision/revision_get_flags.go @@ -0,0 +1,71 @@ +// Copyright © 2019 The Knative Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or im +// See the License for the specific language governing permissions and +// limitations under the License. + +package revision + +import ( + "github.com/knative/client/pkg/kn/commands" + hprinters "github.com/knative/client/pkg/printers" + "github.com/spf13/cobra" + "k8s.io/cli-runtime/pkg/genericclioptions" +) + +// RevisionGetFlags composes common printer flag structs +// used in the Get command. +type RevisionGetFlags struct { + GenericPrintFlags *genericclioptions.PrintFlags + HumanReadableFlags *commands.HumanPrintFlags +} + +// AllowedFormats is the list of formats in which data can be displayed +func (f *RevisionGetFlags) AllowedFormats() []string { + formats := f.GenericPrintFlags.AllowedFormats() + formats = append(formats, f.HumanReadableFlags.AllowedFormats()...) + return formats +} + +// ToPrinter attempts to find a composed set of RevisionGetFlags suitable for +// returning a printer based on current flag values. +func (f *RevisionGetFlags) ToPrinter() (hprinters.ResourcePrinter, error) { + // if there are flags specified for generic printing + if f.GenericPrintFlags.OutputFlagSpecified() { + p, err := f.GenericPrintFlags.ToPrinter() + if err != nil { + return nil, err + } + return p, nil + } + // if no flags specified, use the table printing + p, err := f.HumanReadableFlags.ToPrinter(RevisionGetHandlers) + if err != nil { + return nil, err + } + return p, nil +} + +// AddFlags receives a *cobra.Command reference and binds +// flags related to humanreadable and template printing. +func (f *RevisionGetFlags) AddFlags(cmd *cobra.Command) { + f.GenericPrintFlags.AddFlags(cmd) + f.HumanReadableFlags.AddFlags(cmd) +} + +// NewGetPrintFlags returns flags associated with humanreadable, +// template, and "name" printing, with default values set. +func NewRevisionGetFlags() *RevisionGetFlags { + return &RevisionGetFlags{ + GenericPrintFlags: genericclioptions.NewPrintFlags(""), + HumanReadableFlags: commands.NewHumanPrintFlags(), + } +} diff --git a/pkg/kn/commands/revision_get_test.go b/pkg/kn/commands/revision/revision_get_test.go similarity index 85% rename from pkg/kn/commands/revision_get_test.go rename to pkg/kn/commands/revision/revision_get_test.go index 9ebab3835b..0a7059b29d 100644 --- a/pkg/kn/commands/revision_get_test.go +++ b/pkg/kn/commands/revision/revision_get_test.go @@ -12,29 +12,23 @@ // See the License for the specific language governing permissions and // limitations under the License. -package commands +package revision import ( - "bytes" "strings" "testing" + "github.com/knative/client/pkg/kn/commands" serving "github.com/knative/serving/pkg/apis/serving" v1alpha1 "github.com/knative/serving/pkg/apis/serving/v1alpha1" - servingclient "github.com/knative/serving/pkg/client/clientset/versioned/typed/serving/v1alpha1" - "github.com/knative/serving/pkg/client/clientset/versioned/typed/serving/v1alpha1/fake" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" client_testing "k8s.io/client-go/testing" ) func fakeRevisionGet(args []string, response *v1alpha1.RevisionList) (action client_testing.Action, output []string, err error) { - buf := new(bytes.Buffer) - fakeServing := &fake.FakeServingV1alpha1{&client_testing.Fake{}} - cmd := NewKnCommand(KnParams{ - Output: buf, - ServingFactory: func() (servingclient.ServingV1alpha1Interface, error) { return fakeServing, nil }, - }) + knParams := &commands.KnParams{} + cmd, fakeServing, buf := commands.CreateTestKnCommand(NewRevisionCommand(knParams), knParams) fakeServing.AddReactor("*", "*", func(a client_testing.Action) (bool, runtime.Object, error) { action = a @@ -82,6 +76,14 @@ func TestRevisionGetDefaultOutput(t *testing.T) { testContains(t, output[2], []string{"bar", "bar-wxyz"}, "value") } +func testContains(t *testing.T, output string, sub []string, element string) { + for _, each := range sub { + if !strings.Contains(output, each) { + t.Errorf("Missing %s: %s", element, each) + } + } +} + func createMockRevisionWithParams(name, svcName string) *v1alpha1.Revision { revision := &v1alpha1.Revision{ TypeMeta: metav1.TypeMeta{ diff --git a/pkg/kn/commands/configuration_edit_flags.go b/pkg/kn/commands/service/configuration_edit_flags.go similarity index 99% rename from pkg/kn/commands/configuration_edit_flags.go rename to pkg/kn/commands/service/configuration_edit_flags.go index 184e046844..e65b354c94 100644 --- a/pkg/kn/commands/configuration_edit_flags.go +++ b/pkg/kn/commands/service/configuration_edit_flags.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package commands +package service import ( "fmt" diff --git a/pkg/kn/commands/service/human_readable_flags.go b/pkg/kn/commands/service/human_readable_flags.go new file mode 100644 index 0000000000..46a04358a9 --- /dev/null +++ b/pkg/kn/commands/service/human_readable_flags.go @@ -0,0 +1,83 @@ +// Copyright © 2019 The Knative Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package service + +import ( + "github.com/knative/client/pkg/kn/commands" + hprinters "github.com/knative/client/pkg/printers" + servingv1alpha1 "github.com/knative/serving/pkg/apis/serving/v1alpha1" + metav1beta1 "k8s.io/apimachinery/pkg/apis/meta/v1beta1" + "k8s.io/apimachinery/pkg/runtime" +) + +// ServiceGetHandlers adds print handlers for service get command +func ServiceGetHandlers(h hprinters.PrintHandler) { + kServiceColumnDefinitions := []metav1beta1.TableColumnDefinition{ + {Name: "Name", Type: "string", Description: "Name of the knative service."}, + {Name: "Domain", Type: "string", Description: "Domain name of the knative service."}, + //{Name: "LastCreatedRevision", Type: "string", Description: "Name of last revision created."}, + //{Name: "LastReadyRevision", Type: "string", Description: "Name of last ready revision."}, + {Name: "Generation", Type: "integer", Description: "Sequence number of 'Generation' of the service that was last processed by the controller."}, + {Name: "Age", Type: "string", Description: "Age of the service."}, + {Name: "Conditions", Type: "string", Description: "Conditions describing statuses of service components."}, + {Name: "Ready", Type: "string", Description: "Ready condition status of the service."}, + {Name: "Reason", Type: "string", Description: "Reason for non-ready condition of the service."}, + } + h.TableHandler(kServiceColumnDefinitions, printKService) + h.TableHandler(kServiceColumnDefinitions, printKServiceList) +} + +// Private functions + +// printKServiceList populates the knative service list table rows +func printKServiceList(kServiceList *servingv1alpha1.ServiceList, options hprinters.PrintOptions) ([]metav1beta1.TableRow, error) { + rows := make([]metav1beta1.TableRow, 0, len(kServiceList.Items)) + for _, ksvc := range kServiceList.Items { + r, err := printKService(&ksvc, options) + if err != nil { + return nil, err + } + rows = append(rows, r...) + } + return rows, nil +} + +// printKService populates the knative service table rows +func printKService(kService *servingv1alpha1.Service, options hprinters.PrintOptions) ([]metav1beta1.TableRow, error) { + name := kService.Name + domain := kService.Status.RouteStatusFields.DeprecatedDomain + //lastCreatedRevision := kService.Status.LatestCreatedRevisionName + //lastReadyRevision := kService.Status.LatestReadyRevisionName + generation := kService.Status.ObservedGeneration + age := commands.TranslateTimestampSince(kService.CreationTimestamp) + conditions := commands.ConditionsValue(kService.Status.Conditions) + ready := commands.ReadyCondition(kService.Status.Conditions) + reason := commands.NonReadyConditionReason(kService.Status.Conditions) + + row := metav1beta1.TableRow{ + Object: runtime.RawExtension{Object: kService}, + } + row.Cells = append(row.Cells, + name, + domain, + //lastCreatedRevision, + //lastReadyRevision, + generation, + age, + conditions, + ready, + reason) + return []metav1beta1.TableRow{row}, nil +} diff --git a/pkg/kn/commands/service.go b/pkg/kn/commands/service/service.go similarity index 89% rename from pkg/kn/commands/service.go rename to pkg/kn/commands/service/service.go index 392c250679..f6caac007d 100644 --- a/pkg/kn/commands/service.go +++ b/pkg/kn/commands/service/service.go @@ -12,13 +12,14 @@ // See the License for the specific language governing permissions and // limitations under the License. -package commands +package service import ( + "github.com/knative/client/pkg/kn/commands" "github.com/spf13/cobra" ) -func NewServiceCommand(p *KnParams) *cobra.Command { +func NewServiceCommand(p *commands.KnParams) *cobra.Command { serviceCmd := &cobra.Command{ Use: "service", Short: "Service command group", diff --git a/pkg/kn/commands/service_create.go b/pkg/kn/commands/service/service_create.go similarity index 93% rename from pkg/kn/commands/service_create.go rename to pkg/kn/commands/service/service_create.go index dcda990958..6339810c6d 100644 --- a/pkg/kn/commands/service_create.go +++ b/pkg/kn/commands/service/service_create.go @@ -12,12 +12,13 @@ // See the License for the specific language governing permissions and // limitations under the License. -package commands +package service import ( "errors" "fmt" + "github.com/knative/client/pkg/kn/commands" servingv1alpha1 "github.com/knative/serving/pkg/apis/serving/v1alpha1" "github.com/spf13/cobra" corev1 "k8s.io/api/core/v1" @@ -25,7 +26,7 @@ import ( v1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) -func NewServiceCreateCommand(p *KnParams) *cobra.Command { +func NewServiceCreateCommand(p *commands.KnParams) *cobra.Command { var editFlags ConfigurationEditFlags serviceCreateCommand := &cobra.Command{ @@ -58,7 +59,7 @@ func NewServiceCreateCommand(p *KnParams) *cobra.Command { return errors.New("requires the image name to run.") } - namespace, err := GetNamespace(cmd) + namespace, err := commands.GetNamespace(cmd) if err != nil { return err } @@ -111,7 +112,7 @@ func NewServiceCreateCommand(p *KnParams) *cobra.Command { return nil }, } - AddNamespaceFlags(serviceCreateCommand.Flags(), false) + commands.AddNamespaceFlags(serviceCreateCommand.Flags(), false) editFlags.AddCreateFlags(serviceCreateCommand) return serviceCreateCommand } diff --git a/pkg/kn/commands/service_create_test.go b/pkg/kn/commands/service/service_create_test.go similarity index 95% rename from pkg/kn/commands/service_create_test.go rename to pkg/kn/commands/service/service_create_test.go index 7cfc014dd6..4476757199 100644 --- a/pkg/kn/commands/service_create_test.go +++ b/pkg/kn/commands/service/service_create_test.go @@ -12,20 +12,18 @@ // See the License for the specific language governing permissions and // limitations under the License. -package commands +package service import ( - "bytes" "errors" "fmt" "reflect" "strings" "testing" + "github.com/knative/client/pkg/kn/commands" servinglib "github.com/knative/client/pkg/serving" "github.com/knative/serving/pkg/apis/serving/v1alpha1" - serving "github.com/knative/serving/pkg/client/clientset/versioned/typed/serving/v1alpha1" - "github.com/knative/serving/pkg/client/clientset/versioned/typed/serving/v1alpha1/fake" corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/api/resource" "k8s.io/apimachinery/pkg/runtime" @@ -37,13 +35,8 @@ func fakeServiceCreate(args []string) ( created *v1alpha1.Service, output string, err error) { - - buf := new(bytes.Buffer) - fakeServing := &fake.FakeServingV1alpha1{&client_testing.Fake{}} - cmd := NewKnCommand(KnParams{ - Output: buf, - ServingFactory: func() (serving.ServingV1alpha1Interface, error) { return fakeServing, nil }, - }) + knParams := &commands.KnParams{} + cmd, fakeServing, buf := commands.CreateTestKnCommand(NewServiceCommand(knParams), knParams) fakeServing.AddReactor("*", "*", func(a client_testing.Action) (bool, runtime.Object, error) { createAction, ok := a.(client_testing.CreateAction) diff --git a/pkg/kn/commands/service_delete.go b/pkg/kn/commands/service/service_delete.go similarity index 86% rename from pkg/kn/commands/service_delete.go rename to pkg/kn/commands/service/service_delete.go index bff303d366..6e782d12fb 100644 --- a/pkg/kn/commands/service_delete.go +++ b/pkg/kn/commands/service/service_delete.go @@ -12,17 +12,19 @@ // See the License for the specific language governing permissions and // limitations under the License. -package commands +package service import ( "errors" "fmt" + + "github.com/knative/client/pkg/kn/commands" "github.com/spf13/cobra" v1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) // NewServiceDeleteCommand represent 'service delete' command -func NewServiceDeleteCommand(p *KnParams) *cobra.Command { +func NewServiceDeleteCommand(p *commands.KnParams) *cobra.Command { serviceDeleteCommand := &cobra.Command{ Use: "delete NAME", Short: "Delete a service.", @@ -41,7 +43,7 @@ func NewServiceDeleteCommand(p *KnParams) *cobra.Command { if err != nil { return err } - namespace, err := GetNamespace(cmd) + namespace, err := commands.GetNamespace(cmd) if err != nil { return err } @@ -57,6 +59,6 @@ func NewServiceDeleteCommand(p *KnParams) *cobra.Command { return nil }, } - AddNamespaceFlags(serviceDeleteCommand.Flags(), false) + commands.AddNamespaceFlags(serviceDeleteCommand.Flags(), false) return serviceDeleteCommand } diff --git a/pkg/kn/commands/service_describe.go b/pkg/kn/commands/service/service_describe.go similarity index 88% rename from pkg/kn/commands/service_describe.go rename to pkg/kn/commands/service/service_describe.go index 7052ddad43..ce462c39cb 100644 --- a/pkg/kn/commands/service_describe.go +++ b/pkg/kn/commands/service/service_describe.go @@ -12,19 +12,19 @@ // See the License for the specific language governing permissions and // limitations under the License. -package commands +package service import ( "errors" + "github.com/knative/client/pkg/kn/commands" "github.com/spf13/cobra" v1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime/schema" "k8s.io/cli-runtime/pkg/genericclioptions" ) -func NewServiceDescribeCommand(p *KnParams) *cobra.Command { - +func NewServiceDescribeCommand(p *commands.KnParams) *cobra.Command { serviceDescribePrintFlags := genericclioptions.NewPrintFlags("").WithDefaultOutput("yaml") serviceDescribeCommand := &cobra.Command{ Use: "describe NAME", @@ -38,7 +38,7 @@ func NewServiceDescribeCommand(p *KnParams) *cobra.Command { return err } - namespace, err := GetNamespace(cmd) + namespace, err := commands.GetNamespace(cmd) if err != nil { return err } @@ -62,7 +62,7 @@ func NewServiceDescribeCommand(p *KnParams) *cobra.Command { return nil }, } - AddNamespaceFlags(serviceDescribeCommand.Flags(), false) + commands.AddNamespaceFlags(serviceDescribeCommand.Flags(), false) serviceDescribePrintFlags.AddFlags(serviceDescribeCommand) return serviceDescribeCommand } diff --git a/pkg/kn/commands/service_describe_test.go b/pkg/kn/commands/service/service_describe_test.go similarity index 84% rename from pkg/kn/commands/service_describe_test.go rename to pkg/kn/commands/service/service_describe_test.go index 4cac4a46c4..a80b139a49 100644 --- a/pkg/kn/commands/service_describe_test.go +++ b/pkg/kn/commands/service/service_describe_test.go @@ -12,16 +12,14 @@ // See the License for the specific language governing permissions and // limitations under the License. -package commands +package service import ( - "bytes" "encoding/json" "testing" + "github.com/knative/client/pkg/kn/commands" "github.com/knative/serving/pkg/apis/serving/v1alpha1" - serving "github.com/knative/serving/pkg/client/clientset/versioned/typed/serving/v1alpha1" - "github.com/knative/serving/pkg/client/clientset/versioned/typed/serving/v1alpha1/fake" "k8s.io/apimachinery/pkg/api/equality" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" @@ -30,12 +28,8 @@ import ( ) func fakeServiceDescribe(args []string, response *v1alpha1.Service) (action client_testing.Action, output string, err error) { - buf := new(bytes.Buffer) - fakeServing := &fake.FakeServingV1alpha1{&client_testing.Fake{}} - cmd := NewKnCommand(KnParams{ - Output: buf, - ServingFactory: func() (serving.ServingV1alpha1Interface, error) { return fakeServing, nil }, - }) + knParams := &commands.KnParams{} + cmd, fakeServing, buf := commands.CreateTestKnCommand(NewServiceCommand(knParams), knParams) fakeServing.AddReactor("*", "*", func(a client_testing.Action) (bool, runtime.Object, error) { action = a diff --git a/pkg/kn/commands/service_get.go b/pkg/kn/commands/service/service_get.go similarity index 88% rename from pkg/kn/commands/service_get.go rename to pkg/kn/commands/service/service_get.go index 1f22129649..6d78d6d6cb 100644 --- a/pkg/kn/commands/service_get.go +++ b/pkg/kn/commands/service/service_get.go @@ -12,18 +12,19 @@ // See the License for the specific language governing permissions and // limitations under the License. -package commands +package service import ( "fmt" + "github.com/knative/client/pkg/kn/commands" "github.com/spf13/cobra" v1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime/schema" ) // NewServiceGetCommand represents 'kn service get' command -func NewServiceGetCommand(p *KnParams) *cobra.Command { +func NewServiceGetCommand(p *commands.KnParams) *cobra.Command { serviceGetFlags := NewServiceGetFlags() serviceGetCommand := &cobra.Command{ @@ -34,7 +35,7 @@ func NewServiceGetCommand(p *KnParams) *cobra.Command { if err != nil { return err } - namespace, err := GetNamespace(cmd) + namespace, err := commands.GetNamespace(cmd) if err != nil { return err } @@ -63,7 +64,7 @@ func NewServiceGetCommand(p *KnParams) *cobra.Command { return nil }, } - AddNamespaceFlags(serviceGetCommand.Flags(), true) + commands.AddNamespaceFlags(serviceGetCommand.Flags(), true) serviceGetFlags.AddFlags(serviceGetCommand) return serviceGetCommand } diff --git a/pkg/kn/commands/service/service_get_flags.go b/pkg/kn/commands/service/service_get_flags.go new file mode 100644 index 0000000000..f54d97671e --- /dev/null +++ b/pkg/kn/commands/service/service_get_flags.go @@ -0,0 +1,71 @@ +// Copyright © 2019 The Knative Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or im +// See the License for the specific language governing permissions and +// limitations under the License. + +package service + +import ( + "github.com/knative/client/pkg/kn/commands" + hprinters "github.com/knative/client/pkg/printers" + "github.com/spf13/cobra" + "k8s.io/cli-runtime/pkg/genericclioptions" +) + +// ServiceGetFlags composes common printer flag structs +// used in the Get command. +type ServiceGetFlags struct { + GenericPrintFlags *genericclioptions.PrintFlags + HumanReadableFlags *commands.HumanPrintFlags +} + +// AllowedFormats is the list of formats in which data can be displayed +func (f *ServiceGetFlags) AllowedFormats() []string { + formats := f.GenericPrintFlags.AllowedFormats() + formats = append(formats, f.HumanReadableFlags.AllowedFormats()...) + return formats +} + +// ToPrinter attempts to find a composed set of ServiceGetFlags suitable for +// returning a printer based on current flag values. +func (f *ServiceGetFlags) ToPrinter() (hprinters.ResourcePrinter, error) { + // if there are flags specified for generic printing + if f.GenericPrintFlags.OutputFlagSpecified() { + p, err := f.GenericPrintFlags.ToPrinter() + if err != nil { + return nil, err + } + return p, nil + } + // if no flags specified, use the table printing + p, err := f.HumanReadableFlags.ToPrinter(ServiceGetHandlers) + if err != nil { + return nil, err + } + return p, nil +} + +// AddFlags receives a *cobra.Command reference and binds +// flags related to humanreadable and template printing. +func (f *ServiceGetFlags) AddFlags(cmd *cobra.Command) { + f.GenericPrintFlags.AddFlags(cmd) + f.HumanReadableFlags.AddFlags(cmd) +} + +// NewGetPrintFlags returns flags associated with humanreadable, +// template, and "name" printing, with default values set. +func NewServiceGetFlags() *ServiceGetFlags { + return &ServiceGetFlags{ + GenericPrintFlags: genericclioptions.NewPrintFlags(""), + HumanReadableFlags: commands.NewHumanPrintFlags(), + } +} diff --git a/pkg/kn/commands/service_get_test.go b/pkg/kn/commands/service/service_get_test.go similarity index 87% rename from pkg/kn/commands/service_get_test.go rename to pkg/kn/commands/service/service_get_test.go index 17ec61e8cf..8988875920 100644 --- a/pkg/kn/commands/service_get_test.go +++ b/pkg/kn/commands/service/service_get_test.go @@ -12,29 +12,23 @@ // See the License for the specific language governing permissions and // limitations under the License. -package commands +package service import ( - "bytes" "strings" "testing" + "github.com/knative/client/pkg/kn/commands" duckv1beta1 "github.com/knative/pkg/apis/duck/v1beta1" v1alpha1 "github.com/knative/serving/pkg/apis/serving/v1alpha1" - servingclient "github.com/knative/serving/pkg/client/clientset/versioned/typed/serving/v1alpha1" - "github.com/knative/serving/pkg/client/clientset/versioned/typed/serving/v1alpha1/fake" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" client_testing "k8s.io/client-go/testing" ) func fakeServiceGet(args []string, response *v1alpha1.ServiceList) (action client_testing.Action, output []string, err error) { - buf := new(bytes.Buffer) - fakeServing := &fake.FakeServingV1alpha1{&client_testing.Fake{}} - cmd := NewKnCommand(KnParams{ - Output: buf, - ServingFactory: func() (servingclient.ServingV1alpha1Interface, error) { return fakeServing, nil }, - }) + knParams := &commands.KnParams{} + cmd, fakeServing, buf := commands.CreateTestKnCommand(NewServiceCommand(knParams), knParams) fakeServing.AddReactor("*", "*", func(a client_testing.Action) (bool, runtime.Object, error) { action = a diff --git a/pkg/kn/commands/service_update.go b/pkg/kn/commands/service/service_update.go similarity index 88% rename from pkg/kn/commands/service_update.go rename to pkg/kn/commands/service/service_update.go index 1fad551b82..88eeb27669 100644 --- a/pkg/kn/commands/service_update.go +++ b/pkg/kn/commands/service/service_update.go @@ -12,16 +12,17 @@ // See the License for the specific language governing permissions and // limitations under the License. -package commands +package service import ( "errors" + "github.com/knative/client/pkg/kn/commands" "github.com/spf13/cobra" v1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) -func NewServiceUpdateCommand(p *KnParams) *cobra.Command { +func NewServiceUpdateCommand(p *commands.KnParams) *cobra.Command { var editFlags ConfigurationEditFlags serviceUpdateCommand := &cobra.Command{ @@ -38,7 +39,7 @@ func NewServiceUpdateCommand(p *KnParams) *cobra.Command { return errors.New("requires the service name.") } - namespace, err := GetNamespace(cmd) + namespace, err := commands.GetNamespace(cmd) if err != nil { return err } @@ -67,7 +68,7 @@ func NewServiceUpdateCommand(p *KnParams) *cobra.Command { return nil }, } - AddNamespaceFlags(serviceUpdateCommand.Flags(), false) + commands.AddNamespaceFlags(serviceUpdateCommand.Flags(), false) editFlags.AddUpdateFlags(serviceUpdateCommand) return serviceUpdateCommand } diff --git a/pkg/kn/commands/service_update_test.go b/pkg/kn/commands/service/service_update_test.go similarity index 95% rename from pkg/kn/commands/service_update_test.go rename to pkg/kn/commands/service/service_update_test.go index 6bbe450ed1..f21e67e7a3 100644 --- a/pkg/kn/commands/service_update_test.go +++ b/pkg/kn/commands/service/service_update_test.go @@ -12,19 +12,17 @@ // See the License for the specific language governing permissions and // limitations under the License. -package commands +package service import ( - "bytes" "errors" "fmt" "reflect" "testing" + "github.com/knative/client/pkg/kn/commands" servinglib "github.com/knative/client/pkg/serving" "github.com/knative/serving/pkg/apis/serving/v1alpha1" - serving "github.com/knative/serving/pkg/client/clientset/versioned/typed/serving/v1alpha1" - "github.com/knative/serving/pkg/client/clientset/versioned/typed/serving/v1alpha1/fake" corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/api/resource" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -37,13 +35,8 @@ func fakeServiceUpdate(original *v1alpha1.Service, args []string) ( updated *v1alpha1.Service, output string, err error) { - - buf := new(bytes.Buffer) - fakeServing := &fake.FakeServingV1alpha1{&client_testing.Fake{}} - cmd := NewKnCommand(KnParams{ - Output: buf, - ServingFactory: func() (serving.ServingV1alpha1Interface, error) { return fakeServing, nil }, - }) + knParams := &commands.KnParams{} + cmd, fakeServing, buf := commands.CreateTestKnCommand(NewServiceCommand(knParams), knParams) fakeServing.AddReactor("update", "*", func(a client_testing.Action) (bool, runtime.Object, error) { updateAction, ok := a.(client_testing.UpdateAction) diff --git a/pkg/kn/commands/service_get_flags.go b/pkg/kn/commands/service_get_flags.go deleted file mode 100644 index 40980e388a..0000000000 --- a/pkg/kn/commands/service_get_flags.go +++ /dev/null @@ -1,182 +0,0 @@ -// Copyright © 2019 The Knative Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or im -// See the License for the specific language governing permissions and -// limitations under the License. - -package commands - -import ( - "fmt" - hprinters "github.com/knative/client/pkg/printers" - "github.com/knative/pkg/apis" - duckv1beta1 "github.com/knative/pkg/apis/duck/v1beta1" - servingv1alpha1 "github.com/knative/serving/pkg/apis/serving/v1alpha1" - "github.com/spf13/cobra" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - metav1beta1 "k8s.io/apimachinery/pkg/apis/meta/v1beta1" - "k8s.io/apimachinery/pkg/runtime" - "k8s.io/apimachinery/pkg/util/duration" - "k8s.io/cli-runtime/pkg/genericclioptions" - "time" -) - -// ServiceGetFlags composes common printer flag structs -// used in the Get command. -type ServiceGetFlags struct { - GenericPrintFlags *genericclioptions.PrintFlags - HumanReadableFlags *HumanPrintFlags -} - -// AllowedFormats is the list of formats in which data can be displayed -func (f *ServiceGetFlags) AllowedFormats() []string { - formats := f.GenericPrintFlags.AllowedFormats() - formats = append(formats, f.HumanReadableFlags.AllowedFormats()...) - return formats -} - -// ToPrinter attempts to find a composed set of ServiceGetFlags suitable for -// returning a printer based on current flag values. -func (f *ServiceGetFlags) ToPrinter() (hprinters.ResourcePrinter, error) { - // if there are flags specified for generic printing - if f.GenericPrintFlags.OutputFlagSpecified() { - p, err := f.GenericPrintFlags.ToPrinter() - if err != nil { - return nil, err - } - return p, nil - } - // if no flags specified, use the table printing - p, err := f.HumanReadableFlags.ToPrinter() - if err != nil { - return nil, err - } - return p, nil -} - -// AddFlags receives a *cobra.Command reference and binds -// flags related to humanreadable and template printing. -func (f *ServiceGetFlags) AddFlags(cmd *cobra.Command) { - f.GenericPrintFlags.AddFlags(cmd) - f.HumanReadableFlags.AddFlags(cmd) -} - -// NewGetPrintFlags returns flags associated with humanreadable, -// template, and "name" printing, with default values set. -func NewServiceGetFlags() *ServiceGetFlags { - return &ServiceGetFlags{ - GenericPrintFlags: genericclioptions.NewPrintFlags(""), - HumanReadableFlags: NewHumanPrintFlags(), - } -} - -// ServiceGetHandlers adds print handlers for service get command -func ServiceGetHandlers(h hprinters.PrintHandler) { - kServiceColumnDefinitions := []metav1beta1.TableColumnDefinition{ - {Name: "Name", Type: "string", Description: "Name of the knative service."}, - {Name: "Domain", Type: "string", Description: "Domain name of the knative service."}, - //{Name: "LastCreatedRevision", Type: "string", Description: "Name of last revision created."}, - //{Name: "LastReadyRevision", Type: "string", Description: "Name of last ready revision."}, - {Name: "Generation", Type: "integer", Description: "Sequence number of 'Generation' of the service that was last processed by the controller."}, - {Name: "Age", Type: "string", Description: "Age of the service."}, - {Name: "Conditions", Type: "string", Description: "Conditions describing statuses of service components."}, - {Name: "Ready", Type: "string", Description: "Ready condition status of the service."}, - {Name: "Reason", Type: "string", Description: "Reason for non-ready condition of the service."}, - } - h.TableHandler(kServiceColumnDefinitions, printKService) - h.TableHandler(kServiceColumnDefinitions, printKServiceList) -} - -// conditionsValue returns the True conditions count among total conditions -func conditionsValue(conditions duckv1beta1.Conditions) string { - var ok int - for _, condition := range conditions { - if condition.Status == "True" { - ok++ - } - } - return fmt.Sprintf("%d OK / %d", ok, len(conditions)) -} - -// readyCondition returns status of resource's Ready type condition -func readyCondition(conditions duckv1beta1.Conditions) string { - for _, condition := range conditions { - if condition.Type == apis.ConditionReady { - return string(condition.Status) - } - } - return "" -} - -func nonReadyConditionReason(conditions duckv1beta1.Conditions) string { - for _, condition := range conditions { - if condition.Type == apis.ConditionReady { - if string(condition.Status) == "True" { - return "" - } - if condition.Message != "" { - return fmt.Sprintf("%s : %s", condition.Reason, condition.Message) - } - return string(condition.Reason) - } - } - return "" -} - -// translateTimestampSince returns the elapsed time since timestamp in -// human-readable approximation. -func translateTimestampSince(timestamp metav1.Time) string { - if timestamp.IsZero() { - return "" - } - return duration.HumanDuration(time.Since(timestamp.Time)) -} - -// printKServiceList populates the knative service list table rows -func printKServiceList(kServiceList *servingv1alpha1.ServiceList, options hprinters.PrintOptions) ([]metav1beta1.TableRow, error) { - rows := make([]metav1beta1.TableRow, 0, len(kServiceList.Items)) - for _, ksvc := range kServiceList.Items { - r, err := printKService(&ksvc, options) - if err != nil { - return nil, err - } - rows = append(rows, r...) - } - return rows, nil -} - -// printKService populates the knative service table rows -func printKService(kService *servingv1alpha1.Service, options hprinters.PrintOptions) ([]metav1beta1.TableRow, error) { - name := kService.Name - domain := kService.Status.RouteStatusFields.DeprecatedDomain - //lastCreatedRevision := kService.Status.LatestCreatedRevisionName - //lastReadyRevision := kService.Status.LatestReadyRevisionName - generation := kService.Status.ObservedGeneration - age := translateTimestampSince(kService.CreationTimestamp) - conditions := conditionsValue(kService.Status.Conditions) - ready := readyCondition(kService.Status.Conditions) - reason := nonReadyConditionReason(kService.Status.Conditions) - - row := metav1beta1.TableRow{ - Object: runtime.RawExtension{Object: kService}, - } - row.Cells = append(row.Cells, - name, - domain, - //lastCreatedRevision, - //lastReadyRevision, - generation, - age, - conditions, - ready, - reason) - return []metav1beta1.TableRow{row}, nil -} diff --git a/pkg/kn/commands/test_helper.go b/pkg/kn/commands/test_helper.go new file mode 100644 index 0000000000..1f7de1398a --- /dev/null +++ b/pkg/kn/commands/test_helper.go @@ -0,0 +1,66 @@ +// Copyright © 2018 The Knative Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package commands + +import ( + "bytes" + "flag" + + serving "github.com/knative/serving/pkg/client/clientset/versioned/typed/serving/v1alpha1" + "github.com/knative/serving/pkg/client/clientset/versioned/typed/serving/v1alpha1/fake" + "github.com/spf13/cobra" + client_testing "k8s.io/client-go/testing" +) + +func CreateTestKnCommand(cmd *cobra.Command, knParams *KnParams) (*cobra.Command, *fake.FakeServingV1alpha1, *bytes.Buffer) { + buf := new(bytes.Buffer) + fakeServing := &fake.FakeServingV1alpha1{&client_testing.Fake{}} + knParams.Output = buf + knParams.ServingFactory = func() (serving.ServingV1alpha1Interface, error) { return fakeServing, nil } + knCommand := newKnCommand(cmd, knParams) + return knCommand, fakeServing, buf +} + +func newKnCommand(subCommand *cobra.Command, params *KnParams) *cobra.Command { + rootCmd := &cobra.Command{ + Use: "kn", + Short: "Knative client", + Long: `Manage your Knative building blocks: + +Serving: Manage your services and release new software to them. +Build: Create builds and keep track of their results. +Eventing: Manage event subscriptions and channels. Connect up event sources.`, + + // Disable docs header + DisableAutoGenTag: true, + + // Affects children as well + SilenceUsage: true, + + // Prevents Cobra from dealing with errors as we deal with them in main.go + SilenceErrors: true, + } + if params.Output != nil { + rootCmd.SetOutput(params.Output) + } + rootCmd.PersistentFlags().StringVar(&CfgFile, "config", "", "config file (default is $HOME/.kn.yaml)") + rootCmd.PersistentFlags().StringVar(&KubeCfgFile, "kubeconfig", "", "kubectl config file (default is $HOME/.kube/config)") + + rootCmd.AddCommand(subCommand) + + // For glog parse error. + flag.CommandLine.Parse([]string{}) + return rootCmd +} diff --git a/pkg/kn/commands/types.go b/pkg/kn/commands/types.go new file mode 100644 index 0000000000..41e7f6d600 --- /dev/null +++ b/pkg/kn/commands/types.go @@ -0,0 +1,52 @@ +// Copyright © 2018 The Knative Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package commands + +import ( + "io" + + serving "github.com/knative/serving/pkg/client/clientset/versioned/typed/serving/v1alpha1" + "k8s.io/client-go/tools/clientcmd" +) + +// CfgFile is Kn's config file is the path for the Kubernetes config +var CfgFile string + +// KubeCfgFile is the path for the Kubernetes config +var KubeCfgFile string + +// Parameters for creating commands. Useful for inserting mocks for testing. +type KnParams struct { + Output io.Writer + ServingFactory func() (serving.ServingV1alpha1Interface, error) +} + +func (c *KnParams) Initialize() { + if c.ServingFactory == nil { + c.ServingFactory = GetConfig + } +} + +func GetConfig() (serving.ServingV1alpha1Interface, error) { + config, err := clientcmd.BuildConfigFromFlags("", KubeCfgFile) + if err != nil { + return nil, err + } + client, err := serving.NewForConfig(config) + if err != nil { + return nil, err + } + return client, nil +} diff --git a/pkg/kn/commands/version.go b/pkg/kn/commands/version.go index fde2360d83..8a69f1f885 100644 --- a/pkg/kn/commands/version.go +++ b/pkg/kn/commands/version.go @@ -16,6 +16,7 @@ package commands import ( "fmt" + "github.com/spf13/cobra" ) diff --git a/pkg/kn/commands/root.go b/pkg/kn/core/root.go similarity index 65% rename from pkg/kn/commands/root.go rename to pkg/kn/core/root.go index 17acc9c2e5..957acb6ec4 100644 --- a/pkg/kn/commands/root.go +++ b/pkg/kn/core/root.go @@ -12,44 +12,29 @@ // See the License for the specific language governing permissions and // limitations under the License. -package commands +package core import ( "flag" "fmt" - "io" "os" "path/filepath" - serving "github.com/knative/serving/pkg/client/clientset/versioned/typed/serving/v1alpha1" + "github.com/knative/client/pkg/kn/commands" + "github.com/knative/client/pkg/kn/commands/revision" + "github.com/knative/client/pkg/kn/commands/service" homedir "github.com/mitchellh/go-homedir" "github.com/spf13/cobra" "github.com/spf13/viper" _ "k8s.io/client-go/plugin/pkg/client/auth/gcp" _ "k8s.io/client-go/plugin/pkg/client/auth/oidc" - "k8s.io/client-go/tools/clientcmd" ) -var cfgFile string -var kubeCfgFile string - -// Parameters for creating commands. Useful for inserting mocks for testing. -type KnParams struct { - Output io.Writer - ServingFactory func() (serving.ServingV1alpha1Interface, error) -} - -func (c *KnParams) Initialize() { - if c.ServingFactory == nil { - c.ServingFactory = GetConfig - } -} - // rootCmd represents the base command when called without any subcommands -func NewKnCommand(params ...KnParams) *cobra.Command { - var p *KnParams +func NewKnCommand(params ...commands.KnParams) *cobra.Command { + var p *commands.KnParams if len(params) == 0 { - p = &KnParams{} + p = &commands.KnParams{} } else if len(params) == 1 { p = ¶ms[0] } else { @@ -78,12 +63,13 @@ Eventing: Manage event subscriptions and channels. Connect up event sources.`, if p.Output != nil { rootCmd.SetOutput(p.Output) } - rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.kn.yaml)") - rootCmd.PersistentFlags().StringVar(&kubeCfgFile, "kubeconfig", "", "kubectl config file (default is $HOME/.kube/config)") - rootCmd.AddCommand(NewServiceCommand(p)) - rootCmd.AddCommand(NewRevisionCommand(p)) - rootCmd.AddCommand(NewCompletionCommand(p)) - rootCmd.AddCommand(NewVersionCommand(p)) + rootCmd.PersistentFlags().StringVar(&commands.CfgFile, "config", "", "config file (default is $HOME/.kn.yaml)") + rootCmd.PersistentFlags().StringVar(&commands.KubeCfgFile, "kubeconfig", "", "kubectl config file (default is $HOME/.kube/config)") + + rootCmd.AddCommand(service.NewServiceCommand(p)) + rootCmd.AddCommand(revision.NewRevisionCommand(p)) + rootCmd.AddCommand(commands.NewCompletionCommand(p)) + rootCmd.AddCommand(commands.NewVersionCommand(p)) // For glog parse error. flag.CommandLine.Parse([]string{}) @@ -97,26 +83,26 @@ func InitializeConfig() { } func initKubeConfig() { - if kubeCfgFile != "" { + if commands.KubeCfgFile != "" { return } if kubeEnvConf, ok := os.LookupEnv("KUBECONFIG"); ok { - kubeCfgFile = kubeEnvConf + commands.KubeCfgFile = kubeEnvConf } else { home, err := homedir.Dir() if err != nil { fmt.Fprintln(os.Stderr, err) os.Exit(1) } - kubeCfgFile = filepath.Join(home, ".kube", "config") + commands.KubeCfgFile = filepath.Join(home, ".kube", "config") } } // initConfig reads in config file and ENV variables if set. func initConfig() { - if cfgFile != "" { + if commands.CfgFile != "" { // Use config file from the flag. - viper.SetConfigFile(cfgFile) + viper.SetConfigFile(commands.CfgFile) } else { // Find home directory. home, err := homedir.Dir() @@ -137,15 +123,3 @@ func initConfig() { fmt.Fprintln(os.Stderr, "Using config file:", viper.ConfigFileUsed()) } } - -func GetConfig() (serving.ServingV1alpha1Interface, error) { - config, err := clientcmd.BuildConfigFromFlags("", kubeCfgFile) - if err != nil { - return nil, err - } - client, err := serving.NewForConfig(config) - if err != nil { - return nil, err - } - return client, nil -} diff --git a/vendor/modules.txt b/vendor/modules.txt index a09b674b03..02aa63c7f8 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -73,17 +73,17 @@ github.com/knative/pkg/kmeta github.com/knative/pkg/ptr github.com/knative/pkg/configmap # github.com/knative/serving v0.6.0 +github.com/knative/serving/pkg/client/clientset/versioned/typed/serving/v1alpha1 +github.com/knative/serving/pkg/client/clientset/versioned/typed/serving/v1alpha1/fake github.com/knative/serving/pkg/apis/serving github.com/knative/serving/pkg/apis/serving/v1alpha1 -github.com/knative/serving/pkg/client/clientset/versioned/typed/serving/v1alpha1 +github.com/knative/serving/pkg/client/clientset/versioned/scheme github.com/knative/serving/pkg/apis/autoscaling github.com/knative/serving/pkg/apis/networking github.com/knative/serving/pkg/apis/networking/v1alpha1 github.com/knative/serving/pkg/apis/serving/v1beta1 -github.com/knative/serving/pkg/client/clientset/versioned/scheme -github.com/knative/serving/pkg/client/clientset/versioned/typed/serving/v1alpha1/fake -github.com/knative/serving/pkg/apis/config github.com/knative/serving/pkg/apis/autoscaling/v1alpha1 +github.com/knative/serving/pkg/apis/config # github.com/knative/test-infra v0.0.0-20190531180034-a3c073a2fea1 github.com/knative/test-infra/scripts # github.com/magiconair/properties v1.8.0 @@ -137,9 +137,9 @@ golang.org/x/oauth2/jwt golang.org/x/sys/unix golang.org/x/sys/windows # golang.org/x/text v0.3.0 +golang.org/x/text/encoding/unicode golang.org/x/text/transform golang.org/x/text/unicode/norm -golang.org/x/text/encoding/unicode golang.org/x/text/encoding golang.org/x/text/encoding/internal golang.org/x/text/encoding/internal/identifier @@ -197,30 +197,32 @@ k8s.io/api/storage/v1 k8s.io/api/storage/v1alpha1 k8s.io/api/storage/v1beta1 # k8s.io/apimachinery v0.0.0-20190221084156-01f179d85dbc -k8s.io/apimachinery/pkg/api/resource k8s.io/apimachinery/pkg/apis/meta/v1 +k8s.io/apimachinery/pkg/util/duration k8s.io/apimachinery/pkg/apis/meta/v1beta1 k8s.io/apimachinery/pkg/runtime k8s.io/apimachinery/pkg/runtime/schema -k8s.io/apimachinery/pkg/util/duration +k8s.io/apimachinery/pkg/api/resource k8s.io/apimachinery/pkg/api/meta k8s.io/apimachinery/pkg/util/runtime k8s.io/apimachinery/pkg/api/equality k8s.io/apimachinery/pkg/api/validation -k8s.io/apimachinery/pkg/util/sets -k8s.io/apimachinery/pkg/util/validation -k8s.io/apimachinery/pkg/apis/meta/v1/unstructured k8s.io/apimachinery/pkg/runtime/serializer k8s.io/apimachinery/pkg/types k8s.io/apimachinery/pkg/watch -k8s.io/apimachinery/pkg/util/intstr +k8s.io/apimachinery/pkg/labels k8s.io/apimachinery/pkg/conversion k8s.io/apimachinery/pkg/fields -k8s.io/apimachinery/pkg/labels k8s.io/apimachinery/pkg/selection -k8s.io/apimachinery/pkg/conversion/queryparams -k8s.io/apimachinery/pkg/util/errors +k8s.io/apimachinery/pkg/util/intstr +k8s.io/apimachinery/pkg/api/errors k8s.io/apimachinery/pkg/util/json +k8s.io/apimachinery/pkg/util/strategicpatch +k8s.io/apimachinery/pkg/util/errors +k8s.io/apimachinery/pkg/util/validation +k8s.io/apimachinery/pkg/util/sets +k8s.io/apimachinery/pkg/apis/meta/v1/unstructured +k8s.io/apimachinery/pkg/conversion/queryparams k8s.io/apimachinery/pkg/util/naming k8s.io/apimachinery/pkg/util/net k8s.io/apimachinery/pkg/util/yaml @@ -230,37 +232,35 @@ k8s.io/apimachinery/pkg/runtime/serializer/json k8s.io/apimachinery/pkg/runtime/serializer/protobuf k8s.io/apimachinery/pkg/runtime/serializer/recognizer k8s.io/apimachinery/pkg/runtime/serializer/versioning -k8s.io/apimachinery/pkg/api/errors k8s.io/apimachinery/pkg/runtime/serializer/streaming k8s.io/apimachinery/third_party/forked/golang/reflect +k8s.io/apimachinery/pkg/util/mergepatch +k8s.io/apimachinery/third_party/forked/golang/json k8s.io/apimachinery/pkg/apis/meta/v1/unstructured/unstructuredscheme k8s.io/apimachinery/pkg/version -k8s.io/apimachinery/pkg/util/strategicpatch k8s.io/apimachinery/pkg/util/cache k8s.io/apimachinery/pkg/util/clock k8s.io/apimachinery/pkg/util/diff k8s.io/apimachinery/pkg/util/wait k8s.io/apimachinery/pkg/util/framer -k8s.io/apimachinery/pkg/util/mergepatch -k8s.io/apimachinery/third_party/forked/golang/json k8s.io/apimachinery/pkg/apis/meta/internalversion # k8s.io/cli-runtime v0.0.0-20190325194458-f2b4781c3ae1 k8s.io/cli-runtime/pkg/genericclioptions k8s.io/cli-runtime/pkg/genericclioptions/printers k8s.io/cli-runtime/pkg/genericclioptions/resource # k8s.io/client-go v0.0.0-20190226174127-78295b709ec6 +k8s.io/client-go/testing +k8s.io/client-go/tools/clientcmd k8s.io/client-go/plugin/pkg/client/auth/gcp k8s.io/client-go/plugin/pkg/client/auth/oidc -k8s.io/client-go/tools/clientcmd k8s.io/client-go/rest -k8s.io/client-go/discovery -k8s.io/client-go/restmapper +k8s.io/client-go/tools/auth k8s.io/client-go/tools/clientcmd/api +k8s.io/client-go/tools/clientcmd/api/latest k8s.io/client-go/util/homedir +k8s.io/client-go/discovery +k8s.io/client-go/restmapper k8s.io/client-go/util/jsonpath -k8s.io/client-go/tools/auth -k8s.io/client-go/tools/clientcmd/api/latest -k8s.io/client-go/testing k8s.io/client-go/dynamic k8s.io/client-go/tools/cache k8s.io/client-go/pkg/version @@ -270,9 +270,9 @@ k8s.io/client-go/tools/metrics k8s.io/client-go/transport k8s.io/client-go/util/cert k8s.io/client-go/util/flowcontrol +k8s.io/client-go/tools/clientcmd/api/v1 k8s.io/client-go/kubernetes/scheme k8s.io/client-go/third_party/forked/golang/template -k8s.io/client-go/tools/clientcmd/api/v1 k8s.io/client-go/tools/pager k8s.io/client-go/util/buffer k8s.io/client-go/util/retry