29
29
import io .kubernetes .client .openapi .models .V1HostPathVolumeSource ;
30
30
import io .kubernetes .client .openapi .models .V1LabelSelector ;
31
31
import io .kubernetes .client .openapi .models .V1LocalObjectReference ;
32
+ import io .kubernetes .client .openapi .models .V1NFSVolumeSource ;
32
33
import io .kubernetes .client .openapi .models .V1ObjectFieldSelector ;
33
34
import io .kubernetes .client .openapi .models .V1ObjectMeta ;
34
35
import io .kubernetes .client .openapi .models .V1PersistentVolume ;
55
56
import io .kubernetes .client .openapi .models .V1Subject ;
56
57
import io .kubernetes .client .openapi .models .V1Volume ;
57
58
import io .kubernetes .client .openapi .models .V1VolumeMount ;
59
+ import io .kubernetes .client .util .Yaml ;
58
60
import oracle .weblogic .kubernetes .TestConstants ;
59
61
import oracle .weblogic .kubernetes .actions .TestActions ;
60
62
import oracle .weblogic .kubernetes .actions .impl .primitive .Command ;
76
78
import static oracle .weblogic .kubernetes .TestConstants .DB_PREBUILT_IMAGE_NAME ;
77
79
import static oracle .weblogic .kubernetes .TestConstants .IMAGE_PULL_POLICY ;
78
80
import static oracle .weblogic .kubernetes .TestConstants .KUBERNETES_CLI ;
81
+ import static oracle .weblogic .kubernetes .TestConstants .NFS_SERVER ;
79
82
import static oracle .weblogic .kubernetes .TestConstants .OKD ;
80
83
import static oracle .weblogic .kubernetes .TestConstants .OKE_CLUSTER ;
81
84
import static oracle .weblogic .kubernetes .TestConstants .ORACLE_DB_SECRET_NAME ;
104
107
import static oracle .weblogic .kubernetes .utils .FileUtils .replaceStringInFile ;
105
108
import static oracle .weblogic .kubernetes .utils .ImageUtils .createBaseRepoSecret ;
106
109
import static oracle .weblogic .kubernetes .utils .ImageUtils .createTestRepoSecret ;
107
- import static oracle .weblogic .kubernetes .utils .PersistentVolumeUtils .setVolumeSource ;
108
110
import static oracle .weblogic .kubernetes .utils .PodUtils .checkPodDoesNotExist ;
109
111
import static oracle .weblogic .kubernetes .utils .ThreadSafeLogger .getLogger ;
110
112
import static org .apache .commons .io .FileUtils .deleteDirectory ;
@@ -858,9 +860,6 @@ public static String createOracleDBUsingOperator(String dbName, String sysPasswo
858
860
replaceStringInFile (dbYaml .toString (), "pullFrom:" , "pullFrom: " + DB_IMAGE_19C );
859
861
replaceStringInFile (dbYaml .toString (), "pullSecrets:" , "pullSecrets: " + BASE_IMAGES_REPO_SECRET_NAME );
860
862
String storageClass = "weblogic-domain-storage-class" ;
861
- if (OKE_CLUSTER ) {
862
- storageClass = "oci-fss" ;
863
- }
864
863
replaceStringInFile (dbYaml .toString (), "storageClass: \" oci-bv\" " ,
865
864
"storageClass: \" " + storageClass + "\" " );
866
865
replaceStringInFile (dbYaml .toString (), "accessMode: \" ReadWriteOnce\" " , "accessMode: \" ReadWriteMany\" " );
@@ -1015,16 +1014,15 @@ public static void deleteOracleDB(String namespace, String dbName) {
1015
1014
public static void createPV (String pvName ) {
1016
1015
1017
1016
LoggingFacade logger = getLogger ();
1018
- Path pvHostPath = null ;
1017
+ Path pvHostPath = Paths . get ( PV_ROOT , pvName ) ;
1019
1018
1020
1019
logger .info ("creating persistent volume {0}" , pvName );
1021
-
1020
+
1022
1021
// when tests are running in local box the PV directories need to exist
1023
1022
if (!OKE_CLUSTER && !OKD ) {
1024
1023
try {
1025
- pvHostPath = Files .createDirectories (Paths .get (
1026
- PV_ROOT , pvName ));
1027
1024
logger .info ("Creating PV directory host path {0}" , pvHostPath );
1025
+ Files .createDirectories (pvHostPath );
1028
1026
deleteDirectory (pvHostPath .toFile ());
1029
1027
createDirectories (pvHostPath );
1030
1028
} catch (IOException ioex ) {
@@ -1034,15 +1032,29 @@ public static void createPV(String pvName) {
1034
1032
}
1035
1033
1036
1034
V1PersistentVolume v1pv = new V1PersistentVolume ()
1035
+ .metadata (new V1ObjectMeta ()
1036
+ .name (pvName ))
1037
1037
.spec (new V1PersistentVolumeSpec ()
1038
1038
.addAccessModesItem ("ReadWriteMany" )
1039
1039
.volumeMode ("Filesystem" )
1040
1040
.putCapacityItem ("storage" , Quantity .fromString ("100Gi" ))
1041
1041
.persistentVolumeReclaimPolicy ("Recycle" )
1042
- .accessModes (Arrays .asList ("ReadWriteMany" )))
1043
- .metadata (new V1ObjectMeta ()
1044
- .name (pvName ));
1045
- setVolumeSource (pvHostPath , v1pv );
1042
+ .accessModes (Arrays .asList ("ReadWriteMany" )));
1043
+ if (OKD ) {
1044
+ v1pv .getSpec ()
1045
+ .storageClassName ("okd-nfsmnt" )
1046
+ .nfs (new V1NFSVolumeSource ()
1047
+ .path (PV_ROOT )
1048
+ .server (NFS_SERVER )
1049
+ .readOnly (false ));
1050
+ } else {
1051
+ v1pv .getSpec ()
1052
+ .storageClassName ("weblogic-domain-storage-class" )
1053
+ .hostPath (new V1HostPathVolumeSource ()
1054
+ .path (pvHostPath .toString ()));
1055
+ }
1056
+ logger .info (Yaml .dump (v1pv ));
1057
+
1046
1058
boolean success = assertDoesNotThrow (() -> createPersistentVolume (v1pv ),
1047
1059
"Failed to create persistent volume" );
1048
1060
assertTrue (success , "PersistentVolume creation failed" );
0 commit comments