Skip to content

refactor: remove unused scaledJobGenerations sync.Map#7791

Merged
wozniakjan merged 1 commit into
kedacore:mainfrom
Fedosin:remove-scaled-job-generations-map
May 28, 2026
Merged

refactor: remove unused scaledJobGenerations sync.Map#7791
wozniakjan merged 1 commit into
kedacore:mainfrom
Fedosin:remove-scaled-job-generations-map

Conversation

@Fedosin

@Fedosin Fedosin commented May 27, 2026

Copy link
Copy Markdown
Contributor

The scaledJobGenerations sync.Map field on ScaledJobReconciler was written to (Store in requestScaleLoop, Delete in stopScaleLoop) but never read from.

Unlike ScaledObjectReconciler, which uses scaledObjectsGenerations via scaledObjectGenerationChanged() to skip unnecessary scale-loop restarts when the spec hasn't changed, ScaledJobReconciler unconditionally calls requestScaleLoop on every successful reconcile. This made the generation tracking dead code.

This PR removes:

  • The scaledJobGenerations *sync.Map field from the struct
  • Its initialization in SetupWithManager
  • The cache.MetaNamespaceKeyFunc key computation and Store/Delete calls in requestScaleLoop/stopScaleLoop
  • The now-unused "k8s.io/client-go/tools/cache" import

requestScaleLoop and stopScaleLoop are simplified to directly delegate to HandleScalableObject / DeleteScalableObject.

Checklist

  • When introducing a new scaler, I agree with the scaling governance policy
  • I have verified that my change is according to the deprecations & breaking changes policy
  • Tests have been added (if applicable)
  • Ensure make generate-scalers-schema has been run to update any outdated generated files
  • Changelog has been updated and is aligned with our changelog requirements, only when the change impacts end users
  • A PR is opened to update our Helm chart (repo) (if applicable, ie. when deployment manifests are modified)
  • A PR is opened to update the documentation on (repo) (if applicable)
  • Commits are signed with Developer Certificate of Origin (DCO - learn more)

Fixes #
Relates to #

The scaledJobGenerations sync.Map was written to (Store/Delete) but
never read from — unlike ScaledObject's scaledObjectsGenerations which
is checked via scaledObjectGenerationChanged() to avoid unnecessary
scale-loop restarts.

Since ScaledJob unconditionally restarts its scale loop on every
reconcile, the generation tracking served no purpose. This removes
the dead field, its initialization, and the associated key computation
logic, along with the now-unused "k8s.io/client-go/tools/cache" import.

Signed-off-by: Mikhail Fedosin <mfedosin@redhat.com>
@Fedosin Fedosin requested a review from a team as a code owner May 27, 2026 18:39
@snyk-io

snyk-io Bot commented May 27, 2026

Copy link
Copy Markdown

Snyk checks have passed. No issues have been found so far.

Status Scan Engine Critical High Medium Low Total (0)
Open Source Security 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

@github-actions

Copy link
Copy Markdown

Thank you for your contribution! 🙏

Please understand that we will do our best to review your PR and give you feedback as soon as possible, but please bear with us if it takes a little longer as expected.

While you are waiting, make sure to:

  • Add an entry in our changelog in alphabetical order and link related issue
  • Update the documentation, if needed
  • Add unit & e2e tests for your changes
  • GitHub checks are passing
  • Is the DCO check failing? Here is how you can fix DCO issues

Once the initial tests are successful, a KEDA member will ensure that the e2e tests are run. Once the e2e tests have been successfully completed, the PR may be merged at a later date. Please be patient.

Learn more about our contribution guide.

@keda-automation keda-automation requested a review from a team May 27, 2026 18:39

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR removes dead generation-tracking state from ScaledJobReconciler, simplifying ScaledJob scale-loop start/stop handling now that the stored generation value is not read anywhere.

Changes:

  • Removed scaledJobGenerations and its sync.Map initialization.
  • Removed unused cache key generation and Store/Delete calls from ScaledJob scale-loop helpers.
  • Also changes the ScaledJob ready CloudEvent type, which is outside the stated refactor scope.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread controllers/keda/scaledjob_controller.go Outdated
@rickbrouwer

rickbrouwer commented May 28, 2026

Copy link
Copy Markdown
Member

Apart from the removal of unused code, I also see a change that looks like a fix (ScaledObjectReadyType instead of ScaledJobReadyType).

For traceability, I think it is worth adding an item to the changelog.

/edit:

ah, also copilot think the same

@Fedosin Fedosin force-pushed the remove-scaled-job-generations-map branch from 7017741 to 0cbc6ca Compare May 28, 2026 07:22
@keda-automation keda-automation requested a review from a team May 28, 2026 07:22
@Fedosin

Fedosin commented May 28, 2026

Copy link
Copy Markdown
Contributor Author

Right... I'm going to open another PR with the event type change.

@Fedosin

Fedosin commented May 28, 2026

Copy link
Copy Markdown
Contributor Author

#7792

@rickbrouwer

rickbrouwer commented May 28, 2026

Copy link
Copy Markdown
Member

/run-e2e internal
Update: You can check the progress here

@wozniakjan

wozniakjan commented May 28, 2026

Copy link
Copy Markdown
Member

/run-e2e internal
Update: You can check the progress here

passed tests: 34
Execution of tests/internals/trigger_authentication_validation/trigger_authentication_validation_test.go, has passed after "one" attempts
Execution of tests/internals/status_update/status_update_test.go, has passed after "one" attempts
Execution of tests/internals/restore_original/restore_original_test.go, has passed after "one" attempts
Execution of tests/internals/file_based_auth/file_based_auth_test.go, has passed after "one" attempts
Execution of tests/internals/scaling_strategies/eager_scaling_strategy/eager_scaling_strategy_test.go, has passed after "one" attempts
Execution of tests/internals/idle_replicas/idle_replicas_test.go, has passed after "one" attempts
Execution of tests/internals/subresource_scale/subresource_scale_test.go, has passed after "one" attempts
Execution of tests/internals/replicaset_scale/replicaset_scale_test.go, has passed after "one" attempts
Execution of tests/internals/eventemitter/azureeventgridtopic/azureeventgridtopic_test.go, has passed after "one" attempts
Execution of tests/internals/custom_hpa_name/custom_hpa_name_test.go, has passed after "one" attempts
Execution of tests/internals/scaled_job_validation/scaled_job_validation_test.go, has passed after "one" attempts
Execution of tests/internals/pause_scale_out/pause_scale_out_test.go, has passed after "one" attempts
Execution of tests/internals/min_replica_sj/min_replica_sj_test.go, has passed after "one" attempts
Execution of tests/internals/value_metric_type/value_metric_type_test.go, has passed after "one" attempts
Execution of tests/internals/update_ta/update_ta_test.go, has passed after "one" attempts
Execution of tests/internals/scaled_object_validation/scaled_object_validation_test.go, has passed after "one" attempts
Execution of tests/internals/scaled_job_conditions/scaled_job_conditions_test.go, has passed after "one" attempts
Execution of tests/internals/pause_scale_in/pause_scale_in_test.go, has passed after "one" attempts
Execution of tests/internals/pause_scale_in_restore/pause_scale_in_restore_test.go, has passed after "two" attempts
Execution of tests/internals/trigger_update_so/trigger_update_so_test.go, has passed after "one" attempts
Execution of tests/internals/global_custom_ca/global_custom_ca_test.go, has passed after "one" attempts
Execution of tests/internals/force_activation/force_activation_test.go, has passed after "two" attempts
Execution of tests/internals/initial_delay_cooldownperiod/initial_delay_cooldownperiod_test.go, has passed after "one" attempts
Execution of tests/internals/replica_update_so/replica_update_so_test.go, has passed after "one" attempts
Execution of tests/internals/events/events_test.go, has passed after "two" attempts
Execution of tests/internals/cache_metrics/cache_metrics_test.go, has passed after "one" attempts
Execution of tests/internals/pause_scaledjob/pause_scaledjob_test.go, has passed after "one" attempts
Execution of tests/internals/cloudevent_source/cloudevent_source_test.go, has passed after "one" attempts
Execution of tests/internals/polling_cooldown_so/polling_cooldown_so_test.go, has passed after "one" attempts
Execution of tests/internals/scaling_modifiers/scaling_modifiers_test.go, has passed after "one" attempts
Execution of tests/internals/pause_scaledobject/pause_scaledobject_test.go, has passed after "two" attempts
Execution of tests/internals/fallback/deployments/fallback_test.go, has passed after "one" attempts
Execution of tests/internals/fallback/rollouts/fallback_test.go, has passed after "one" attempts
Execution of tests/internals/pause_scaledobject_explicitly/pause_scaledobject_explicitly_test.go, has passed after "two" attempts
failed tests: 1
Execution of tests/internals/scaling_strategies/accurate_scaling_strategy/accurate_scaling_strategy_test.go, has failed after "three" attempts

@wozniakjan wozniakjan enabled auto-merge (squash) May 28, 2026 12:46
@rickbrouwer

rickbrouwer commented May 28, 2026

Copy link
Copy Markdown
Member

/run-e2e internal
Update: You can check the progress here

passed tests: 35
Execution of tests/internals/trigger_authentication_validation/trigger_authentication_validation_test.go, has passed after "one" attempts
Execution of tests/internals/force_activation/force_activation_test.go, has passed after "one" attempts
Execution of tests/internals/status_update/status_update_test.go, has passed after "one" attempts
Execution of tests/internals/restore_original/restore_original_test.go, has passed after "one" attempts
Execution of tests/internals/scaled_object_validation/scaled_object_validation_test.go, has passed after "one" attempts
Execution of tests/internals/scaled_job_validation/scaled_job_validation_test.go, has passed after "one" attempts
Execution of tests/internals/file_based_auth/file_based_auth_test.go, has passed after "one" attempts
Execution of tests/internals/min_replica_sj/min_replica_sj_test.go, has passed after "one" attempts
Execution of tests/internals/replicaset_scale/replicaset_scale_test.go, has passed after "one" attempts
Execution of tests/internals/subresource_scale/subresource_scale_test.go, has passed after "one" attempts
Execution of tests/internals/value_metric_type/value_metric_type_test.go, has passed after "one" attempts
Execution of tests/internals/eventemitter/azureeventgridtopic/azureeventgridtopic_test.go, has passed after "one" attempts
Execution of tests/internals/scaling_strategies/eager_scaling_strategy/eager_scaling_strategy_test.go, has passed after "one" attempts
Execution of tests/internals/global_custom_ca/global_custom_ca_test.go, has passed after "one" attempts
Execution of tests/internals/pause_scaledobject/pause_scaledobject_test.go, has passed after "one" attempts
Execution of tests/internals/idle_replicas/idle_replicas_test.go, has passed after "one" attempts
Execution of tests/internals/events/events_test.go, has passed after "one" attempts
Execution of tests/internals/pause_scale_in_restore/pause_scale_in_restore_test.go, has passed after "two" attempts
Execution of tests/internals/pause_scale_in/pause_scale_in_test.go, has passed after "one" attempts
Execution of tests/internals/custom_hpa_name/custom_hpa_name_test.go, has passed after "one" attempts
Execution of tests/internals/pause_scale_out/pause_scale_out_test.go, has passed after "one" attempts
Execution of tests/internals/replica_update_so/replica_update_so_test.go, has passed after "one" attempts
Execution of tests/internals/initial_delay_cooldownperiod/initial_delay_cooldownperiod_test.go, has passed after "one" attempts
Execution of tests/internals/update_ta/update_ta_test.go, has passed after "one" attempts
Execution of tests/internals/cache_metrics/cache_metrics_test.go, has passed after "one" attempts
Execution of tests/internals/cloudevent_source/cloudevent_source_test.go, has passed after "one" attempts
Execution of tests/internals/scaled_job_conditions/scaled_job_conditions_test.go, has passed after "one" attempts
Execution of tests/internals/trigger_update_so/trigger_update_so_test.go, has passed after "one" attempts
Execution of tests/internals/pause_scaledjob/pause_scaledjob_test.go, has passed after "one" attempts
Execution of tests/internals/scaling_strategies/accurate_scaling_strategy/accurate_scaling_strategy_test.go, has passed after "one" attempts
Execution of tests/internals/polling_cooldown_so/polling_cooldown_so_test.go, has passed after "one" attempts
Execution of tests/internals/scaling_modifiers/scaling_modifiers_test.go, has passed after "one" attempts
Execution of tests/internals/pause_scaledobject_explicitly/pause_scaledobject_explicitly_test.go, has passed after "one" attempts
Execution of tests/internals/fallback/deployments/fallback_test.go, has passed after "one" attempts
Execution of tests/internals/fallback/rollouts/fallback_test.go, has passed after "one" attempts
failed tests: 0

@wozniakjan wozniakjan merged commit cebd0a6 into kedacore:main May 28, 2026
24 checks passed
shcherbak pushed a commit to shcherbak/keda that referenced this pull request Jun 3, 2026
The scaledJobGenerations sync.Map was written to (Store/Delete) but
never read from — unlike ScaledObject's scaledObjectsGenerations which
is checked via scaledObjectGenerationChanged() to avoid unnecessary
scale-loop restarts.

Since ScaledJob unconditionally restarts its scale loop on every
reconcile, the generation tracking served no purpose. This removes
the dead field, its initialization, and the associated key computation
logic, along with the now-unused "k8s.io/client-go/tools/cache" import.

Signed-off-by: Mikhail Fedosin <mfedosin@redhat.com>
Signed-off-by: Yurii Shcherbak <ju.shcherbak@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants