@@ -37,6 +37,7 @@ type TopicApplierConfig struct {
3737 RetentionDropStepDuration time.Duration
3838 SkipConfirm bool
3939 IgnoreFewerPartitionsError bool
40+ Destructive bool
4041 SleepLoopDuration time.Duration
4142 TopicConfig config.TopicConfig
4243}
@@ -392,6 +393,8 @@ func (t *TopicApplier) updateSettings(
392393 return err
393394 }
394395
396+ configEntries := []kafka.ConfigEntry {}
397+
395398 if len (diffKeys ) > 0 {
396399 diffsTable , err := FormatSettingsDiff (topicSettings , topicInfo .Config , diffKeys )
397400 if err != nil {
@@ -416,6 +419,23 @@ func (t *TopicApplier) updateSettings(
416419 )
417420 }
418421
422+ configEntries , err = topicSettings .ToConfigEntries (diffKeys )
423+ if err != nil {
424+ return err
425+ }
426+ }
427+
428+ if len (missingKeys ) > 0 && t .config .Destructive {
429+ log .Infof (
430+ "Found %d key(s) set in cluster but missing from config to be deleted:\n %s" ,
431+ len (missingKeys ),
432+ FormatMissingKeys (topicInfo .Config , missingKeys ),
433+ )
434+
435+ configEntries = append (configEntries , topicSettings .ToEmptyConfigEntries (missingKeys )... )
436+ }
437+
438+ if len (configEntries ) > 0 {
419439 if t .config .DryRun {
420440 log .Infof ("Skipping update because dryRun is set to true" )
421441 return nil
@@ -430,11 +450,6 @@ func (t *TopicApplier) updateSettings(
430450 }
431451 log .Infof ("OK, updating" )
432452
433- configEntries , err := topicSettings .ToConfigEntries (diffKeys )
434- if err != nil {
435- return err
436- }
437-
438453 _ , err = t .adminClient .UpdateTopicConfig (
439454 ctx ,
440455 t .topicName ,
@@ -446,7 +461,7 @@ func (t *TopicApplier) updateSettings(
446461 }
447462 }
448463
449- if len (missingKeys ) > 0 {
464+ if len (missingKeys ) > 0 && ! t . config . Destructive {
450465 log .Warnf (
451466 "Found %d key(s) set in cluster but missing from config:\n %s\n These will be left as-is." ,
452467 len (missingKeys ),
0 commit comments