2929import io .kubernetes .client .openapi .models .V1HostPathVolumeSource ;
3030import io .kubernetes .client .openapi .models .V1LabelSelector ;
3131import io .kubernetes .client .openapi .models .V1LocalObjectReference ;
32+ import io .kubernetes .client .openapi .models .V1NFSVolumeSource ;
3233import io .kubernetes .client .openapi .models .V1ObjectFieldSelector ;
3334import io .kubernetes .client .openapi .models .V1ObjectMeta ;
3435import io .kubernetes .client .openapi .models .V1PersistentVolume ;
5556import io .kubernetes .client .openapi .models .V1Subject ;
5657import io .kubernetes .client .openapi .models .V1Volume ;
5758import io .kubernetes .client .openapi .models .V1VolumeMount ;
59+ import io .kubernetes .client .util .Yaml ;
5860import oracle .weblogic .kubernetes .TestConstants ;
5961import oracle .weblogic .kubernetes .actions .TestActions ;
6062import oracle .weblogic .kubernetes .actions .impl .primitive .Command ;
7678import static oracle .weblogic .kubernetes .TestConstants .DB_PREBUILT_IMAGE_NAME ;
7779import static oracle .weblogic .kubernetes .TestConstants .IMAGE_PULL_POLICY ;
7880import static oracle .weblogic .kubernetes .TestConstants .KUBERNETES_CLI ;
81+ import static oracle .weblogic .kubernetes .TestConstants .NFS_SERVER ;
7982import static oracle .weblogic .kubernetes .TestConstants .OKD ;
8083import static oracle .weblogic .kubernetes .TestConstants .OKE_CLUSTER ;
8184import static oracle .weblogic .kubernetes .TestConstants .ORACLE_DB_SECRET_NAME ;
102105import static oracle .weblogic .kubernetes .utils .FileUtils .replaceStringInFile ;
103106import static oracle .weblogic .kubernetes .utils .ImageUtils .createBaseRepoSecret ;
104107import static oracle .weblogic .kubernetes .utils .ImageUtils .createTestRepoSecret ;
105- import static oracle .weblogic .kubernetes .utils .PersistentVolumeUtils .setVolumeSource ;
106108import static oracle .weblogic .kubernetes .utils .ThreadSafeLogger .getLogger ;
107109import static org .apache .commons .io .FileUtils .deleteDirectory ;
108110import static org .awaitility .Awaitility .with ;
@@ -841,14 +843,15 @@ public static String createOracleDBUsingOperator(String dbName, String sysPasswo
841843 Files .deleteIfExists (dbYaml );
842844 FileUtils .copy (Paths .get (RESOURCE_DIR , "dboperator" , "singleinstancedatabase.yaml" ), dbYaml );
843845
846+ String storageClass = "weblogic-domain-storage-class" ;
844847 replaceStringInFile (dbYaml .toString (), "name: sidb-sample" , "name: " + dbName );
845848 replaceStringInFile (dbYaml .toString (), "namespace: default" , "namespace: " + namespace );
846849 replaceStringInFile (dbYaml .toString (), "secretName:" , "secretName: " + secretName );
847850 replaceStringInFile (dbYaml .toString (), "secretKey:" , "secretKey: " + secretKey );
848851 replaceStringInFile (dbYaml .toString (), "pullFrom:" , "pullFrom: " + DB_IMAGE_19C );
849852 replaceStringInFile (dbYaml .toString (), "pullSecrets:" , "pullSecrets: " + BASE_IMAGES_REPO_SECRET_NAME );
850853 replaceStringInFile (dbYaml .toString (), "storageClass: \" oci-bv\" " ,
851- "storageClass: \" weblogic-domain-storage-class \" " );
854+ "storageClass: \" " + storageClass + " \" " );
852855 replaceStringInFile (dbYaml .toString (), "accessMode: \" ReadWriteOnce\" " , "accessMode: \" ReadWriteMany\" " );
853856 replaceStringInFile (dbYaml .toString (), "volumeName: \" \" " , "volumeName: \" " + pvName + "\" " );
854857
@@ -981,16 +984,15 @@ public static String createOraclePrebuiltDBUsingOperator(String dbName, String s
981984 public static void createPV (String pvName ) {
982985
983986 LoggingFacade logger = getLogger ();
984- Path pvHostPath = null ;
987+ Path pvHostPath = Paths . get ( PV_ROOT , pvName ) ;
985988
986989 logger .info ("creating persistent volume {0}" , pvName );
987-
990+
988991 // when tests are running in local box the PV directories need to exist
989992 if (!OKE_CLUSTER && !OKD ) {
990993 try {
991- pvHostPath = Files .createDirectories (Paths .get (
992- PV_ROOT , pvName ));
993994 logger .info ("Creating PV directory host path {0}" , pvHostPath );
995+ Files .createDirectories (pvHostPath );
994996 deleteDirectory (pvHostPath .toFile ());
995997 createDirectories (pvHostPath );
996998 } catch (IOException ioex ) {
@@ -1000,15 +1002,29 @@ public static void createPV(String pvName) {
10001002 }
10011003
10021004 V1PersistentVolume v1pv = new V1PersistentVolume ()
1005+ .metadata (new V1ObjectMeta ()
1006+ .name (pvName ))
10031007 .spec (new V1PersistentVolumeSpec ()
10041008 .addAccessModesItem ("ReadWriteMany" )
10051009 .volumeMode ("Filesystem" )
10061010 .putCapacityItem ("storage" , Quantity .fromString ("100Gi" ))
10071011 .persistentVolumeReclaimPolicy ("Recycle" )
1008- .accessModes (Arrays .asList ("ReadWriteMany" )))
1009- .metadata (new V1ObjectMeta ()
1010- .name (pvName ));
1011- setVolumeSource (pvHostPath , v1pv );
1012+ .accessModes (Arrays .asList ("ReadWriteMany" )));
1013+ if (OKD ) {
1014+ v1pv .getSpec ()
1015+ .storageClassName ("okd-nfsmnt" )
1016+ .nfs (new V1NFSVolumeSource ()
1017+ .path (PV_ROOT )
1018+ .server (NFS_SERVER )
1019+ .readOnly (false ));
1020+ } else {
1021+ v1pv .getSpec ()
1022+ .storageClassName ("weblogic-domain-storage-class" )
1023+ .hostPath (new V1HostPathVolumeSource ()
1024+ .path (pvHostPath .toString ()));
1025+ }
1026+ logger .info (Yaml .dump (v1pv ));
1027+
10121028 boolean success = assertDoesNotThrow (() -> createPersistentVolume (v1pv ),
10131029 "Failed to create persistent volume" );
10141030 assertTrue (success , "PersistentVolume creation failed" );
0 commit comments