@@ -480,41 +480,82 @@ public List<String> getValidationFailures() {
480480 }
481481
482482 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+
483492 private List <String > failures = new ArrayList <>();
484493 private Set <String > clusterNames = new HashSet <>();
485494 private Set <String > serverNames = new HashSet <>();
486495
487496 List <String > getValidationFailures () {
488497 addDuplicateNames ();
498+ addInvalidMountPaths ();
489499 addUnmappedLogHome ();
490500
491501 return failures ;
492502 }
493503
494504 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 ('_' , '-' );
497525 }
498526
499527 private void checkDuplicateServerName (String s ) {
500528 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 ));
502530 else
503531 serverNames .add (s );
504532 }
505533
506534 private void checkDuplicateClusterName (String s ) {
507535 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 ));
509537 else
510538 clusterNames .add (s );
511539 }
512540
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+
513550 private void addUnmappedLogHome () {
514551 if (!isLogHomeEnabled ()) return ;
515552
516553 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" ;
518559 }
519560
520561 private boolean mapsLogHome (String mountPath ) {
0 commit comments