Skip to content

Commit 3cb9148

Browse files
committed
CSPL-4360 Fix errors with failing validation on status
1 parent e4e083a commit 3cb9148

File tree

3 files changed

+30
-31
lines changed

3 files changed

+30
-31
lines changed

pkg/splunk/enterprise/indexercluster.go

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,6 @@ func ApplyIndexerClusterManager(ctx context.Context, client splcommon.Controller
7777

7878
// updates status after function completes
7979
cr.Status.ClusterManagerPhase = enterpriseApi.PhaseError
80-
if cr.Status.Replicas < cr.Spec.Replicas {
81-
cr.Status.Bus = &enterpriseApi.BusSpec{}
82-
cr.Status.LargeMessageStore = &enterpriseApi.LargeMessageStoreSpec{}
83-
}
8480
cr.Status.Replicas = cr.Spec.Replicas
8581
cr.Status.Selector = fmt.Sprintf("app.kubernetes.io/instance=splunk-%s-indexer", cr.GetName())
8682
if cr.Status.Peers == nil {
@@ -296,7 +292,7 @@ func ApplyIndexerClusterManager(ctx context.Context, client splcommon.Controller
296292

297293
// If bus is updated
298294
if cr.Spec.BusRef.Name != "" {
299-
if !reflect.DeepEqual(cr.Status.Bus, bus.Spec) || !reflect.DeepEqual(cr.Status.LargeMessageStore, lms.Spec) {
295+
if cr.Status.Bus == nil || cr.Status.LargeMessageStore == nil || !reflect.DeepEqual(*cr.Status.Bus, bus.Spec) || !reflect.DeepEqual(*cr.Status.LargeMessageStore, lms.Spec) {
300296
mgr := newIndexerClusterPodManager(scopedLog, cr, namespaceScopedSecret, splclient.NewSplunkClient)
301297
err = mgr.handlePullBusChange(ctx, cr, busCopy, lmsCopy, client)
302298
if err != nil {
@@ -305,9 +301,6 @@ func ApplyIndexerClusterManager(ctx context.Context, client splcommon.Controller
305301
return result, err
306302
}
307303

308-
cr.Status.Bus = &bus.Spec
309-
cr.Status.LargeMessageStore = &lms.Spec
310-
311304
for i := int32(0); i < cr.Spec.Replicas; i++ {
312305
idxcClient := mgr.getClient(ctx, i)
313306
err = idxcClient.RestartSplunk()
@@ -316,6 +309,9 @@ func ApplyIndexerClusterManager(ctx context.Context, client splcommon.Controller
316309
}
317310
scopedLog.Info("Restarted splunk", "indexer", i)
318311
}
312+
313+
cr.Status.Bus = &bus.Spec
314+
cr.Status.LargeMessageStore = &lms.Spec
319315
}
320316
}
321317

@@ -407,10 +403,6 @@ func ApplyIndexerCluster(ctx context.Context, client splcommon.ControllerClient,
407403
// updates status after function completes
408404
cr.Status.Phase = enterpriseApi.PhaseError
409405
cr.Status.ClusterMasterPhase = enterpriseApi.PhaseError
410-
if cr.Status.Replicas < cr.Spec.Replicas {
411-
cr.Status.Bus = &enterpriseApi.BusSpec{}
412-
cr.Status.LargeMessageStore = &enterpriseApi.LargeMessageStoreSpec{}
413-
}
414406
cr.Status.Replicas = cr.Spec.Replicas
415407
cr.Status.Selector = fmt.Sprintf("app.kubernetes.io/instance=splunk-%s-indexer", cr.GetName())
416408
if cr.Status.Peers == nil {
@@ -629,7 +621,7 @@ func ApplyIndexerCluster(ctx context.Context, client splcommon.ControllerClient,
629621

630622
// If bus is updated
631623
if cr.Spec.BusRef.Name != "" {
632-
if !reflect.DeepEqual(cr.Status.Bus, bus.Spec) || !reflect.DeepEqual(cr.Status.LargeMessageStore, lms.Spec) {
624+
if cr.Status.Bus == nil || cr.Status.LargeMessageStore == nil || !reflect.DeepEqual(*cr.Status.Bus, bus.Spec) || !reflect.DeepEqual(*cr.Status.LargeMessageStore, lms.Spec) {
633625
mgr := newIndexerClusterPodManager(scopedLog, cr, namespaceScopedSecret, splclient.NewSplunkClient)
634626
err = mgr.handlePullBusChange(ctx, cr, busCopy, lmsCopy, client)
635627
if err != nil {
@@ -638,9 +630,6 @@ func ApplyIndexerCluster(ctx context.Context, client splcommon.ControllerClient,
638630
return result, err
639631
}
640632

641-
cr.Status.Bus = &bus.Spec
642-
cr.Status.LargeMessageStore = &lms.Spec
643-
644633
for i := int32(0); i < cr.Spec.Replicas; i++ {
645634
idxcClient := mgr.getClient(ctx, i)
646635
err = idxcClient.RestartSplunk()
@@ -649,6 +638,9 @@ func ApplyIndexerCluster(ctx context.Context, client splcommon.ControllerClient,
649638
}
650639
scopedLog.Info("Restarted splunk", "indexer", i)
651640
}
641+
642+
cr.Status.Bus = &bus.Spec
643+
cr.Status.LargeMessageStore = &lms.Spec
652644
}
653645
}
654646

@@ -1336,6 +1328,13 @@ func (mgr *indexerClusterPodManager) handlePullBusChange(ctx context.Context, ne
13361328
}
13371329
splunkClient := newSplunkClientForBusPipeline(fmt.Sprintf("https://%s:8089", fqdnName), "admin", string(adminPwd))
13381330

1331+
if newCR.Status.Bus == nil {
1332+
newCR.Status.Bus = &enterpriseApi.BusSpec{}
1333+
}
1334+
if newCR.Status.LargeMessageStore == nil {
1335+
newCR.Status.LargeMessageStore = &enterpriseApi.LargeMessageStoreSpec{}
1336+
}
1337+
13391338
afterDelete := false
13401339
if (bus.Spec.SQS.Name != "" && newCR.Status.Bus.SQS.Name != "" && bus.Spec.SQS.Name != newCR.Status.Bus.SQS.Name) ||
13411340
(bus.Spec.Provider != "" && newCR.Status.Bus.Provider != "" && bus.Spec.Provider != newCR.Status.Bus.Provider) {

pkg/splunk/enterprise/ingestorcluster.go

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,6 @@ func ApplyIngestorCluster(ctx context.Context, client client.Client, cr *enterpr
7272
// Update the CR Status
7373
defer updateCRStatus(ctx, client, cr, &err)
7474

75-
if cr.Status.Replicas < cr.Spec.Replicas {
76-
cr.Status.Bus = &enterpriseApi.BusSpec{}
77-
cr.Status.LargeMessageStore = &enterpriseApi.LargeMessageStoreSpec{}
78-
}
7975
cr.Status.Replicas = cr.Spec.Replicas
8076

8177
// If needed, migrate the app framework status
@@ -260,7 +256,7 @@ func ApplyIngestorCluster(ctx context.Context, client client.Client, cr *enterpr
260256
}
261257

262258
// If bus is updated
263-
if !reflect.DeepEqual(cr.Status.Bus, bus.Spec) || !reflect.DeepEqual(cr.Status.LargeMessageStore, lms.Spec) {
259+
if cr.Status.Bus == nil || cr.Status.LargeMessageStore == nil || !reflect.DeepEqual(*cr.Status.Bus, bus.Spec) || !reflect.DeepEqual(*cr.Status.LargeMessageStore, lms.Spec) {
264260
mgr := newIngestorClusterPodManager(scopedLog, cr, namespaceScopedSecret, splclient.NewSplunkClient, client)
265261
err = mgr.handlePushBusChange(ctx, cr, busCopy, lmsCopy, client)
266262
if err != nil {
@@ -269,9 +265,6 @@ func ApplyIngestorCluster(ctx context.Context, client client.Client, cr *enterpr
269265
return result, err
270266
}
271267

272-
cr.Status.Bus = &bus.Spec
273-
cr.Status.LargeMessageStore = &lms.Spec
274-
275268
for i := int32(0); i < cr.Spec.Replicas; i++ {
276269
ingClient := mgr.getClient(ctx, i)
277270
err = ingClient.RestartSplunk()
@@ -280,6 +273,9 @@ func ApplyIngestorCluster(ctx context.Context, client client.Client, cr *enterpr
280273
}
281274
scopedLog.Info("Restarted splunk", "ingestor", i)
282275
}
276+
277+
cr.Status.Bus = &bus.Spec
278+
cr.Status.LargeMessageStore = &lms.Spec
283279
}
284280

285281
// Upgrade fron automated MC to MC CRD
@@ -392,6 +388,13 @@ func (mgr *ingestorClusterPodManager) handlePushBusChange(ctx context.Context, n
392388
}
393389
splunkClient := mgr.newSplunkClient(fmt.Sprintf("https://%s:8089", fqdnName), "admin", string(adminPwd))
394390

391+
if newCR.Status.Bus == nil {
392+
newCR.Status.Bus = &enterpriseApi.BusSpec{}
393+
}
394+
if newCR.Status.LargeMessageStore == nil {
395+
newCR.Status.LargeMessageStore = &enterpriseApi.LargeMessageStoreSpec{}
396+
}
397+
395398
afterDelete := false
396399
if (bus.Spec.SQS.Name != "" && newCR.Status.Bus.SQS.Name != "" && bus.Spec.SQS.Name != newCR.Status.Bus.SQS.Name) ||
397400
(bus.Spec.Provider != "" && newCR.Status.Bus.Provider != "" && bus.Spec.Provider != newCR.Status.Bus.Provider) {
@@ -437,15 +440,9 @@ func (mgr *ingestorClusterPodManager) handlePushBusChange(ctx context.Context, n
437440
// getChangedBusFieldsForIngestor returns a list of changed bus and pipeline fields for ingestor pods
438441
func getChangedBusFieldsForIngestor(bus *enterpriseApi.Bus, lms *enterpriseApi.LargeMessageStore, busIngestorStatus *enterpriseApi.IngestorCluster, afterDelete bool, s3AccessKey, s3SecretKey string) (busChangedFields, pipelineChangedFields [][]string) {
439442
oldPB := busIngestorStatus.Status.Bus
440-
if oldPB == nil {
441-
oldPB = &enterpriseApi.BusSpec{}
442-
}
443443
newPB := &bus.Spec
444444

445445
oldLMS := busIngestorStatus.Status.LargeMessageStore
446-
if oldLMS == nil {
447-
oldLMS = &enterpriseApi.LargeMessageStoreSpec{}
448-
}
449446
newLMS := &lms.Spec
450447

451448
// Push changed bus fields

pkg/splunk/enterprise/ingestorcluster_test.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -454,7 +454,10 @@ func TestGetChangedBusFieldsForIngestor(t *testing.T) {
454454
Name: lms.Name,
455455
},
456456
},
457-
Status: enterpriseApi.IngestorClusterStatus{},
457+
Status: enterpriseApi.IngestorClusterStatus{
458+
Bus: &enterpriseApi.BusSpec{},
459+
LargeMessageStore: &enterpriseApi.LargeMessageStoreSpec{},
460+
},
458461
}
459462

460463
key := "key"

0 commit comments

Comments
 (0)