1717
1818package org .apache .flink .kubernetes .operator .bluegreen .client ;
1919
20+ import io .fabric8 .kubernetes .api .model .ConfigMap ;
21+ import io .fabric8 .kubernetes .client .informers .ResourceEventHandler ;
2022import org .apache .flink .configuration .Configuration ;
2123import org .apache .flink .kubernetes .operator .api .bluegreen .BlueGreenDeploymentType ;
2224import org .apache .flink .kubernetes .operator .api .bluegreen .GateContext ;
2527import org .apache .flink .streaming .api .functions .ProcessFunction ;
2628import org .apache .flink .util .Collector ;
2729import org .apache .flink .util .Preconditions ;
28-
29- import io .fabric8 .kubernetes .api .model .ConfigMap ;
30- import io .fabric8 .kubernetes .client .informers .ResourceEventHandler ;
3130import org .slf4j .Logger ;
3231import org .slf4j .LoggerFactory ;
3332
@@ -49,8 +48,8 @@ abstract class GateProcessFunction<I> extends ProcessFunction<I, I> implements S
4948 // TODO: make this configurable? This cannot be a constant
5049 protected final int subtaskIndexGuide = 1 ;
5150
52- protected GateKubernetesService gateKubernetesService ;
53- protected Boolean clearToTeardown = false ;
51+ private GateKubernetesService gateKubernetesService ;
52+ private Boolean clearToTeardown = false ;
5453 protected GateContext baseContext ;
5554 private String namespace ;
5655 private String configMapName ;
@@ -60,8 +59,7 @@ abstract class GateProcessFunction<I> extends ProcessFunction<I, I> implements S
6059 public GateProcessFunction (
6160 BlueGreenDeploymentType blueGreenDeploymentType ,
6261 String namespace ,
63- String configMapName ,
64- GateKubernetesService gateKubernetesService ) {
62+ String configMapName ) {
6563 Preconditions .checkArgument (
6664 blueGreenDeploymentType == BlueGreenDeploymentType .BLUE
6765 || blueGreenDeploymentType == BlueGreenDeploymentType .GREEN ,
@@ -70,19 +68,12 @@ public GateProcessFunction(
7068 this .blueGreenDeploymentType = blueGreenDeploymentType ;
7169 this .namespace = namespace ;
7270 this .configMapName = configMapName ;
73- this .gateKubernetesService = gateKubernetesService ;
7471 }
7572
7673 @ Override
7774 public void open (Configuration parameters ) throws Exception {
7875 super .open (parameters );
7976
80- // Only create service if not injected
81- if (gateKubernetesService == null ) {
82- this .gateKubernetesService = new GateKubernetesService (namespace , configMapName );
83- }
84-
85- // Always set up informers, whether service was injected or created
8677 setKubernetesEnvironment ();
8778 processConfigMap (gateKubernetesService .parseConfigMap ());
8879 }
@@ -113,6 +104,8 @@ public void processElement(I value, ProcessFunction<I, I>.Context ctx, Collector
113104 }
114105
115106 private void setKubernetesEnvironment () {
107+ this .gateKubernetesService = new GateKubernetesService (namespace , configMapName );
108+
116109 logInfo ("Preparing Informers..." );
117110 var resourceEventHandler =
118111 new ResourceEventHandler <ConfigMap >() {
@@ -167,26 +160,18 @@ private void processConfigMap(ConfigMap configMap) {
167160 onContextUpdate (baseContext , filteredData );
168161 }
169162
170- protected void notifyClearToTeardown () {
163+ protected final void notifyClearToTeardown () {
171164 // Notify only once
172165 if (!clearToTeardown && getRuntimeContext ().getIndexOfThisSubtask () == subtaskIndexGuide ) {
173166 logInfo ("Setting " + CLEAR_TO_TEARDOWN );
174- performConfigMapUpdate (
167+ gateKubernetesService . updateConfigMapEntries (
175168 Map .of (TRANSITION_STAGE .getLabel (), CLEAR_TO_TEARDOWN .toString ()));
176169 logInfo (CLEAR_TO_TEARDOWN + " set!" );
177170 this .clearToTeardown = true ;
178171 }
179172 }
180173
181- /**
182- * Template method for updating ConfigMap entries. Override in tests to avoid actual K8s
183- * updates.
184- */
185- protected void performConfigMapUpdate (Map <String , String > updates ) {
186- gateKubernetesService .updateConfigMapEntries (updates );
187- }
188-
189- protected void updateConfigMapCustomEntries (Map <String , String > customEntries )
174+ protected final void updateConfigMapCustomEntries (Map <String , String > customEntries )
190175 throws IllegalAccessException {
191176 // Validating only "custom" entries/keys can be updated
192177 var keysToUpdate = customEntries .keySet ();
@@ -203,7 +188,7 @@ protected void updateConfigMapCustomEntries(Map<String, String> customEntries)
203188 throw new IllegalAccessException (error );
204189 }
205190 logInfo ("Updating custom entries: " + customEntries );
206- performConfigMapUpdate (customEntries );
191+ gateKubernetesService . updateConfigMapEntries (customEntries );
207192 }
208193
209194 // Temporary "utility" function for development
0 commit comments