Skip to content

Commit

Permalink
fix(serving): Remove hardcoded GVK and look it up from schema
Browse files Browse the repository at this point in the history
  • Loading branch information
rhuss committed Jul 8, 2019
1 parent ca90232 commit 81e6b76
Show file tree
Hide file tree
Showing 40 changed files with 1,473 additions and 508 deletions.
25 changes: 9 additions & 16 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,23 @@ module github.com/knative/client

require (
github.com/cpuguy83/go-md2man v1.0.10 // indirect
github.com/evanphx/json-patch v4.2.0+incompatible // 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/protobuf v1.3.1 // indirect
github.com/google/btree v1.0.0 // indirect
github.com/google/go-cmp v0.3.0 // indirect
github.com/google/go-containerregistry v0.0.0-20190503220729-1c6c7f61e8a5 // indirect
github.com/google/go-containerregistry v0.0.0-20190623150931-ca8b66cb1b79 // 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/googleapis/gnostic v0.3.0 // indirect
github.com/gregjones/httpcache v0.0.0-20190611155906-901d90724c79 // 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/build v0.7.0 // indirect
github.com/knative/pkg v0.0.0-20190617142447-13b093adc272
github.com/knative/serving v0.6.0
github.com/knative/test-infra v0.0.0-20190702025031-91d37e4abc30
github.com/mattbaird/jsonpatch v0.0.0-20171005235357-81af80346b1a // indirect
Expand All @@ -31,20 +29,15 @@ 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
go.uber.org/atomic v1.4.0 // indirect
go.uber.org/multierr v1.1.0 // indirect
go.uber.org/zap v1.10.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/net v0.0.0-20190628185345-da137c7871d7 // indirect
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45 // indirect
golang.org/x/time v0.0.0-20190308202827-9d24e82272b4 // indirect
golang.org/x/tools v0.0.0-20190628034336-212fb13d595e // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gotest.tools v2.2.0+incompatible
k8s.io/api v0.0.0-20190226173710-145d52631d00
k8s.io/apimachinery v0.0.0-20190221084156-01f179d85dbc
k8s.io/cli-runtime v0.0.0-20190325194458-f2b4781c3ae1
k8s.io/client-go v0.0.0-20190226174127-78295b709ec6
k8s.io/kube-openapi v0.0.0-20190510232812-a01b7d5d6c22 // indirect
k8s.io/kube-openapi v0.0.0-20190603182131-db7b694dc208 // indirect
sigs.k8s.io/yaml v1.1.0
)
10 changes: 10 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ github.com/evanphx/json-patch v4.1.0+incompatible h1:K1MDoo4AZ4wU0GIU/fPmtZg7Vpz
github.com/evanphx/json-patch v4.1.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLiYLvXMP4fmwYFNcr97nuDLSk=
github.com/evanphx/json-patch v4.2.0+incompatible h1:fUDGZCv/7iAN7u0puUVhvKCcsR6vRfwrJatElLBEf0I=
github.com/evanphx/json-patch v4.2.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLiYLvXMP4fmwYFNcr97nuDLSk=
github.com/evanphx/json-patch v4.5.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLiYLvXMP4fmwYFNcr97nuDLSk=
github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I=
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
github.com/ghodss/yaml v0.0.0-20150909031657-73d445a93680 h1:ZktWZesgun21uEDrwW7iEV1zPCGQldM2atlJZ3TdvVM=
Expand Down Expand Up @@ -93,6 +94,7 @@ github.com/google/go-containerregistry v0.0.0-20190424210018-7d6d1d3cd63b h1:3Kv
github.com/google/go-containerregistry v0.0.0-20190424210018-7d6d1d3cd63b/go.mod h1:yZAFP63pRshzrEYLXLGPmUt0Ay+2zdjmMN1loCnRLUk=
github.com/google/go-containerregistry v0.0.0-20190503220729-1c6c7f61e8a5 h1:wXZCVr9/0naJbZhAzKDzj/sgnduf8qn9ldjkI/CND9k=
github.com/google/go-containerregistry v0.0.0-20190503220729-1c6c7f61e8a5/go.mod h1:yZAFP63pRshzrEYLXLGPmUt0Ay+2zdjmMN1loCnRLUk=
github.com/google/go-containerregistry v0.0.0-20190623150931-ca8b66cb1b79/go.mod h1:yZAFP63pRshzrEYLXLGPmUt0Ay+2zdjmMN1loCnRLUk=
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=
Expand All @@ -105,10 +107,12 @@ github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+
github.com/googleapis/gnostic v0.0.0-20170426233943-68f4ded48ba9/go.mod h1:sJBsCZ4ayReDTBIg8b9dl28c5xFWyhBTVRp3pOg5EKY=
github.com/googleapis/gnostic v0.2.0 h1:l6N3VoaVzTncYYW+9yOz2LJJammFZGBO13sqgEhpy9g=
github.com/googleapis/gnostic v0.2.0/go.mod h1:sJBsCZ4ayReDTBIg8b9dl28c5xFWyhBTVRp3pOg5EKY=
github.com/googleapis/gnostic v0.3.0/go.mod h1:sJBsCZ4ayReDTBIg8b9dl28c5xFWyhBTVRp3pOg5EKY=
github.com/gorilla/context v1.1.1/go.mod h1:kBGZzfjB9CEq2AlWe17Uuf7NDRt0dE0s8S51q0aT7Yg=
github.com/gorilla/mux v1.6.2/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2zaAs=
github.com/gregjones/httpcache v0.0.0-20190212212710-3befbb6ad0cc h1:f8eY6cV/x1x+HLjOp4r72s/31/V2aTUtg5oKRRPf8/Q=
github.com/gregjones/httpcache v0.0.0-20190212212710-3befbb6ad0cc/go.mod h1:FecbI9+v66THATjSRHfNgh1IVFe/9kFxbXtjV0ctIMA=
github.com/gregjones/httpcache v0.0.0-20190611155906-901d90724c79/go.mod h1:FecbI9+v66THATjSRHfNgh1IVFe/9kFxbXtjV0ctIMA=
github.com/grpc-ecosystem/grpc-gateway v1.8.5 h1:2+KSC78XiO6Qy0hIjfc1OD9H+hsaJdJlb8Kqsd41CTE=
github.com/grpc-ecosystem/grpc-gateway v1.8.5/go.mod h1:vNeuVxBJEsws4ogUvrchl83t/GYV9WGTSLVdBhOQFDY=
github.com/hashicorp/golang-lru v0.5.0 h1:CL2msUPvZTLb5O648aiLNJw3hnBxN2+1Jq8rCOH9wdo=
Expand Down Expand Up @@ -137,10 +141,12 @@ github.com/knative/build v0.5.0 h1:q2W4+BmT3jEOSOXZ44UXndJUAHLWUd20QtMQAFGWzsU=
github.com/knative/build v0.5.0/go.mod h1:/sU74ZQkwlYA5FwYDJhYTy61i/Kn+5eWfln2jDbw3Qo=
github.com/knative/build v0.6.0 h1:tAhqGbRL3/wFOfEc4srO8XDNV8DxUE+z6TzKW0JPWsE=
github.com/knative/build v0.6.0/go.mod h1:/sU74ZQkwlYA5FwYDJhYTy61i/Kn+5eWfln2jDbw3Qo=
github.com/knative/build v0.7.0/go.mod h1:/sU74ZQkwlYA5FwYDJhYTy61i/Kn+5eWfln2jDbw3Qo=
github.com/knative/pkg v0.0.0-20190329155329-916205998db9 h1:DnGe2nwEq+ibifGZt4HoD4akmX1K9Tcx3CjNwFpSZow=
github.com/knative/pkg v0.0.0-20190329155329-916205998db9/go.mod h1:7Ijfhw7rfB+H9VtosIsDYvZQ+qYTz7auK3fHW/5z4ww=
github.com/knative/pkg v0.0.0-20190518173526-34792a92cec2 h1:OA4f02os85BMZbC6DxNL5gbGHRxPgjQW+IDENES7QFc=
github.com/knative/pkg v0.0.0-20190518173526-34792a92cec2/go.mod h1:7Ijfhw7rfB+H9VtosIsDYvZQ+qYTz7auK3fHW/5z4ww=
github.com/knative/pkg v0.0.0-20190617142447-13b093adc272/go.mod h1:7Ijfhw7rfB+H9VtosIsDYvZQ+qYTz7auK3fHW/5z4ww=
github.com/knative/serving v0.5.2 h1:jsmeIN7B6oDHrK0jmtFRf7hWWr+KrjXVHuArK8jo5Nw=
github.com/knative/serving v0.5.2/go.mod h1:ljvMfwQy2qanaM/8xnBSK4Mz3Vv2NawC2fo5kFRJS1A=
github.com/knative/serving v0.6.0 h1:2SOr1jAvrUPO1y0mJvpiTe3bJTSMd2tKXflmHCM0MAA=
Expand Down Expand Up @@ -290,13 +296,15 @@ golang.org/x/net v0.0.0-20190424112056-4829fb13d2c6 h1:FP8hkuE6yUEaJnK7O2eTuejKW
golang.org/x/net v0.0.0-20190424112056-4829fb13d2c6/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190514140710-3ec191127204 h1:4yG6GqBtw9C+UrLp6s2wtSniayy/Vd/3F7ffLE427XI=
golang.org/x/net v0.0.0-20190514140710-3ec191127204/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190628185345-da137c7871d7/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
golang.org/x/oauth2 v0.0.0-20190319182350-c85d3e98c914/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
golang.org/x/oauth2 v0.0.0-20190402181905-9f3314589c9a h1:tImsplftrFpALCYumobsd0K86vlAs/eXGFms2txfJfA=
golang.org/x/oauth2 v0.0.0-20190402181905-9f3314589c9a/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
golang.org/x/oauth2 v0.0.0-20190517181255-950ef44c6e07 h1:XC1K3wNjuz44KaI+cj85C9TW85w/46RH7J+DTXNH5Wk=
golang.org/x/oauth2 v0.0.0-20190517181255-950ef44c6e07/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4 h1:YUO/7uOKsKeq9UokNS62b8FYywz3ker1l1vDZRCRefw=
Expand Down Expand Up @@ -385,7 +393,9 @@ k8s.io/kube-openapi v0.0.0-20190418160015-6b3d3b2d5666 h1:hlzz2EvLPcefAcG/j0tOZp
k8s.io/kube-openapi v0.0.0-20190418160015-6b3d3b2d5666/go.mod h1:jqYp7BKXW0Jl+F1dWXBieUmcHKMPpGHGWA0uqfpOZZ4=
k8s.io/kube-openapi v0.0.0-20190510232812-a01b7d5d6c22 h1:f0BTap/vrgs21vVbJ1ySdsNtcivpA1x4ut6Wla9HKKw=
k8s.io/kube-openapi v0.0.0-20190510232812-a01b7d5d6c22/go.mod h1:iU+ZGYsNlvU9XKUSso6SQfKTCCw7lFduMZy26Mgr2Fw=
k8s.io/kube-openapi v0.0.0-20190603182131-db7b694dc208/go.mod h1:nfDlWeOsu3pUf4yWGL+ERqohP4YsZcBJXWMK+gkzOA4=
sigs.k8s.io/structured-merge-diff v0.0.0-20181214233322-d43a45b8663b/go.mod h1:wWxsB5ozmmv/SG7nM11ayaAW51xMvak/t1r0CSlcokI=
sigs.k8s.io/structured-merge-diff v0.0.0-20190426204423-ea680f03cc65/go.mod h1:wWxsB5ozmmv/SG7nM11ayaAW51xMvak/t1r0CSlcokI=
sigs.k8s.io/structured-merge-diff v0.0.0-20190525122527-15d366b2352e/go.mod h1:wWxsB5ozmmv/SG7nM11ayaAW51xMvak/t1r0CSlcokI=
sigs.k8s.io/yaml v1.1.0 h1:4A07+ZFc2wgJwo8YNlQpr1rVlgUDlxXHhPJciaPY5gs=
sigs.k8s.io/yaml v1.1.0/go.mod h1:UJmg0vDUVViEyp3mgSv9WPwZCDxu4rQW1olrI1uml+o=
15 changes: 13 additions & 2 deletions pkg/kn/commands/namespaced.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func AddNamespaceFlags(flags *pflag.FlagSet, allowAll bool) {
}

// GetNamespace returns namespace from command specified by flag
func (kn *KnParams) GetNamespace(cmd *cobra.Command) (string, error) {
func (params *KnParams) GetNamespace(cmd *cobra.Command) (string, error) {
namespace := cmd.Flag("namespace").Value.String()
// check value of all-namepace only if its defined
if cmd.Flags().Lookup("all-namespaces") != nil {
Expand All @@ -55,10 +55,21 @@ func (kn *KnParams) GetNamespace(cmd *cobra.Command) (string, error) {
// if all-namepaces=False or namespace not given, use default namespace
if namespace == "" {
var err error
namespace, err = kn.NamespaceFactory()
namespace, err = params.CurrentNamespace()
if err != nil {
return "", err
}
}
return namespace, nil
}

func (params *KnParams) CurrentNamespace() (string, error) {
if params.fixedCurrentNamespace != "" {
return params.fixedCurrentNamespace, nil
}
if params.ClientConfig == nil {
params.ClientConfig = params.GetClientConfig()
}
name, _, err := params.ClientConfig.Namespace()
return name, err
}
10 changes: 5 additions & 5 deletions pkg/kn/commands/namespaced_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func TestGetNamespaceSample(t *testing.T) {
expectedNamespace := "test1"
testCmd.SetArgs([]string{"--namespace", expectedNamespace})
testCmd.Execute()
kp := &KnParams{NamespaceFactory: func() (string, error) { return FakeNamespace, nil }}
kp := &KnParams{fixedCurrentNamespace: FakeNamespace}
actualNamespace, err := kp.GetNamespace(testCmd)
if err != nil {
t.Fatal(err)
Expand All @@ -52,7 +52,7 @@ func TestGetNamespaceDefault(t *testing.T) {
testCmd := testCommandGenerator(true)
expectedNamespace := "current"
testCmd.Execute()
kp := &KnParams{NamespaceFactory: func() (string, error) { return FakeNamespace, nil }}
kp := &KnParams{fixedCurrentNamespace: FakeNamespace}
actualNamespace, err := kp.GetNamespace(testCmd)
if err != nil {
t.Fatal(err)
Expand All @@ -70,7 +70,7 @@ func TestGetNamespaceAllNamespacesSet(t *testing.T) {
sampleNamespace := "test1"
testCmd.SetArgs([]string{"--namespace", sampleNamespace, "--all-namespaces"})
testCmd.Execute()
kp := &KnParams{NamespaceFactory: func() (string, error) { return FakeNamespace, nil }}
kp := &KnParams{fixedCurrentNamespace: FakeNamespace}
actualNamespace, err := kp.GetNamespace(testCmd)
if err != nil {
t.Fatal(err)
Expand All @@ -87,7 +87,7 @@ func TestGetNamespaceDefaultAllNamespacesUnset(t *testing.T) {
expectedNamespace := ""
testCmd.SetArgs([]string{"--all-namespaces"})
testCmd.Execute()
kp := &KnParams{NamespaceFactory: func() (string, error) { return FakeNamespace, nil }}
kp := &KnParams{fixedCurrentNamespace: FakeNamespace}
actualNamespace, err := kp.GetNamespace(testCmd)
if err != nil {
t.Fatal(err)
Expand All @@ -103,7 +103,7 @@ func TestGetNamespaceAllNamespacesNotDefined(t *testing.T) {
expectedNamespace := "test1"
testCmd.SetArgs([]string{"--namespace", expectedNamespace})
testCmd.Execute()
kp := &KnParams{NamespaceFactory: func() (string, error) { return FakeNamespace, nil }}
kp := &KnParams{fixedCurrentNamespace: FakeNamespace}
actualNamespace, err := kp.GetNamespace(testCmd)
if err != nil {
t.Fatal(err)
Expand Down
13 changes: 5 additions & 8 deletions pkg/kn/commands/revision/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ import (
"errors"
"fmt"

"github.com/knative/client/pkg/kn/commands"
"github.com/spf13/cobra"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

"github.com/knative/client/pkg/kn/commands"
)

// NewRevisionDeleteCommand represent 'revision delete' command
Expand All @@ -35,18 +35,15 @@ func NewRevisionDeleteCommand(p *commands.KnParams) *cobra.Command {
if len(args) != 1 {
return errors.New("'revision delete' requires the revision name given as single argument")
}
client, err := p.ServingFactory()
namespace, err := p.GetNamespace(cmd)
if err != nil {
return err
}
namespace, err := p.GetNamespace(cmd)
client, err := p.NewClient(namespace)
if err != nil {
return err
}
err = client.Revisions(namespace).Delete(
args[0],
&metav1.DeleteOptions{},
)
err = client.DeleteRevision(args[0])
if err != nil {
return err
}
Expand Down
15 changes: 5 additions & 10 deletions pkg/kn/commands/revision/revision_describe.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ import (

"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"
)

Expand All @@ -34,16 +32,16 @@ func NewRevisionDescribeCommand(p *commands.KnParams) *cobra.Command {
return errors.New("requires the revision name.")
}

client, err := p.ServingFactory()
namespace, err := p.GetNamespace(cmd)
if err != nil {
return err
}

namespace, err := p.GetNamespace(cmd)
client, err := p.NewClient(namespace)
if err != nil {
return err
}
revision, err := client.Revisions(namespace).Get(args[0], v1.GetOptions{})

revision, err := client.GetRevision(args[0])
if err != nil {
return err
}
Expand All @@ -52,10 +50,7 @@ func NewRevisionDescribeCommand(p *commands.KnParams) *cobra.Command {
if err != nil {
return err
}
revision.GetObjectKind().SetGroupVersionKind(schema.GroupVersionKind{
Group: "knative.dev",
Version: "v1alpha1",
Kind: "Revision"})

err = printer.PrintObj(revision, cmd.OutOrStdout())
if err != nil {
return err
Expand Down
55 changes: 29 additions & 26 deletions pkg/kn/commands/revision/revision_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,10 @@ package revision
import (
"fmt"

"github.com/knative/client/pkg/kn/commands"
"github.com/knative/serving/pkg/apis/serving"
"github.com/knative/serving/pkg/apis/serving/v1alpha1"
"github.com/spf13/cobra"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/runtime/schema"

"github.com/knative/client/pkg/kn/commands"
)

// NewRevisionListCommand represents 'kn revision list' command
Expand All @@ -40,42 +38,47 @@ func NewRevisionListCommand(p *commands.KnParams) *cobra.Command {
# List revisions for a service 'svc1' in namespace 'myapp'
kn revision list -s svc1 -n myapp`,
RunE: func(cmd *cobra.Command, args []string) error {
client, err := p.ServingFactory()
namespace, err := p.GetNamespace(cmd)
if err != nil {
return err
}
namespace, err := p.GetNamespace(cmd)
client, err := p.NewClient(namespace)
if err != nil {
return err
}
listOptions := v1.ListOptions{}
var revisionList *v1alpha1.RevisionList
if cmd.Flags().Changed("service") {
service := cmd.Flag("service").Value.String()
// Ensure requested service exist
_, err := client.Services(namespace).Get(service, v1.GetOptions{})
serviceName := cmd.Flag("service").Value.String()

// Verify that service exists
_, err := client.GetService(serviceName)
if err != nil {
return err
}
listOptions.LabelSelector = labels.Set(
map[string]string{serving.ServiceLabelKey: service}).String()
}
revision, err := client.Revisions(namespace).List(listOptions)
if err != nil {
return err
}
if len(revision.Items) == 0 {
fmt.Fprintf(cmd.OutOrStdout(), "No resources found.\n")
return nil
revisionList, err = client.ListRevisionsForService(serviceName)
if err != nil {
return err
}
if len(revisionList.Items) == 0 {
fmt.Fprintf(cmd.OutOrStdout(), "No revisions found for service '%s'.\n", serviceName)
return nil
}
} else {
revisionList, err = client.ListRevisions()
if err != nil {
return err
}
if len(revisionList.Items) == 0 {
fmt.Fprintf(cmd.OutOrStdout(), "No revisions found.\n")
return nil
}
}
revision.GetObjectKind().SetGroupVersionKind(schema.GroupVersionKind{
Group: "knative.dev",
Version: "v1alpha1",
Kind: "revision"})

printer, err := revisionListFlags.ToPrinter()
if err != nil {
return err
}
err = printer.PrintObj(revision, cmd.OutOrStdout())
err = printer.PrintObj(revisionList, cmd.OutOrStdout())
if err != nil {
return err
}
Expand Down
Loading

0 comments on commit 81e6b76

Please sign in to comment.