[FLINK-37448] Report actual TaskManager count in status.taskManager.replicas - #1146
[FLINK-37448] Report actual TaskManager count in status.taskManager.replicas#1146vsantwana wants to merge 2 commits into
Conversation
…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>
Dennis-Mircea
left a comment
There was a problem hiding this comment.
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.
9535ecb to
23775ea
Compare
Dennis-Mircea
left a comment
There was a problem hiding this comment.
One more docs spot goes stale with this change. The docs were restructured in #1164, which added a Status and Lifecycle page describing this field. docs/content/docs/custom-resource/status-and-lifecycle.md still lists taskManager as "populated in application mode only", which is no longer accurate, you now set it in AbstractFlinkDeploymentObserver for session clusters too (and your new SessionObserverTest confirms it). Suggested row:
| `taskManager` | `FlinkDeployment` | The TaskManager label selector and the actual number of TaskManagers registered with the running cluster, backing the Kubernetes scale subresource. Populated once the running cluster has been observed |
Please mirror the edit into docs/content.zh/docs/custom-resource/status-and-lifecycle.md as well (the zh tree is kept as a 1:1 mirror, same as you're already doing for reference.md).
gyfora
left a comment
There was a problem hiding this comment.
Hot @vsantwana , can you please address @Dennis-Mircea 's doc comment and then we can merge this :)
What is the purpose of the change
status.taskManager.replicaspreviously 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
FlinkService#getTaskManagerReplicas(Configuration), implemented inAbstractFlinkServicevia the existing/taskmanagersREST call;getClusterInfonow routes through it (single source of truth).AbstractFlinkDeploymentObserver#observeClusterInfonow setsstatus.taskManager(label selector + actual replica count) whenever the JobManager is ready, covering both application and session clusters.ReconciliationUtils#getTaskManagerInfono longer derives the count from the spec; at reconcile time it only sets the label selector (replicas stay0until the cluster is observed) and still clears the info when not running.TaskManagerInfo.replicasJavaDoc and the generated CRD eference docs to reflect the new semantics.Note: this changes the semantics of
status.taskManager.replicasfrom a spec-derived value to the observed cluster state.Verifying this change
This change added tests and can be verified as follows:
ApplicationObserverTest#observeReportsActualTaskManagerReplicasverifies thestatus reflects the cluster's actual TaskManager count (independent of the
spec-derived value) and tracks changes across observations.
TestingFlinkServicegained an overridabletaskManagerReplicasstub(defaults to a converged cluster, i.e. the spec-derived count).
Does this pull request potentially affect one of the following parts:
CustomResourceDescriptors: no (the field already exists; only its reported value changes)Documentation