Skip to content

Commit 6288a9b

Browse files
committed
test: add basic object lifecycle tests for KafkaCluster controller
Tests verify: - KafkaCluster CRs can be created successfully - KafkaCluster specs can be updated - Multiple clusters can coexist in same namespace These are true unit tests that don't require full reconciliation and don't interfere with other controller tests in the suite.
1 parent 5c4d2f7 commit 6288a9b

File tree

4 files changed

+841
-52
lines changed

4 files changed

+841
-52
lines changed

api/v1beta1/common_types.go

Lines changed: 135 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -155,13 +155,13 @@ func (r CruiseControlState) IsSucceeded() bool {
155155
}
156156

157157
// IsDiskRebalanceSucceeded returns true if CruiseControlVolumeState is disk rebalance succeeded
158-
func (r CruiseControlVolumeState) IsDiskRebalanceSucceeded() bool {
159-
return r == GracefulDiskRebalanceSucceeded
158+
func (s CruiseControlVolumeState) IsDiskRebalanceSucceeded() bool {
159+
return s == GracefulDiskRebalanceSucceeded
160160
}
161161

162162
// IsDiskRemovalSucceeded returns true if CruiseControlVolumeState is disk removal succeeded
163-
func (r CruiseControlVolumeState) IsDiskRemovalSucceeded() bool {
164-
return r == GracefulDiskRemovalSucceeded
163+
func (s CruiseControlVolumeState) IsDiskRemovalSucceeded() bool {
164+
return s == GracefulDiskRemovalSucceeded
165165
}
166166

167167
// IsSSL determines if the receiver is using SSL
@@ -248,99 +248,186 @@ const (
248248
// WaitingForRackAwareness states the broker is waiting for the rack awareness config
249249
WaitingForRackAwareness RackAwarenessState = "WaitingForRackAwareness"
250250

251-
// Upscale cruise control states
252-
// GracefulUpscaleRequired states that a broker upscale is required
251+
// GracefulUpscaleRequired indicates that a broker upscale operation is needed.
252+
// This is the initial state when new brokers are added to the cluster and Cruise Control
253+
// needs to rebalance partitions to distribute load across the new brokers.
254+
// Transition: Required -> Scheduled -> Running -> Succeeded/CompletedWithError/Paused
253255
GracefulUpscaleRequired CruiseControlState = "GracefulUpscaleRequired"
254-
// GracefulUpscaleRunning states that the broker upscale task is still running in CC
256+
// GracefulUpscaleRunning indicates that the broker upscale task is actively executing in Cruise Control.
257+
// During this state, CC is moving partition replicas to the new brokers to balance the cluster load.
258+
// The operation may take significant time depending on cluster size and data volume.
255259
GracefulUpscaleRunning CruiseControlState = "GracefulUpscaleRunning"
256-
// GracefulUpscaleScheduled states that the broker upscale CCOperation is created and the task is waiting for execution
260+
// GracefulUpscaleScheduled indicates that a CruiseControlOperation resource has been created
261+
// for the broker upscale task and is waiting in the queue for execution.
262+
// This state occurs when CC is busy with other operations or waiting for prerequisites.
257263
GracefulUpscaleScheduled CruiseControlState = "GracefulUpscaleScheduled"
258-
// GracefulUpscaleSucceeded states the broker is updated gracefully OR
259-
// states that the broker is part of the initial cluster creation where CC topic is still in creating stage
264+
// GracefulUpscaleSucceeded indicates that the broker upscale completed successfully and
265+
// partitions have been rebalanced across the new brokers. This is also the state for brokers
266+
// that are part of the initial cluster creation while the Cruise Control topic is being created.
260267
GracefulUpscaleSucceeded CruiseControlState = "GracefulUpscaleSucceeded"
261-
// GracefulUpscaleCompletedWithError states that the broker upscale task completed with an error
268+
// GracefulUpscaleCompletedWithError indicates that the broker upscale task finished but
269+
// encountered errors during execution. The operation may be retried automatically depending
270+
// on the error type and retry policy configuration.
262271
GracefulUpscaleCompletedWithError CruiseControlState = "GracefulUpscaleCompletedWithError"
263-
// GracefulUpscalePaused states that the broker upscale task is completed with an error and it will not be retried, it is paused
272+
// GracefulUpscalePaused indicates that the broker upscale task encountered an error and
273+
// has been paused. The operation will not be automatically retried and requires manual
274+
// intervention to resolve the issue before resuming.
264275
GracefulUpscalePaused CruiseControlState = "GracefulUpscalePaused"
276+
265277
// Downscale cruise control states
266-
// GracefulDownscaleRequired states that a broker downscale is required
278+
279+
// GracefulDownscaleRequired indicates that a broker downscale operation is needed.
280+
// This state is set when brokers are being removed from the cluster and Cruise Control
281+
// must migrate all partition replicas off the brokers before they can be safely decommissioned.
282+
// Transition: Required -> Scheduled -> Running -> Succeeded/CompletedWithError/Paused
267283
GracefulDownscaleRequired CruiseControlState = "GracefulDownscaleRequired"
268-
// GracefulDownscaleScheduled states that the broker downscale CCOperation is created and the task is waiting for execution
284+
// GracefulDownscaleScheduled indicates that a CruiseControlOperation resource has been created
285+
// for the broker downscale task and is waiting in the queue for execution.
286+
// This state occurs when CC is busy with other operations or waiting for prerequisites.
269287
GracefulDownscaleScheduled CruiseControlState = "GracefulDownscaleScheduled"
270-
// GracefulDownscaleRunning states that the broker downscale is still running in CC
288+
// GracefulDownscaleRunning indicates that the broker downscale task is actively executing in Cruise Control.
289+
// During this state, CC is moving all partition replicas off the brokers being removed to ensure
290+
// no data loss occurs. This operation may take significant time depending on data volume.
271291
GracefulDownscaleRunning CruiseControlState = "GracefulDownscaleRunning"
272-
// GracefulDownscaleSucceeded states that the broker downscaled gracefully
292+
// GracefulDownscaleSucceeded indicates that the broker downscale completed successfully.
293+
// All partition replicas have been migrated off the removed brokers and they can be safely
294+
// decommissioned without data loss or service interruption.
273295
GracefulDownscaleSucceeded CruiseControlState = "GracefulDownscaleSucceeded"
274-
// GracefulDownscaleCompletedWithError states that the broker downscale task completed with an error
296+
// GracefulDownscaleCompletedWithError indicates that the broker downscale task finished but
297+
// encountered errors during execution. The operation may be retried automatically depending
298+
// on the error type and retry policy configuration.
275299
GracefulDownscaleCompletedWithError CruiseControlState = "GracefulDownscaleCompletedWithError"
276-
// GracefulDownscalePaused states that the broker downscale task is completed with an error and it will not be retried, it is paused. In this case further downscale tasks can be executed
300+
// GracefulDownscalePaused indicates that the broker downscale task encountered an error and
301+
// has been paused. The operation will not be automatically retried and requires manual intervention.
302+
// Note: In this state, further downscale tasks can still be executed for other brokers.
277303
GracefulDownscalePaused CruiseControlState = "GracefulDownscalePaused"
278304

279305
// Disk removal cruise control states
280-
// GracefulDiskRemovalRequired states that the broker volume needs to be removed
306+
307+
// GracefulDiskRemovalRequired indicates that a broker volume needs to be removed from the cluster.
308+
// This state is set when storage volumes are being decommissioned and Cruise Control must migrate
309+
// all partition replicas off the volume before it can be safely removed.
310+
// Transition: Required -> Scheduled -> Running -> Succeeded/CompletedWithError/Paused
281311
GracefulDiskRemovalRequired CruiseControlVolumeState = "GracefulDiskRemovalRequired"
282-
// GracefulDiskRemovalRunning states that for the broker volume a CC disk removal is in progress
312+
// GracefulDiskRemovalRunning indicates that a Cruise Control disk removal operation is actively
313+
// executing for the broker volume. During this state, CC is moving all partition replicas from
314+
// the volume to other available disks to ensure no data loss occurs.
283315
GracefulDiskRemovalRunning CruiseControlVolumeState = "GracefulDiskRemovalRunning"
284-
// GracefulDiskRemovalSucceeded states that the for the broker volume removal has succeeded
316+
// GracefulDiskRemovalSucceeded indicates that the broker volume removal completed successfully.
317+
// All partition replicas have been migrated off the volume and it can be safely removed
318+
// from the broker without data loss or service interruption.
285319
GracefulDiskRemovalSucceeded CruiseControlVolumeState = "GracefulDiskRemovalSucceeded"
286-
// GracefulDiskRemovalScheduled states that the broker volume removal CCOperation is created and the task is waiting for execution
320+
// GracefulDiskRemovalScheduled indicates that a CruiseControlOperation resource has been created
321+
// for the volume removal task and is waiting in the queue for execution.
322+
// This state occurs when CC is busy with other operations or waiting for prerequisites.
287323
GracefulDiskRemovalScheduled CruiseControlVolumeState = "GracefulDiskRemovalScheduled"
288-
// GracefulDiskRemovalCompletedWithError states that the broker volume removal task completed with an error
324+
// GracefulDiskRemovalCompletedWithError indicates that the broker volume removal task finished
325+
// but encountered errors during execution. The operation may be retried automatically depending
326+
// on the error type and retry policy configuration.
289327
GracefulDiskRemovalCompletedWithError CruiseControlVolumeState = "GracefulDiskRemovalCompletedWithError"
290-
// GracefulDiskRemovalPaused states that the broker volume removal task is completed with an error and it will not be retried, it is paused
328+
// GracefulDiskRemovalPaused indicates that the broker volume removal task encountered an error
329+
// and has been paused. The operation will not be automatically retried and requires manual
330+
// intervention to resolve the issue before resuming.
291331
GracefulDiskRemovalPaused CruiseControlVolumeState = "GracefulDiskRemovalPaused"
292332

293333
// Disk rebalance cruise control states
294-
// GracefulDiskRebalanceRequired states that the broker volume needs a CC disk rebalance
334+
335+
// GracefulDiskRebalanceRequired indicates that a broker volume needs disk rebalancing.
336+
// This state is set when storage utilization is uneven across volumes and Cruise Control
337+
// should redistribute partition replicas to achieve better balance and performance.
338+
// Transition: Required -> Scheduled -> Running -> Succeeded/CompletedWithError/Paused
295339
GracefulDiskRebalanceRequired CruiseControlVolumeState = "GracefulDiskRebalanceRequired"
296-
// GracefulDiskRebalanceRunning states that for the broker volume a CC disk rebalance is in progress
340+
// GracefulDiskRebalanceRunning indicates that a Cruise Control disk rebalance operation is
341+
// actively executing for the broker volume. During this state, CC is moving partition replicas
342+
// between volumes to achieve more even storage utilization and improve performance.
297343
GracefulDiskRebalanceRunning CruiseControlVolumeState = "GracefulDiskRebalanceRunning"
298-
// GracefulDiskRebalanceSucceeded states that the for the broker volume rebalance has succeeded
344+
// GracefulDiskRebalanceSucceeded indicates that the broker volume rebalance completed successfully.
345+
// Partition replicas have been redistributed across volumes to achieve better storage balance
346+
// and the volume is now optimally utilized.
299347
GracefulDiskRebalanceSucceeded CruiseControlVolumeState = "GracefulDiskRebalanceSucceeded"
300-
// GracefulDiskRebalanceScheduled states that the broker volume rebalance CCOperation is created and the task is waiting for execution
348+
// GracefulDiskRebalanceScheduled indicates that a CruiseControlOperation resource has been created
349+
// for the volume rebalance task and is waiting in the queue for execution.
350+
// This state occurs when CC is busy with other operations or waiting for prerequisites.
301351
GracefulDiskRebalanceScheduled CruiseControlVolumeState = "GracefulDiskRebalanceScheduled"
302-
// GracefulDiskRebalanceCompletedWithError states that the broker volume rebalance task completed with an error
352+
// GracefulDiskRebalanceCompletedWithError indicates that the broker volume rebalance task finished
353+
// but encountered errors during execution. The operation may be retried automatically depending
354+
// on the error type and retry policy configuration.
303355
GracefulDiskRebalanceCompletedWithError CruiseControlVolumeState = "GracefulDiskRebalanceCompletedWithError"
304-
// GracefulDiskRebalancePaused states that the broker volume rebalance task is completed with an error and it will not be retried, it is paused
356+
// GracefulDiskRebalancePaused indicates that the broker volume rebalance task encountered an error
357+
// and has been paused. The operation will not be automatically retried and requires manual
358+
// intervention to resolve the issue before resuming.
305359
GracefulDiskRebalancePaused CruiseControlVolumeState = "GracefulDiskRebalancePaused"
306360

307-
// CruiseControlTopicNotReady states the CC required topic is not yet created
361+
// CruiseControlTopicNotReady indicates that the Cruise Control metrics topic has not been created yet.
362+
// This internal topic is required for CC to collect and store broker metrics. Operations cannot
363+
// proceed until this topic is successfully created and ready.
308364
CruiseControlTopicNotReady CruiseControlTopicStatus = "CruiseControlTopicNotReady"
309-
// CruiseControlTopicReady states the CC required topic is created
365+
// CruiseControlTopicReady indicates that the Cruise Control metrics topic has been successfully created
366+
// and is ready to receive broker metrics. This is a prerequisite for CC operations to execute.
310367
CruiseControlTopicReady CruiseControlTopicStatus = "CruiseControlTopicReady"
311-
// CruiseControlTaskActive states the CC task is scheduled but not yet running
368+
// CruiseControlTaskActive indicates that a Cruise Control task has been scheduled and is waiting
369+
// in the queue but has not yet started execution. This occurs when CC is processing other tasks
370+
// or waiting for required conditions to be met.
312371
CruiseControlTaskActive CruiseControlUserTaskState = "Active"
313-
// CruiseControlTaskInExecution states the CC task is executing
372+
// CruiseControlTaskInExecution indicates that a Cruise Control task is currently executing.
373+
// During this state, CC is actively performing the requested operation such as rebalancing
374+
// partitions, adding/removing brokers, or moving replicas between disks.
314375
CruiseControlTaskInExecution CruiseControlUserTaskState = "InExecution"
315-
// CruiseControlTaskCompleted states the CC task completed successfully
376+
// CruiseControlTaskCompleted indicates that a Cruise Control task finished successfully.
377+
// The requested operation has been completed without errors and the cluster is in the desired state.
316378
CruiseControlTaskCompleted CruiseControlUserTaskState = "Completed"
317-
// CruiseControlTaskCompletedWithError states the CC task completed with error
379+
// CruiseControlTaskCompletedWithError indicates that a Cruise Control task finished but encountered
380+
// errors during execution. The task may have partially completed or failed entirely. Check the
381+
// error details to determine if retry or manual intervention is needed.
318382
CruiseControlTaskCompletedWithError CruiseControlUserTaskState = "CompletedWithError"
319-
// KafkaClusterReconciling states that the cluster is still in reconciling stage
383+
// KafkaClusterReconciling indicates that the Kafka cluster is in the reconciliation phase.
384+
// During this state, the operator is working to bring the cluster to the desired state by
385+
// creating, updating, or deleting resources. This is a transitional state during initial
386+
// cluster creation or when applying configuration changes.
320387
KafkaClusterReconciling ClusterState = "ClusterReconciling"
321-
// KafkaClusterRollingUpgrading states that the cluster is rolling upgrading
388+
// KafkaClusterRollingUpgrading indicates that the Kafka cluster is performing a rolling upgrade.
389+
// Brokers are being restarted one at a time to apply configuration changes, version upgrades,
390+
// or other updates while maintaining cluster availability and minimizing service disruption.
322391
KafkaClusterRollingUpgrading ClusterState = "ClusterRollingUpgrading"
323-
// KafkaClusterRunning states that the cluster is in running state
392+
// KafkaClusterRunning indicates that the Kafka cluster is in a healthy running state.
393+
// All brokers are operational, configurations are in sync, and the cluster is ready to
394+
// handle producer and consumer traffic without ongoing maintenance operations.
324395
KafkaClusterRunning ClusterState = "ClusterRunning"
325396

326-
// ConfigInSync states that the generated brokerConfig is in sync with the Broker
397+
// ConfigInSync indicates that the generated broker configuration matches the actual configuration
398+
// running on the broker. No configuration changes are pending and the broker is operating with
399+
// the desired settings.
327400
ConfigInSync ConfigurationState = "ConfigInSync"
328-
// ConfigOutOfSync states that the generated brokerConfig is out of sync with the Broker
401+
// ConfigOutOfSync indicates that the generated broker configuration differs from the actual
402+
// configuration running on the broker. A rolling restart or dynamic update may be required
403+
// to apply the pending configuration changes.
329404
ConfigOutOfSync ConfigurationState = "ConfigOutOfSync"
330-
// PerBrokerConfigInSync states that the generated per-broker brokerConfig is in sync with the Broker
405+
// PerBrokerConfigInSync indicates that the generated per-broker dynamic configuration is in sync
406+
// with the broker's actual configuration. Per-broker configs are broker-specific settings that
407+
// can be updated dynamically without requiring a broker restart.
331408
PerBrokerConfigInSync PerBrokerConfigurationState = "PerBrokerConfigInSync"
332-
// PerBrokerConfigOutOfSync states that the generated per-broker brokerConfig is out of sync with the Broker
409+
// PerBrokerConfigOutOfSync indicates that the generated per-broker dynamic configuration differs
410+
// from the broker's actual configuration. The operator will attempt to apply these changes
411+
// dynamically using Kafka's configuration API without restarting the broker.
333412
PerBrokerConfigOutOfSync PerBrokerConfigurationState = "PerBrokerConfigOutOfSync"
334-
// PerBrokerConfigError states that the generated per-broker brokerConfig can not be set in the Broker
413+
// PerBrokerConfigError indicates that the operator failed to apply the per-broker dynamic
414+
// configuration to the broker. This may be due to invalid configuration values, broker API
415+
// errors, or permission issues. Manual intervention may be required to resolve the error.
335416
PerBrokerConfigError PerBrokerConfigurationState = "PerBrokerConfigError"
336417

337-
// SecurityProtocolSSL
418+
// SecurityProtocolSSL enables SSL/TLS encryption for broker communication without SASL authentication.
419+
// This protocol provides encryption in transit but relies on SSL/TLS certificates for authentication.
338420
SecurityProtocolSSL SecurityProtocol = "ssl"
339-
// SecurityProtocolPlaintext
421+
// SecurityProtocolPlaintext uses unencrypted communication with no authentication.
422+
// This protocol should only be used in trusted networks as all data is transmitted in clear text.
340423
SecurityProtocolPlaintext SecurityProtocol = "plaintext"
341-
// SecurityProtocolSaslSSL
424+
// SecurityProtocolSaslSSL combines SASL authentication with SSL/TLS encryption.
425+
// This protocol provides both strong authentication (via SASL mechanisms like SCRAM, GSSAPI, etc.)
426+
// and encryption in transit, making it the most secure option for production environments.
342427
SecurityProtocolSaslSSL SecurityProtocol = "sasl_ssl"
343-
// SecurityProtocolSaslPlaintext
428+
// SecurityProtocolSaslPlaintext enables SASL authentication over unencrypted connections.
429+
// This protocol provides authentication but transmits data in clear text, including credentials
430+
// during the authentication handshake. Use with caution and only in trusted networks.
344431
SecurityProtocolSaslPlaintext SecurityProtocol = "sasl_plaintext"
345432

346433
// SSLClientAuthRequired states that the client authentication is required when SSL is enabled

0 commit comments

Comments
 (0)