Skip to content

[FLINK-37448] Report actual TaskManager count in status.taskManager.replicas#1146

Open
vsantwana wants to merge 2 commits into
apache:mainfrom
vsantwana:FLINK-37448-tm-replicas
Open

[FLINK-37448] Report actual TaskManager count in status.taskManager.replicas#1146
vsantwana wants to merge 2 commits into
apache:mainfrom
vsantwana:FLINK-37448-tm-replicas

Conversation

@vsantwana

@vsantwana vsantwana commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

What is the purpose of the change

status.taskManager.replicas previously held a value computed from the spec at reconcile time (ceil(parallelism / slots)). This is inaccurate for deployments where the number of TaskManagers fluctuates dynamically rather than being fixed by configuration - most notably standalone clusters running in reactive mode.

This change makes the field report the actual number of TaskManagers registered with the running Flink cluster, sourced from the Flink REST API (/taskmanagers), for both application and session deployments.

Brief change log

  • Added FlinkService#getTaskManagerReplicas(Configuration), implemented in AbstractFlinkService via the existing /taskmanagers REST call; getClusterInfo now routes through it (single source of truth).
  • AbstractFlinkDeploymentObserver#observeClusterInfo now sets status.taskManager (label selector + actual replica count) whenever the JobManager is ready, covering both application and session clusters.
  • ReconciliationUtils#getTaskManagerInfo no longer derives the count from the spec; at reconcile time it only sets the label selector (replicas stay 0 until the cluster is observed) and still clears the info when not running.
  • Extracted the duplicated TaskManager label selector into FlinkUtils#getTaskManagerLabelSelector`.
  • Updated the TaskManagerInfo.replicas JavaDoc and the generated CRD eference docs to reflect the new semantics.

Note: this changes the semantics of status.taskManager.replicas from a spec-derived value to the observed cluster state.

Verifying this change

This change added tests and can be verified as follows:

  • ApplicationObserverTest#observeReportsActualTaskManagerReplicas verifies the
    status reflects the cluster's actual TaskManager count (independent of the
    spec-derived value) and tracks changes across observations.
  • TestingFlinkService gained an overridable taskManagerReplicas stub
    (defaults to a converged cluster, i.e. the spec-derived count).
  • Existing controller/observer/service/metrics tests updated/confirmed.

Does this pull request potentially affect one of the following parts:

  • Dependencies (does it add or upgrade a dependency): no
  • The public API, i.e., is any changes to the CustomResourceDescriptors: no (the field already exists; only its reported value changes)
  • Core observer or reconciler logic that is regularly executed: yes

Documentation

  • Does this pull request introduce a new feature? no (behavior change to an existing status field)
  • If yes, how is the feature documented? JavaDocs / docs (CRD reference updated)

@vsantwana
vsantwana marked this pull request as draft June 23, 2026 04:48
…eplicas

Previously status.taskManager.replicas was computed from the spec at
reconcile time (ceil(parallelism / slots)), which is inaccurate for
deployments where the TaskManager count fluctuates dynamically (e.g.
standalone reactive mode).

This now populates the field during observation from the live Flink REST
API (actual registered TaskManagers) for both application and session
deployments. A new FlinkService#getTaskManagerReplicas method exposes the
count, the observer sets the status, and the reconciler only sets the
label selector (replicas stay 0 until the cluster is observed).

Note: this changes the semantics of status.taskManager.replicas from a
spec-derived value to the actual cluster state.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@vsantwana
vsantwana marked this pull request as ready for review June 23, 2026 09:41

@Dennis-Mircea Dennis-Mircea 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.

This PR needs more test coverage as well. The new tests covers only the application observer. The change deliberately covers session clusters too, but there is no session-path test. Consider tightening the test coverage as well.

…TM replicas across reconciles

Addresses PR apache#1146 review feedback:
- Fold FlinkService#getTaskManagerReplicas into getClusterInfo, which now
  returns a small ClusterInfo record (info map + observed replica count).
  Eliminates the duplicate /taskmanagers REST call from the observer path.
- ReconciliationUtils#getTaskManagerInfo now preserves the last observed
  replica count when transitioning through a RUNNING reconcile, so the
  scale subresource no longer transiently reports 0 after upgrades or
  spec changes; observation refreshes the count afterwards.
- Trim verbose comments in the observer, ReconciliationUtils and the
  controller test.
- Add ReconciliationUtilsTest#taskManagerReplicasPreservedAcrossReconciles.
@vsantwana
vsantwana force-pushed the FLINK-37448-tm-replicas branch from 9535ecb to 23775ea Compare July 15, 2026 09:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants