Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add --command-config options to kafka::topic to permit topic manageme… #376

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
12 changes: 11 additions & 1 deletion REFERENCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -1648,7 +1648,7 @@ Default value: `$kafka::params::producer_log4j_opts`

### <a name="kafka--topic"></a>`kafka::topic`

This defined type handles the creation of Kafka topics.
  altering broker configs (e.g. specify sasl and ssl configs)

#### Examples

Expand All @@ -1674,6 +1674,7 @@ The following parameters are available in the `kafka::topic` defined type:
* [`partitions`](#-kafka--topic--partitions)
* [`bin_dir`](#-kafka--topic--bin_dir)
* [`config`](#-kafka--topic--config)
* [`cmd_config`](#-kafka--topic--cmd_config)

##### <a name="-kafka--topic--ensure"></a>`ensure`

Expand Down Expand Up @@ -1735,3 +1736,12 @@ See the Kafka documentation for full details on the topic configs.

Default value: `undef`

##### <a name="-kafka--topic--cmd_config"></a>`cmd_config`

Data type: `Optional[Stdlib::Absolutepath]`

Property file containing configs to be passed to Admin Client.
This is used only with --bootstrap-server option for describing and

Default value: `undef`

16 changes: 15 additions & 1 deletion manifests/topic.pp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@
# A topic configuration override for the topic being created or altered.
# See the Kafka documentation for full details on the topic configs.
#
# @param cmd_config
# Property file containing configs to be passed to Admin Client.
# This is used only with --bootstrap-server option for describing and
#  altering broker configs (e.g. specify sasl and ssl configs)
#
define kafka::topic (
Optional[String[1]] $ensure = undef,
Optional[String[1]] $zookeeper = undef,
Expand All @@ -42,6 +47,7 @@
Integer $partitions = 1,
String[1] $bin_dir = '/opt/kafka/bin',
Optional[Hash[String[1],String[1]]] $config = undef,
Optional[Stdlib::Absolutepath] $cmd_config = undef,
) {
$_zookeeper = "--zookeeper ${zookeeper}"
$_bootstrap_server = "--bootstrap-server ${bootstrap_server}"
Expand All @@ -52,10 +58,18 @@
fail('Either zookeeper or bootstrap_server parameter must be defined!')
}

if $zookeeper and $cmd_config {
warn('cmd_config will be ignored: This is used only with bootstrap_server')
}

if $zookeeper {
$_connection = $_zookeeper
} else {
$_connection = $_bootstrap_server
if $cmd_config {
$_connection = "${_bootstrap_server} --command-config ${cmd_config}"
} else {
$_connection = $_bootstrap_server
}
}

if $config {
Expand Down
19 changes: 19 additions & 0 deletions spec/defines/topic_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,25 @@
)
}
end

context 'when create topic demo for kafka v3 and command-config' do
let(:title) { 'demo' }
let :params do
{
'ensure' => 'present',
'bootstrap_server' => 'localhost:9092',
'replication_factor' => 1,
'partitions' => 1,
'cmd_config' => '/opt/kafka/config/admin.config',
}
end

it {
is_expected.to contain_exec('create topic demo').with(
command: 'kafka-topics.sh --create --bootstrap-server localhost:9092 --command-config /opt/kafka/config/admin.config --replication-factor 1 --partitions 1 --topic demo '
)
}
end
end
end
end
Loading