Skip to content

Commit

Permalink
Embed the namespace in request body while creating channels
Browse files Browse the repository at this point in the history
 since on the eventing side, defaulting for channel isnt picking
 the namespace from the context (see knative/eventing#4514)

 workaround for knative#1100
 this changeset should be reverted when eventing#4514 is resolved
  • Loading branch information
navidshaikh committed Nov 12, 2020
1 parent b93ca9b commit 1387781
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 10 deletions.
4 changes: 2 additions & 2 deletions pkg/kn/commands/channel/channel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
2 changes: 1 addition & 1 deletion pkg/kn/commands/channel/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
4 changes: 2 additions & 2 deletions pkg/kn/commands/channel/create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand All @@ -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"))
Expand Down
2 changes: 1 addition & 1 deletion pkg/kn/commands/channel/describe_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand Down
4 changes: 2 additions & 2 deletions pkg/kn/commands/channel/list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
5 changes: 3 additions & 2 deletions pkg/messaging/v1beta1/channels_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
}}
}
Expand Down

0 comments on commit 1387781

Please sign in to comment.