@@ -238,7 +238,7 @@ func ApplySplunkConfig(ctx context.Context, client splcommon.ControllerClient, c
238238 return namespaceScopedSecret , nil
239239}
240240
241- // ReconcileCRSpecificConfigMap reconciles CR Specific config map exists and contains the ManualUpdate field set to "on "
241+ // ReconcileCRSpecificConfigMap reconciles CR Specific config map exists and contains the ManualUpdate field set to "off "
242242func ReconcileCRSpecificConfigMap (ctx context.Context , client splcommon.ControllerClient , cr splcommon.MetaObject ) error {
243243 reqLogger := log .FromContext (ctx )
244244 scopedLog := reqLogger .WithName ("ReconcileCRSpecificConfigMap" ).WithValues ("name" , cr .GetName (), "namespace" , cr .GetNamespace ())
@@ -256,7 +256,7 @@ func ReconcileCRSpecificConfigMap(ctx context.Context, client splcommon.Controll
256256 Namespace : cr .GetNamespace (),
257257 },
258258 Data : map [string ]string {
259- "ManualUpdate" : "on " ,
259+ "ManualUpdate" : "off " ,
260260 },
261261 }
262262 err = client .Create (ctx , configMap )
@@ -273,7 +273,7 @@ func ReconcileCRSpecificConfigMap(ctx context.Context, client splcommon.Controll
273273
274274 // Check if the ManualUpdate field exists
275275 if _ , exists := configMap .Data ["ManualUpdate" ]; ! exists {
276- configMap .Data ["ManualUpdate" ] = "on "
276+ configMap .Data ["ManualUpdate" ] = "off "
277277 err = client .Update (ctx , configMap )
278278 if err != nil {
279279 scopedLog .Error (err , "Failed to update config map with ManualUpdate field" )
@@ -1456,6 +1456,7 @@ func isAppRepoPollingEnabled(appStatusContext *enterpriseApi.AppDeploymentContex
14561456 return appStatusContext .AppsRepoStatusPollInterval != 0
14571457}
14581458
1459+ // shouldCheckAppRepoStatus
14591460func shouldCheckAppRepoStatus (ctx context.Context , client splcommon.ControllerClient , cr splcommon.MetaObject , appStatusContext * enterpriseApi.AppDeploymentContext , kind string , turnOffManualChecking * bool ) bool {
14601461 // If polling is disabled, check if manual update is on.
14611462 if ! isAppRepoPollingEnabled (appStatusContext ) {
@@ -1469,6 +1470,12 @@ func shouldCheckAppRepoStatus(ctx context.Context, client splcommon.ControllerCl
14691470 * turnOffManualChecking = true
14701471 }
14711472 return true
1473+ } else {
1474+ configMapName := fmt .Sprintf ("splunk-config-%s" , cr .GetName ())
1475+ if getManualUpdateStatus (ctx , client , cr , configMapName ) == "on" {
1476+ * turnOffManualChecking = true
1477+ return true
1478+ }
14721479 }
14731480 } else {
14741481 return HasAppRepoCheckTimerExpired (ctx , appStatusContext )
@@ -1489,7 +1496,21 @@ func getCleanObjectDigest(rawObjectDigest *string) (*string, error) {
14891496 return & cleanObjectHash , nil
14901497}
14911498
1492- // updateManualAppUpdateConfigMapLocked updates the manual app update config map
1499+
1500+ // updateManualAppUpdateConfigMapLocked updates the manual app update configuration map for a given custom resource (CR).
1501+ // It locks the resource mutex for the config map, retrieves the config map, and updates the status and reference count
1502+ // based on whether manual checking is turned off or not.
1503+ //
1504+ // Parameters:
1505+ // - ctx: The context for the request.
1506+ // - client: The controller client to interact with the Kubernetes API.
1507+ // - cr: The custom resource meta object.
1508+ // - appStatusContext: The application deployment context.
1509+ // - kind: The kind of the custom resource.
1510+ // - turnOffManualChecking: A boolean indicating whether to turn off manual checking.
1511+ //
1512+ // Returns:
1513+ // - error: An error if the operation fails, otherwise nil.
14931514func updateManualAppUpdateConfigMapLocked (ctx context.Context , client splcommon.ControllerClient , cr splcommon.MetaObject , appStatusContext * enterpriseApi.AppDeploymentContext , kind string , turnOffManualChecking bool ) error {
14941515 reqLogger := log .FromContext (ctx )
14951516 scopedLog := reqLogger .WithName ("updateManualAppUpdateConfigMap" ).WithValues ("name" , cr .GetName (), "namespace" , cr .GetNamespace ())
@@ -1498,43 +1519,67 @@ func updateManualAppUpdateConfigMapLocked(ctx context.Context, client splcommon.
14981519 configMapName := GetSplunkManualAppUpdateConfigMapName (cr .GetNamespace ())
14991520 namespacedName := types.NamespacedName {Namespace : cr .GetNamespace (), Name : configMapName }
15001521
1501- mux := getResourceMutex (configMapName )
1502- mux .Lock ()
1503- defer mux .Unlock ()
1504- configMap , err := splctrl .GetConfigMap (ctx , client , namespacedName )
1522+ {
1523+ mux := getResourceMutex (configMapName )
1524+ mux .Lock ()
1525+ defer mux .Unlock ()
1526+ configMap , err := splctrl .GetConfigMap (ctx , client , namespacedName )
1527+ if err != nil {
1528+ scopedLog .Error (err , "Unable to get configMap" , "name" , namespacedName .Name )
1529+ return err
1530+ }
1531+
1532+ // first check the refCount and status
1533+ //
1534+ numOfObjects := getManualUpdateRefCount (ctx , client , cr , configMapName )
1535+
1536+ // turn off the manual checking for this CR kind in the configMap
1537+ if turnOffManualChecking {
1538+ scopedLog .Info ("Turning off manual checking of apps update" , "Kind" , kind )
1539+ // reset the status back to "off" and
1540+ // refCount to original count
1541+ status = "off"
1542+ numOfObjects = getNumOfOwnerRefsKind (configMap , kind )
1543+ } else {
1544+ //just decrement the refCount if the status is "on"
1545+ status = getManualUpdateStatus (ctx , client , cr , configMapName )
1546+ if status == "on" {
1547+ numOfObjects --
1548+ }
1549+ }
1550+
1551+ // prepare the configMapData
1552+ configMapData := fmt .Sprintf (`status: %s
1553+ refCount: %d` , status , numOfObjects )
1554+
1555+ configMap .Data [kind ] = configMapData
1556+
1557+ err = splutil .UpdateResource (ctx , client , configMap )
1558+ if err != nil {
1559+ scopedLog .Error (err , "Could not update the configMap" , "name" , namespacedName .Name )
1560+ return err
1561+ }
1562+ }
1563+
1564+ // now check namespace specific configmap if it contains manualUpdate settings
1565+ crScopedConfigMapName := fmt .Sprintf ("splunk-config-%s" , cr .GetName ())
1566+ crNamespacedName := types.NamespacedName {Namespace : cr .GetNamespace (), Name : crScopedConfigMapName }
1567+ configMap , err := splctrl .GetConfigMap (ctx , client , crNamespacedName )
15051568 if err != nil {
15061569 scopedLog .Error (err , "Unable to get configMap" , "name" , namespacedName .Name )
15071570 return err
15081571 }
1509-
1510- numOfObjects := getManualUpdateRefCount (ctx , client , cr , configMapName )
1511-
1512- // turn off the manual checking for this CR kind in the configMap
15131572 if turnOffManualChecking {
1514- scopedLog .Info ("Turning off manual checking of apps update" , "Kind" , kind )
1515- // reset the status back to "off" and
1516- // refCount to original count
1573+ scopedLog .Info ("Turning off manual checking of apps update in per CR configmap" , "Kind" , kind )
15171574 status = "off"
1518- numOfObjects = getNumOfOwnerRefsKind (configMap , kind )
1519- } else {
1520- //just decrement the refCount if the status is "on"
1521- status = getManualUpdateStatus (ctx , client , cr , configMapName )
1522- if status == "on" {
1523- numOfObjects --
1524- }
15251575 }
1526-
1527- // prepare the configMapData
1528- configMapData := fmt .Sprintf (`status: %s
1529- refCount: %d` , status , numOfObjects )
1530-
1531- configMap .Data [kind ] = configMapData
1532-
1576+
15331577 err = splutil .UpdateResource (ctx , client , configMap )
15341578 if err != nil {
1535- scopedLog .Error (err , "Could not update the configMap" , "name" , namespacedName .Name )
1579+ scopedLog .Error (err , "Could not update the per CR configMap" , "name" , crNamespacedName .Name )
15361580 return err
15371581 }
1582+
15381583 return nil
15391584}
15401585
0 commit comments