Skip to content

Commit e0a10ba

Browse files
committed
CSPL-4360 Fix validation that fails for status
1 parent fafed27 commit e0a10ba

File tree

4 files changed

+32
-42
lines changed

4 files changed

+32
-42
lines changed

pkg/splunk/enterprise/indexercluster.go

Lines changed: 14 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1327,20 +1327,22 @@ func (mgr *indexerClusterPodManager) handlePullQueueChange(ctx context.Context,
13271327
}
13281328
splunkClient := newSplunkClientForQueuePipeline(fmt.Sprintf("https://%s:8089", fqdnName), "admin", string(adminPwd))
13291329

1330-
if newCR.Status.Queue == nil {
1331-
newCR.Status.Queue = &enterpriseApi.QueueSpec{}
1330+
newCrStatusQueue := newCR.Status.Queue
1331+
if newCrStatusQueue == nil {
1332+
newCrStatusQueue = &enterpriseApi.QueueSpec{}
13321333
}
1333-
if newCR.Status.ObjectStorage == nil {
1334-
newCR.Status.ObjectStorage = &enterpriseApi.ObjectStorageSpec{}
1334+
newCrStatusObjectStorage := newCR.Status.ObjectStorage
1335+
if newCrStatusObjectStorage == nil {
1336+
newCrStatusObjectStorage = &enterpriseApi.ObjectStorageSpec{}
13351337
}
13361338

13371339
afterDelete := false
1338-
if (queue.Spec.SQS.Name != "" && newCR.Status.Queue.SQS.Name != "" && queue.Spec.SQS.Name != newCR.Status.Queue.SQS.Name) ||
1339-
(queue.Spec.Provider != "" && newCR.Status.Queue.Provider != "" && queue.Spec.Provider != newCR.Status.Queue.Provider) {
1340-
if err := splunkClient.DeleteConfFileProperty(scopedLog, "outputs", fmt.Sprintf("remote_queue:%s", newCR.Status.Queue.SQS.Name)); err != nil {
1340+
if (queue.Spec.SQS.Name != "" && newCrStatusQueue.SQS.Name != "" && queue.Spec.SQS.Name != newCrStatusQueue.SQS.Name) ||
1341+
(queue.Spec.Provider != "" && newCrStatusQueue.Provider != "" && queue.Spec.Provider != newCrStatusQueue.Provider) {
1342+
if err := splunkClient.DeleteConfFileProperty(scopedLog, "outputs", fmt.Sprintf("remote_queue:%s", newCrStatusQueue.SQS.Name)); err != nil {
13411343
updateErr = err
13421344
}
1343-
if err := splunkClient.DeleteConfFileProperty(scopedLog, "inputs", fmt.Sprintf("remote_queue:%s", newCR.Status.Queue.SQS.Name)); err != nil {
1345+
if err := splunkClient.DeleteConfFileProperty(scopedLog, "inputs", fmt.Sprintf("remote_queue:%s", newCrStatusQueue.SQS.Name)); err != nil {
13441346
updateErr = err
13451347
}
13461348
afterDelete = true
@@ -1360,7 +1362,7 @@ func (mgr *indexerClusterPodManager) handlePullQueueChange(ctx context.Context,
13601362
}
13611363
}
13621364

1363-
queueChangedFieldsInputs, queueChangedFieldsOutputs, pipelineChangedFields := getChangedQueueFieldsForIndexer(&queue, &os, newCR, afterDelete, s3AccessKey, s3SecretKey)
1365+
queueChangedFieldsInputs, queueChangedFieldsOutputs, pipelineChangedFields := getChangedQueueFieldsForIndexer(&queue, &os, newCrStatusQueue, newCrStatusObjectStorage, afterDelete, s3AccessKey, s3SecretKey)
13641366

13651367
for _, pbVal := range queueChangedFieldsOutputs {
13661368
if err := splunkClient.UpdateConfFile(scopedLog, "outputs", fmt.Sprintf("remote_queue:%s", queue.Spec.SQS.Name), [][]string{pbVal}); err != nil {
@@ -1386,22 +1388,10 @@ func (mgr *indexerClusterPodManager) handlePullQueueChange(ctx context.Context,
13861388
}
13871389

13881390
// getChangedQueueFieldsForIndexer returns a list of changed queue and pipeline fields for indexer pods
1389-
func getChangedQueueFieldsForIndexer(queue *enterpriseApi.Queue, os *enterpriseApi.ObjectStorage, queueIndexerStatus *enterpriseApi.IndexerCluster, afterDelete bool, s3AccessKey, s3SecretKey string) (queueChangedFieldsInputs, queueChangedFieldsOutputs, pipelineChangedFields [][]string) {
1390-
// Compare queue fields
1391-
oldQueue := queueIndexerStatus.Status.Queue
1392-
if oldQueue == nil {
1393-
oldQueue = &enterpriseApi.QueueSpec{}
1394-
}
1395-
newQueue := queue.Spec
1396-
1397-
oldOS := queueIndexerStatus.Status.ObjectStorage
1398-
if oldOS == nil {
1399-
oldOS = &enterpriseApi.ObjectStorageSpec{}
1400-
}
1401-
newOS := os.Spec
1402-
1391+
func getChangedQueueFieldsForIndexer(queue *enterpriseApi.Queue, os *enterpriseApi.ObjectStorage, queueStatus *enterpriseApi.QueueSpec, osStatus *enterpriseApi.ObjectStorageSpec, afterDelete bool, s3AccessKey, s3SecretKey string) (queueChangedFieldsInputs, queueChangedFieldsOutputs, pipelineChangedFields [][]string) {
14031392
// Push all queue fields
1404-
queueChangedFieldsInputs, queueChangedFieldsOutputs = pullQueueChanged(oldQueue, &newQueue, oldOS, &newOS, afterDelete, s3AccessKey, s3SecretKey)
1393+
queueChangedFieldsInputs, queueChangedFieldsOutputs = pullQueueChanged(queueStatus, &queue.Spec, osStatus, &os.Spec, afterDelete, s3AccessKey, s3SecretKey)
1394+
14051395
// Always set all pipeline fields, not just changed ones
14061396
pipelineChangedFields = pipelineConfig(true)
14071397

pkg/splunk/enterprise/indexercluster_test.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2096,11 +2096,15 @@ func TestGetChangedQueueFieldsForIndexer(t *testing.T) {
20962096
Name: os.Name,
20972097
},
20982098
},
2099+
Status: enterpriseApi.IndexerClusterStatus{
2100+
Queue: &enterpriseApi.QueueSpec{},
2101+
ObjectStorage: &enterpriseApi.ObjectStorageSpec{},
2102+
},
20992103
}
21002104

21012105
key := "key"
21022106
secret := "secret"
2103-
queueChangedFieldsInputs, queueChangedFieldsOutputs, pipelineChangedFields := getChangedQueueFieldsForIndexer(&queue, &os, newCR, false, key, secret)
2107+
queueChangedFieldsInputs, queueChangedFieldsOutputs, pipelineChangedFields := getChangedQueueFieldsForIndexer(&queue, &os, newCR.Status.Queue, newCR.Status.ObjectStorage, false, key, secret)
21042108
assert.Equal(t, 10, len(queueChangedFieldsInputs))
21052109
assert.Equal(t, [][]string{
21062110
{"remote_queue.type", provider},

pkg/splunk/enterprise/ingestorcluster.go

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -388,17 +388,19 @@ func (mgr *ingestorClusterPodManager) handlePushQueueChange(ctx context.Context,
388388
}
389389
splunkClient := mgr.newSplunkClient(fmt.Sprintf("https://%s:8089", fqdnName), "admin", string(adminPwd))
390390

391-
if newCR.Status.Queue == nil {
392-
newCR.Status.Queue = &enterpriseApi.QueueSpec{}
391+
newCrStatusQueue := newCR.Status.Queue
392+
if newCrStatusQueue == nil {
393+
newCrStatusQueue = &enterpriseApi.QueueSpec{}
393394
}
394-
if newCR.Status.ObjectStorage == nil {
395-
newCR.Status.ObjectStorage = &enterpriseApi.ObjectStorageSpec{}
395+
newCrStatusObjectStorage := newCR.Status.ObjectStorage
396+
if newCrStatusObjectStorage == nil {
397+
newCrStatusObjectStorage = &enterpriseApi.ObjectStorageSpec{}
396398
}
397399

398400
afterDelete := false
399-
if (queue.Spec.SQS.Name != "" && newCR.Status.Queue.SQS.Name != "" && queue.Spec.SQS.Name != newCR.Status.Queue.SQS.Name) ||
400-
(queue.Spec.Provider != "" && newCR.Status.Queue.Provider != "" && queue.Spec.Provider != newCR.Status.Queue.Provider) {
401-
if err := splunkClient.DeleteConfFileProperty(scopedLog, "outputs", fmt.Sprintf("remote_queue:%s", newCR.Status.Queue.SQS.Name)); err != nil {
401+
if (queue.Spec.SQS.Name != "" && newCrStatusQueue.SQS.Name != "" && queue.Spec.SQS.Name != newCrStatusQueue.SQS.Name) ||
402+
(queue.Spec.Provider != "" && newCrStatusQueue.Provider != "" && queue.Spec.Provider != newCrStatusQueue.Provider) {
403+
if err := splunkClient.DeleteConfFileProperty(scopedLog, "outputs", fmt.Sprintf("remote_queue:%s", newCrStatusQueue.SQS.Name)); err != nil {
402404
updateErr = err
403405
}
404406
afterDelete = true
@@ -418,7 +420,7 @@ func (mgr *ingestorClusterPodManager) handlePushQueueChange(ctx context.Context,
418420
}
419421
}
420422

421-
queueChangedFields, pipelineChangedFields := getChangedQueueFieldsForIngestor(&queue, &os, newCR, afterDelete, s3AccessKey, s3SecretKey)
423+
queueChangedFields, pipelineChangedFields := getChangedQueueFieldsForIngestor(&queue, &os, newCrStatusQueue, newCrStatusObjectStorage,afterDelete, s3AccessKey, s3SecretKey)
422424

423425
for _, pbVal := range queueChangedFields {
424426
if err := splunkClient.UpdateConfFile(scopedLog, "outputs", fmt.Sprintf("remote_queue:%s", queue.Spec.SQS.Name), [][]string{pbVal}); err != nil {
@@ -438,15 +440,9 @@ func (mgr *ingestorClusterPodManager) handlePushQueueChange(ctx context.Context,
438440
}
439441

440442
// getChangedBusFieldsForIngestor returns a list of changed bus and pipeline fields for ingestor pods
441-
func getChangedQueueFieldsForIngestor(queue *enterpriseApi.Queue, os *enterpriseApi.ObjectStorage, queueIngestorStatus *enterpriseApi.IngestorCluster, afterDelete bool, s3AccessKey, s3SecretKey string) (queueChangedFields, pipelineChangedFields [][]string) {
442-
oldQueue := queueIngestorStatus.Status.Queue
443-
newQueue := &queue.Spec
444-
445-
oldOS := queueIngestorStatus.Status.ObjectStorage
446-
newOS := &os.Spec
447-
443+
func getChangedQueueFieldsForIngestor(queue *enterpriseApi.Queue, os *enterpriseApi.ObjectStorage, queueStatus *enterpriseApi.QueueSpec, osStatus *enterpriseApi.ObjectStorageSpec, afterDelete bool, s3AccessKey, s3SecretKey string) (queueChangedFields, pipelineChangedFields [][]string) {
448444
// Push changed bus fields
449-
queueChangedFields = pushQueueChanged(oldQueue, newQueue, oldOS, newOS, afterDelete, s3AccessKey, s3SecretKey)
445+
queueChangedFields = pushQueueChanged(queueStatus, &queue.Spec, osStatus, &os.Spec, afterDelete, s3AccessKey, s3SecretKey)
450446

451447
// Always changed pipeline fields
452448
pipelineChangedFields = pipelineConfig(false)

pkg/splunk/enterprise/ingestorcluster_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,7 @@ func TestGetChangedQueueFieldsForIngestor(t *testing.T) {
462462

463463
key := "key"
464464
secret := "secret"
465-
queueChangedFields, pipelineChangedFields := getChangedQueueFieldsForIngestor(&queue, &os, newCR, false, key, secret)
465+
queueChangedFields, pipelineChangedFields := getChangedQueueFieldsForIngestor(&queue, &os, newCR.Status.Queue, newCR.Status.ObjectStorage, false, key, secret)
466466

467467
assert.Equal(t, 12, len(queueChangedFields))
468468
assert.Equal(t, [][]string{

0 commit comments

Comments
 (0)