You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@flink.apache.org by "Dennis-Mircea (via GitHub)" <gi...@apache.org> on 2026/08/28 15:42:58 UTC

[PR] [hotfix] Replace deprecated Flink, JOSDK, and fabric8 APIs [flink-kubernetes-operator]

Dennis-Mircea opened a new pull request, #1197:
URL: https://github.com/apache/flink-kubernetes-operator/pull/1197

   <!--
   *Thank you very much for contributing to the Apache Flink Kubernetes Operator - we are happy that you want to help us improve the project. To help the community review your contribution in the best possible way, please go through the checklist below, which will get the contribution into a shape in which it can be best reviewed.*
   
   ## Contribution Checklist
   
     - Make sure that the pull request corresponds to a [JIRA issue](https://issues.apache.org/jira/projects/FLINK/issues). Exceptions are made for typos in JavaDoc or documentation files, which need no JIRA issue.
     
     - Name the pull request in the form "[FLINK-XXXX] [component] Title of the pull request", where *FLINK-XXXX* should be replaced by the actual issue number. Skip *component* if you are unsure about which is the best component.
     Typo fixes that have no associated JIRA issue should be named following this pattern: `[hotfix][docs] Fix typo in event time introduction` or `[hotfix][javadocs] Expand JavaDoc for PuncuatedWatermarkGenerator`.
   
     - Fill out the template below to describe the changes contributed by the pull request. That will give reviewers the context they need to do the review.
     
     - Make sure that the change passes the automated tests, i.e., `mvn clean verify` passes. You can read more on how we use GitHub Actions for CI [here](https://nightlies.apache.org/flink/flink-kubernetes-operator-docs-main/docs/development/guide/#cicd).
   
     - Each pull request should address only one issue, not mix up code from multiple issues.
     
     - Each commit in the pull request has a meaningful commit message (including the JIRA id)
   
     - Once all items of the checklist are addressed, remove the above text and this checklist, leaving only the filled out template below.
   
   
   **(The sections below can be removed for hotfixes of typos)**
   -->
   
   ## What is the purpose of the change
   
   The purpose of this PR is to replace the external deprecated Flink core, JOSDK, and fabric8 APIs.
   
   
   ## Brief change log
   
   Flink-related:
   - Replaced the deprecated typed `Configuration` accessors with the generic ones.
   - Replaced the deprecated `ExecutionCheckpointingOptions` with `CheckpointingOptions`.
   - Replaced the deprecated `SavepointConfigOptions` with `StateRecoveryOptions `.
   
   JOSDK-related:
   - Replaced the deprecated `installShutdownHook` method.
   - Replaced the deprecated `LeaderElectionConfiguration` with `LeaderElectionConfigurationBuilder`.
   
   Fabric8-related:
   - Replaced the deprecated `replace()` with `update()`.
   - Replaced the deprecated `createOrReplace()` with `createOr(NonDeletingOperation::update)` or `createOr(r -> r.unlock().update())` or `forEach(Resource::update)` based on the case.
   
   ## Verifying this change
   <!--
   Please make sure both new and modified tests in this PR follows the conventions defined in our code quality guide: https://flink.apache.org/contributing/code-style-and-quality-common.html#testing
   -->
   
   This change can be verified with the existing tests that still pass with this update.
   
   ## 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
     - Core observer or reconciler logic that is regularly executed: no
   
   ## Documentation
   
     - Does this pull request introduce a new feature? no
     - If yes, how is the feature documented? not applicable
   
   ---
   
   ##### Was generative AI tooling used to co-author this PR?
   
   <!--
   If generative AI tooling has been used in the process of authoring this PR, please
   change the checkbox below to `[X]` followed by the name of the tool, and uncomment the
   "Generated-by" line. See the ASF Generative Tooling Guidance for details:
   https://www.apache.org/legal/generative-tooling.html
   
   You are responsible for the quality and correctness of every change in this PR
   regardless of the tooling used. Low-effort AI-generated PRs will be closed. See
   AGENTS.md for the full guidance.
   -->
   
   - [ ] Yes (please specify the tool below)
   
   <!--
   Generated-by: [Tool Name and Version]
   -->
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [hotfix] Replace deprecated Flink, JOSDK, and fabric8 APIs [flink-kubernetes-operator]

Posted by "csviri (via GitHub)" <gi...@apache.org>.
csviri commented on code in PR #1197:
URL: https://github.com/apache/flink-kubernetes-operator/pull/1197#discussion_r4022984546


##########
flink-kubernetes-operator/src/main/java/org/apache/flink/kubernetes/operator/config/FlinkOperatorConfiguration.java:
##########
@@ -313,20 +313,30 @@ private static LeaderElectionConfiguration getLeaderElectionConfig(Configuration
             return null;
         }
 
-        return new LeaderElectionConfiguration(
-                conf.getOptional(
-                                KubernetesOperatorConfigOptions.OPERATOR_LEADER_ELECTION_LEASE_NAME)
-                        .orElseThrow(
-                                () ->
-                                        new IllegalConfigurationException(
-                                                KubernetesOperatorConfigOptions
-                                                                .OPERATOR_LEADER_ELECTION_LEASE_NAME
-                                                                .key()
-                                                        + " must be defined when operator leader election is enabled.")),
-                null,
-                conf.get(KubernetesOperatorConfigOptions.OPERATOR_LEADER_ELECTION_LEASE_DURATION),
-                conf.get(KubernetesOperatorConfigOptions.OPERATOR_LEADER_ELECTION_RENEW_DEADLINE),
-                conf.get(KubernetesOperatorConfigOptions.OPERATOR_LEADER_ELECTION_RETRY_PERIOD));
+        return LeaderElectionConfigurationBuilder.aLeaderElectionConfiguration(

Review Comment:
   Yes, this seems to be a bug in JOSDK, will create a patch for that. Will be part of next patch release version.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [hotfix] Replace deprecated Flink, JOSDK, and fabric8 APIs [flink-kubernetes-operator]

Posted by "csviri (via GitHub)" <gi...@apache.org>.
csviri commented on code in PR #1197:
URL: https://github.com/apache/flink-kubernetes-operator/pull/1197#discussion_r4022984546


##########
flink-kubernetes-operator/src/main/java/org/apache/flink/kubernetes/operator/config/FlinkOperatorConfiguration.java:
##########
@@ -313,20 +313,30 @@ private static LeaderElectionConfiguration getLeaderElectionConfig(Configuration
             return null;
         }
 
-        return new LeaderElectionConfiguration(
-                conf.getOptional(
-                                KubernetesOperatorConfigOptions.OPERATOR_LEADER_ELECTION_LEASE_NAME)
-                        .orElseThrow(
-                                () ->
-                                        new IllegalConfigurationException(
-                                                KubernetesOperatorConfigOptions
-                                                                .OPERATOR_LEADER_ELECTION_LEASE_NAME
-                                                                .key()
-                                                        + " must be defined when operator leader election is enabled.")),
-                null,
-                conf.get(KubernetesOperatorConfigOptions.OPERATOR_LEADER_ELECTION_LEASE_DURATION),
-                conf.get(KubernetesOperatorConfigOptions.OPERATOR_LEADER_ELECTION_RENEW_DEADLINE),
-                conf.get(KubernetesOperatorConfigOptions.OPERATOR_LEADER_ELECTION_RETRY_PERIOD));
+        return LeaderElectionConfigurationBuilder.aLeaderElectionConfiguration(

Review Comment:
   Yes, this seems to be a bug in JOSDK, will create a patch for that.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [hotfix] Replace deprecated Flink, JOSDK, and fabric8 APIs [flink-kubernetes-operator]

Posted by "spuru9 (via GitHub)" <gi...@apache.org>.
spuru9 commented on code in PR #1197:
URL: https://github.com/apache/flink-kubernetes-operator/pull/1197#discussion_r3911391552


##########
flink-kubernetes-operator/src/main/java/org/apache/flink/kubernetes/operator/config/FlinkOperatorConfiguration.java:
##########
@@ -313,20 +313,30 @@ private static LeaderElectionConfiguration getLeaderElectionConfig(Configuration
             return null;
         }
 
-        return new LeaderElectionConfiguration(
-                conf.getOptional(
-                                KubernetesOperatorConfigOptions.OPERATOR_LEADER_ELECTION_LEASE_NAME)
-                        .orElseThrow(
-                                () ->
-                                        new IllegalConfigurationException(
-                                                KubernetesOperatorConfigOptions
-                                                                .OPERATOR_LEADER_ELECTION_LEASE_NAME
-                                                                .key()
-                                                        + " must be defined when operator leader election is enabled.")),
-                null,
-                conf.get(KubernetesOperatorConfigOptions.OPERATOR_LEADER_ELECTION_LEASE_DURATION),
-                conf.get(KubernetesOperatorConfigOptions.OPERATOR_LEADER_ELECTION_RENEW_DEADLINE),
-                conf.get(KubernetesOperatorConfigOptions.OPERATOR_LEADER_ELECTION_RETRY_PERIOD));
+        return LeaderElectionConfigurationBuilder.aLeaderElectionConfiguration(

Review Comment:
   In JOSDK 5.5.0, `LeaderElectionConfigurationBuilder.build()` is implemented as:
   ```java
       public LeaderElectionConfiguration build() {
           return buildForTest(false);
       }
   ```
   
   This hardcodes exitOnStopLeading = false (the builder's Javadoc notes false should only be used for tests).
   
     Previously, the deprecated constructor new LeaderElectionConfiguration(...) set exitOnStopLeading = true. When exitOnStopLeading is true, if the operator loses its leadership lease, LeaderElectionManager.stopLeading() executes System.exit(1) so Kubernetes restarts the pod and allows a standby replica to take over cleanly.
   
   With .build(), exitOnStopLeading becomes false, so stopLeading() will merely log "Stopped leading, configured not to exit" and keep running without exiting. This can cause split-brain or stuck reconciliation threads during HA failovers.
   
   Please use .buildForTest(true) here so that production HA failover semantics (System.exit(1) on lost lease) are preserved.



##########
flink-kubernetes-operator/src/main/java/org/apache/flink/kubernetes/operator/utils/FlinkUtils.java:
##########
@@ -258,7 +258,11 @@ public static void deleteJobGraphInKubernetesHA(
             }
         }
         if (shouldUpdate) {
-            kubernetesClient.resourceList(configMaps).inNamespace(namespace).createOrReplace();
+            kubernetesClient
+                    .resourceList(configMaps)
+                    .inNamespace(namespace)
+                    .resources()
+                    .forEach(Resource::update);

Review Comment:
   `configMaps` contains all HA ConfigMaps for the cluster (e.g. dispatch leader, JM leader, etc.). Calling `.resources().forEach(Resource::update)` sends an HTTP `PUT` update for **every single ConfigMap** in the list, even those that were untouched.
       
       1. It issues unnecessary `PUT` requests for unmodified ConfigMaps.
       2. If any untouched ConfigMap (such as an active leader lease ConfigMap) was concurrently modified in the cluster, its `resourceVersion` will be stale and `Resource::update` will throw a `409 Conflict` exception, aborting the cleanup.
       
   Suggestion: collect only the modified ConfigMaps in the loop above and update only those:
   ```
               List<ConfigMap> modifiedConfigMaps = new ArrayList<>();
               for (ConfigMap configMap : configMaps.getItems()) {
                   if (configMap.getData() == null || configMap.getData().isEmpty()) {
                       continue;
                   }
                   if (configMap.getData().entrySet().removeIf(FlinkUtils::isJobGraphKey)) {
                       modifiedConfigMaps.add(configMap);
                       LOG.info("Job graph in ConfigMap {} is deleted", configMap.getMetadata().getName());
                   }
               }
               modifiedConfigMaps.forEach(cm -> kubernetesClient.resource(cm).inNamespace(namespace).update());
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [hotfix] Replace deprecated Flink, JOSDK, and fabric8 APIs [flink-kubernetes-operator]

Posted by "Dennis-Mircea (via GitHub)" <gi...@apache.org>.
Dennis-Mircea commented on code in PR #1197:
URL: https://github.com/apache/flink-kubernetes-operator/pull/1197#discussion_r4027085536


##########
flink-kubernetes-operator/src/main/java/org/apache/flink/kubernetes/operator/config/FlinkOperatorConfiguration.java:
##########
@@ -313,20 +313,30 @@ private static LeaderElectionConfiguration getLeaderElectionConfig(Configuration
             return null;
         }
 
-        return new LeaderElectionConfiguration(
-                conf.getOptional(
-                                KubernetesOperatorConfigOptions.OPERATOR_LEADER_ELECTION_LEASE_NAME)
-                        .orElseThrow(
-                                () ->
-                                        new IllegalConfigurationException(
-                                                KubernetesOperatorConfigOptions
-                                                                .OPERATOR_LEADER_ELECTION_LEASE_NAME
-                                                                .key()
-                                                        + " must be defined when operator leader election is enabled.")),
-                null,
-                conf.get(KubernetesOperatorConfigOptions.OPERATOR_LEADER_ELECTION_LEASE_DURATION),
-                conf.get(KubernetesOperatorConfigOptions.OPERATOR_LEADER_ELECTION_RENEW_DEADLINE),
-                conf.get(KubernetesOperatorConfigOptions.OPERATOR_LEADER_ELECTION_RETRY_PERIOD));
+        return LeaderElectionConfigurationBuilder.aLeaderElectionConfiguration(

Review Comment:
   Should we wait for the new JOSDK patch to be adopted as part of the operator or is it fine to go with the workaround that @spuru9 suggested? cc @gyfora 



##########
flink-kubernetes-operator/src/main/java/org/apache/flink/kubernetes/operator/utils/EventUtils.java:
##########
@@ -271,7 +271,7 @@ private static boolean labelCheck(
 
     private static Optional<Event> createOrReplaceEvent(KubernetesClient client, Event event) {
         try {
-            Event createdEvent = client.resource(event).createOrReplace();
+            Event createdEvent = client.resource(event).createOr(r -> r.unlock().update());

Review Comment:
   The thing is that, having just `update` in place, this will perform an optimistic-lock PUT, and if multiple concurrent updates happen at the same time, it will result in 409 and it will fail the reconciliation cycle.
   
   The old `createOrReplace` was a forced replace, which is what we want for best-effort events, and `unlock()` was meant to keep that.
   
   Looking again at this point from a different perspective, the `unlock()` only runs on the conflict branch, after the `create` returns, but `create` can fail with a 500 when a POST is executed with the same resourceVersion (see https://github.com/kubernetes/kubernetes/blob/master/staging/src/k8s.io/apiserver/pkg/storage/errors.go#L30).
   
   To resolve this, I used the fabric8 migration FAQ recommendation presented here: https://github.com/fabric8io/kubernetes-client/blob/main/doc/FAQ.md#alternatives-to-createorreplace-and-replace. I think we should all good with this approach.



##########
flink-kubernetes-operator/src/main/java/org/apache/flink/kubernetes/operator/utils/FlinkUtils.java:
##########
@@ -258,7 +258,11 @@ public static void deleteJobGraphInKubernetesHA(
             }
         }
         if (shouldUpdate) {
-            kubernetesClient.resourceList(configMaps).inNamespace(namespace).createOrReplace();
+            kubernetesClient
+                    .resourceList(configMaps)
+                    .inNamespace(namespace)
+                    .resources()
+                    .forEach(Resource::update);

Review Comment:
   Good suggestion, I've added it.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [hotfix] Replace deprecated Flink, JOSDK, and fabric8 APIs [flink-kubernetes-operator]

Posted by "gyfora (via GitHub)" <gi...@apache.org>.
gyfora commented on code in PR #1197:
URL: https://github.com/apache/flink-kubernetes-operator/pull/1197#discussion_r4027151504


##########
flink-kubernetes-operator/src/main/java/org/apache/flink/kubernetes/operator/config/FlinkOperatorConfiguration.java:
##########
@@ -313,20 +313,30 @@ private static LeaderElectionConfiguration getLeaderElectionConfig(Configuration
             return null;
         }
 
-        return new LeaderElectionConfiguration(
-                conf.getOptional(
-                                KubernetesOperatorConfigOptions.OPERATOR_LEADER_ELECTION_LEASE_NAME)
-                        .orElseThrow(
-                                () ->
-                                        new IllegalConfigurationException(
-                                                KubernetesOperatorConfigOptions
-                                                                .OPERATOR_LEADER_ELECTION_LEASE_NAME
-                                                                .key()
-                                                        + " must be defined when operator leader election is enabled.")),
-                null,
-                conf.get(KubernetesOperatorConfigOptions.OPERATOR_LEADER_ELECTION_LEASE_DURATION),
-                conf.get(KubernetesOperatorConfigOptions.OPERATOR_LEADER_ELECTION_RENEW_DEADLINE),
-                conf.get(KubernetesOperatorConfigOptions.OPERATOR_LEADER_ELECTION_RETRY_PERIOD));
+        return LeaderElectionConfigurationBuilder.aLeaderElectionConfiguration(

Review Comment:
   I leave this decision to @csviri , he knows the expected timeline for the fix. We could also just avoid touching this part until the josdk patch is available  



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [hotfix] Replace deprecated Flink, JOSDK, and fabric8 APIs [flink-kubernetes-operator]

Posted by "gyfora (via GitHub)" <gi...@apache.org>.
gyfora commented on code in PR #1197:
URL: https://github.com/apache/flink-kubernetes-operator/pull/1197#discussion_r4017298505


##########
flink-kubernetes-operator/src/main/java/org/apache/flink/kubernetes/operator/utils/EventUtils.java:
##########
@@ -271,7 +271,7 @@ private static boolean labelCheck(
 
     private static Optional<Event> createOrReplaceEvent(KubernetesClient client, Event event) {
         try {
-            Event createdEvent = client.resource(event).createOrReplace();
+            Event createdEvent = client.resource(event).createOr(r -> r.unlock().update());

Review Comment:
   why not `NonDeletingOperation::update`?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [hotfix] Replace deprecated Flink, JOSDK, and fabric8 APIs [flink-kubernetes-operator]

Posted by "spuru9 (via GitHub)" <gi...@apache.org>.
spuru9 commented on code in PR #1197:
URL: https://github.com/apache/flink-kubernetes-operator/pull/1197#discussion_r4027141816


##########
flink-kubernetes-operator/src/main/java/org/apache/flink/kubernetes/operator/config/FlinkOperatorConfiguration.java:
##########
@@ -313,20 +313,30 @@ private static LeaderElectionConfiguration getLeaderElectionConfig(Configuration
             return null;
         }
 
-        return new LeaderElectionConfiguration(
-                conf.getOptional(
-                                KubernetesOperatorConfigOptions.OPERATOR_LEADER_ELECTION_LEASE_NAME)
-                        .orElseThrow(
-                                () ->
-                                        new IllegalConfigurationException(
-                                                KubernetesOperatorConfigOptions
-                                                                .OPERATOR_LEADER_ELECTION_LEASE_NAME
-                                                                .key()
-                                                        + " must be defined when operator leader election is enabled.")),
-                null,
-                conf.get(KubernetesOperatorConfigOptions.OPERATOR_LEADER_ELECTION_LEASE_DURATION),
-                conf.get(KubernetesOperatorConfigOptions.OPERATOR_LEADER_ELECTION_RENEW_DEADLINE),
-                conf.get(KubernetesOperatorConfigOptions.OPERATOR_LEADER_ELECTION_RETRY_PERIOD));
+        return LeaderElectionConfigurationBuilder.aLeaderElectionConfiguration(

Review Comment:
   Given we wont be shipping this in this release and I see a PR for the JOSDK patch, it should be fine. We can add a note in this PR or the other that this is changing the following behavior. 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [hotfix] Replace deprecated Flink, JOSDK, and fabric8 APIs [flink-kubernetes-operator]

Posted by "csviri (via GitHub)" <gi...@apache.org>.
csviri commented on code in PR #1197:
URL: https://github.com/apache/flink-kubernetes-operator/pull/1197#discussion_r4023062708


##########
flink-kubernetes-operator/src/main/java/org/apache/flink/kubernetes/operator/config/FlinkOperatorConfiguration.java:
##########
@@ -313,20 +313,30 @@ private static LeaderElectionConfiguration getLeaderElectionConfig(Configuration
             return null;
         }
 
-        return new LeaderElectionConfiguration(
-                conf.getOptional(
-                                KubernetesOperatorConfigOptions.OPERATOR_LEADER_ELECTION_LEASE_NAME)
-                        .orElseThrow(
-                                () ->
-                                        new IllegalConfigurationException(
-                                                KubernetesOperatorConfigOptions
-                                                                .OPERATOR_LEADER_ELECTION_LEASE_NAME
-                                                                .key()
-                                                        + " must be defined when operator leader election is enabled.")),
-                null,
-                conf.get(KubernetesOperatorConfigOptions.OPERATOR_LEADER_ELECTION_LEASE_DURATION),
-                conf.get(KubernetesOperatorConfigOptions.OPERATOR_LEADER_ELECTION_RENEW_DEADLINE),
-                conf.get(KubernetesOperatorConfigOptions.OPERATOR_LEADER_ELECTION_RETRY_PERIOD));
+        return LeaderElectionConfigurationBuilder.aLeaderElectionConfiguration(

Review Comment:
   https://github.com/operator-framework/java-operator-sdk/pull/3619



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org