Skip to content

Commit 05513f6

Browse files
committed
test
1 parent 10a4fc0 commit 05513f6

File tree

3 files changed

+71
-49
lines changed

3 files changed

+71
-49
lines changed

internal/controller/indexercluster_controller.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,12 @@ func (r *IndexerClusterReconciler) SetupWithManager(mgr ctrl.Manager) error {
171171
mgr.GetRESTMapper(),
172172
&enterpriseApi.IndexerCluster{},
173173
)).
174+
Watches(&enterpriseApi.BusConfiguration{},
175+
handler.EnqueueRequestForOwner(
176+
mgr.GetScheme(),
177+
mgr.GetRESTMapper(),
178+
&enterpriseApi.IndexerCluster{},
179+
)).
174180
WithOptions(controller.Options{
175181
MaxConcurrentReconciles: enterpriseApi.TotalWorker,
176182
}).

pkg/splunk/enterprise/indexercluster.go

Lines changed: 45 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
"context"
2020
"errors"
2121
"fmt"
22+
"reflect"
2223
"regexp"
2324
"sort"
2425
"strconv"
@@ -104,6 +105,28 @@ func ApplyIndexerClusterManager(ctx context.Context, client splcommon.Controller
104105
cr.Status.IdxcPasswordChangedSecrets = make(map[string]bool)
105106
}
106107

108+
// If bus config is updated
109+
if cr.Spec.BusConfigurationRef.Name != "" {
110+
if !reflect.DeepEqual(cr.Status.BusConfiguration, busConfig.Spec) && cr.Status.Phase == enterpriseApi.PhaseReady {
111+
namespaceScopedSecret, err := ApplySplunkConfig(ctx, client, cr, cr.Spec.CommonSplunkSpec, SplunkIngestor)
112+
if err != nil {
113+
scopedLog.Error(err, "create or update general config failed", "error", err.Error())
114+
eventPublisher.Warning(ctx, "ApplySplunkConfig", fmt.Sprintf("create or update general config failed with error %s", err.Error()))
115+
return result, err
116+
}
117+
118+
mgr := newIndexerClusterPodManager(scopedLog, cr, namespaceScopedSecret, splclient.NewSplunkClient)
119+
120+
err = mgr.handlePullBusChange(ctx, cr, busConfig, client)
121+
if err != nil {
122+
scopedLog.Error(err, "Failed to update conf file for Bus/Pipeline config change after pod creation")
123+
return result, err
124+
}
125+
126+
cr.Status.BusConfiguration = busConfig.Spec
127+
}
128+
}
129+
107130
// create or update general config resources
108131
namespaceScopedSecret, err := ApplySplunkConfig(ctx, client, cr, cr.Spec.CommonSplunkSpec, SplunkIndexer)
109132
if err != nil {
@@ -257,15 +280,6 @@ func ApplyIndexerClusterManager(ctx context.Context, client splcommon.Controller
257280

258281
// no need to requeue if everything is ready
259282
if cr.Status.Phase == enterpriseApi.PhaseReady {
260-
if cr.Spec.BusConfigurationRef.Name != "" {
261-
err = mgr.handlePullBusChange(ctx, cr, busConfig, client)
262-
if err != nil {
263-
scopedLog.Error(err, "Failed to update conf file for Bus/Pipeline config change after pod creation")
264-
return result, err
265-
}
266-
}
267-
cr.Status.BusConfiguration = busConfig.Spec
268-
269283
//update MC
270284
//Retrieve monitoring console ref from CM Spec
271285
cmMonitoringConsoleConfigRef, err := RetrieveCMSpec(ctx, client, cr)
@@ -382,6 +396,28 @@ func ApplyIndexerCluster(ctx context.Context, client splcommon.ControllerClient,
382396
cr.Status.IdxcPasswordChangedSecrets = make(map[string]bool)
383397
}
384398

399+
// If bus config is updated
400+
if cr.Spec.BusConfigurationRef.Name != "" {
401+
if !reflect.DeepEqual(cr.Status.BusConfiguration, busConfig.Spec) && cr.Status.Phase == enterpriseApi.PhaseReady {
402+
namespaceScopedSecret, err := ApplySplunkConfig(ctx, client, cr, cr.Spec.CommonSplunkSpec, SplunkIngestor)
403+
if err != nil {
404+
scopedLog.Error(err, "create or update general config failed", "error", err.Error())
405+
eventPublisher.Warning(ctx, "ApplySplunkConfig", fmt.Sprintf("create or update general config failed with error %s", err.Error()))
406+
return result, err
407+
}
408+
409+
mgr := newIndexerClusterPodManager(scopedLog, cr, namespaceScopedSecret, splclient.NewSplunkClient)
410+
411+
err = mgr.handlePullBusChange(ctx, cr, busConfig, client)
412+
if err != nil {
413+
scopedLog.Error(err, "Failed to update conf file for Bus/Pipeline config change after pod creation")
414+
return result, err
415+
}
416+
417+
cr.Status.BusConfiguration = busConfig.Spec
418+
}
419+
}
420+
385421
// Update the CR Status
386422
defer updateCRStatus(ctx, client, cr, &err)
387423

@@ -538,29 +574,6 @@ func ApplyIndexerCluster(ctx context.Context, client splcommon.ControllerClient,
538574

539575
// no need to requeue if everything is ready
540576
if cr.Status.Phase == enterpriseApi.PhaseReady {
541-
if cr.Spec.BusConfigurationRef.Name != "" {
542-
busConfig := enterpriseApi.BusConfiguration{}
543-
ns := cr.GetNamespace()
544-
if cr.Spec.BusConfigurationRef.Namespace != "" {
545-
ns = cr.Spec.BusConfigurationRef.Namespace
546-
}
547-
err := client.Get(context.Background(), types.NamespacedName{
548-
Name: cr.Spec.BusConfigurationRef.Name,
549-
Namespace: ns,
550-
}, &busConfig)
551-
if err != nil {
552-
return result, err
553-
}
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-
562-
cr.Status.BusConfiguration = busConfig.Spec
563-
564577
//update MC
565578
//Retrieve monitoring console ref from CM Spec
566579
cmMonitoringConsoleConfigRef, err := RetrieveCMSpec(ctx, client, cr)

pkg/splunk/enterprise/ingestorcluster.go

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,26 @@ func ApplyIngestorCluster(ctx context.Context, client client.Client, cr *enterpr
9090

9191
cr.Status.Replicas = cr.Spec.Replicas
9292

93+
// If bus config is updated
94+
if !reflect.DeepEqual(cr.Status.BusConfiguration, busConfig.Spec) && cr.Status.Phase == enterpriseApi.PhaseReady {
95+
namespaceScopedSecret, err := ApplySplunkConfig(ctx, client, cr, cr.Spec.CommonSplunkSpec, SplunkIngestor)
96+
if err != nil {
97+
scopedLog.Error(err, "create or update general config failed", "error", err.Error())
98+
eventPublisher.Warning(ctx, "ApplySplunkConfig", fmt.Sprintf("create or update general config failed with error %s", err.Error()))
99+
return result, err
100+
}
101+
102+
mgr := newIngestorClusterPodManager(scopedLog, cr, namespaceScopedSecret, splclient.NewSplunkClient)
103+
104+
err = mgr.handlePushBusChange(ctx, cr, busConfig, client)
105+
if err != nil {
106+
scopedLog.Error(err, "Failed to update conf file for Bus/Pipeline config change after pod creation")
107+
return result, err
108+
}
109+
110+
cr.Status.BusConfiguration = busConfig.Spec
111+
}
112+
93113
// If needed, migrate the app framework status
94114
err = checkAndMigrateAppDeployStatus(ctx, client, cr, &cr.Status.AppContext, &cr.Spec.AppFrameworkConfig, true)
95115
if err != nil {
@@ -223,23 +243,6 @@ func ApplyIngestorCluster(ctx context.Context, client client.Client, cr *enterpr
223243

224244
// No need to requeue if everything is ready
225245
if cr.Status.Phase == enterpriseApi.PhaseReady {
226-
namespaceScopedSecret, err := ApplySplunkConfig(ctx, client, cr, cr.Spec.CommonSplunkSpec, SplunkIngestor)
227-
if err != nil {
228-
scopedLog.Error(err, "create or update general config failed", "error", err.Error())
229-
eventPublisher.Warning(ctx, "ApplySplunkConfig", fmt.Sprintf("create or update general config failed with error %s", err.Error()))
230-
return result, err
231-
}
232-
233-
mgr := newIngestorClusterPodManager(scopedLog, cr, namespaceScopedSecret, splclient.NewSplunkClient)
234-
235-
err = mgr.handlePushBusChange(ctx, cr, busConfig, client)
236-
if err != nil {
237-
scopedLog.Error(err, "Failed to update conf file for Bus/Pipeline config change after pod creation")
238-
return result, err
239-
}
240-
241-
cr.Status.BusConfiguration = busConfig.Spec
242-
243246
// Upgrade fron automated MC to MC CRD
244247
namespacedName := types.NamespacedName{Namespace: cr.GetNamespace(), Name: GetSplunkStatefulsetName(SplunkMonitoringConsole, cr.GetNamespace())}
245248
err = splctrl.DeleteReferencesToAutomatedMCIfExists(ctx, client, cr, namespacedName)

0 commit comments

Comments
 (0)