From 1387781ca65ba5b3900ab4557949d8f60dde6599 Mon Sep 17 00:00:00 2001 From: Navid Shaikh Date: Thu, 12 Nov 2020 14:46:34 +0530 Subject: [PATCH 1/2] Embed the namespace in request body while creating channels since on the eventing side, defaulting for channel isnt picking the namespace from the context (see https://github.com/knative/eventing/issues/4514) workaround for #1100 this changeset should be reverted when eventing#4514 is resolved --- pkg/kn/commands/channel/channel_test.go | 4 ++-- pkg/kn/commands/channel/create.go | 2 +- pkg/kn/commands/channel/create_test.go | 4 ++-- pkg/kn/commands/channel/describe_test.go | 2 +- pkg/kn/commands/channel/list_test.go | 4 ++-- pkg/messaging/v1beta1/channels_client.go | 5 +++-- 6 files changed, 11 insertions(+), 10 deletions(-) diff --git a/pkg/kn/commands/channel/channel_test.go b/pkg/kn/commands/channel/channel_test.go index 861c1d9e3c..f015f7c33d 100644 --- a/pkg/kn/commands/channel/channel_test.go +++ b/pkg/kn/commands/channel/channel_test.go @@ -76,6 +76,6 @@ func cleanupChannelMockClient() { channelClientFactory = nil } -func createChannel(name string, gvk *schema.GroupVersionKind) *v1beta1.Channel { - return clientv1beta1.NewChannelBuilder(name).Type(gvk).Build() +func createChannel(name, namespace string, gvk *schema.GroupVersionKind) *v1beta1.Channel { + return clientv1beta1.NewChannelBuilder(name, namespace).Type(gvk).Build() } diff --git a/pkg/kn/commands/channel/create.go b/pkg/kn/commands/channel/create.go index 8f5e2251e6..f952b50744 100644 --- a/pkg/kn/commands/channel/create.go +++ b/pkg/kn/commands/channel/create.go @@ -60,7 +60,7 @@ func NewChannelCreateCommand(p *commands.KnParams) *cobra.Command { return err } - cb := knmessagingv1beta1.NewChannelBuilder(name) + cb := knmessagingv1beta1.NewChannelBuilder(name, namespace) if cmd.Flag("type").Changed { gvk, err := ctypeFlags.Parse() diff --git a/pkg/kn/commands/channel/create_test.go b/pkg/kn/commands/channel/create_test.go index b8649793b6..45b35088b8 100644 --- a/pkg/kn/commands/channel/create_test.go +++ b/pkg/kn/commands/channel/create_test.go @@ -43,7 +43,7 @@ func TestCreateChannelErrorCaseTypeFormat(t *testing.T) { func TestCreateChannelDefaultChannel(t *testing.T) { cClient := v1beta1.NewMockKnChannelsClient(t) cRecorder := cClient.Recorder() - cRecorder.CreateChannel(createChannel("pipe", nil), nil) + cRecorder.CreateChannel(createChannel("pipe", "default", nil), nil) out, err := executeChannelCommand(cClient, "create", "pipe") assert.NilError(t, err, "channel should be created") assert.Assert(t, util.ContainsAll(out, "created", "pipe", "default")) @@ -53,7 +53,7 @@ func TestCreateChannelDefaultChannel(t *testing.T) { func TestCreateChannelWithTypeFlagInMemoryChannel(t *testing.T) { cClient := v1beta1.NewMockKnChannelsClient(t) cRecorder := cClient.Recorder() - cRecorder.CreateChannel(createChannel("pipe", &schema.GroupVersionKind{Group: "messaging.knative.dev", Version: "v1beta1", Kind: "InMemoryChannel"}), nil) + cRecorder.CreateChannel(createChannel("pipe", "default", &schema.GroupVersionKind{Group: "messaging.knative.dev", Version: "v1beta1", Kind: "InMemoryChannel"}), nil) out, err := executeChannelCommand(cClient, "create", "pipe", "--type", "imcv1beta1") assert.NilError(t, err, "channel should be created") assert.Assert(t, util.ContainsAll(out, "created", "pipe", "default")) diff --git a/pkg/kn/commands/channel/describe_test.go b/pkg/kn/commands/channel/describe_test.go index dc153a6557..70154cdabb 100644 --- a/pkg/kn/commands/channel/describe_test.go +++ b/pkg/kn/commands/channel/describe_test.go @@ -45,7 +45,7 @@ func TestDescribeChannelErrorCaseNotFound(t *testing.T) { func TestDescribeChannel(t *testing.T) { cClient := v1beta1.NewMockKnChannelsClient(t) cRecorder := cClient.Recorder() - cRecorder.GetChannel("pipe", createChannel("pipe", &schema.GroupVersionKind{Group: "messaging.knative.dev", Version: "v1beta1", Kind: "InMemoryChannel"}), nil) + cRecorder.GetChannel("pipe", createChannel("pipe", "default", &schema.GroupVersionKind{Group: "messaging.knative.dev", Version: "v1beta1", Kind: "InMemoryChannel"}), nil) out, err := executeChannelCommand(cClient, "describe", "pipe") assert.NilError(t, err, "channel should be described") assert.Assert(t, util.ContainsAll(out, "messaging.knative.dev", "v1beta1", "InMemoryChannel", "pipe")) diff --git a/pkg/kn/commands/channel/list_test.go b/pkg/kn/commands/channel/list_test.go index c9116338eb..1329396826 100644 --- a/pkg/kn/commands/channel/list_test.go +++ b/pkg/kn/commands/channel/list_test.go @@ -41,8 +41,8 @@ func TestChannelList(t *testing.T) { cRecorder := cClient.Recorder() clist := &messagingv1beta1.ChannelList{} clist.Items = []messagingv1beta1.Channel{ - *createChannel("c0", &schema.GroupVersionKind{Group: "messaging.knative.dev", Version: "v1beta1", Kind: "InMemoryChannel"}), - *createChannel("c1", &schema.GroupVersionKind{Group: "messaging.knative.dev", Version: "v1beta1", Kind: "InMemoryChannel"}), + *createChannel("c0", "default", &schema.GroupVersionKind{Group: "messaging.knative.dev", Version: "v1beta1", Kind: "InMemoryChannel"}), + *createChannel("c1", "default", &schema.GroupVersionKind{Group: "messaging.knative.dev", Version: "v1beta1", Kind: "InMemoryChannel"}), } cRecorder.ListChannel(clist, nil) out, err := executeChannelCommand(cClient, "list") diff --git a/pkg/messaging/v1beta1/channels_client.go b/pkg/messaging/v1beta1/channels_client.go index 2c93e5cbe1..a247b8b261 100644 --- a/pkg/messaging/v1beta1/channels_client.go +++ b/pkg/messaging/v1beta1/channels_client.go @@ -122,10 +122,11 @@ type ChannelBuilder struct { } // NewChannelBuilder for building Channel object -func NewChannelBuilder(name string) *ChannelBuilder { +func NewChannelBuilder(name, namespace string) *ChannelBuilder { return &ChannelBuilder{channel: &v1beta1.Channel{ ObjectMeta: metav1.ObjectMeta{ - Name: name, + Name: name, + Namespace: namespace, }, }} } From c455c9729ea08f7f0abe6b92ce87146902d0f4da Mon Sep 17 00:00:00 2001 From: Navid Shaikh Date: Thu, 12 Nov 2020 15:26:40 +0530 Subject: [PATCH 2/2] Add CHANGELOG --- CHANGELOG.adoc | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/CHANGELOG.adoc b/CHANGELOG.adoc index 08ce674a27..dbbbed9c0d 100644 --- a/CHANGELOG.adoc +++ b/CHANGELOG.adoc @@ -12,6 +12,16 @@ | https://github.com/knative/client/pull/[#] //// +### Unreleased +[cols="1,10,3", options="header", width="100%"] +|=== +| | Description | PR + +| 🐛 +| Embed the namespace in request body while creating channels +| https://github.com/knative/client/pull/1117[#1117] +|=== + ### v0.19.0 (2020-11-11) [cols="1,10,3", options="header", width="100%"] |===