Skip to content

Commit

Permalink
add --command-config options to kafka::topic to permit topic manageme…
Browse files Browse the repository at this point in the history
…nt if sasl or custom client configuration are required
  • Loading branch information
bovy89 committed Oct 29, 2024
1 parent bf54af5 commit ad6b9c2
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 2 deletions.
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

0 comments on commit ad6b9c2

Please sign in to comment.