Skip to content

Commit 3c7b2d7

Browse files
committed
CSPL-4360 Fix failing tests
1 parent 143dbe0 commit 3c7b2d7

File tree

4 files changed

+54
-36
lines changed

4 files changed

+54
-36
lines changed

pkg/splunk/enterprise/indexercluster.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1346,7 +1346,7 @@ func (mgr *indexerClusterPodManager) handlePullBusChange(ctx context.Context, ne
13461346

13471347
// Secret reference
13481348
s3AccessKey, s3SecretKey := "", ""
1349-
if bus.Spec.Provider == "sqs" {
1349+
if bus.Spec.Provider == "sqs" && newCR.Spec.ServiceAccount == "" {
13501350
for _, vol := range bus.Spec.SQS.VolList {
13511351
if vol.SecretRef != "" {
13521352
s3AccessKey, s3SecretKey, err = GetBusRemoteVolumeSecrets(ctx, vol, k8s, newCR)
@@ -1431,8 +1431,10 @@ func pullBusChanged(oldBus, newBus *enterpriseApi.BusSpec, oldLMS, newLMS *enter
14311431
inputs = append(inputs, []string{"remote_queue.type", busProvider})
14321432
}
14331433
if !reflect.DeepEqual(oldBus.SQS.VolList, newBus.SQS.VolList) || afterDelete {
1434-
inputs = append(inputs, []string{fmt.Sprintf("remote_queue.%s.access_key", busProvider), s3AccessKey})
1435-
inputs = append(inputs, []string{fmt.Sprintf("remote_queue.%s.secret_key", busProvider), s3SecretKey})
1434+
if s3AccessKey != "" && s3SecretKey != "" {
1435+
inputs = append(inputs, []string{fmt.Sprintf("remote_queue.%s.access_key", busProvider), s3AccessKey})
1436+
inputs = append(inputs, []string{fmt.Sprintf("remote_queue.%s.secret_key", busProvider), s3SecretKey})
1437+
}
14361438
}
14371439
if oldBus.SQS.Region != newBus.SQS.Region || afterDelete {
14381440
inputs = append(inputs, []string{fmt.Sprintf("remote_queue.%s.auth_region", busProvider), newBus.SQS.Region})

pkg/splunk/enterprise/indexercluster_test.go

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2404,7 +2404,7 @@ func TestApplyIndexerClusterManager_Bus_Success(t *testing.T) {
24042404
c := fake.NewClientBuilder().WithScheme(scheme).Build()
24052405

24062406
// Object definitions
2407-
bus := enterpriseApi.Bus{
2407+
bus := &enterpriseApi.Bus{
24082408
TypeMeta: metav1.TypeMeta{
24092409
Kind: "Bus",
24102410
APIVersion: "enterprise.splunk.com/v4",
@@ -2423,7 +2423,26 @@ func TestApplyIndexerClusterManager_Bus_Success(t *testing.T) {
24232423
},
24242424
},
24252425
}
2426-
c.Create(ctx, &bus)
2426+
c.Create(ctx, bus)
2427+
2428+
lms := &enterpriseApi.LargeMessageStore{
2429+
TypeMeta: metav1.TypeMeta{
2430+
Kind: "LargeMessageStore",
2431+
APIVersion: "enterprise.splunk.com/v4",
2432+
},
2433+
ObjectMeta: metav1.ObjectMeta{
2434+
Name: "lms",
2435+
Namespace: "test",
2436+
},
2437+
Spec: enterpriseApi.LargeMessageStoreSpec{
2438+
Provider: "s3",
2439+
S3: enterpriseApi.S3Spec{
2440+
Endpoint: "https://s3.us-west-2.amazonaws.com",
2441+
Path: "s3://bucket/key",
2442+
},
2443+
},
2444+
}
2445+
c.Create(ctx, lms)
24272446

24282447
cm := &enterpriseApi.ClusterManager{
24292448
TypeMeta: metav1.TypeMeta{Kind: "ClusterManager"},
@@ -2449,6 +2468,10 @@ func TestApplyIndexerClusterManager_Bus_Success(t *testing.T) {
24492468
Name: bus.Name,
24502469
Namespace: bus.Namespace,
24512470
},
2471+
LargeMessageStoreRef: corev1.ObjectReference{
2472+
Name: lms.Name,
2473+
Namespace: lms.Namespace,
2474+
},
24522475
CommonSplunkSpec: enterpriseApi.CommonSplunkSpec{
24532476
ClusterManagerRef: corev1.ObjectReference{
24542477
Name: "cm",

pkg/splunk/enterprise/ingestorcluster.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,7 @@ func (mgr *ingestorClusterPodManager) handlePushBusChange(ctx context.Context, n
401401

402402
// Secret reference
403403
s3AccessKey, s3SecretKey := "", ""
404-
if bus.Spec.Provider == "sqs" {
404+
if bus.Spec.Provider == "sqs" && newCR.Spec.ServiceAccount == "" {
405405
for _, vol := range bus.Spec.SQS.VolList {
406406
if vol.SecretRef != "" {
407407
s3AccessKey, s3SecretKey, err = GetBusRemoteVolumeSecrets(ctx, vol, k8s, newCR)
@@ -502,8 +502,10 @@ func pushBusChanged(oldBus, newBus *enterpriseApi.BusSpec, oldLMS, newLMS *enter
502502
output = append(output, []string{"remote_queue.type", busProvider})
503503
}
504504
if !reflect.DeepEqual(oldBus.SQS.VolList, newBus.SQS.VolList) || afterDelete {
505-
output = append(output, []string{fmt.Sprintf("remote_queue.%s.access_key", busProvider), s3AccessKey})
506-
output = append(output, []string{fmt.Sprintf("remote_queue.%s.secret_key", busProvider), s3SecretKey})
505+
if s3AccessKey != "" && s3SecretKey != "" {
506+
output = append(output, []string{fmt.Sprintf("remote_queue.%s.access_key", busProvider), s3AccessKey})
507+
output = append(output, []string{fmt.Sprintf("remote_queue.%s.secret_key", busProvider), s3SecretKey})
508+
}
507509
}
508510
if oldBus.SQS.Region != newBus.SQS.Region || afterDelete {
509511
output = append(output, []string{fmt.Sprintf("remote_queue.%s.auth_region", busProvider), newBus.SQS.Region})

pkg/splunk/enterprise/ingestorcluster_test.go

Lines changed: 19 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ import (
3232
appsv1 "k8s.io/api/apps/v1"
3333
corev1 "k8s.io/api/core/v1"
3434
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
35-
"k8s.io/apimachinery/pkg/types"
35+
"k8s.io/apimachinery/pkg/runtime"
36+
"sigs.k8s.io/controller-runtime/pkg/client/fake"
3637
)
3738

3839
func init() {
@@ -55,7 +56,11 @@ func TestApplyIngestorCluster(t *testing.T) {
5556

5657
ctx := context.TODO()
5758

58-
c := spltest.NewMockClient()
59+
scheme := runtime.NewScheme()
60+
_ = enterpriseApi.AddToScheme(scheme)
61+
_ = corev1.AddToScheme(scheme)
62+
_ = appsv1.AddToScheme(scheme)
63+
c := fake.NewClientBuilder().WithScheme(scheme).Build()
5964

6065
// Object definitions
6166
provider := "sqs_smartbus"
@@ -81,7 +86,7 @@ func TestApplyIngestorCluster(t *testing.T) {
8186
}
8287
c.Create(ctx, bus)
8388

84-
lms := enterpriseApi.LargeMessageStore{
89+
lms := &enterpriseApi.LargeMessageStore{
8590
TypeMeta: metav1.TypeMeta{
8691
Kind: "LargeMessageStore",
8792
APIVersion: "enterprise.splunk.com/v4",
@@ -98,7 +103,7 @@ func TestApplyIngestorCluster(t *testing.T) {
98103
},
99104
},
100105
}
101-
c.Create(ctx, &lms)
106+
c.Create(ctx, lms)
102107

103108
cr := &enterpriseApi.IngestorCluster{
104109
TypeMeta: metav1.TypeMeta{
@@ -112,7 +117,8 @@ func TestApplyIngestorCluster(t *testing.T) {
112117
Spec: enterpriseApi.IngestorClusterSpec{
113118
Replicas: 3,
114119
CommonSplunkSpec: enterpriseApi.CommonSplunkSpec{
115-
Mock: true,
120+
Mock: true,
121+
ServiceAccount: "sa",
116122
},
117123
BusRef: corev1.ObjectReference{
118124
Name: bus.Name,
@@ -242,29 +248,6 @@ func TestApplyIngestorCluster(t *testing.T) {
242248
assert.True(t, result.Requeue)
243249
assert.NotEqual(t, enterpriseApi.PhaseError, cr.Status.Phase)
244250

245-
// Ensure stored StatefulSet status reflects readiness after any reconcile modifications
246-
fetched := &appsv1.StatefulSet{}
247-
_ = c.Get(ctx, types.NamespacedName{Name: "splunk-test-ingestor", Namespace: "test"}, fetched)
248-
fetched.Status.Replicas = replicas
249-
fetched.Status.ReadyReplicas = replicas
250-
fetched.Status.UpdatedReplicas = replicas
251-
if fetched.Status.UpdateRevision == "" {
252-
fetched.Status.UpdateRevision = "v1"
253-
}
254-
c.Update(ctx, fetched)
255-
256-
// Guarantee all pods have matching revision label
257-
for _, pn := range []string{"splunk-test-ingestor-0", "splunk-test-ingestor-1", "splunk-test-ingestor-2"} {
258-
p := &corev1.Pod{}
259-
if err := c.Get(ctx, types.NamespacedName{Name: pn, Namespace: "test"}, p); err == nil {
260-
if p.Labels == nil {
261-
p.Labels = map[string]string{}
262-
}
263-
p.Labels["controller-revision-hash"] = fetched.Status.UpdateRevision
264-
c.Update(ctx, p)
265-
}
266-
}
267-
268251
// outputs.conf
269252
origNew := newIngestorClusterPodManager
270253
mockHTTPClient := &spltest.MockHTTPClient{}
@@ -280,6 +263,7 @@ func TestApplyIngestorCluster(t *testing.T) {
280263
defer func() { newIngestorClusterPodManager = origNew }()
281264

282265
propertyKVList := [][]string{
266+
{"remote_queue.type", provider},
283267
{fmt.Sprintf("remote_queue.%s.encoding_format", provider), "s2s"},
284268
{fmt.Sprintf("remote_queue.%s.auth_region", provider), bus.Spec.SQS.Region},
285269
{fmt.Sprintf("remote_queue.%s.endpoint", provider), bus.Spec.SQS.Endpoint},
@@ -318,6 +302,13 @@ func TestApplyIngestorCluster(t *testing.T) {
318302
}
319303
}
320304

305+
for i := 0; i < int(cr.Status.ReadyReplicas); i++ {
306+
podName := fmt.Sprintf("splunk-test-ingestor-%d", i)
307+
baseURL := fmt.Sprintf("https://%s.splunk-%s-ingestor-headless.%s.svc.cluster.local:8089/services/server/control/restart", podName, cr.GetName(), cr.GetNamespace())
308+
req, _ := http.NewRequest("POST", baseURL, nil)
309+
mockHTTPClient.AddHandler(req, 200, "", nil)
310+
}
311+
321312
// Second reconcile should now yield Ready
322313
cr.Status.TelAppInstalled = true
323314
result, err = ApplyIngestorCluster(ctx, c, cr)

0 commit comments

Comments
 (0)