Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions pkg/splunk/client/enterprise.go
Original file line number Diff line number Diff line change
Expand Up @@ -629,10 +629,7 @@ func (c *SplunkClient) DecommissionIndexerClusterPeer(enforceCounts bool) error
}

// BundlePush pushes the CM master apps bundle to all the indexer peers
func (c *SplunkClient) BundlePush(ignoreIdenticalBundle bool, mock bool) error {
if mock {
return nil
}
func (c *SplunkClient) BundlePush(ignoreIdenticalBundle bool) error {
endpoint := fmt.Sprintf("%s/services/cluster/master/control/default/apply", c.ManagementURI)
reqBody := fmt.Sprintf("&ignore_identical_bundle=%t", ignoreIdenticalBundle)

Expand Down
2 changes: 1 addition & 1 deletion pkg/splunk/client/enterprise_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ func TestBundlePush(t *testing.T) {
wantRequest, _ := http.NewRequest("POST", "https://localhost:8089/services/cluster/master/control/default/apply", body)

test := func(c SplunkClient) error {
return c.BundlePush(true, false)
return c.BundlePush(true)
}
splunkClientTester(t, "TestBundlePush", 200, "", wantRequest, test)
}
Expand Down
60 changes: 60 additions & 0 deletions pkg/splunk/controller/configmap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (

corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"

spltest "github.com/splunk/splunk-operator/pkg/splunk/test"
)
Expand All @@ -41,3 +42,62 @@ func TestApplyConfigMap(t *testing.T) {
}
spltest.ReconcileTester(t, "TestApplyConfigMap", &current, revised, createCalls, updateCalls, reconcile, false)
}

func TestGetConfigMap(t *testing.T) {
current := corev1.ConfigMap{
ObjectMeta: metav1.ObjectMeta{
Name: "defaults",
Namespace: "test",
},
}

client := spltest.NewMockClient()
namespacedName := types.NamespacedName{Namespace: current.GetNamespace(), Name: current.GetName()}

_, err := GetConfigMap(client, namespacedName)
if err == nil {
t.Errorf("Should return an error, when the configMap doesn't exist")
}

_, err = ApplyConfigMap(client, &current)
if err != nil {
t.Errorf("Failed to create the configMap. Error: %s", err.Error())
}

_, err = GetConfigMap(client, namespacedName)
if err != nil {
t.Errorf("Should not return an error, when the configMap exists")
}
}

func TestGetConfigMapResourceVersion(t *testing.T) {
current := corev1.ConfigMap{
ObjectMeta: metav1.ObjectMeta{
Name: "defaults",
Namespace: "test",
},
}

client := spltest.NewMockClient()
namespacedName := types.NamespacedName{Namespace: current.GetNamespace(), Name: current.GetName()}

_, err := GetConfigMap(client, namespacedName)
if err == nil {
t.Errorf("Should return an error, when the configMap doesn't exist")
}

_, err = GetConfigMapResourceVersion(client, namespacedName)
if err == nil {
t.Errorf("Should return an error, when the configMap doesn't exist")
}

_, err = ApplyConfigMap(client, &current)
if err != nil {
t.Errorf("Failed to create the configMap. Error: %s", err.Error())
}

_, err = GetConfigMapResourceVersion(client, namespacedName)
if err != nil {
t.Errorf("Should not return an error, when the configMap exists")
}
}
6 changes: 2 additions & 4 deletions pkg/splunk/enterprise/clustermaster.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,9 +186,7 @@ func CheckIfsmartstoreConfigMapUpdatedToPod(c splcommon.ControllerClient, cr *en
command := fmt.Sprintf("cat /mnt/splunk-operator/local/%s", configToken)
stdOut, stdErr, err := splutil.PodExecCommand(c, cmPodName, cr.GetNamespace(), []string{"/bin/sh"}, command, false, false)
if err != nil || stdErr != "" {
if cr.Spec.Mock == false {
return fmt.Errorf("Failed to check config token value on pod. stdout=%s, stderror=%s, error=%v", stdOut, stdErr, err)
}
return fmt.Errorf("Failed to check config token value on pod. stdout=%s, stderror=%s, error=%v", stdOut, stdErr, err)
}

configMap, exists := getSmartstoreConfigMap(c, cr, SplunkClusterMaster)
Expand Down Expand Up @@ -267,5 +265,5 @@ func PushMasterAppsBundle(c splcommon.ControllerClient, cr *enterprisev1.Cluster
// Get a Splunk client to execute the REST call
splunkClient := splclient.NewSplunkClient(fmt.Sprintf("https://%s:8089", fqdnName), "admin", string(adminPwd))

return splunkClient.BundlePush(true, cr.Spec.Mock)
return splunkClient.BundlePush(true)
}
45 changes: 37 additions & 8 deletions pkg/splunk/enterprise/clustermaster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package enterprise

import (
"fmt"
"strings"
"testing"
"time"

Expand Down Expand Up @@ -243,6 +244,13 @@ func TestPerformCmBundlePush(t *testing.T) {

client := spltest.NewMockClient()

// When the secret object is not present, should return an error
current.Status.BundlePushTracker.NeedToPushMasterApps = true
err := PerformCmBundlePush(client, &current)
if err == nil {
t.Errorf("Should return error, when the secret object is not present")
}

secret, err := splutil.ApplyNamespaceScopedSecretObject(client, "test")
if err != nil {
t.Errorf(err.Error())
Expand All @@ -261,23 +269,36 @@ func TestPerformCmBundlePush(t *testing.T) {
Data: map[string]string{configToken: ""},
}

_, err = splctrl.ApplyConfigMap(client, &smartstoreConfigMap)
if err != nil {
t.Errorf(err.Error())
}

current.Status.BundlePushTracker.NeedToPushMasterApps = true
current.Status.BundlePushTracker.LastCheckInterval = time.Now().Unix() - 100

_, err = splctrl.ApplyConfigMap(client, &smartstoreConfigMap)
//Re-attempting to push the CM bundle in less than 5 seconds should return an error
current.Status.BundlePushTracker.LastCheckInterval = time.Now().Unix() - 1
err = PerformCmBundlePush(client, &current)
if err == nil {
t.Errorf("Bundle Push Should fail, if attempted to push within 5 seconds interval")
}

//Re-attempting to push the CM bundle after 5 seconds passed, should not return an error
current.Status.BundlePushTracker.LastCheckInterval = time.Now().Unix() - 10
err = PerformCmBundlePush(client, &current)
if err != nil {
t.Errorf("Bundle Push failed")
if err != nil && strings.HasPrefix(err.Error(), "Will re-attempt to push the bundle after the 5 seconds") {
t.Errorf("Bundle Push Should not fail if reattempted after 5 seconds interval passed. Error: %s", err.Error())
}

// When the CM Bundle push is not pending, should not return an error
current.Status.BundlePushTracker.NeedToPushMasterApps = false
err = PerformCmBundlePush(client, &current)
if err != nil {
t.Errorf("Bundle Push failed")
t.Errorf("Should not return an error when the Bundle push is not required. Error: %s", err.Error())
}
}

func TestPushMasterAppsBundlePush(t *testing.T) {
func TestPushMasterAppsBundle(t *testing.T) {

current := enterprisev1.ClusterMaster{
TypeMeta: metav1.TypeMeta{
Expand All @@ -296,6 +317,12 @@ func TestPushMasterAppsBundlePush(t *testing.T) {

client := spltest.NewMockClient()

//Without global secret object, should return an error
err := PushMasterAppsBundle(client, &current)
if err == nil {
t.Errorf("Bundle push should fail, when the secret object is not found")
}

secret, err := splutil.ApplyNamespaceScopedSecretObject(client, "test")
if err != nil {
t.Errorf(err.Error())
Expand All @@ -306,8 +333,10 @@ func TestPushMasterAppsBundlePush(t *testing.T) {
t.Errorf(err.Error())
}

//Without password, should return an error
delete(secret.Data, "password")
err = PushMasterAppsBundle(client, &current)
if err != nil {
t.Errorf("Bundle Push failed")
if err == nil {
t.Errorf("Bundle push should fail, when the password is not found")
}
}
17 changes: 0 additions & 17 deletions pkg/splunk/enterprise/configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -659,23 +659,6 @@ func updateSplunkPodTemplateWithConfig(client splcommon.ControllerClient, podTem
}
}

// LogSmartStoreVolumes logs smartstore volumes
func LogSmartStoreVolumes(volumeList []enterprisev1.VolumeSpec) {
scopedLog := logC.WithName("LogSmartStoreVolumes")
//var temp string
for _, volume := range volumeList {
scopedLog.Info("Volume: ", "name: ", volume.Name, "endpoint: ", volume.Endpoint, "path: ", volume.Path)
}
}

// LogSmartStoreIndexes logs smartstore indexes
func LogSmartStoreIndexes(indexList []enterprisev1.IndexSpec) {
scopedLog := logC.WithName("LogSmartStoreIndexes")
for _, index := range indexList {
scopedLog.Info("Index: ", "name: ", index.Name, "remotePath: ", index.RemotePath, "volumeName", index.VolName)
}
}

// isSmartstoreEnabled checks and returns true if smartstore is configured
func isSmartstoreConfigured(smartstore *enterprisev1.SmartStoreSpec) bool {
if smartstore == nil {
Expand Down
Loading