@@ -19,6 +19,7 @@ import (
1919 "context"
2020 "errors"
2121 "fmt"
22+ "reflect"
2223 "regexp"
2324 "sort"
2425 "strconv"
@@ -66,24 +67,8 @@ func ApplyIndexerClusterManager(ctx context.Context, client splcommon.Controller
6667 // Update the CR Status
6768 defer updateCRStatus (ctx , client , cr , & err )
6869
69- // Bus config
70- busConfig := enterpriseApi.BusConfiguration {}
71- if cr .Spec .BusConfigurationRef .Name != "" {
72- ns := cr .GetNamespace ()
73- if cr .Spec .BusConfigurationRef .Namespace != "" {
74- ns = cr .Spec .BusConfigurationRef .Namespace
75- }
76- err = client .Get (context .Background (), types.NamespacedName {
77- Name : cr .Spec .BusConfigurationRef .Name ,
78- Namespace : ns ,
79- }, & busConfig )
80- if err != nil {
81- return result , err
82- }
83- }
84-
8570 // validate and updates defaults for CR
86- err = validateIndexerClusterSpec (ctx , client , cr , & busConfig )
71+ err = validateIndexerClusterSpec (ctx , client , cr )
8772 if err != nil {
8873 eventPublisher .Warning (ctx , "validateIndexerClusterSpec" , fmt .Sprintf ("validate indexercluster spec failed %s" , err .Error ()))
8974 scopedLog .Error (err , "Failed to validate indexercluster spec" )
@@ -92,6 +77,7 @@ func ApplyIndexerClusterManager(ctx context.Context, client splcommon.Controller
9277
9378 // updates status after function completes
9479 cr .Status .ClusterManagerPhase = enterpriseApi .PhaseError
80+ replicasBefore := cr .Status .Replicas
9581 cr .Status .Replicas = cr .Spec .Replicas
9682 cr .Status .Selector = fmt .Sprintf ("app.kubernetes.io/instance=splunk-%s-indexer" , cr .GetName ())
9783 if cr .Status .Peers == nil {
@@ -257,14 +243,36 @@ func ApplyIndexerClusterManager(ctx context.Context, client splcommon.Controller
257243
258244 // no need to requeue if everything is ready
259245 if cr .Status .Phase == enterpriseApi .PhaseReady {
246+ // Bus config
247+ busConfig := enterpriseApi.BusConfiguration {}
260248 if cr .Spec .BusConfigurationRef .Name != "" {
261- err = mgr .handlePullBusChange (ctx , cr , busConfig , client )
249+ ns := cr .GetNamespace ()
250+ if cr .Spec .BusConfigurationRef .Namespace != "" {
251+ ns = cr .Spec .BusConfigurationRef .Namespace
252+ }
253+ err = client .Get (context .Background (), types.NamespacedName {
254+ Name : cr .Spec .BusConfigurationRef .Name ,
255+ Namespace : ns ,
256+ }, & busConfig )
262257 if err != nil {
263- scopedLog .Error (err , "Failed to update conf file for Bus/Pipeline config change after pod creation" )
264258 return result , err
265259 }
266260 }
267- cr .Status .BusConfiguration = busConfig .Spec
261+
262+ // If bus config is updated
263+ if cr .Spec .BusConfigurationRef .Name != "" {
264+ if ! reflect .DeepEqual (cr .Status .BusConfiguration , busConfig .Spec ) || replicasBefore < cr .Spec .Replicas {
265+ mgr := newIndexerClusterPodManager (scopedLog , cr , namespaceScopedSecret , splclient .NewSplunkClient )
266+
267+ err = mgr .handlePullBusChange (ctx , cr , busConfig , client )
268+ if err != nil {
269+ scopedLog .Error (err , "Failed to update conf file for Bus/Pipeline config change after pod creation" )
270+ return result , err
271+ }
272+
273+ cr .Status .BusConfiguration = busConfig .Spec
274+ }
275+ }
268276
269277 //update MC
270278 //Retrieve monitoring console ref from CM Spec
@@ -345,31 +353,16 @@ func ApplyIndexerCluster(ctx context.Context, client splcommon.ControllerClient,
345353 eventPublisher , _ := newK8EventPublisher (client , cr )
346354 cr .Kind = "IndexerCluster"
347355
348- // Bus config
349- busConfig := enterpriseApi.BusConfiguration {}
350- if cr .Spec .BusConfigurationRef .Name != "" {
351- ns := cr .GetNamespace ()
352- if cr .Spec .BusConfigurationRef .Namespace != "" {
353- ns = cr .Spec .BusConfigurationRef .Namespace
354- }
355- err := client .Get (context .Background (), types.NamespacedName {
356- Name : cr .Spec .BusConfigurationRef .Name ,
357- Namespace : ns ,
358- }, & busConfig )
359- if err != nil {
360- return result , err
361- }
362- }
363-
364356 // validate and updates defaults for CR
365- err := validateIndexerClusterSpec (ctx , client , cr , & busConfig )
357+ err := validateIndexerClusterSpec (ctx , client , cr )
366358 if err != nil {
367359 return result , err
368360 }
369361
370362 // updates status after function completes
371363 cr .Status .Phase = enterpriseApi .PhaseError
372364 cr .Status .ClusterMasterPhase = enterpriseApi .PhaseError
365+ replicasBefore := cr .Status .Replicas
373366 cr .Status .Replicas = cr .Spec .Replicas
374367 cr .Status .Selector = fmt .Sprintf ("app.kubernetes.io/instance=splunk-%s-indexer" , cr .GetName ())
375368 if cr .Status .Peers == nil {
@@ -538,29 +531,37 @@ func ApplyIndexerCluster(ctx context.Context, client splcommon.ControllerClient,
538531
539532 // no need to requeue if everything is ready
540533 if cr .Status .Phase == enterpriseApi .PhaseReady {
534+ // Bus config
535+ busConfig := enterpriseApi.BusConfiguration {}
541536 if cr .Spec .BusConfigurationRef .Name != "" {
542- busConfig := enterpriseApi.BusConfiguration {}
543537 ns := cr .GetNamespace ()
544538 if cr .Spec .BusConfigurationRef .Namespace != "" {
545539 ns = cr .Spec .BusConfigurationRef .Namespace
546540 }
547- err : = client .Get (context .Background (), types.NamespacedName {
541+ err = client .Get (context .Background (), types.NamespacedName {
548542 Name : cr .Spec .BusConfigurationRef .Name ,
549543 Namespace : ns ,
550544 }, & busConfig )
551545 if err != nil {
552546 return result , err
553547 }
548+ }
554549
555- err = mgr .handlePullBusChange (ctx , cr , busConfig , client )
556- if err != nil {
557- scopedLog .Error (err , "Failed to update conf file for Bus/Pipeline config change after pod creation" )
558- return result , err
550+ // If bus config is updated
551+ if cr .Spec .BusConfigurationRef .Name != "" {
552+ if ! reflect .DeepEqual (cr .Status .BusConfiguration , busConfig .Spec ) || replicasBefore < cr .Spec .Replicas {
553+ mgr := newIndexerClusterPodManager (scopedLog , cr , namespaceScopedSecret , splclient .NewSplunkClient )
554+
555+ err = mgr .handlePullBusChange (ctx , cr , busConfig , client )
556+ if err != nil {
557+ scopedLog .Error (err , "Failed to update conf file for Bus/Pipeline config change after pod creation" )
558+ return result , err
559+ }
560+
561+ cr .Status .BusConfiguration = busConfig .Spec
559562 }
560563 }
561564
562- cr .Status .BusConfiguration = busConfig .Spec
563-
564565 //update MC
565566 //Retrieve monitoring console ref from CM Spec
566567 cmMonitoringConsoleConfigRef , err := RetrieveCMSpec (ctx , client , cr )
@@ -1126,7 +1127,7 @@ func getIndexerStatefulSet(ctx context.Context, client splcommon.ControllerClien
11261127}
11271128
11281129// validateIndexerClusterSpec checks validity and makes default updates to a IndexerClusterSpec, and returns error if something is wrong.
1129- func validateIndexerClusterSpec (ctx context.Context , c splcommon.ControllerClient , cr * enterpriseApi.IndexerCluster , busConfig * enterpriseApi. BusConfiguration ) error {
1130+ func validateIndexerClusterSpec (ctx context.Context , c splcommon.ControllerClient , cr * enterpriseApi.IndexerCluster ) error {
11301131 // We cannot have 0 replicas in IndexerCluster spec, since this refers to number of indexers in an indexer cluster
11311132 if cr .Spec .Replicas == 0 {
11321133 cr .Spec .Replicas = 1
@@ -1231,7 +1232,7 @@ func (mgr *indexerClusterPodManager) handlePullBusChange(ctx context.Context, ne
12311232 // Only update config for pods that exist
12321233 readyReplicas := newCR .Status .ReadyReplicas
12331234
1234- // List all pods for this IngestorCluster StatefulSet
1235+ // List all pods for this IndexerCluster StatefulSet
12351236 var updateErr error
12361237 for n := 0 ; n < int (readyReplicas ); n ++ {
12371238 memberName := GetSplunkStatefulsetPodName (SplunkIndexer , newCR .GetName (), int32 (n ))
@@ -1245,10 +1246,10 @@ func (mgr *indexerClusterPodManager) handlePullBusChange(ctx context.Context, ne
12451246 afterDelete := false
12461247 if (busConfig .Spec .SQS .QueueName != "" && newCR .Status .BusConfiguration .SQS .QueueName != "" && busConfig .Spec .SQS .QueueName != newCR .Status .BusConfiguration .SQS .QueueName ) ||
12471248 (busConfig .Spec .Type != "" && newCR .Status .BusConfiguration .Type != "" && busConfig .Spec .Type != newCR .Status .BusConfiguration .Type ) {
1248- if err := splunkClient .DeleteConfFileProperty ("outputs" , fmt .Sprintf ("remote_queue:%s" , busConfig . Spec .SQS .QueueName )); err != nil {
1249+ if err := splunkClient .DeleteConfFileProperty ("outputs" , fmt .Sprintf ("remote_queue:%s" , newCR . Status . BusConfiguration .SQS .QueueName )); err != nil {
12491250 updateErr = err
12501251 }
1251- if err := splunkClient .DeleteConfFileProperty ("inputs" , fmt .Sprintf ("remote_queue:%s" , busConfig . Spec .SQS .QueueName )); err != nil {
1252+ if err := splunkClient .DeleteConfFileProperty ("inputs" , fmt .Sprintf ("remote_queue:%s" , newCR . Status . BusConfiguration .SQS .QueueName )); err != nil {
12521253 updateErr = err
12531254 }
12541255 afterDelete = true
0 commit comments