@@ -228,7 +228,7 @@ func ApplyIngestorCluster(ctx context.Context, client client.Client, cr *enterpr
228228
229229 // If bus config is updated
230230 if ! reflect .DeepEqual (cr .Status .BusConfiguration , busConfig .Spec ) {
231- mgr := newIngestorClusterPodManager (scopedLog , cr , namespaceScopedSecret , splclient .NewSplunkClient )
231+ mgr := newIngestorClusterPodManager (scopedLog , cr , namespaceScopedSecret , splclient .NewSplunkClient , client )
232232
233233 err = mgr .handlePushBusChange (ctx , cr , busConfig , client )
234234 if err != nil {
@@ -238,6 +238,15 @@ func ApplyIngestorCluster(ctx context.Context, client client.Client, cr *enterpr
238238 }
239239
240240 cr .Status .BusConfiguration = busConfig .Spec
241+
242+ for i := int32 (0 ); i < cr .Spec .Replicas ; i ++ {
243+ ingClient := mgr .getClient (ctx , i )
244+ err = ingClient .RestartSplunk ()
245+ if err != nil {
246+ return result , err
247+ }
248+ scopedLog .Info ("Restarted splunk" , "ingestor" , i )
249+ }
241250 }
242251
243252 // Upgrade fron automated MC to MC CRD
@@ -280,6 +289,27 @@ func ApplyIngestorCluster(ctx context.Context, client client.Client, cr *enterpr
280289 return result , nil
281290}
282291
292+ // getClient for ingestorClusterPodManager returns a SplunkClient for the member n
293+ func (mgr * ingestorClusterPodManager ) getClient (ctx context.Context , n int32 ) * splclient.SplunkClient {
294+ reqLogger := log .FromContext (ctx )
295+ scopedLog := reqLogger .WithName ("ingestorClusterPodManager.getClient" ).WithValues ("name" , mgr .cr .GetName (), "namespace" , mgr .cr .GetNamespace ())
296+
297+ // Get Pod Name
298+ memberName := GetSplunkStatefulsetPodName (SplunkIngestor , mgr .cr .GetName (), n )
299+
300+ // Get Fully Qualified Domain Name
301+ fqdnName := splcommon .GetServiceFQDN (mgr .cr .GetNamespace (),
302+ fmt .Sprintf ("%s.%s" , memberName , GetSplunkServiceName (SplunkIngestor , mgr .cr .GetName (), true )))
303+
304+ // Retrieve admin password from Pod
305+ adminPwd , err := splutil .GetSpecificSecretTokenFromPod (ctx , mgr .c , memberName , mgr .cr .GetNamespace (), "password" )
306+ if err != nil {
307+ scopedLog .Error (err , "Couldn't retrieve the admin password from pod" )
308+ }
309+
310+ return mgr .newSplunkClient (fmt .Sprintf ("https://%s:8089" , fqdnName ), "admin" , adminPwd )
311+ }
312+
283313// validateIngestorClusterSpec checks validity and makes default updates to a IngestorClusterSpec and returns error if something is wrong
284314func validateIngestorClusterSpec (ctx context.Context , c splcommon.ControllerClient , cr * enterpriseApi.IngestorCluster ) error {
285315 // We cannot have 0 replicas in IngestorCluster spec since this refers to number of ingestion pods in an ingestor cluster
@@ -372,19 +402,21 @@ func getChangedBusFieldsForIngestor(busConfig *enterpriseApi.BusConfiguration, b
372402}
373403
374404type ingestorClusterPodManager struct {
405+ c splcommon.ControllerClient
375406 log logr.Logger
376407 cr * enterpriseApi.IngestorCluster
377408 secrets * corev1.Secret
378409 newSplunkClient func (managementURI , username , password string ) * splclient.SplunkClient
379410}
380411
381412// newIngestorClusterPodManager function to create pod manager this is added to write unit test case
382- var newIngestorClusterPodManager = func (log logr.Logger , cr * enterpriseApi.IngestorCluster , secret * corev1.Secret , newSplunkClient NewSplunkClientFunc ) ingestorClusterPodManager {
413+ var newIngestorClusterPodManager = func (log logr.Logger , cr * enterpriseApi.IngestorCluster , secret * corev1.Secret , newSplunkClient NewSplunkClientFunc , c splcommon. ControllerClient ) ingestorClusterPodManager {
383414 return ingestorClusterPodManager {
384415 log : log ,
385416 cr : cr ,
386417 secrets : secret ,
387418 newSplunkClient : newSplunkClient ,
419+ c : c ,
388420 }
389421}
390422
0 commit comments