77import java .util .ArrayList ;
88import java .util .Arrays ;
99import java .util .Collections ;
10+ import java .util .HashMap ;
1011import java .util .Iterator ;
1112import java .util .LinkedHashMap ;
1213import java .util .List ;
@@ -45,6 +46,7 @@ public class SchemaConversionUtils {
4546 private static final String NAME = "name" ;
4647 private static final String SPEC = "spec" ;
4748 private static final String STATUS = "status" ;
49+ private static final String CONDITIONS = "conditions" ;
4850 private static final String TYPE = "type" ;
4951 private static final String CLUSTERS = "clusters" ;
5052 private static final String CLUSTER_NAME = "clusterName" ;
@@ -59,6 +61,7 @@ public class SchemaConversionUtils {
5961 private static final String DOLLAR_SPEC = "$.spec" ;
6062 private static final String DOLLAR_SPEC_SERVERPOD = "$.spec.serverPod" ;
6163 private static final String DOLLAR_SPEC_AS_SERVERPOD = "$.spec.adminServer.serverPod" ;
64+ private static final String DOLLAR_STATUS = "$.status" ;
6265
6366 public static final String INTERNAL = "Internal" ;
6467
@@ -70,6 +73,14 @@ public class SchemaConversionUtils {
7073 "Aborted" , INTERNAL , "TopologyMismatch" , "ReplicasTooHigh" ,
7174 "ServerPod" , "Kubernetes" , "Introspection" , "DomainInvalid" );
7275
76+ private static final String PROGRESSING = "Progressing" ;
77+ private static final String COMPLETED = "Completed" ;
78+ private static final String AVAILABLE = "Available" ;
79+ private static final String FAILED = "Failed" ;
80+
81+ private static final List <String > STATUS_CONDITION_TYPES_V8 = List .of (
82+ PROGRESSING , AVAILABLE , "ConfigChangesPendingRestart" , FAILED );
83+
7384 private static final String VOLUME_MOUNTS = "volumeMounts" ;
7485 private static final String VOLUMES = "volumes" ;
7586 private static final String VOLUME = "volume" ;
@@ -139,6 +150,13 @@ public Resources convertDomainSchema(Map<String, Object> domain, ResourceLookup
139150 try {
140151 Map <String , Object > toBePreserved = new TreeMap <>();
141152 removeAndPreserveLogHomeLayout (spec , toBePreserved );
153+ Map <String , Object > status = getStatus (domain );
154+ removeAndPreserveConditionsV9 (status , toBePreserved );
155+ Optional .ofNullable (status ).ifPresent (s -> {
156+ if (status .isEmpty ()) {
157+ domain .remove (STATUS );
158+ }
159+ });
142160
143161 preserveV9 (PRESERVED_V9 , domain , toBePreserved , apiVersion );
144162 } catch (IOException io ) {
@@ -301,39 +319,45 @@ private void convertDomainStatusTargetV9(Map<String, Object> domain) {
301319 }
302320
303321 private void convertCompletedToProgressing (Map <String , Object > domain ) {
304- Iterator <Map <String , String >> conditions = getStatusConditions (domain ).iterator ();
305- while (conditions .hasNext ()) {
306- Map <String , String > condition = conditions .next ();
307- if ("Completed" .equals (condition .get (TYPE ))) {
308- if ("False" .equals (condition .get (STATUS ))) {
309- condition .put (TYPE , "Progressing" );
310- condition .put (STATUS , "True" );
311- } else {
312- conditions .remove ();
313- }
314- }
315- }
322+ convertCondition (domain , COMPLETED , "False" , PROGRESSING , "True" );
316323 }
317324
318325 private void convertProgressingToCompleted (Map <String , Object > domain ) {
319- Iterator <Map <String , String >> conditions = getStatusConditions (domain ).iterator ();
320- while (conditions .hasNext ()) {
321- Map <String , String > condition = conditions .next ();
322- if ("Progressing" .equals (condition .get (TYPE ))) {
323- if ("True" .equals (condition .get (STATUS ))) {
324- condition .put (TYPE , "Completed" );
325- condition .put (STATUS , "False" );
326- } else {
327- conditions .remove ();
326+ convertCondition (domain , PROGRESSING , "True" , COMPLETED , "False" );
327+ }
328+
329+ private void convertCondition (Map <String , Object > domain ,
330+ String type , String expectedStatus , String repType , String repStatus ) {
331+ Map <String , Object > status = getStatus (domain );
332+ Optional .ofNullable (status ).ifPresent (s -> {
333+ List <Map <String , String >> conditions = (List <Map <String , String >>) status .get (CONDITIONS );
334+ Optional .ofNullable (conditions ).ifPresent (c -> {
335+ Iterator <Map <String , String >> it = conditions .iterator ();
336+ while (it .hasNext ()) {
337+ Map <String , String > condition = it .next ();
338+ if (type .equals (condition .get (TYPE ))) {
339+ if (expectedStatus .equals (condition .get (STATUS ))) {
340+ condition .put (TYPE , repType );
341+ condition .put (STATUS , repStatus );
342+ } else {
343+ it .remove ();
344+ }
345+ }
328346 }
329- }
330- }
347+ if (conditions .isEmpty ()) {
348+ status .remove (CONDITIONS );
349+ }
350+ if (status .isEmpty ()) {
351+ domain .remove (STATUS );
352+ }
353+ });
354+ });
331355 }
332356
333357 @ Nonnull
334358 private List <Map <String ,String >> getStatusConditions (Map <String , Object > domain ) {
335359 return (List <Map <String ,String >>) Optional .ofNullable (getStatus (domain ))
336- .map (status -> status .get ("conditions" ))
360+ .map (status -> status .get (CONDITIONS ))
337361 .orElse (Collections .emptyList ());
338362 }
339363
@@ -346,7 +370,7 @@ private void renameUnsupportedDomainStatusAvailableConditionReasonV8ToV9(Map<Str
346370 }
347371
348372 private void renameFailedReasonIfUnsupported (Map <String , Object > domain , Map <String , String > condition ) {
349- if ("Failed" .equals (condition .get (TYPE ))) {
373+ if (FAILED .equals (condition .get (TYPE ))) {
350374 String currentReason = condition .get (REASON );
351375 if (isUnsupportedReason (currentReason )) {
352376 Map <String , Object > meta = getMetadata (domain );
@@ -359,7 +383,7 @@ private void renameFailedReasonIfUnsupported(Map<String, Object> domain, Map<Str
359383 }
360384
361385 private void renameAvailableReasonIfUnsupported (Map <String , Object > domain , Map <String , String > condition ) {
362- if ("Available" .equals (condition .get (TYPE ))) {
386+ if (AVAILABLE .equals (condition .get (TYPE ))) {
363387 String currentReason = condition .get (REASON );
364388 if (currentReason != null && isUnsupportedReason (currentReason )) {
365389 Map <String , Object > meta = getMetadata (domain );
@@ -388,13 +412,13 @@ private void renameUnsupportedDomainStatusAvailableConditionReasonV9ToV8(Map<Str
388412 }
389413
390414 private void restoreFailedReason (Map <String , String > condition , String reason ) {
391- if ("Failed" .equals (condition .get (TYPE ))) {
415+ if (FAILED .equals (condition .get (TYPE ))) {
392416 condition .put (REASON , reason );
393417 }
394418 }
395419
396420 private void restoreAvailableReason (Map <String , String > condition , String reason ) {
397- if ("Available" .equals (condition .get (TYPE ))) {
421+ if (AVAILABLE .equals (condition .get (TYPE ))) {
398422 condition .put (REASON , reason );
399423 }
400424 }
@@ -776,10 +800,34 @@ private void adjustLogHomeLayoutDefault(Map<String, Object> spec, String apiVers
776800 private void removeAndPreserveLogHomeLayout (Map <String , Object > spec , Map <String , Object > toBePreserved ) {
777801 Object existing = Optional .ofNullable (spec .remove (LHL )).orElse ("ByServers" );
778802 if (!"Flat" .equals (existing )) {
779- preserve (toBePreserved , "$.spec" , Map .of (LHL , existing ));
803+ preserve (toBePreserved , DOLLAR_SPEC , Map .of (LHL , existing ));
780804 }
781805 }
782806
807+ private void removeAndPreserveConditionsV9 (Map <String , Object > status , Map <String , Object > toBePreserved ) {
808+ Optional .ofNullable (status ).ifPresent (s -> {
809+ List <Map <String , String >> conditions = (List <Map <String , String >>) status .get (CONDITIONS );
810+ List <Map <String , String >> removed = new ArrayList <>();
811+ if (conditions != null ) {
812+ List <Map <String , String >> filteredConditions = conditions .stream ().filter (cond -> {
813+ if (!STATUS_CONDITION_TYPES_V8 .contains (cond .get (TYPE ))) {
814+ removed .add (cond );
815+ return false ;
816+ }
817+ return true ;
818+ }).collect (Collectors .toList ());
819+ if (filteredConditions .isEmpty ()) {
820+ status .remove (CONDITIONS );
821+ } else {
822+ status .put (CONDITIONS , filteredConditions );
823+ }
824+ }
825+ if (!removed .isEmpty ()) {
826+ preserve (toBePreserved , DOLLAR_STATUS , Map .of (CONDITIONS , removed ));
827+ }
828+ });
829+ }
830+
783831 private void removeAndPreserveIstio (Map <String , Object > spec , Map <String , Object > toBePreserved ) {
784832 Optional .ofNullable (getConfiguration (spec )).ifPresent (configuration -> {
785833 Object existing = configuration .remove ("istio" );
@@ -904,7 +952,7 @@ private void removeAddedAdminChannelPortForwardingEnabled(Map<String, Object> do
904952
905953 @ FunctionalInterface
906954 interface RestoreValidator {
907- public boolean validateRestore (Map <String , Object > domain , Map <String , Object > scope , Map <String , Object > value );
955+ boolean validateRestore (Map <String , Object > domain , Map <String , Object > scope , Map <String , Object > value );
908956 }
909957
910958 @ SuppressWarnings ("java:S112" )
@@ -928,6 +976,9 @@ private void restore(Map<String, Object> domain, Map<String, Object> toBeRestore
928976 if (toBeRestored != null && !toBeRestored .isEmpty ()) {
929977 ReadContext context = JsonPath .parse (domain );
930978 toBeRestored .forEach ((key , value ) -> {
979+ if (DOLLAR_STATUS .equals (key ) && getStatus (domain ) == null ) {
980+ domain .put (STATUS , new HashMap <>());
981+ }
931982 JsonPath path = JsonPath .compile (key );
932983 Optional .of (read (context , path )).map (List ::stream )
933984 .ifPresent (stream -> stream .forEach (item -> {
0 commit comments