@@ -47,13 +47,19 @@ func TestReconciler_pvc(t *testing.T) {
4747 },
4848 }
4949
50+ brokerConfig := & v1beta1.BrokerConfig {}
51+
5052 testCases := []struct {
5153 testName string
54+ brokerConfig * v1beta1.BrokerConfig
55+ kRaftMode bool
5256 storageConfig v1beta1.StorageConfig
5357 expectedPersistentVolumeClaim * corev1.PersistentVolumeClaim
5458 }{
5559 {
56- testName : "storage config with no template" ,
60+ testName : "storage config with no template" ,
61+ brokerConfig : brokerConfig ,
62+ kRaftMode : false ,
5763 storageConfig : v1beta1.StorageConfig {
5864 MountPath : "/kafka-logs-1" ,
5965 PvcSpec : & corev1.PersistentVolumeClaimSpec {
@@ -71,6 +77,7 @@ func TestReconciler_pvc(t *testing.T) {
7177 v1beta1 .AppLabelKey : "kafka" ,
7278 v1beta1 .KafkaCRLabelKey : kafkaCluster .GetName (),
7379 v1beta1 .BrokerIdLabelKey : "2" ,
80+ v1beta1 .PvcRolesKey : "broker" ,
7481 },
7582 Annotations : map [string ]string {
7683 "mountPath" : "/kafka-logs-1" ,
@@ -84,7 +91,9 @@ func TestReconciler_pvc(t *testing.T) {
8491 },
8592 },
8693 {
87- testName : "storage config with template" ,
94+ testName : "storage config with template" ,
95+ brokerConfig : brokerConfig ,
96+ kRaftMode : false ,
8897 storageConfig : v1beta1.StorageConfig {
8998 MountPath : "/kafka-logs-1" ,
9099 PvcSpec : & corev1.PersistentVolumeClaimSpec {
@@ -108,6 +117,7 @@ func TestReconciler_pvc(t *testing.T) {
108117 v1beta1 .AppLabelKey : "kafka" ,
109118 v1beta1 .KafkaCRLabelKey : kafkaCluster .GetName (),
110119 v1beta1 .BrokerIdLabelKey : "2" ,
120+ v1beta1 .PvcRolesKey : "broker" ,
111121 },
112122 Annotations : map [string ]string {
113123 "mountPath" : "/kafka-logs-1" ,
@@ -125,7 +135,9 @@ func TestReconciler_pvc(t *testing.T) {
125135 },
126136 },
127137 {
128- testName : "storage config with template and very long mount path" ,
138+ testName : "storage config with template and very long mount path" ,
139+ brokerConfig : brokerConfig ,
140+ kRaftMode : false ,
129141 storageConfig : v1beta1.StorageConfig {
130142 MountPath : "/mountpath/that/exceeds63characters/kafka-logs-123456789123456789" ,
131143 PvcSpec : & corev1.PersistentVolumeClaimSpec {
@@ -147,6 +159,7 @@ func TestReconciler_pvc(t *testing.T) {
147159 v1beta1 .AppLabelKey : "kafka" ,
148160 v1beta1 .KafkaCRLabelKey : kafkaCluster .GetName (),
149161 v1beta1 .BrokerIdLabelKey : "2" ,
162+ v1beta1 .PvcRolesKey : "broker" ,
150163 },
151164 Annotations : map [string ]string {
152165 "mountPath" : "/mountpath/that/exceeds63characters/kafka-logs-123456789123456789" ,
@@ -164,7 +177,9 @@ func TestReconciler_pvc(t *testing.T) {
164177 },
165178 },
166179 {
167- testName : "storage config with volume name template" ,
180+ testName : "storage config with volume name template" ,
181+ brokerConfig : brokerConfig ,
182+ kRaftMode : false ,
168183 storageConfig : v1beta1.StorageConfig {
169184 MountPath : "/kafka-logs-1" ,
170185 PvcSpec : & corev1.PersistentVolumeClaimSpec {
@@ -180,6 +195,7 @@ func TestReconciler_pvc(t *testing.T) {
180195 v1beta1 .AppLabelKey : "kafka" ,
181196 v1beta1 .KafkaCRLabelKey : kafkaCluster .GetName (),
182197 v1beta1 .BrokerIdLabelKey : "2" ,
198+ v1beta1 .PvcRolesKey : "broker" ,
183199 },
184200 Annotations : map [string ]string {
185201 "mountPath" : "/kafka-logs-1" ,
@@ -190,6 +206,84 @@ func TestReconciler_pvc(t *testing.T) {
190206 },
191207 },
192208 },
209+ {
210+ testName : "kraft controller-only node" ,
211+ brokerConfig : & v1beta1.BrokerConfig {Roles : []string {v1beta1 .ControllerNodeProcessRole }},
212+ kRaftMode : true ,
213+ storageConfig : v1beta1.StorageConfig {
214+ MountPath : "/kafka-logs-1" ,
215+ PvcSpec : & corev1.PersistentVolumeClaimSpec {},
216+ },
217+ expectedPersistentVolumeClaim : & corev1.PersistentVolumeClaim {
218+ ObjectMeta : metav1.ObjectMeta {
219+ Namespace : kafkaCluster .GetNamespace (),
220+ Name : "" ,
221+ GenerateName : fmt .Sprintf ("%s-2-storage-1-" , kafkaCluster .GetName ()),
222+ Labels : map [string ]string {
223+ v1beta1 .AppLabelKey : "kafka" ,
224+ v1beta1 .KafkaCRLabelKey : kafkaCluster .GetName (),
225+ v1beta1 .BrokerIdLabelKey : "2" ,
226+ v1beta1 .PvcRolesKey : "controller" ,
227+ },
228+ Annotations : map [string ]string {
229+ "mountPath" : "/kafka-logs-1" ,
230+ },
231+ },
232+ Spec : corev1.PersistentVolumeClaimSpec {},
233+ },
234+ },
235+ {
236+ testName : "kraft broker-only node" ,
237+ brokerConfig : & v1beta1.BrokerConfig {Roles : []string {v1beta1 .BrokerNodeProcessRole }},
238+ kRaftMode : true ,
239+ storageConfig : v1beta1.StorageConfig {
240+ MountPath : "/kafka-logs-1" ,
241+ PvcSpec : & corev1.PersistentVolumeClaimSpec {},
242+ },
243+ expectedPersistentVolumeClaim : & corev1.PersistentVolumeClaim {
244+ ObjectMeta : metav1.ObjectMeta {
245+ Namespace : kafkaCluster .GetNamespace (),
246+ Name : "" ,
247+ GenerateName : fmt .Sprintf ("%s-2-storage-1-" , kafkaCluster .GetName ()),
248+ Labels : map [string ]string {
249+ v1beta1 .AppLabelKey : "kafka" ,
250+ v1beta1 .KafkaCRLabelKey : kafkaCluster .GetName (),
251+ v1beta1 .BrokerIdLabelKey : "2" ,
252+ v1beta1 .PvcRolesKey : "broker" ,
253+ },
254+ Annotations : map [string ]string {
255+ "mountPath" : "/kafka-logs-1" ,
256+ },
257+ },
258+ Spec : corev1.PersistentVolumeClaimSpec {},
259+ },
260+ },
261+ {
262+ testName : "kraft combined broker+controller node" ,
263+ brokerConfig : & v1beta1.BrokerConfig {Roles : []string {v1beta1 .BrokerNodeProcessRole , v1beta1 .ControllerNodeProcessRole }},
264+ kRaftMode : true ,
265+ storageConfig : v1beta1.StorageConfig {
266+ MountPath : "/kafka-logs-1" ,
267+ PvcSpec : & corev1.PersistentVolumeClaimSpec {},
268+ },
269+ expectedPersistentVolumeClaim : & corev1.PersistentVolumeClaim {
270+ ObjectMeta : metav1.ObjectMeta {
271+ Namespace : kafkaCluster .GetNamespace (),
272+ Name : "" ,
273+ GenerateName : fmt .Sprintf ("%s-2-storage-1-" , kafkaCluster .GetName ()),
274+ Labels : map [string ]string {
275+ v1beta1 .AppLabelKey : "kafka" ,
276+ v1beta1 .KafkaCRLabelKey : kafkaCluster .GetName (),
277+ v1beta1 .BrokerIdLabelKey : "2" ,
278+ v1beta1 .PvcRolesKey : "broker_controller" ,
279+ },
280+ Annotations : map [string ]string {
281+ "mountPath" : "/kafka-logs-1" ,
282+ },
283+ },
284+ Spec : corev1.PersistentVolumeClaimSpec {},
285+ },
286+ },
193287 }
194288
195289 t .Parallel ()
@@ -198,7 +292,7 @@ func TestReconciler_pvc(t *testing.T) {
198292 test := test
199293
200294 t .Run (test .testName , func (t * testing.T ) {
201- pvc , err := r .pvc (2 , 1 , test .storageConfig )
295+ pvc , err := r .pvc (2 , 1 , test .storageConfig , test . brokerConfig , test . kRaftMode )
202296
203297 assert .NilError (t , err , "PVC creation should succeed" )
204298
0 commit comments