diff --git a/pkg/splunk/controller/statefulset.go b/pkg/splunk/controller/statefulset.go index 8aa0eef52..c43938e17 100644 --- a/pkg/splunk/controller/statefulset.go +++ b/pkg/splunk/controller/statefulset.go @@ -353,8 +353,8 @@ func DeleteReferencesToAutomatedMCIfExists(ctx context.Context, client splcommon func isCurrentCROwner(cr splcommon.MetaObject, currentOwners []metav1.OwnerReference) bool { // adding extra verification as unit test cases fails since fakeclient do not set UID return reflect.DeepEqual(currentOwners[0].UID, cr.GetUID()) && - (currentOwners[0].Kind == cr.GetObjectKind().GroupVersionKind().Kind) && - (currentOwners[0].Name == cr.GetName()) + (currentOwners[0].Kind == cr.GetObjectKind().GroupVersionKind().Kind) && + (currentOwners[0].Name == cr.GetName()) } // IsStatefulSetScalingUpOrDown checks if we are currently scaling up or down diff --git a/pkg/splunk/enterprise/clustermanager.go b/pkg/splunk/enterprise/clustermanager.go index 6bc052248..9123b282b 100644 --- a/pkg/splunk/enterprise/clustermanager.go +++ b/pkg/splunk/enterprise/clustermanager.go @@ -181,7 +181,6 @@ func ApplyClusterManager(ctx context.Context, client splcommon.ControllerClient, return result, err } - // check if the ClusterManager is ready for version upgrade, if required continueReconcile, err := UpgradePathValidation(ctx, client, cr, cr.Spec.CommonSplunkSpec, nil) if err != nil || !continueReconcile { diff --git a/pkg/splunk/enterprise/clustermanager_test.go b/pkg/splunk/enterprise/clustermanager_test.go index b465edeeb..ff84047e7 100644 --- a/pkg/splunk/enterprise/clustermanager_test.go +++ b/pkg/splunk/enterprise/clustermanager_test.go @@ -1421,6 +1421,14 @@ func TestIsClusterManagerReadyForUpgrade(t *testing.T) { if err != nil { t.Errorf("applyLicenseManager should not have returned error; err=%v", err) } + namespacedName := types.NamespacedName{ + Name: "test", + Namespace: "test", + } + err = client.Get(ctx, namespacedName, &lm) + if err != nil { + t.Errorf("get should not have returned error; err=%v", err) + } lm.Status.Phase = enterpriseApi.PhaseReady err = client.Status().Update(ctx, &lm) if err != nil { @@ -1454,12 +1462,19 @@ func TestIsClusterManagerReadyForUpgrade(t *testing.T) { t.Errorf("applyClusterManager should not have returned error; err=%v", err) } - cm.Spec.Image = "splunk2" + // create pods for license manager + lm.Status.TelAppInstalled = true lm.Spec.Image = "splunk2" + createPods(t, ctx, client, "license-manager", fmt.Sprintf("splunk-%s-license-manager-0", lm.Name), lm.Namespace, lm.Spec.Image) + updateStatefulSetsInTest(t, ctx, client, 1, fmt.Sprintf("splunk-%s-license-manager", lm.Name), lm.Namespace) + // now the statefulset image in spec is updated to splunk2 + _, err = ApplyLicenseManager(ctx, client, &lm) + + // now the statefulset and license manager both should be in ready state _, err = ApplyLicenseManager(ctx, client, &lm) clusterManager := &enterpriseApi.ClusterManager{} - namespacedName := types.NamespacedName{ + namespacedName = types.NamespacedName{ Name: cm.Name, Namespace: cm.Namespace, } @@ -1467,8 +1482,13 @@ func TestIsClusterManagerReadyForUpgrade(t *testing.T) { if err != nil { t.Errorf("changeClusterManagerAnnotations should not have returned error=%v", err) } + clusterManager.Spec.Image = "splunk2" + err = client.Update(ctx, clusterManager) + if err != nil { + t.Errorf("update should not have returned error; err=%v", err) + } - check, err := isClusterManagerReadyForUpgrade(ctx, client, clusterManager) + check, err := UpgradePathValidation(ctx, client, clusterManager, clusterManager.Spec.CommonSplunkSpec, nil) if err != nil { t.Errorf("Unexpected upgradeScenario error %v", err) @@ -1527,6 +1547,15 @@ func TestChangeClusterManagerAnnotations(t *testing.T) { if err != nil { t.Errorf("applyLicenseManager should not have returned error; err=%v", err) } + + namespacedName := types.NamespacedName{ + Name: lm.Name, + Namespace: lm.Namespace, + } + err = client.Get(ctx, namespacedName, lm) + if err != nil { + t.Errorf("changeLicenseManagerAnnotations should not have returned error=%v", err) + } lm.Status.Phase = enterpriseApi.PhaseReady err = client.Status().Update(ctx, lm) if err != nil { @@ -1544,7 +1573,7 @@ func TestChangeClusterManagerAnnotations(t *testing.T) { t.Errorf("changeClusterManagerAnnotations should not have returned error=%v", err) } clusterManager := &enterpriseApi.ClusterManager{} - namespacedName := types.NamespacedName{ + namespacedName = types.NamespacedName{ Name: cm.Name, Namespace: cm.Namespace, } @@ -1685,6 +1714,12 @@ func TestClusterManagerWitReadyState(t *testing.T) { Namespace: clustermanager.Namespace, } + // cluster manager + err = c.Get(ctx, namespacedName, clustermanager) + if err != nil { + t.Errorf("get should not have returned error; err=%v", err) + } + // simulate Ready state clustermanager.Status.Phase = enterpriseApi.PhaseReady clustermanager.Spec.ServiceTemplate.Annotations = map[string]string{ diff --git a/pkg/splunk/enterprise/clustermaster_test.go b/pkg/splunk/enterprise/clustermaster_test.go index 116c6da6a..9289358fd 100644 --- a/pkg/splunk/enterprise/clustermaster_test.go +++ b/pkg/splunk/enterprise/clustermaster_test.go @@ -1220,7 +1220,11 @@ func TestClusterMasterWitReadyState(t *testing.T) { Name: clustermaster.Name, Namespace: clustermaster.Namespace, } - + err = c.Get(ctx, namespacedName, clustermaster) + if err != nil { + t.Errorf("Unexpected get cluster master %v", err) + debug.PrintStack() + } // simulate Ready state clustermaster.Status.Phase = enterpriseApi.PhaseReady clustermaster.Spec.ServiceTemplate.Annotations = map[string]string{ diff --git a/pkg/splunk/enterprise/indexercluster_test.go b/pkg/splunk/enterprise/indexercluster_test.go index cbeb0a1e6..b323f4262 100644 --- a/pkg/splunk/enterprise/indexercluster_test.go +++ b/pkg/splunk/enterprise/indexercluster_test.go @@ -735,7 +735,8 @@ func TestIndexerClusterPodManager(t *testing.T) { {MetaName: "*v1.StatefulSet-test-splunk-stack1"}, {MetaName: "*v1.Secret-test-splunk-test-secret"}, {MetaName: "*v1.Secret-test-splunk-test-secret"}, - {MetaName: "*v1.Pod-test-splunk-stack1-indexer-0"}, + //{MetaName: "*v1.Pod-test-splunk-stack1-indexer-0"}, + {MetaName: "*v1.Pod-test-splunk-manager1-cluster-manager-0"}, {MetaName: "*v1.Pod-test-splunk-manager1-cluster-manager-0"}, {MetaName: "*v1.Pod-test-splunk-stack1-0"}, } @@ -750,7 +751,7 @@ func TestIndexerClusterPodManager(t *testing.T) { listmockCall := []spltest.MockFuncCall{ {ListOpts: listOpts}} - wantCalls := map[string][]spltest.MockFuncCall{"Get": {funcCalls[0], funcCalls[1], funcCalls[1], funcCalls[4], funcCalls[5]}, "Create": {funcCalls[1]}, "List": {listmockCall[0]}} + wantCalls := map[string][]spltest.MockFuncCall{"Get": {funcCalls[0], funcCalls[1], funcCalls[1], funcCalls[4], funcCalls[4], funcCalls[5]}, "Create": {funcCalls[1]}, "List": {listmockCall[0]}} // test 1 ready pod mockHandlers := []spltest.MockHTTPHandler{ @@ -802,6 +803,7 @@ func TestIndexerClusterPodManager(t *testing.T) { {MetaName: "*v1.Secret-test-splunk-test-secret"}, {MetaName: "*v1.Secret-test-splunk-test-secret"}, {MetaName: "*v1.Pod-test-splunk-manager1-cluster-manager-0"}, + {MetaName: "*v1.Pod-test-splunk-manager1-cluster-manager-0"}, {MetaName: "*v1.Pod-test-splunk-stack1-0"}, {MetaName: "*v1.Pod-test-splunk-stack1-indexer-0"}, {MetaName: "*v1.Pod-test-splunk-stack1-indexer-0"}, @@ -815,6 +817,7 @@ func TestIndexerClusterPodManager(t *testing.T) { {MetaName: "*v1.Secret-test-splunk-test-secret"}, {MetaName: "*v1.Secret-test-splunk-test-secret"}, {MetaName: "*v1.Pod-test-splunk-manager1-cluster-manager-0"}, + {MetaName: "*v1.Pod-test-splunk-manager1-cluster-manager-0"}, {MetaName: "*v1.Pod-test-splunk-stack1-0"}, } mockHandlers = []spltest.MockHTTPHandler{mockHandlers[0], mockHandlers[1]} @@ -841,7 +844,7 @@ func TestIndexerClusterPodManager(t *testing.T) { statefulSet.Status.Replicas = 2 statefulSet.Status.ReadyReplicas = 2 statefulSet.Status.UpdatedReplicas = 2 - wantCalls = map[string][]spltest.MockFuncCall{"Get": {funcCalls[0], funcCalls[1], funcCalls[1], funcCalls[4]}, "Create": {funcCalls[1]}} + wantCalls = map[string][]spltest.MockFuncCall{"Get": {funcCalls[0], funcCalls[1], funcCalls[1], funcCalls[4], funcCalls[4]}, "Create": {funcCalls[1]}} method = "indexerClusterPodManager.Update(Pod Not Found)" indexerClusterPodManagerUpdateTester(t, method, mockHandlers, 1, enterpriseApi.PhaseScalingDown, statefulSet, wantCalls, nil, statefulSet, pod) @@ -864,6 +867,7 @@ func TestIndexerClusterPodManager(t *testing.T) { {MetaName: "*v1.Secret-test-splunk-test-secret"}, {MetaName: "*v1.Pod-test-splunk-manager1-cluster-manager-0"}, {MetaName: "*v1.Pod-test-splunk-manager1-cluster-manager-0"}, + {MetaName: "*v1.Pod-test-splunk-manager1-cluster-manager-0"}, {MetaName: "*v1.PersistentVolumeClaim-test-pvc-etc-splunk-stack1-1"}, {MetaName: "*v1.PersistentVolumeClaim-test-pvc-var-splunk-stack1-1"}, } @@ -1576,7 +1580,11 @@ func TestIndexerClusterWithReadyState(t *testing.T) { Name: clustermanager.Name, Namespace: clustermanager.Namespace, } - + err := c.Get(ctx, namespacedName, clustermanager) + if err != nil { + t.Errorf("Unexpected get cluster manager %v", err) + debug.PrintStack() + } clustermanager.Status.Phase = enterpriseApi.PhaseReady clustermanager.Spec.ServiceTemplate.Annotations = map[string]string{ "traffic.sidecar.istio.io/excludeOutboundPorts": "8089,8191,9997", @@ -1589,7 +1597,7 @@ func TestIndexerClusterWithReadyState(t *testing.T) { "app.kubernetes.io/name": "cluster-manager", "app.kubernetes.io/part-of": "splunk-test-cluster-manager", } - err := c.Status().Update(ctx, clustermanager) + err = c.Status().Update(ctx, clustermanager) if err != nil { t.Errorf("Unexpected error while running reconciliation for cluster manager with app framework %v", err) debug.PrintStack() @@ -1755,6 +1763,24 @@ func TestIndexerClusterWithReadyState(t *testing.T) { // simulate create clustermanager instance before reconcilation c.Create(ctx, indexercluster) + GetClusterInfoCall = func(ctx context.Context, mgr *indexerClusterPodManager, mockCall bool) (*splclient.ClusterInfo, error) { + cinfo := &splclient.ClusterInfo{ + MultiSite: "false", + } + return cinfo, nil + } + GetClusterManagerPeersCall = func(ctx context.Context, mgr *indexerClusterPodManager) (map[string]splclient.ClusterManagerPeerInfo, error) { + response := map[string]splclient.ClusterManagerPeerInfo{ + "splunk-test-indexer-0": { + ID: "site-1", + Status: "Up", + ActiveBundleID: "1", + BucketCount: 10, + Searchable: true, + }, + } + return response, err + } _, err = ApplyIndexerClusterManager(ctx, c, indexercluster) if err != nil { t.Errorf("Unexpected error while running reconciliation for indexer cluster %v", err) @@ -1765,7 +1791,11 @@ func TestIndexerClusterWithReadyState(t *testing.T) { Name: indexercluster.Name, Namespace: indexercluster.Namespace, } - + err = c.Get(ctx, namespacedName, indexercluster) + if err != nil { + t.Errorf("Unexpected get indexer cluster %v", err) + debug.PrintStack() + } // simulate Ready state indexercluster.Status.Phase = enterpriseApi.PhaseReady indexercluster.Spec.ServiceTemplate.Annotations = map[string]string{ diff --git a/pkg/splunk/enterprise/licensemanager_test.go b/pkg/splunk/enterprise/licensemanager_test.go index 2979fcd1b..d38f97e1f 100644 --- a/pkg/splunk/enterprise/licensemanager_test.go +++ b/pkg/splunk/enterprise/licensemanager_test.go @@ -1075,7 +1075,11 @@ func TestLicenseManagerWithReadyState(t *testing.T) { Name: licensemanager.Name, Namespace: licensemanager.Namespace, } - + err = c.Get(ctx, namespacedName, licensemanager) + if err != nil { + t.Errorf("Unexpected get license manager %v", err) + debug.PrintStack() + } // simulate Ready state licensemanager.Status.Phase = enterpriseApi.PhaseReady licensemanager.Spec.ServiceTemplate.Annotations = map[string]string{ diff --git a/pkg/splunk/enterprise/monitoringconsole_test.go b/pkg/splunk/enterprise/monitoringconsole_test.go index e72750ec1..3d47b9367 100644 --- a/pkg/splunk/enterprise/monitoringconsole_test.go +++ b/pkg/splunk/enterprise/monitoringconsole_test.go @@ -72,6 +72,7 @@ func TestApplyMonitoringConsole(t *testing.T) { {MetaName: "*v1.ConfigMap-test-splunk-stack1-monitoring-console"}, {MetaName: "*v1.ConfigMap-test-splunk-stack1-monitoring-console"}, {MetaName: "*v1.StatefulSet-test-splunk-stack1-monitoring-console"}, + {MetaName: "*v1.StatefulSet-test-splunk-stack1-monitoring-console"}, {MetaName: "*v4.MonitoringConsole-test-stack1"}, {MetaName: "*v4.MonitoringConsole-test-stack1"}, } @@ -81,15 +82,19 @@ func TestApplyMonitoringConsole(t *testing.T) { {MetaName: "*v1.Secret-test-splunk-test-secret"}, {MetaName: "*v1.Service-test-splunk-stack1-monitoring-console-headless"}, {MetaName: "*v1.Service-test-splunk-stack1-monitoring-console-service"}, + {MetaName: "*v1.StatefulSet-test-splunk-stack1-monitoring-console"}, {MetaName: "*v1.ConfigMap-test-splunk-test-probe-configmap"}, {MetaName: "*v1.Secret-test-splunk-test-secret"}, {MetaName: "*v1.Secret-test-splunk-stack1-monitoring-console-secret-v1"}, + {MetaName: "*v1.ConfigMap-test-splunk-stack1-monitoring-console"}, {MetaName: "*v1.ConfigMap-test-splunk-stack1-monitoring-console"}, {MetaName: "*v1.ConfigMap-test-splunk-stack1-monitoring-console"}, {MetaName: "*v1.StatefulSet-test-splunk-stack1-monitoring-console"}, {MetaName: "*v1.StatefulSet-test-splunk-stack1-monitoring-console"}, + {MetaName: "*v1.StatefulSet-test-splunk-stack1-monitoring-console"}, + {MetaName: "*v4.MonitoringConsole-test-stack1"}, {MetaName: "*v4.MonitoringConsole-test-stack1"}, } @@ -875,7 +880,11 @@ func TestMonitoringConsoleWithReadyState(t *testing.T) { Name: monitoringconsole.Name, Namespace: monitoringconsole.Namespace, } - + err = c.Get(ctx, namespacedName, monitoringconsole) + if err != nil { + t.Errorf("Unexpected get monitoring console %v", err) + debug.PrintStack() + } // simulate Ready state monitoringconsole.Status.Phase = enterpriseApi.PhaseReady monitoringconsole.Spec.ServiceTemplate.Annotations = map[string]string{ @@ -1133,6 +1142,14 @@ func TestIsMonitoringConsoleReadyForUpgrade(t *testing.T) { if err != nil { t.Errorf("applyClusterManager should not have returned error; err=%v", err) } + namespacedName := types.NamespacedName{ + Name: cm.Name, + Namespace: cm.Namespace, + } + err = client.Get(ctx, namespacedName, &cm) + if err != nil { + t.Errorf("isMonitoringConsoleReadyForUpgrade should not have returned error=%v", err) + } cm.Status.Phase = enterpriseApi.PhaseReady err = client.Status().Update(ctx, &cm) if err != nil { @@ -1171,9 +1188,9 @@ func TestIsMonitoringConsoleReadyForUpgrade(t *testing.T) { _, err = ApplyClusterManager(ctx, client, &cm) monitoringConsole := &enterpriseApi.MonitoringConsole{} - namespacedName := types.NamespacedName{ - Name: cm.Name, - Namespace: cm.Namespace, + namespacedName = types.NamespacedName{ + Name: mc.Name, + Namespace: mc.Namespace, } err = client.Get(ctx, namespacedName, monitoringConsole) if err != nil { @@ -1239,6 +1256,14 @@ func TestChangeMonitoringConsoleAnnotations(t *testing.T) { if err != nil { t.Errorf("applyClusterManager should not have returned error; err=%v", err) } + namespacedName := types.NamespacedName{ + Name: cm.Name, + Namespace: cm.Namespace, + } + err = client.Get(ctx, namespacedName, cm) + if err != nil { + t.Errorf("changeMonitoringConsoleAnnotations should not have returned error=%v", err) + } cm.Status.Phase = enterpriseApi.PhaseReady err = client.Status().Update(ctx, cm) if err != nil { @@ -1256,7 +1281,7 @@ func TestChangeMonitoringConsoleAnnotations(t *testing.T) { t.Errorf("changeMonitoringConsoleAnnotations should not have returned error=%v", err) } monitoringConsole := &enterpriseApi.MonitoringConsole{} - namespacedName := types.NamespacedName{ + namespacedName = types.NamespacedName{ Name: cm.Name, Namespace: cm.Namespace, } diff --git a/pkg/splunk/enterprise/searchheadcluster.go b/pkg/splunk/enterprise/searchheadcluster.go index 61bfa3a10..73c9eea0a 100644 --- a/pkg/splunk/enterprise/searchheadcluster.go +++ b/pkg/splunk/enterprise/searchheadcluster.go @@ -459,7 +459,6 @@ func (mgr *searchHeadClusterPodManager) Update(ctx context.Context, c splcommon. return splctrl.UpdateStatefulSetPods(ctx, mgr.c, statefulSet, mgr, desiredReplicas) } - // PrepareScaleDown for searchHeadClusterPodManager prepares search head pod to be removed via scale down event; it returns true when ready func (mgr *searchHeadClusterPodManager) PrepareScaleDown(ctx context.Context, n int32) (bool, error) { // start by quarantining the pod diff --git a/pkg/splunk/enterprise/searchheadcluster_test.go b/pkg/splunk/enterprise/searchheadcluster_test.go index a755f4bd5..d35d0279a 100644 --- a/pkg/splunk/enterprise/searchheadcluster_test.go +++ b/pkg/splunk/enterprise/searchheadcluster_test.go @@ -68,38 +68,51 @@ func TestApplySearchHeadCluster(t *testing.T) { {MetaName: "*v1.Secret-test-splunk-test-secret"}, {MetaName: "*v1.Secret-test-splunk-test-secret"}, {MetaName: "*v1.Secret-test-splunk-test-secret"}, + {MetaName: "*v1.Service-test-splunk-stack1-search-head-headless"}, {MetaName: "*v1.Service-test-splunk-stack1-search-head-service"}, + {MetaName: "*v1.Service-test-splunk-stack1-deployer-service"}, {MetaName: "*v1.StatefulSet-test-splunk-stack1-deployer"}, + {MetaName: "*v1.ConfigMap-test-splunk-test-probe-configmap"}, {MetaName: "*v1.ConfigMap-test-splunk-test-probe-configmap"}, + {MetaName: "*v1.Secret-test-splunk-test-secret"}, {MetaName: "*v1.Secret-test-splunk-stack1-deployer-secret-v1"}, + + {MetaName: "*v1.StatefulSet-test-splunk-stack1-search-head"}, {MetaName: "*v1.StatefulSet-test-splunk-stack1-deployer"}, {MetaName: "*v1.StatefulSet-test-splunk-stack1-search-head"}, + {MetaName: "*v1.ConfigMap-test-splunk-test-probe-configmap"}, {MetaName: "*v1.Secret-test-splunk-test-secret"}, {MetaName: "*v1.Secret-test-splunk-stack1-search-head-secret-v1"}, {MetaName: "*v1.StatefulSet-test-splunk-stack1-search-head"}, {MetaName: "*v1.StatefulSet-test-splunk-stack1-search-head"}, + {MetaName: "*v1.Secret-test-splunk-test-secret"}, {MetaName: "*v4.SearchHeadCluster-test-stack1"}, {MetaName: "*v4.SearchHeadCluster-test-stack1"}, } + createFuncCalls := []spltest.MockFuncCall{ {MetaName: "*v1.Secret-test-splunk-test-secret"}, {MetaName: "*v1.Secret-test-splunk-test-secret"}, {MetaName: "*v1.Service-test-splunk-stack1-search-head-headless"}, {MetaName: "*v1.Service-test-splunk-stack1-search-head-service"}, + {MetaName: "*v1.Service-test-splunk-stack1-deployer-service"}, {MetaName: "*v1.StatefulSet-test-splunk-stack1-deployer"}, + {MetaName: "*v1.ConfigMap-test-splunk-test-probe-configmap"}, {MetaName: "*v1.Secret-test-splunk-test-secret"}, {MetaName: "*v1.Secret-test-splunk-stack1-deployer-secret-v1"}, + {MetaName: "*v1.StatefulSet-test-splunk-stack1-search-head"}, {MetaName: "*v1.StatefulSet-test-splunk-stack1-deployer"}, {MetaName: "*v1.StatefulSet-test-splunk-stack1-deployer"}, {MetaName: "*v1.StatefulSet-test-splunk-stack1-search-head"}, + {MetaName: "*v1.ConfigMap-test-splunk-test-probe-configmap"}, {MetaName: "*v1.Secret-test-splunk-test-secret"}, {MetaName: "*v1.Secret-test-splunk-stack1-search-head-secret-v1"}, @@ -122,8 +135,8 @@ func TestApplySearchHeadCluster(t *testing.T) { listmockCall := []spltest.MockFuncCall{ {ListOpts: listOpts}} - createCalls := map[string][]spltest.MockFuncCall{"Get": funcCalls, "Create": {funcCalls[0], funcCalls[3], funcCalls[4], funcCalls[5], funcCalls[8], funcCalls[10], funcCalls[11], funcCalls[15], funcCalls[16]}, "Update": {funcCalls[0]}, "List": {listmockCall[0], listmockCall[0]}} - updateCalls := map[string][]spltest.MockFuncCall{"Get": createFuncCalls, "Update": {createFuncCalls[5], createFuncCalls[11]}, "List": {listmockCall[0], listmockCall[0]}} + createCalls := map[string][]spltest.MockFuncCall{"Get": funcCalls, "Create": {funcCalls[0], funcCalls[3], funcCalls[4], funcCalls[5], funcCalls[8], funcCalls[10], funcCalls[12], funcCalls[16], funcCalls[17]}, "Update": {funcCalls[0]}, "List": {listmockCall[0], listmockCall[0]}} + updateCalls := map[string][]spltest.MockFuncCall{"Get": createFuncCalls, "Update": {createFuncCalls[5], createFuncCalls[9]}, "List": {listmockCall[0], listmockCall[0]}} statefulSet := enterpriseApi.SearchHeadCluster{ TypeMeta: metav1.TypeMeta{ Kind: "SearchHeadCluster", @@ -294,7 +307,7 @@ func TestSearchHeadClusterPodManager(t *testing.T) { }, } method = "searchHeadClusterPodManager.Update(All pods ready)" - wantCalls = map[string][]spltest.MockFuncCall{"Get": {funcCalls[0], funcCalls[1], funcCalls[1], funcCalls[2], funcCalls[5]}, "Create": {funcCalls[1]}, "List": {listmockCall[0]}} + wantCalls = map[string][]spltest.MockFuncCall{"Get": {funcCalls[0], funcCalls[1], funcCalls[1], funcCalls[2], funcCalls[2], funcCalls[5]}, "Create": {funcCalls[1]}, "List": {listmockCall[0]}} searchHeadClusterPodManagerTester(t, method, mockHandlers, 1, enterpriseApi.PhaseReady, statefulSet, wantCalls, nil, statefulSet, pod) // test pod needs update => transition to detention @@ -307,7 +320,7 @@ func TestSearchHeadClusterPodManager(t *testing.T) { }) pod.ObjectMeta.Labels["controller-revision-hash"] = "v0" method = "searchHeadClusterPodManager.Update(Quarantine Pod)" - wantCalls = map[string][]spltest.MockFuncCall{"Get": {funcCalls[0], funcCalls[1], funcCalls[1], funcCalls[2], funcCalls[5], funcCalls[2], funcCalls[2]}, "Create": {funcCalls[1]}} + wantCalls = map[string][]spltest.MockFuncCall{"Get": {funcCalls[0], funcCalls[1], funcCalls[1], funcCalls[2], funcCalls[2], funcCalls[5], funcCalls[2], funcCalls[2]}, "Create": {funcCalls[1]}} searchHeadClusterPodManagerTester(t, method, mockHandlers, 1, enterpriseApi.PhaseUpdating, statefulSet, wantCalls, nil, statefulSet, pod) // test pod needs update => wait for searches to drain @@ -315,13 +328,13 @@ func TestSearchHeadClusterPodManager(t *testing.T) { mockHandlers[0].Body = strings.Replace(mockHandlers[0].Body, `"status":"Up"`, `"status":"ManualDetention"`, 1) mockHandlers[0].Body = strings.Replace(mockHandlers[0].Body, `"active_historical_search_count":0`, `"active_historical_search_count":1`, 1) method = "searchHeadClusterPodManager.Update(Draining Searches)" - wantCalls = map[string][]spltest.MockFuncCall{"Get": {funcCalls[0], funcCalls[1], funcCalls[1], funcCalls[2], funcCalls[5]}, "Create": {funcCalls[1]}} + wantCalls = map[string][]spltest.MockFuncCall{"Get": {funcCalls[0], funcCalls[1], funcCalls[1], funcCalls[2], funcCalls[2], funcCalls[5]}, "Create": {funcCalls[1]}} searchHeadClusterPodManagerTester(t, method, mockHandlers, 1, enterpriseApi.PhaseUpdating, statefulSet, wantCalls, nil, statefulSet, pod) // test pod needs update => delete pod mockHandlers[0].Body = strings.Replace(mockHandlers[0].Body, `"active_historical_search_count":1`, `"active_historical_search_count":0`, 1) method = "searchHeadClusterPodManager.Update(Delete Pod)" - wantCalls = map[string][]spltest.MockFuncCall{"Get": {funcCalls[0], funcCalls[1], funcCalls[1], funcCalls[2], funcCalls[5]}, "Create": {funcCalls[1]}, "Delete": {funcCalls[5]}} + wantCalls = map[string][]spltest.MockFuncCall{"Get": {funcCalls[0], funcCalls[1], funcCalls[1], funcCalls[2], funcCalls[2], funcCalls[5]}, "Create": {funcCalls[1]}, "Delete": {funcCalls[5]}} searchHeadClusterPodManagerTester(t, method, mockHandlers, 1, enterpriseApi.PhaseUpdating, statefulSet, wantCalls, nil, statefulSet, pod) // test pod update finished => release from detention @@ -334,7 +347,7 @@ func TestSearchHeadClusterPodManager(t *testing.T) { Body: ``, }) method = "searchHeadClusterPodManager.Update(Release Quarantine)" - wantCalls = map[string][]spltest.MockFuncCall{"Get": {funcCalls[0], funcCalls[1], funcCalls[1], funcCalls[2], funcCalls[5], funcCalls[2]}, "Create": {funcCalls[1]}} + wantCalls = map[string][]spltest.MockFuncCall{"Get": {funcCalls[0], funcCalls[1], funcCalls[1], funcCalls[2], funcCalls[2], funcCalls[5], funcCalls[2]}, "Create": {funcCalls[1]}} searchHeadClusterPodManagerTester(t, method, mockHandlers, 1, enterpriseApi.PhaseUpdating, statefulSet, wantCalls, nil, statefulSet, pod) // test scale down => remove member @@ -362,6 +375,7 @@ func TestSearchHeadClusterPodManager(t *testing.T) { {MetaName: "*v1.Secret-test-splunk-test-secret"}, {MetaName: "*v1.Secret-test-splunk-test-secret"}, {MetaName: "*v1.Pod-test-splunk-stack1-search-head-0"}, + {MetaName: "*v1.Pod-test-splunk-stack1-search-head-0"}, {MetaName: "*v1.Pod-test-splunk-stack1-search-head-1"}, {MetaName: "*v1.Pod-test-splunk-stack1-search-head-1"}, {MetaName: "*v1.PersistentVolumeClaim-test-pvc-etc-splunk-stack1-1"}, @@ -1542,7 +1556,11 @@ func TestSearchHeadClusterWithReadyState(t *testing.T) { Name: searchheadcluster.Name, Namespace: searchheadcluster.Namespace, } - + err = c.Get(ctx, namespacedName, searchheadcluster) + if err != nil { + t.Errorf("Unexpected get search head cluster %v", err) + debug.PrintStack() + } // simulate Ready state searchheadcluster.Status.Phase = enterpriseApi.PhaseReady searchheadcluster.Spec.ServiceTemplate.Annotations = map[string]string{ @@ -1903,6 +1921,14 @@ func TestIsSearchHeadReadyForUpgrade(t *testing.T) { if err != nil { t.Errorf("applyMonitoringConsole should not have returned error; err=%v", err) } + namespacedName := types.NamespacedName{ + Name: mc.Name, + Namespace: mc.Namespace, + } + err = client.Get(ctx, namespacedName, &mc) + if err != nil { + t.Errorf("Get Search Head Cluster should not have returned error=%v", err) + } mc.Status.Phase = enterpriseApi.PhaseReady err = client.Status().Update(ctx, &mc) if err != nil { @@ -1942,7 +1968,7 @@ func TestIsSearchHeadReadyForUpgrade(t *testing.T) { _, err = ApplyMonitoringConsole(ctx, client, &mc) searchHeadCluster := &enterpriseApi.SearchHeadCluster{} - namespacedName := types.NamespacedName{ + namespacedName = types.NamespacedName{ Name: shc.Name, Namespace: shc.Namespace, } diff --git a/pkg/splunk/enterprise/standalone_test.go b/pkg/splunk/enterprise/standalone_test.go index 6443fc3c8..e6a5a4fdc 100644 --- a/pkg/splunk/enterprise/standalone_test.go +++ b/pkg/splunk/enterprise/standalone_test.go @@ -1281,7 +1281,11 @@ func TestStandaloneWithReadyState(t *testing.T) { Name: standalone.Name, Namespace: standalone.Namespace, } - + err = c.Get(ctx, namespacedName, &standalone) + if err != nil { + t.Errorf("Unexpected get standalone %v", err) + debug.PrintStack() + } // simulate Ready state standalone.Status.Phase = enterpriseApi.PhaseReady standalone.Spec.ServiceTemplate.Annotations = map[string]string{ diff --git a/pkg/splunk/enterprise/upgrade.go b/pkg/splunk/enterprise/upgrade.go index a65c7af17..c5eb842a6 100644 --- a/pkg/splunk/enterprise/upgrade.go +++ b/pkg/splunk/enterprise/upgrade.go @@ -5,8 +5,8 @@ import ( "fmt" enterpriseApi "github.com/splunk/splunk-operator/api/v4" - splcommon "github.com/splunk/splunk-operator/pkg/splunk/common" splclient "github.com/splunk/splunk-operator/pkg/splunk/client" + splcommon "github.com/splunk/splunk-operator/pkg/splunk/common" appsv1 "k8s.io/api/apps/v1" k8serrors "k8s.io/apimachinery/pkg/api/errors" "k8s.io/apimachinery/pkg/types" @@ -14,7 +14,7 @@ import ( "sigs.k8s.io/controller-runtime/pkg/log" ) -//helps in mock function +// helps in mock function var GetClusterInfoCall = func(ctx context.Context, mgr *indexerClusterPodManager, mockCall bool) (*splclient.ClusterInfo, error) { cm := mgr.getClusterManagerClient(ctx) return cm.GetClusterInfo(false) diff --git a/pkg/splunk/enterprise/upgrade_test.go b/pkg/splunk/enterprise/upgrade_test.go index bd392f103..ec5931148 100644 --- a/pkg/splunk/enterprise/upgrade_test.go +++ b/pkg/splunk/enterprise/upgrade_test.go @@ -6,9 +6,8 @@ import ( "runtime/debug" "testing" - - splclient "github.com/splunk/splunk-operator/pkg/splunk/client" enterpriseApi "github.com/splunk/splunk-operator/api/v4" + splclient "github.com/splunk/splunk-operator/pkg/splunk/client" "github.com/splunk/splunk-operator/pkg/splunk/common" splcommon "github.com/splunk/splunk-operator/pkg/splunk/common" appsv1 "k8s.io/api/apps/v1" @@ -21,8 +20,6 @@ import ( "sigs.k8s.io/controller-runtime/pkg/client/fake" ) - - func TestUpgradePathValidation(t *testing.T) { builder := fake.NewClientBuilder() @@ -346,7 +343,7 @@ func TestUpgradePathValidation(t *testing.T) { GetSearchHeadCaptainInfo = func(ctx context.Context, mgr *searchHeadClusterPodManager, n int32) (*splclient.SearchHeadCaptainInfo, error) { shci := &splclient.SearchHeadCaptainInfo{ ServiceReady: true, - Initialized: true, + Initialized: true, } return shci, nil } @@ -380,21 +377,21 @@ func TestUpgradePathValidation(t *testing.T) { } GetClusterManagerPeersCall = func(ctx context.Context, mgr *indexerClusterPodManager) (map[string]splclient.ClusterManagerPeerInfo, error) { response := map[string]splclient.ClusterManagerPeerInfo{ - "splunk-test-indexer-0" : { - ID : "site-1", - Status: "Up", - ActiveBundleID : "1", - BucketCount: 10, - Searchable: true, + "splunk-test-indexer-0": { + ID: "site-1", + Status: "Up", + ActiveBundleID: "1", + BucketCount: 10, + Searchable: true, }, } - return response,err + return response, err } GetClusterManagerInfoCall = func(ctx context.Context, mgr *indexerClusterPodManager) (*splclient.ClusterManagerInfo, error) { - response := &splclient.ClusterManagerInfo{ - Initialized: true, + response := &splclient.ClusterManagerInfo{ + Initialized: true, IndexingReady: true, - ServiceReady: true, + ServiceReady: true, } return response, err } @@ -406,9 +403,8 @@ func TestUpgradePathValidation(t *testing.T) { } // create pods for indexer cluster - createPods(t , ctx, client, "indexer", fmt.Sprintf("splunk-%s-indexer-0",idx.Name), idx.Namespace, idx.Spec.Image) - updateStatefulSetsInTest(t, ctx, client, 1, fmt.Sprintf("splunk-%s-indexer",idx.Name), idx.Namespace) - + createPods(t, ctx, client, "indexer", fmt.Sprintf("splunk-%s-indexer-0", idx.Name), idx.Namespace, idx.Spec.Image) + updateStatefulSetsInTest(t, ctx, client, 1, fmt.Sprintf("splunk-%s-indexer", idx.Name), idx.Namespace) // search head cluster is not ready, so wait for search head cluster _, err = ApplyIndexerClusterManager(ctx, client, &idx) @@ -524,7 +520,7 @@ func TestUpgradePathValidation(t *testing.T) { if err != nil { t.Errorf("applySearchHeadCluster after update should not have returned error; err=%v", err) } - _, err = ApplyIndexerClusterManager(ctx, client, &idx) + _, err = ApplyIndexerClusterManager(ctx, client, &idx) if err != nil { t.Errorf("ApplyIndexerClusterManager after update should not have returned error; err=%v", err) } @@ -540,8 +536,8 @@ func TestUpgradePathValidation(t *testing.T) { cm.Status.TelAppInstalled = true // create pods for indexer cluster - createPods(t , ctx, client, "indexer", fmt.Sprintf("splunk-%s-indexer-0",idx.Name), idx.Namespace, newImage) - updateStatefulSetsInTest(t, ctx, client, 1, fmt.Sprintf("splunk-%s-indexer",idx.Name), idx.Namespace) + createPods(t, ctx, client, "indexer", fmt.Sprintf("splunk-%s-indexer-0", idx.Name), idx.Namespace, newImage) + updateStatefulSetsInTest(t, ctx, client, 1, fmt.Sprintf("splunk-%s-indexer", idx.Name), idx.Namespace) // create pods for cluster manager createPods(t, ctx, client, "monitoring-console", fmt.Sprintf("splunk-%s-monitoring-console-0", lm.Name), lm.Namespace, newImage) @@ -606,7 +602,7 @@ func TestUpgradePathValidation(t *testing.T) { func createPods(t *testing.T, ctx context.Context, client common.ControllerClient, crtype, name, namespace, image string) { stpod := &corev1.Pod{} namespacesName := types.NamespacedName{ - Name: name, + Name: name, Namespace: namespace, } err := client.Get(ctx, namespacesName, stpod)