@@ -33,6 +33,7 @@ import (
3333 "k8s.io/apimachinery/pkg/types"
3434 utilruntime "k8s.io/apimachinery/pkg/util/runtime"
3535 clientgoscheme "k8s.io/client-go/kubernetes/scheme"
36+ "k8s.io/apimachinery/pkg/runtime/schema"
3637 "sigs.k8s.io/controller-runtime/pkg/client/fake"
3738 "sigs.k8s.io/controller-runtime/pkg/log"
3839 "sigs.k8s.io/controller-runtime/pkg/reconcile"
@@ -222,9 +223,10 @@ func TestApplySplunkConfig(t *testing.T) {
222223 {MetaName : "*v1.Secret-test-splunk-test-secret" },
223224 {MetaName : "*v1.ConfigMap-test-splunk-stack1-search-head-defaults" },
224225 {MetaName : "*v1.ConfigMap-test-splunk-stack1-search-head-defaults" },
226+ {MetaName : "*v1.ConfigMap-test-splunk-search-head-stack1-configmap" },
225227 }
226- createCalls := map [string ][]spltest.MockFuncCall {"Get" : funcCalls , "Create" : {funcCalls [0 ], funcCalls [3 ]}, "Update" : {funcCalls [0 ]}}
227- updateCalls := map [string ][]spltest.MockFuncCall {"Get" : {funcCalls [0 ], funcCalls [1 ], funcCalls [3 ]}}
228+ createCalls := map [string ][]spltest.MockFuncCall {"Get" : funcCalls , "Create" : {funcCalls [0 ], funcCalls [3 ], funcCalls [ 5 ] }, "Update" : {funcCalls [0 ]}}
229+ updateCalls := map [string ][]spltest.MockFuncCall {"Get" : {funcCalls [0 ], funcCalls [1 ], funcCalls [3 ], funcCalls [ 5 ] }}
228230 searchHeadCR := enterpriseApi.SearchHeadCluster {
229231 TypeMeta : metav1.TypeMeta {
230232 Kind : "SearcHead" ,
@@ -234,6 +236,11 @@ func TestApplySplunkConfig(t *testing.T) {
234236 Namespace : "test" ,
235237 },
236238 }
239+ var gvk schema.GroupVersionKind
240+ gvk .Kind = "SearchHead"
241+ gvk .Group = "enterprise.splunk.com"
242+ gvk .Version = "v4"
243+ searchHeadCR .SetGroupVersionKind (gvk )
237244 searchHeadCR .Spec .Defaults = "defaults-yaml"
238245 searchHeadRevised := searchHeadCR .DeepCopy ()
239246 searchHeadRevised .Spec .Image = "splunk/test"
@@ -268,9 +275,10 @@ func TestApplySplunkConfig(t *testing.T) {
268275 }
269276 funcCalls = []spltest.MockFuncCall {
270277 {MetaName : "*v1.Secret-test-splunk-test-secret" },
278+ {MetaName : "*v1.ConfigMap-test-splunk-cluster-master-stack1-configmap" },
271279 }
272- createCalls = map [string ][]spltest.MockFuncCall {"Get" : {funcCalls [0 ], funcCalls [0 ], funcCalls [0 ]}, "Create" : funcCalls , "Update" : {funcCalls [0 ]}}
273- updateCalls = map [string ][]spltest.MockFuncCall {"Get" : {funcCalls [0 ], funcCalls [0 ]}}
280+ createCalls = map [string ][]spltest.MockFuncCall {"Get" : {funcCalls [0 ], funcCalls [0 ], funcCalls [0 ], funcCalls [ 1 ] }, "Create" : funcCalls , "Update" : {funcCalls [0 ]}}
281+ updateCalls = map [string ][]spltest.MockFuncCall {"Get" : {funcCalls [0 ], funcCalls [0 ], funcCalls [ 1 ] }}
274282
275283 spltest .ReconcileTesterWithoutRedundantCheck (t , "TestApplySplunkConfig" , & indexerCR , indexerRevised , createCalls , updateCalls , reconcile , false )
276284
@@ -695,7 +703,7 @@ func TestInitAndCheckAppInfoStatusShouldNotFail(t *testing.T) {
695703
696704 crConfigMap1 := & corev1.ConfigMap {
697705 ObjectMeta : metav1.ObjectMeta {
698- Name : fmt .Sprintf ("splunk-config-%s" , cr .Name ),
706+ Name : fmt .Sprintf (perCrConfigMapNameStr , KindToInstanceString ( cr . Kind ) , cr .Name ),
699707 Namespace : cr .GetNamespace (),
700708 },
701709 Data : map [string ]string {
@@ -714,7 +722,7 @@ func TestInitAndCheckAppInfoStatusShouldNotFail(t *testing.T) {
714722
715723 crConfigMap2 := & corev1.ConfigMap {
716724 ObjectMeta : metav1.ObjectMeta {
717- Name : fmt .Sprintf ("splunk-config-%s" , revised .Name ),
725+ Name : fmt .Sprintf (perCrConfigMapNameStr , KindToInstanceString ( revised . Kind ) , revised .Name ),
718726 Namespace : cr .GetNamespace (),
719727 },
720728 Data : map [string ]string {
@@ -1339,19 +1347,25 @@ func TestUpdateManualAppUpdateConfigMapLocked(t *testing.T) {
13391347 kind := cr .GetObjectKind ().GroupVersionKind ().Kind
13401348 var turnOffManualChecking bool
13411349
1342- crKindMap := make (map [string ]string )
1343- configMapData := `status: on
1344- refCount: 1`
1345- crKindMap [cr .GetObjectKind ().GroupVersionKind ().Kind ] = configMapData
1346-
1347- configMap := splctrl .PrepareConfigMap (GetSplunkManualAppUpdateConfigMapName (cr .GetNamespace ()), cr .GetNamespace (), crKindMap )
1348-
13491350 // Test1: with no confiMap added, we should return error
13501351 err := updateManualAppUpdateConfigMapLocked (ctx , c , & cr , appStatusContext , kind , turnOffManualChecking )
13511352 if err == nil {
13521353 t .Errorf ("updateManualAppUpdateConfigMapLocked should have returned error since there is no configMap yet." )
13531354 }
13541355
1356+ crKindMap := make (map [string ]string )
1357+ crKindMap ["manualUpdate" ] = "off"
1358+ crConfigMap := splctrl .PrepareConfigMap (fmt .Sprintf (perCrConfigMapNameStr , KindToInstanceString (cr .GroupVersionKind ().Kind ), cr .GetName ()), cr .GetNamespace (), crKindMap )
1359+
1360+ // now add the confiMap to the client
1361+ c .AddObject (crConfigMap )
1362+
1363+ crKindMap = make (map [string ]string )
1364+ configMapData := `status: on
1365+ refCount: 1`
1366+ crKindMap [cr .GetObjectKind ().GroupVersionKind ().Kind ] = configMapData
1367+ configMap := splctrl .PrepareConfigMap (GetSplunkManualAppUpdateConfigMapName (cr .GetNamespace ()), cr .GetNamespace (), crKindMap )
1368+
13551369 // now add the confiMap to the client
13561370 c .AddObject (configMap )
13571371
0 commit comments