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 ;
102
105
import static oracle .weblogic .kubernetes .utils .FileUtils .replaceStringInFile ;
103
106
import static oracle .weblogic .kubernetes .utils .ImageUtils .createBaseRepoSecret ;
104
107
import static oracle .weblogic .kubernetes .utils .ImageUtils .createTestRepoSecret ;
105
- import static oracle .weblogic .kubernetes .utils .PersistentVolumeUtils .setVolumeSource ;
106
108
import static oracle .weblogic .kubernetes .utils .ThreadSafeLogger .getLogger ;
107
109
import static org .apache .commons .io .FileUtils .deleteDirectory ;
108
110
import static org .awaitility .Awaitility .with ;
@@ -841,14 +843,15 @@ public static String createOracleDBUsingOperator(String dbName, String sysPasswo
841
843
Files .deleteIfExists (dbYaml );
842
844
FileUtils .copy (Paths .get (RESOURCE_DIR , "dboperator" , "singleinstancedatabase.yaml" ), dbYaml );
843
845
846
+ String storageClass = "weblogic-domain-storage-class" ;
844
847
replaceStringInFile (dbYaml .toString (), "name: sidb-sample" , "name: " + dbName );
845
848
replaceStringInFile (dbYaml .toString (), "namespace: default" , "namespace: " + namespace );
846
849
replaceStringInFile (dbYaml .toString (), "secretName:" , "secretName: " + secretName );
847
850
replaceStringInFile (dbYaml .toString (), "secretKey:" , "secretKey: " + secretKey );
848
851
replaceStringInFile (dbYaml .toString (), "pullFrom:" , "pullFrom: " + DB_IMAGE_19C );
849
852
replaceStringInFile (dbYaml .toString (), "pullSecrets:" , "pullSecrets: " + BASE_IMAGES_REPO_SECRET_NAME );
850
853
replaceStringInFile (dbYaml .toString (), "storageClass: \" oci-bv\" " ,
851
- "storageClass: \" weblogic-domain-storage-class \" " );
854
+ "storageClass: \" " + storageClass + " \" " );
852
855
replaceStringInFile (dbYaml .toString (), "accessMode: \" ReadWriteOnce\" " , "accessMode: \" ReadWriteMany\" " );
853
856
replaceStringInFile (dbYaml .toString (), "volumeName: \" \" " , "volumeName: \" " + pvName + "\" " );
854
857
@@ -981,16 +984,15 @@ public static String createOraclePrebuiltDBUsingOperator(String dbName, String s
981
984
public static void createPV (String pvName ) {
982
985
983
986
LoggingFacade logger = getLogger ();
984
- Path pvHostPath = null ;
987
+ Path pvHostPath = Paths . get ( PV_ROOT , pvName ) ;
985
988
986
989
logger .info ("creating persistent volume {0}" , pvName );
987
-
990
+
988
991
// when tests are running in local box the PV directories need to exist
989
992
if (!OKE_CLUSTER && !OKD ) {
990
993
try {
991
- pvHostPath = Files .createDirectories (Paths .get (
992
- PV_ROOT , pvName ));
993
994
logger .info ("Creating PV directory host path {0}" , pvHostPath );
995
+ Files .createDirectories (pvHostPath );
994
996
deleteDirectory (pvHostPath .toFile ());
995
997
createDirectories (pvHostPath );
996
998
} catch (IOException ioex ) {
@@ -1000,15 +1002,29 @@ public static void createPV(String pvName) {
1000
1002
}
1001
1003
1002
1004
V1PersistentVolume v1pv = new V1PersistentVolume ()
1005
+ .metadata (new V1ObjectMeta ()
1006
+ .name (pvName ))
1003
1007
.spec (new V1PersistentVolumeSpec ()
1004
1008
.addAccessModesItem ("ReadWriteMany" )
1005
1009
.volumeMode ("Filesystem" )
1006
1010
.putCapacityItem ("storage" , Quantity .fromString ("100Gi" ))
1007
1011
.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
+
1012
1028
boolean success = assertDoesNotThrow (() -> createPersistentVolume (v1pv ),
1013
1029
"Failed to create persistent volume" );
1014
1030
assertTrue (success , "PersistentVolume creation failed" );
0 commit comments