Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions contrib/kafka/pkg/controller/channel/reconcile.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,16 @@ import (
const (
finalizerName = controllerAgentName

// DefaultNumPartitions defines the default number of partitions
DefaultNumPartitions = 1

// DefaultReplicationFactor defines the default number of replications
DefaultReplicationFactor = 1
)

type channelArgs struct {
NumPartitions int32
NumPartitions int32
ReplicationFactor int16
}

// Reconcile compares the actual state with the desired, and attempts to
Expand Down Expand Up @@ -206,8 +211,12 @@ func (r *reconciler) provisionChannel(channel *eventingv1alpha1.Channel, kafkaCl
arguments.NumPartitions = DefaultNumPartitions
}

if arguments.ReplicationFactor == 0 {
arguments.ReplicationFactor = DefaultReplicationFactor
}

err := kafkaClusterAdmin.CreateTopic(topicName, &sarama.TopicDetail{
ReplicationFactor: 1,
ReplicationFactor: arguments.ReplicationFactor,
NumPartitions: arguments.NumPartitions,
}, false)
if err == sarama.ErrTopicAlreadyExists {
Expand Down
11 changes: 11 additions & 0 deletions contrib/kafka/pkg/controller/channel/reconcile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ const (
topicPrefix = "knative-eventing-channel"
testUID = "test-uid"
argumentNumPartitions = "NumPartitions"
argumentReplicationFactor = "ReplicationFactor"
)

var (
Expand Down Expand Up @@ -276,11 +277,21 @@ func TestProvisionChannel(t *testing.T) {
c: getNewChannelWithArgs(channelName, map[string]interface{}{argumentNumPartitions: "invalid"}),
wantError: fmt.Sprintf("error unmarshalling arguments: json: cannot unmarshal string into Go struct field channelArgs.%s of type int32", argumentNumPartitions),
},
{
name: "provision with invalid channel arguments - errors",
c: getNewChannelWithArgs(channelName, map[string]interface{}{argumentReplicationFactor: "invalid"}),
wantError: fmt.Sprintf("error unmarshalling arguments: json: cannot unmarshal string into Go struct field channelArgs.%s of type int16", argumentReplicationFactor),
},
{
name: "provision with nil channel arguments - errors",
c: getNewChannelWithArgs(channelName, map[string]interface{}{argumentNumPartitions: "nil"}),
wantError: fmt.Sprintf("error unmarshalling arguments: json: cannot unmarshal string into Go struct field channelArgs.%s of type int32", argumentNumPartitions),
},
{
name: "provision with nil channel arguments - errors",
c: getNewChannelWithArgs(channelName, map[string]interface{}{argumentReplicationFactor: "nil"}),
wantError: fmt.Sprintf("error unmarshalling arguments: json: cannot unmarshal string into Go struct field channelArgs.%s of type int16", argumentReplicationFactor),
},
{
name: "provision with unmarshallable channel arguments - errors",
c: func() *eventingv1alpha1.Channel {
Expand Down