@@ -125,16 +125,19 @@ private void updateNamespace() {
125125 protected JsonObject updateCondition (VmDefinition from , String type ,
126126 boolean state , String reason , String message ) {
127127 JsonObject status = from .statusJson ();
128- // Optimize , as we can get this several times
128+ // Avoid redundant updates , as this may be called several times
129129 var current = status .getAsJsonArray ("conditions" ).asList ().stream ()
130130 .map (cond -> (JsonObject ) cond )
131131 .filter (cond -> type .equals (cond .get ("type" ).getAsString ()))
132132 .findFirst ();
133- if ( current .isPresent ( )
134- && current .map (c -> c . get ( "status" ). getAsString ())
135- . map ( "True" :: equals ). map ( s -> s == state ). orElse ( false )
133+ var stateUnchanged = current .map ( c -> c . get ( "status" ). getAsString () )
134+ .map ("True" :: equals ). map ( s -> s == state ). orElse ( false );
135+ if ( stateUnchanged
136136 && current .map (c -> c .get ("reason" ).getAsString ())
137- .map (reason ::equals ).orElse (false )) {
137+ .map (reason ::equals ).orElse (false )
138+ && current .map (c -> c .get ("observedGeneration" ).getAsLong ())
139+ .map (from .getMetadata ().getGeneration ()::equals )
140+ .orElse (false )) {
138141 return status ;
139142 }
140143
@@ -143,7 +146,9 @@ protected JsonObject updateCondition(VmDefinition from, String type,
143146 "status" , state ? "True" : "False" ,
144147 "observedGeneration" , from .getMetadata ().getGeneration (),
145148 "reason" , reason ,
146- "lastTransitionTime" , Instant .now ().toString ()));
149+ "lastTransitionTime" , stateUnchanged
150+ ? current .get ().get ("lastTransitionTime" ).getAsString ()
151+ : Instant .now ().toString ()));
147152 if (message != null ) {
148153 condition .put ("message" , message );
149154 }
0 commit comments