Skip to content

Commit c66f1a9

Browse files
committed
test
1 parent 10a4fc0 commit c66f1a9

File tree

3 files changed

+77
-55
lines changed

3 files changed

+77
-55
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"
@@ -90,6 +91,28 @@ func ApplyIndexerClusterManager(ctx context.Context, client splcommon.Controller
9091
return result, err
9192
}
9293

94+
// If bus config is updated
95+
if cr.Spec.BusConfigurationRef.Name != "" {
96+
if !reflect.DeepEqual(cr.Status.BusConfiguration, busConfig.Spec) && cr.Status.Phase == enterpriseApi.PhaseReady {
97+
namespaceScopedSecret, err := ApplySplunkConfig(ctx, client, cr, cr.Spec.CommonSplunkSpec, SplunkIngestor)
98+
if err != nil {
99+
scopedLog.Error(err, "create or update general config failed", "error", err.Error())
100+
eventPublisher.Warning(ctx, "ApplySplunkConfig", fmt.Sprintf("create or update general config failed with error %s", err.Error()))
101+
return result, err
102+
}
103+
104+
mgr := newIndexerClusterPodManager(scopedLog, cr, namespaceScopedSecret, splclient.NewSplunkClient)
105+
106+
err = mgr.handlePullBusChange(ctx, cr, busConfig, client)
107+
if err != nil {
108+
scopedLog.Error(err, "Failed to update conf file for Bus/Pipeline config change after pod creation")
109+
return result, err
110+
}
111+
112+
cr.Status.BusConfiguration = busConfig.Spec
113+
}
114+
}
115+
93116
// updates status after function completes
94117
cr.Status.ClusterManagerPhase = enterpriseApi.PhaseError
95118
cr.Status.Replicas = cr.Spec.Replicas
@@ -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)
@@ -367,6 +381,28 @@ func ApplyIndexerCluster(ctx context.Context, client splcommon.ControllerClient,
367381
return result, err
368382
}
369383

384+
// If bus config is updated
385+
if cr.Spec.BusConfigurationRef.Name != "" {
386+
if !reflect.DeepEqual(cr.Status.BusConfiguration, busConfig.Spec) && cr.Status.Phase == enterpriseApi.PhaseReady {
387+
namespaceScopedSecret, err := ApplySplunkConfig(ctx, client, cr, cr.Spec.CommonSplunkSpec, SplunkIngestor)
388+
if err != nil {
389+
scopedLog.Error(err, "create or update general config failed", "error", err.Error())
390+
eventPublisher.Warning(ctx, "ApplySplunkConfig", fmt.Sprintf("create or update general config failed with error %s", err.Error()))
391+
return result, err
392+
}
393+
394+
mgr := newIndexerClusterPodManager(scopedLog, cr, namespaceScopedSecret, splclient.NewSplunkClient)
395+
396+
err = mgr.handlePullBusChange(ctx, cr, busConfig, client)
397+
if err != nil {
398+
scopedLog.Error(err, "Failed to update conf file for Bus/Pipeline config change after pod creation")
399+
return result, err
400+
}
401+
402+
cr.Status.BusConfiguration = busConfig.Spec
403+
}
404+
}
405+
370406
// updates status after function completes
371407
cr.Status.Phase = enterpriseApi.PhaseError
372408
cr.Status.ClusterMasterPhase = enterpriseApi.PhaseError
@@ -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: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,6 @@ func ApplyIngestorCluster(ctx context.Context, client client.Client, cr *enterpr
5858

5959
cr.Kind = "IngestorCluster"
6060

61-
// Initialize phase
62-
cr.Status.Phase = enterpriseApi.PhaseError
63-
64-
// Update the CR Status
65-
defer updateCRStatus(ctx, client, cr, &err)
66-
6761
// Bus config
6862
busConfig := enterpriseApi.BusConfiguration{}
6963
if cr.Spec.BusConfigurationRef.Name != "" {
@@ -88,6 +82,32 @@ func ApplyIngestorCluster(ctx context.Context, client client.Client, cr *enterpr
8882
return result, err
8983
}
9084

85+
// If bus config is updated
86+
if !reflect.DeepEqual(cr.Status.BusConfiguration, busConfig.Spec) && cr.Status.Phase == enterpriseApi.PhaseReady {
87+
namespaceScopedSecret, err := ApplySplunkConfig(ctx, client, cr, cr.Spec.CommonSplunkSpec, SplunkIngestor)
88+
if err != nil {
89+
scopedLog.Error(err, "create or update general config failed", "error", err.Error())
90+
eventPublisher.Warning(ctx, "ApplySplunkConfig", fmt.Sprintf("create or update general config failed with error %s", err.Error()))
91+
return result, err
92+
}
93+
94+
mgr := newIngestorClusterPodManager(scopedLog, cr, namespaceScopedSecret, splclient.NewSplunkClient)
95+
96+
err = mgr.handlePushBusChange(ctx, cr, busConfig, client)
97+
if err != nil {
98+
scopedLog.Error(err, "Failed to update conf file for Bus/Pipeline config change after pod creation")
99+
return result, err
100+
}
101+
102+
cr.Status.BusConfiguration = busConfig.Spec
103+
}
104+
105+
// Initialize phase
106+
cr.Status.Phase = enterpriseApi.PhaseError
107+
108+
// Update the CR Status
109+
defer updateCRStatus(ctx, client, cr, &err)
110+
91111
cr.Status.Replicas = cr.Spec.Replicas
92112

93113
// If needed, migrate the app framework status
@@ -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)