Skip to content

Commit 92a70c5

Browse files
committed
CSPL-4212 Add Splunkd restart
1 parent 4e37060 commit 92a70c5

File tree

5 files changed

+60
-18
lines changed

5 files changed

+60
-18
lines changed

pkg/splunk/enterprise/indexercluster.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,15 @@ func ApplyIndexerClusterManager(ctx context.Context, client splcommon.Controller
274274
}
275275

276276
cr.Status.BusConfiguration = busConfig.Spec
277+
278+
for i := int32(0); i < cr.Spec.Replicas; i++ {
279+
idxcClient := mgr.getClient(ctx, i)
280+
err = idxcClient.RestartSplunk()
281+
if err != nil {
282+
return result, err
283+
}
284+
scopedLog.Info("Restarted splunk", "indexer", i)
285+
}
277286
}
278287
}
279288

@@ -565,6 +574,15 @@ func ApplyIndexerCluster(ctx context.Context, client splcommon.ControllerClient,
565574
}
566575

567576
cr.Status.BusConfiguration = busConfig.Spec
577+
578+
for i := int32(0); i < cr.Spec.Replicas; i++ {
579+
idxcClient := mgr.getClient(ctx, i)
580+
err = idxcClient.RestartSplunk()
581+
if err != nil {
582+
return result, err
583+
}
584+
scopedLog.Info("Restarted splunk", "indexer", i)
585+
}
568586
}
569587
}
570588

pkg/splunk/enterprise/ingestorcluster.go

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ func ApplyIngestorCluster(ctx context.Context, client client.Client, cr *enterpr
228228

229229
// If bus config is updated
230230
if !reflect.DeepEqual(cr.Status.BusConfiguration, busConfig.Spec) {
231-
mgr := newIngestorClusterPodManager(scopedLog, cr, namespaceScopedSecret, splclient.NewSplunkClient)
231+
mgr := newIngestorClusterPodManager(scopedLog, cr, namespaceScopedSecret, splclient.NewSplunkClient, client)
232232

233233
err = mgr.handlePushBusChange(ctx, cr, busConfig, client)
234234
if err != nil {
@@ -238,6 +238,15 @@ func ApplyIngestorCluster(ctx context.Context, client client.Client, cr *enterpr
238238
}
239239

240240
cr.Status.BusConfiguration = busConfig.Spec
241+
242+
for i := int32(0); i < cr.Spec.Replicas; i++ {
243+
ingClient := mgr.getClient(ctx, i)
244+
err = ingClient.RestartSplunk()
245+
if err != nil {
246+
return result, err
247+
}
248+
scopedLog.Info("Restarted splunk", "ingestor", i)
249+
}
241250
}
242251

243252
// Upgrade fron automated MC to MC CRD
@@ -280,6 +289,27 @@ func ApplyIngestorCluster(ctx context.Context, client client.Client, cr *enterpr
280289
return result, nil
281290
}
282291

292+
// getClient for ingestorClusterPodManager returns a SplunkClient for the member n
293+
func (mgr *ingestorClusterPodManager) getClient(ctx context.Context, n int32) *splclient.SplunkClient {
294+
reqLogger := log.FromContext(ctx)
295+
scopedLog := reqLogger.WithName("ingestorClusterPodManager.getClient").WithValues("name", mgr.cr.GetName(), "namespace", mgr.cr.GetNamespace())
296+
297+
// Get Pod Name
298+
memberName := GetSplunkStatefulsetPodName(SplunkIngestor, mgr.cr.GetName(), n)
299+
300+
// Get Fully Qualified Domain Name
301+
fqdnName := splcommon.GetServiceFQDN(mgr.cr.GetNamespace(),
302+
fmt.Sprintf("%s.%s", memberName, GetSplunkServiceName(SplunkIngestor, mgr.cr.GetName(), true)))
303+
304+
// Retrieve admin password from Pod
305+
adminPwd, err := splutil.GetSpecificSecretTokenFromPod(ctx, mgr.c, memberName, mgr.cr.GetNamespace(), "password")
306+
if err != nil {
307+
scopedLog.Error(err, "Couldn't retrieve the admin password from pod")
308+
}
309+
310+
return mgr.newSplunkClient(fmt.Sprintf("https://%s:8089", fqdnName), "admin", adminPwd)
311+
}
312+
283313
// validateIngestorClusterSpec checks validity and makes default updates to a IngestorClusterSpec and returns error if something is wrong
284314
func validateIngestorClusterSpec(ctx context.Context, c splcommon.ControllerClient, cr *enterpriseApi.IngestorCluster) error {
285315
// We cannot have 0 replicas in IngestorCluster spec since this refers to number of ingestion pods in an ingestor cluster
@@ -372,19 +402,21 @@ func getChangedBusFieldsForIngestor(busConfig *enterpriseApi.BusConfiguration, b
372402
}
373403

374404
type ingestorClusterPodManager struct {
405+
c splcommon.ControllerClient
375406
log logr.Logger
376407
cr *enterpriseApi.IngestorCluster
377408
secrets *corev1.Secret
378409
newSplunkClient func(managementURI, username, password string) *splclient.SplunkClient
379410
}
380411

381412
// newIngestorClusterPodManager function to create pod manager this is added to write unit test case
382-
var newIngestorClusterPodManager = func(log logr.Logger, cr *enterpriseApi.IngestorCluster, secret *corev1.Secret, newSplunkClient NewSplunkClientFunc) ingestorClusterPodManager {
413+
var newIngestorClusterPodManager = func(log logr.Logger, cr *enterpriseApi.IngestorCluster, secret *corev1.Secret, newSplunkClient NewSplunkClientFunc, c splcommon.ControllerClient) ingestorClusterPodManager {
383414
return ingestorClusterPodManager{
384415
log: log,
385416
cr: cr,
386417
secrets: secret,
387418
newSplunkClient: newSplunkClient,
419+
c: c,
388420
}
389421
}
390422

pkg/splunk/enterprise/ingestorcluster_test.go

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,14 @@ import (
2525
"github.com/go-logr/logr"
2626
enterpriseApi "github.com/splunk/splunk-operator/api/v4"
2727
splclient "github.com/splunk/splunk-operator/pkg/splunk/client"
28+
splcommon "github.com/splunk/splunk-operator/pkg/splunk/common"
2829
spltest "github.com/splunk/splunk-operator/pkg/splunk/test"
2930
splutil "github.com/splunk/splunk-operator/pkg/splunk/util"
3031
"github.com/stretchr/testify/assert"
3132
appsv1 "k8s.io/api/apps/v1"
3233
corev1 "k8s.io/api/core/v1"
3334
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
34-
"k8s.io/apimachinery/pkg/runtime"
3535
"k8s.io/apimachinery/pkg/types"
36-
"sigs.k8s.io/controller-runtime/pkg/client/fake"
3736
)
3837

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

5756
ctx := context.TODO()
5857

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

6560
// Object definitions
6661
busConfig := &enterpriseApi.BusConfiguration{
@@ -250,8 +245,9 @@ func TestApplyIngestorCluster(t *testing.T) {
250245
// outputs.conf
251246
origNew := newIngestorClusterPodManager
252247
mockHTTPClient := &spltest.MockHTTPClient{}
253-
newIngestorClusterPodManager = func(l logr.Logger, cr *enterpriseApi.IngestorCluster, secret *corev1.Secret, _ NewSplunkClientFunc) ingestorClusterPodManager {
248+
newIngestorClusterPodManager = func(l logr.Logger, cr *enterpriseApi.IngestorCluster, secret *corev1.Secret, _ NewSplunkClientFunc, c splcommon.ControllerClient) ingestorClusterPodManager {
254249
return ingestorClusterPodManager{
250+
c: c,
255251
log: l, cr: cr, secrets: secret,
256252
newSplunkClient: func(uri, user, pass string) *splclient.SplunkClient {
257253
return &splclient.SplunkClient{ManagementURI: uri, Username: user, Password: pass, Client: mockHTTPClient}

pkg/splunk/enterprise/util_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2624,6 +2624,8 @@ func TestUpdateCRStatus(t *testing.T) {
26242624
WithStatusSubresource(&enterpriseApi.Standalone{}).
26252625
WithStatusSubresource(&enterpriseApi.MonitoringConsole{}).
26262626
WithStatusSubresource(&enterpriseApi.IndexerCluster{}).
2627+
WithStatusSubresource(&enterpriseApi.BusConfiguration{}).
2628+
WithStatusSubresource(&enterpriseApi.IngestorCluster{}).
26272629
WithStatusSubresource(&enterpriseApi.SearchHeadCluster{})
26282630
c := builder.Build()
26292631
ctx := context.TODO()
@@ -3302,9 +3304,11 @@ func TestGetCurrentImage(t *testing.T) {
33023304
WithStatusSubresource(&enterpriseApi.ClusterManager{}).
33033305
WithStatusSubresource(&enterpriseApi.Standalone{}).
33043306
WithStatusSubresource(&enterpriseApi.MonitoringConsole{}).
3307+
WithStatusSubresource(&enterpriseApi.BusConfiguration{}).
33053308
WithStatusSubresource(&enterpriseApi.IndexerCluster{}).
33063309
WithStatusSubresource(&enterpriseApi.SearchHeadCluster{}).
33073310
WithStatusSubresource(&enterpriseApi.IngestorCluster{})
3311+
33083312
client := builder.Build()
33093313
client.Create(ctx, &current)
33103314
_, err := ApplyClusterManager(ctx, client, &current)

test/index_and_ingestion_separation/index_and_ingestion_separation_test.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -384,14 +384,6 @@ var _ = Describe("indingsep test", func() {
384384
err = deployment.UpdateCR(ctx, bus)
385385
Expect(err).To(Succeed(), "Unable to deploy Bus Configuration with updated CR")
386386

387-
// Ensure that Ingestor Cluster has not been restarted
388-
testcaseEnvInst.Log.Info("Ensure that Ingestor Cluster has not been restarted")
389-
testenv.IngestorReady(ctx, deployment, testcaseEnvInst)
390-
391-
// Ensure that Indexer Cluster has not been restarted
392-
testcaseEnvInst.Log.Info("Ensure that Indexer Cluster has not been restarted")
393-
testenv.SingleSiteIndexersReady(ctx, deployment, testcaseEnvInst)
394-
395387
// Get instance of current Ingestor Cluster CR with latest config
396388
testcaseEnvInst.Log.Info("Get instance of current Ingestor Cluster CR with latest config")
397389
ingest := &enterpriseApi.IngestorCluster{}

0 commit comments

Comments
 (0)