Skip to content

Commit 0a58aad

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

File tree

3 files changed

+21
-22
lines changed

3 files changed

+21
-22
lines changed

pkg/splunk/enterprise/indexercluster.go

Lines changed: 9 additions & 10 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 {
@@ -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 {
@@ -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: 8 additions & 11 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 {
@@ -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)