@@ -480,41 +480,82 @@ public List<String> getValidationFailures() {
480
480
}
481
481
482
482
class Validator {
483
+ static final String DUPLICATE_SERVER_NAME_FOUND
484
+ = "More than one item under spec.managedServers in the domain resource has DNS-1123 name '%s'" ;
485
+ static final String DUPLICATE_CLUSTER_NAME_FOUND
486
+ = "More than one item under spec.clusters in the domain resource has DNS-1123 name '%s'" ;
487
+ static final String LOG_HOME_PATH_NOT_MOUNTED
488
+ = "No volume mount contains path for log home '%s', %s in the domain resource" ;
489
+ static final String BAD_VOLUME_MOUNT_PATH
490
+ = "The mount path '%s', in entry '%s' of domain resource additionalVolumeMounts, is not valid" ;
491
+
483
492
private List <String > failures = new ArrayList <>();
484
493
private Set <String > clusterNames = new HashSet <>();
485
494
private Set <String > serverNames = new HashSet <>();
486
495
487
496
List <String > getValidationFailures () {
488
497
addDuplicateNames ();
498
+ addInvalidMountPaths ();
489
499
addUnmappedLogHome ();
490
500
491
501
return failures ;
492
502
}
493
503
494
504
private void addDuplicateNames () {
495
- getSpec ().getManagedServers ().stream ().map (ManagedServer ::getServerName ).forEach (this ::checkDuplicateServerName );
496
- getSpec ().getClusters ().stream ().map (Cluster ::getClusterName ).forEach (this ::checkDuplicateClusterName );
505
+ getSpec ().getManagedServers ()
506
+ .stream ()
507
+ .map (ManagedServer ::getServerName )
508
+ .map (this ::toDns1123LegalName )
509
+ .forEach (this ::checkDuplicateServerName );
510
+ getSpec ().getClusters ()
511
+ .stream ()
512
+ .map (Cluster ::getClusterName )
513
+ .map (this ::toDns1123LegalName )
514
+ .forEach (this ::checkDuplicateClusterName );
515
+ }
516
+
517
+ /**
518
+ * Converts value to nearest DNS-1123 legal name, which can be used as a Kubernetes identifier.
519
+ *
520
+ * @param value Input value
521
+ * @return nearest DNS-1123 legal name
522
+ */
523
+ String toDns1123LegalName (String value ) {
524
+ return value .toLowerCase ().replace ('_' , '-' );
497
525
}
498
526
499
527
private void checkDuplicateServerName (String s ) {
500
528
if (serverNames .contains (s ))
501
- failures .add (String .format ("More than one server is named '%s'" , s ));
529
+ failures .add (String .format (DUPLICATE_SERVER_NAME_FOUND , s ));
502
530
else
503
531
serverNames .add (s );
504
532
}
505
533
506
534
private void checkDuplicateClusterName (String s ) {
507
535
if (clusterNames .contains (s ))
508
- failures .add (String .format ("More than one cluster is named '%s'" , s ));
536
+ failures .add (String .format (DUPLICATE_CLUSTER_NAME_FOUND , s ));
509
537
else
510
538
clusterNames .add (s );
511
539
}
512
540
541
+ private void addInvalidMountPaths () {
542
+ getSpec ().getAdditionalVolumeMounts ().forEach (this ::checkValidMountPath );
543
+ }
544
+
545
+ private void checkValidMountPath (V1VolumeMount mount ) {
546
+ if (!new File (mount .getMountPath ()).isAbsolute ())
547
+ failures .add (String .format (BAD_VOLUME_MOUNT_PATH , mount .getMountPath (), mount .getName ()));
548
+ }
549
+
513
550
private void addUnmappedLogHome () {
514
551
if (!isLogHomeEnabled ()) return ;
515
552
516
553
if (getSpec ().getAdditionalVolumeMounts ().stream ().map (V1VolumeMount ::getMountPath ).noneMatch (this ::mapsLogHome ))
517
- failures .add ("No volume mount contains path for log home" );
554
+ failures .add (String .format (LOG_HOME_PATH_NOT_MOUNTED , getLogHome (), getLogHomeSource ()));
555
+ }
556
+
557
+ private String getLogHomeSource () {
558
+ return getSpec ().getLogHome () == null ? "implicit" : "specified" ;
518
559
}
519
560
520
561
private boolean mapsLogHome (String mountPath ) {
0 commit comments