Skip to content

Commit 155b21a

Browse files
committed
CSPL-4360 Fix failing to get k8s secret
1 parent e0a10ba commit 155b21a

File tree

3 files changed

+13
-11
lines changed

3 files changed

+13
-11
lines changed

pkg/splunk/enterprise/indexercluster.go

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ func ApplyIndexerClusterManager(ctx context.Context, client splcommon.Controller
115115
cr.Status.ClusterManagerPhase = enterpriseApi.PhaseError
116116
}
117117

118-
mgr := newIndexerClusterPodManager(scopedLog, cr, namespaceScopedSecret, splclient.NewSplunkClient)
118+
mgr := newIndexerClusterPodManager(scopedLog, cr, namespaceScopedSecret, splclient.NewSplunkClient, client)
119119
// Check if we have configured enough number(<= RF) of replicas
120120
if mgr.cr.Status.ClusterManagerPhase == enterpriseApi.PhaseReady {
121121
err = VerifyRFPeers(ctx, mgr, client)
@@ -248,7 +248,7 @@ func ApplyIndexerClusterManager(ctx context.Context, client splcommon.Controller
248248
if cr.Spec.QueueRef.Namespace != "" {
249249
ns = cr.Spec.QueueRef.Namespace
250250
}
251-
err = client.Get(context.Background(), types.NamespacedName{
251+
err = client.Get(ctx, types.NamespacedName{
252252
Name: cr.Spec.QueueRef.Name,
253253
Namespace: ns,
254254
}, &queue)
@@ -272,7 +272,7 @@ func ApplyIndexerClusterManager(ctx context.Context, client splcommon.Controller
272272
if cr.Spec.ObjectStorageRef.Namespace != "" {
273273
ns = cr.Spec.ObjectStorageRef.Namespace
274274
}
275-
err = client.Get(context.Background(), types.NamespacedName{
275+
err = client.Get(ctx, types.NamespacedName{
276276
Name: cr.Spec.ObjectStorageRef.Name,
277277
Namespace: ns,
278278
}, &os)
@@ -292,7 +292,7 @@ func ApplyIndexerClusterManager(ctx context.Context, client splcommon.Controller
292292
// If bus is updated
293293
if cr.Spec.QueueRef.Name != "" {
294294
if cr.Status.Queue == nil || cr.Status.ObjectStorage == nil || !reflect.DeepEqual(*cr.Status.Queue, queue.Spec) || !reflect.DeepEqual(*cr.Status.ObjectStorage, os.Spec) {
295-
mgr := newIndexerClusterPodManager(scopedLog, cr, namespaceScopedSecret, splclient.NewSplunkClient)
295+
mgr := newIndexerClusterPodManager(scopedLog, cr, namespaceScopedSecret, splclient.NewSplunkClient, client)
296296
err = mgr.handlePullQueueChange(ctx, cr, queueCopy, osCopy, client)
297297
if err != nil {
298298
eventPublisher.Warning(ctx, "ApplyIndexerClusterManager", fmt.Sprintf("Failed to update conf file for Queue/Pipeline config change after pod creation: %s", err.Error()))
@@ -443,7 +443,7 @@ func ApplyIndexerCluster(ctx context.Context, client splcommon.ControllerClient,
443443
cr.Status.ClusterMasterPhase = enterpriseApi.PhaseError
444444
}
445445

446-
mgr := newIndexerClusterPodManager(scopedLog, cr, namespaceScopedSecret, splclient.NewSplunkClient)
446+
mgr := newIndexerClusterPodManager(scopedLog, cr, namespaceScopedSecret, splclient.NewSplunkClient, client)
447447
// Check if we have configured enough number(<= RF) of replicas
448448
if mgr.cr.Status.ClusterMasterPhase == enterpriseApi.PhaseReady {
449449
err = VerifyRFPeers(ctx, mgr, client)
@@ -621,7 +621,7 @@ func ApplyIndexerCluster(ctx context.Context, client splcommon.ControllerClient,
621621
// If bus is updated
622622
if cr.Spec.QueueRef.Name != "" {
623623
if cr.Status.Queue == nil || cr.Status.ObjectStorage == nil || !reflect.DeepEqual(*cr.Status.Queue, queue.Spec) || !reflect.DeepEqual(*cr.Status.ObjectStorage, os.Spec) {
624-
mgr := newIndexerClusterPodManager(scopedLog, cr, namespaceScopedSecret, splclient.NewSplunkClient)
624+
mgr := newIndexerClusterPodManager(scopedLog, cr, namespaceScopedSecret, splclient.NewSplunkClient, client)
625625
err = mgr.handlePullQueueChange(ctx, cr, queueCopy, osCopy, client)
626626
if err != nil {
627627
eventPublisher.Warning(ctx, "ApplyIndexerClusterManager", fmt.Sprintf("Failed to update conf file for Queue/Pipeline config change after pod creation: %s", err.Error()))
@@ -722,12 +722,13 @@ type indexerClusterPodManager struct {
722722
}
723723

724724
// newIndexerClusterPodManager function to create pod manager this is added to write unit test case
725-
var newIndexerClusterPodManager = func(log logr.Logger, cr *enterpriseApi.IndexerCluster, secret *corev1.Secret, newSplunkClient NewSplunkClientFunc) indexerClusterPodManager {
725+
var newIndexerClusterPodManager = func(log logr.Logger, cr *enterpriseApi.IndexerCluster, secret *corev1.Secret, newSplunkClient NewSplunkClientFunc, c splcommon.ControllerClient) indexerClusterPodManager {
726726
return indexerClusterPodManager{
727727
log: log,
728728
cr: cr,
729729
secrets: secret,
730730
newSplunkClient: newSplunkClient,
731+
c: c,
731732
}
732733
}
733734

@@ -1391,7 +1392,7 @@ func (mgr *indexerClusterPodManager) handlePullQueueChange(ctx context.Context,
13911392
func getChangedQueueFieldsForIndexer(queue *enterpriseApi.Queue, os *enterpriseApi.ObjectStorage, queueStatus *enterpriseApi.QueueSpec, osStatus *enterpriseApi.ObjectStorageSpec, afterDelete bool, s3AccessKey, s3SecretKey string) (queueChangedFieldsInputs, queueChangedFieldsOutputs, pipelineChangedFields [][]string) {
13921393
// Push all queue fields
13931394
queueChangedFieldsInputs, queueChangedFieldsOutputs = pullQueueChanged(queueStatus, &queue.Spec, osStatus, &os.Spec, afterDelete, s3AccessKey, s3SecretKey)
1394-
1395+
13951396
// Always set all pipeline fields, not just changed ones
13961397
pipelineChangedFields = pipelineConfig(true)
13971398

pkg/splunk/enterprise/indexercluster_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1569,7 +1569,7 @@ func TestIndexerClusterWithReadyState(t *testing.T) {
15691569
return nil
15701570
}
15711571

1572-
newIndexerClusterPodManager = func(log logr.Logger, cr *enterpriseApi.IndexerCluster, secret *corev1.Secret, newSplunkClient NewSplunkClientFunc) indexerClusterPodManager {
1572+
newIndexerClusterPodManager = func(log logr.Logger, cr *enterpriseApi.IndexerCluster, secret *corev1.Secret, newSplunkClient NewSplunkClientFunc, c splcommon.ControllerClient) indexerClusterPodManager {
15731573
return indexerClusterPodManager{
15741574
log: log,
15751575
cr: cr,
@@ -1579,6 +1579,7 @@ func TestIndexerClusterWithReadyState(t *testing.T) {
15791579
c.Client = mclient
15801580
return c
15811581
},
1582+
c: c,
15821583
}
15831584
}
15841585

pkg/splunk/enterprise/ingestorcluster.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ func ApplyIngestorCluster(ctx context.Context, client client.Client, cr *enterpr
238238
if cr.Spec.ObjectStorageRef.Namespace != "" {
239239
ns = cr.Spec.ObjectStorageRef.Namespace
240240
}
241-
err = client.Get(context.Background(), types.NamespacedName{
241+
err = client.Get(ctx, types.NamespacedName{
242242
Name: cr.Spec.ObjectStorageRef.Name,
243243
Namespace: ns,
244244
}, &os)
@@ -420,7 +420,7 @@ func (mgr *ingestorClusterPodManager) handlePushQueueChange(ctx context.Context,
420420
}
421421
}
422422

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

425425
for _, pbVal := range queueChangedFields {
426426
if err := splunkClient.UpdateConfFile(scopedLog, "outputs", fmt.Sprintf("remote_queue:%s", queue.Spec.SQS.Name), [][]string{pbVal}); err != nil {

0 commit comments

Comments
 (0)