Skip to content

Commit 4968df3

Browse files
committed
add --command-config options to kafka::topic to permit topic management if sasl or custom client configuration are required
1 parent bf54af5 commit 4968df3

File tree

3 files changed

+45
-2
lines changed

3 files changed

+45
-2
lines changed

REFERENCE.md

+11-1
Original file line numberDiff line numberDiff line change
@@ -1648,7 +1648,7 @@ Default value: `$kafka::params::producer_log4j_opts`
16481648

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

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

16531653
#### Examples
16541654

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

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

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

17361737
Default value: `undef`
17371738

1739+
##### <a name="-kafka--topic--cmd_config"></a>`cmd_config`
1740+
1741+
Data type: `Optional[Stdlib::Absolutepath]`
1742+
1743+
Property file containing configs to be passed to Admin Client.
1744+
This is used only with --bootstrap-server option for describing and
1745+
1746+
Default value: `undef`
1747+

manifests/topic.pp

+15-1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@
3434
# A topic configuration override for the topic being created or altered.
3535
# See the Kafka documentation for full details on the topic configs.
3636
#
37+
# @param cmd_config
38+
# Property file containing configs to be passed to Admin Client.
39+
# This is used only with --bootstrap-server option for describing and
40+
#  altering broker configs (e.g. specify sasl and ssl configs)
41+
#
3742
define kafka::topic (
3843
Optional[String[1]] $ensure = undef,
3944
Optional[String[1]] $zookeeper = undef,
@@ -42,6 +47,7 @@
4247
Integer $partitions = 1,
4348
String[1] $bin_dir = '/opt/kafka/bin',
4449
Optional[Hash[String[1],String[1]]] $config = undef,
50+
Optional[Stdlib::Absolutepath] $cmd_config = undef,
4551
) {
4652
$_zookeeper = "--zookeeper ${zookeeper}"
4753
$_bootstrap_server = "--bootstrap-server ${bootstrap_server}"
@@ -52,10 +58,18 @@
5258
fail('Either zookeeper or bootstrap_server parameter must be defined!')
5359
}
5460

61+
if $zookeeper and $cmd_config {
62+
warn('cmd_config will be ignored: This is used only with bootstrap_server')
63+
}
64+
5565
if $zookeeper {
5666
$_connection = $_zookeeper
5767
} else {
58-
$_connection = $_bootstrap_server
68+
if $cmd_config {
69+
$_connection = "${_bootstrap_server} --command-config ${cmd_config}"
70+
} else {
71+
$_connection = $_bootstrap_server
72+
}
5973
}
6074

6175
if $config {

spec/defines/topic_spec.rb

+19
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,25 @@
7878
)
7979
}
8080
end
81+
82+
context 'when create topic demo for kafka v3 and command-config' do
83+
let(:title) { 'demo' }
84+
let :params do
85+
{
86+
'ensure' => 'present',
87+
'bootstrap_server' => 'localhost:9092',
88+
'replication_factor' => 1,
89+
'partitions' => 1,
90+
'cmd_config' => '/opt/kafka/config/admin.config',
91+
}
92+
end
93+
94+
it {
95+
is_expected.to contain_exec("create topic #{title}").with(
96+
command: "kafka-topics.sh --create --bootstrap-server #{params[:bootstrap_server]} --command-config #{params[:cmd_config]} --replication-factor #{params[:replication_factor]} --partitions #{params[:partitions]} --topic #{title} "
97+
)
98+
}
99+
end
81100
end
82101
end
83102
end

0 commit comments

Comments
 (0)