Skip to content

Commit 5cad7f9

Browse files
committed
test
1 parent e66db70 commit 5cad7f9

File tree

2 files changed

+30
-15
lines changed

2 files changed

+30
-15
lines changed

pkg/splunk/client/enterprise.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import (
2727
"time"
2828

2929
splcommon "github.com/splunk/splunk-operator/pkg/splunk/common"
30+
logf "sigs.k8s.io/controller-runtime/pkg/log"
3031
)
3132

3233
// SplunkHTTPClient defines the interface used by SplunkClient.
@@ -946,31 +947,44 @@ func (c *SplunkClient) RestartSplunk() error {
946947
// Updates conf files and their properties
947948
// See https://help.splunk.com/en/splunk-enterprise/leverage-rest-apis/rest-api-reference/10.0/configuration-endpoints/configuration-endpoint-descriptions
948949
func (c *SplunkClient) UpdateConfFile(fileName, property, key, value string) error {
950+
logger := logf.Log.WithName("UpdateConfFile")
951+
logger.V(1).Info("Creating/ensuring object in conf file", "fileName", fileName, "property", property)
952+
949953
// Creates an object in a conf file if it doesn't exist
950954
endpoint := fmt.Sprintf("%s/servicesNS/nobody/system/configs/conf-%s", c.ManagementURI, fileName)
951955
body := fmt.Sprintf("name=%s", property)
952956

957+
logger.V(2).Info("POST request to create conf object", "endpoint", endpoint, "body", body)
953958
request, err := http.NewRequest("POST", endpoint, strings.NewReader(body))
954959
if err != nil {
960+
logger.Error(err, "Failed to create HTTP request for conf object creation", "endpoint", endpoint)
955961
return err
956962
}
957963

958964
expectedStatus := []int{200, 201, 409}
959965
err = c.Do(request, expectedStatus, nil)
960966
if err != nil {
967+
logger.Error(err, "Failed to create/ensure conf object", "endpoint", endpoint, "property", property)
961968
return err
962969
}
963970

964971
// Updates a property of an object in a conf file
965972
endpoint = fmt.Sprintf("%s/servicesNS/nobody/system/configs/conf-%s/%s", c.ManagementURI, fileName, property)
966973
body = fmt.Sprintf("%s=%s", key, value)
967974

975+
logger.V(2).Info("POST request to update conf property", "endpoint", endpoint, "body", body, "key", key, "value", value)
968976
request, err = http.NewRequest("POST", endpoint, strings.NewReader(body))
969977
if err != nil {
978+
logger.Error(err, "Failed to create HTTP request for conf property update", "endpoint", endpoint)
970979
return err
971980
}
972981

973982
expectedStatus = []int{200, 201}
974983
err = c.Do(request, expectedStatus, nil)
984+
if err != nil {
985+
logger.Error(err, "Failed to update conf property", "endpoint", endpoint, "key", key, "value", value)
986+
} else {
987+
logger.V(1).Info("Successfully updated conf property", "fileName", fileName, "property", property, "key", key, "value", value)
988+
}
975989
return err
976990
}

pkg/splunk/enterprise/ingestorcluster.go

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -212,12 +212,17 @@ func ApplyIngestorCluster(ctx context.Context, client client.Client, cr *enterpr
212212
}
213213
cr.Status.Phase = phase
214214

215-
if oldCR.Status.ReadyReplicas == 0 && cr.Status.ReadyReplicas > 0 {
216-
_, err := handlePushBusOrPipelineConfigChange(ctx, oldCR, cr, client)
217-
if err != nil {
218-
scopedLog.Error(err, "Failed to update conf file for PushBus/Pipeline config change after pod creation")
219-
return result, err
220-
}
215+
if cr.Status.ReadyReplicas < cr.Spec.Replicas {
216+
// Not all pods are ready, requeue to try again soon
217+
result.Requeue = true
218+
result.RequeueAfter = time.Second * 5
219+
return result, nil
220+
}
221+
222+
_, err = handlePushBusOrPipelineConfigChange(ctx, oldCR, cr, client)
223+
if err != nil {
224+
scopedLog.Error(err, "Failed to update conf file for PushBus/Pipeline config change after pod creation")
225+
return result, err
221226
}
222227

223228
// No need to requeue if everything is ready
@@ -319,18 +324,14 @@ func handlePushBusOrPipelineConfigChange(ctx context.Context, oldCR, newCR *ente
319324
pushBusChangedFields, pipelineChangedFields := getChangedPushBusAndPipelineFields(oldCR, newCR)
320325

321326
for _, field := range pushBusChangedFields {
322-
if pushBusChanged || firstCreate {
323-
if err := splunkClient.UpdateConfFile("outputs", field[0], field[1], field[2]); err != nil {
324-
updateErr = err
325-
}
327+
if err := splunkClient.UpdateConfFile("outputs", field[0], field[1], field[2]); err != nil {
328+
updateErr = err
326329
}
327330
}
328331

329332
for _, field := range pipelineChangedFields {
330-
if pipelineChanged || firstCreate {
331-
if err := splunkClient.UpdateConfFile("default-mode", field[0], field[1], field[2]); err != nil {
332-
updateErr = err
333-
}
333+
if err := splunkClient.UpdateConfFile("default-mode", field[0], field[1], field[2]); err != nil {
334+
updateErr = err
334335
}
335336
}
336337
}
@@ -384,7 +385,7 @@ func getChangedPushBusAndPipelineFields(oldCR, newCR *enterpriseApi.IngestorClus
384385
pipelineChangedFields = append(pipelineChangedFields, []string{"pipeline:remotequeueruleset", "disabled", fmt.Sprintf("%t", newPC.RemoteQueueRuleset)})
385386
}
386387
if oldPC.RuleSet != newPC.RuleSet {
387-
pipelineChangedFields = append(pipelineChangedFields, []string{"pipeline:remotequeueruleset", "disabled", fmt.Sprintf("%t", newPC.RuleSet)})
388+
pipelineChangedFields = append(pipelineChangedFields, []string{"pipeline:ruleset", "disabled", fmt.Sprintf("%t", newPC.RuleSet)})
388389
}
389390
if oldPC.RemoteQueueTyping != newPC.RemoteQueueTyping {
390391
pipelineChangedFields = append(pipelineChangedFields, []string{"pipeline:remotequeuetyping", "disabled", fmt.Sprintf("%t", newPC.RemoteQueueTyping)})

0 commit comments

Comments
 (0)