Skip to content

Commit 139881d

Browse files
committed
Merge branch 'monfix' into 'main'
Fixed pv permission issues in OKE run for prometheus and grafana creation See merge request weblogic-cloud/weblogic-kubernetes-operator!4279
2 parents e27b06e + 5029063 commit 139881d

File tree

4 files changed

+117
-4
lines changed

4 files changed

+117
-4
lines changed

Jenkinsfile.oke

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ pipeline {
119119
)
120120
string(name: 'BRANCH',
121121
description: '',
122-
defaultValue: 'okeextfix'
122+
defaultValue: 'main'
123123
)
124124
string(name: 'WEBLOGIC_IMAGE_NAME',
125125
description: 'WebLogic base image name. Default is the image name in OCIR. Use middleware/weblogic for OCR.',

integration-tests/src/test/java/oracle/weblogic/kubernetes/utils/CommonMiiTestUtils.java

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1204,6 +1204,71 @@ public static void createJobToChangePermissionsOnPvHostPath(String pvName, Strin
12041204
}
12051205
}
12061206

1207+
/**
1208+
* Create a job to change the permissions on the pv host path.
1209+
*
1210+
* @param pvName Name of the persistent volume
1211+
* @param pvcName Name of the persistent volume claim
1212+
* @param namespace Namespace containing the persistent volume claim and where the job should be created in
1213+
* @param mountPath path
1214+
* @param command to change permission
1215+
*/
1216+
public static void createJobToChangePermissionsOnPvHostPath(String pvName, String pvcName,
1217+
String namespace, String mountPath, String command) {
1218+
LoggingFacade logger = getLogger();
1219+
1220+
if (!OKD) {
1221+
logger.info("Running Kubernetes job to create domain");
1222+
V1Job jobBody = new V1Job()
1223+
.metadata(
1224+
new V1ObjectMeta()
1225+
.name("change-permissions-onpv-job-" + pvName) // name of the job
1226+
.namespace(namespace))
1227+
.spec(new V1JobSpec()
1228+
.backoffLimit(0) // try only once
1229+
.template(new V1PodTemplateSpec()
1230+
.spec(new V1PodSpec()
1231+
.restartPolicy("Never")
1232+
.addContainersItem(
1233+
createfixPVCOwnerContainer(pvName,
1234+
mountPath,
1235+
command))
1236+
.volumes(Arrays.asList(
1237+
new V1Volume()
1238+
.name(pvName)
1239+
.persistentVolumeClaim(
1240+
new V1PersistentVolumeClaimVolumeSource()
1241+
.claimName(pvcName))))
1242+
.imagePullSecrets(Arrays.asList(
1243+
new V1LocalObjectReference()
1244+
.name(TEST_IMAGES_REPO_SECRET_NAME)))))); // this secret is used only for non-kind cluster
1245+
1246+
String jobName = createJobAndWaitUntilComplete(jobBody, namespace);
1247+
1248+
// check job status and fail test if the job failed
1249+
V1Job job = assertDoesNotThrow(() -> getJob(jobName, namespace),
1250+
"Getting the job failed");
1251+
if (job != null) {
1252+
V1JobCondition jobCondition = job.getStatus().getConditions().stream().filter(
1253+
v1JobCondition -> "Failed".equals(v1JobCondition.getType()))
1254+
.findAny()
1255+
.orElse(null);
1256+
if (jobCondition != null) {
1257+
logger.severe("Job {0} failed to change permissions on PV hostpath", jobName);
1258+
List<V1Pod> pods = assertDoesNotThrow(() -> listPods(
1259+
namespace, "job-name=" + jobName).getItems(),
1260+
"Listing pods failed");
1261+
if (!pods.isEmpty()) {
1262+
String podLog = assertDoesNotThrow(() -> getPodLog(pods.get(0).getMetadata().getName(), namespace),
1263+
"Failed to get pod log");
1264+
logger.severe(podLog);
1265+
fail("Change permissions on PV hostpath job failed");
1266+
}
1267+
}
1268+
}
1269+
}
1270+
}
1271+
12071272
/**
12081273
* Check logs are written on PV by running the specified command on the pod.
12091274
* @param domainNamespace Kubernetes namespace that the domain is hosted

integration-tests/src/test/java/oracle/weblogic/kubernetes/utils/PersistentVolumeUtils.java

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,9 @@
4242
import static oracle.weblogic.kubernetes.assertions.TestAssertions.pvExists;
4343
import static oracle.weblogic.kubernetes.assertions.TestAssertions.pvNotExists;
4444
import static oracle.weblogic.kubernetes.assertions.TestAssertions.pvcExists;
45+
import static oracle.weblogic.kubernetes.utils.CommonMiiTestUtils.createJobToChangePermissionsOnPvHostPath;
4546
import static oracle.weblogic.kubernetes.utils.CommonTestUtils.testUntil;
47+
import static oracle.weblogic.kubernetes.utils.ImageUtils.createTestRepoSecret;
4648
import static oracle.weblogic.kubernetes.utils.ThreadSafeLogger.getLogger;
4749
import static org.apache.commons.io.FileUtils.deleteDirectory;
4850
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
@@ -211,6 +213,7 @@ private static void setVolumeSource(Path pvHostPath, V1PersistentVolume v1pv, St
211213
String fssDir = FSS_DIR[new Random().nextInt(FSS_DIR.length)];
212214
LoggingFacade logger = getLogger();
213215
logger.info("Using FSS PV directory {0}", fssDir);
216+
logger.info("Using NFS_SERVER {0}", NFS_SERVER);
214217
v1pv.getSpec()
215218
.storageClassName("oci-fss")
216219
.nfs(new V1NFSVolumeSource()
@@ -320,13 +323,26 @@ public static synchronized V1Container createfixPVCOwnerContainer(String pvName,
320323
+ mountPath
321324
+ "/. -maxdepth 1 ! -name '.snapshot' ! -name '.' -print0 | xargs -r -0 chown -R 1000:0";
322325
}
326+
return createfixPVCOwnerContainer(pvName, mountPath, argCommand);
327+
}
328+
329+
/**
330+
* Create container to fix pvc owner for pod.
331+
*
332+
* @param pvName name of pv
333+
* @param mountPath mounting path for pv
334+
* @param command to run for ownership
335+
* @return container object with required ownership based on OKE_CLUSTER variable value.
336+
*/
337+
public static synchronized V1Container createfixPVCOwnerContainer(String pvName, String mountPath, String command) {
338+
323339
V1Container container = new V1Container()
324340
.name("fix-pvc-owner") // change the ownership of the pv to opc:opc
325341
.image(WEBLOGIC_IMAGE_TO_USE_IN_SPEC)
326342
.imagePullPolicy(IMAGE_PULL_POLICY)
327343
.addCommandItem("/bin/sh")
328344
.addArgsItem("-c")
329-
.addArgsItem(argCommand)
345+
.addArgsItem(command)
330346
.volumeMounts(Arrays.asList(
331347
new V1VolumeMount()
332348
.name(pvName)
@@ -404,6 +420,23 @@ public static void createPvAndPvc(String nameSuffix, String namespace,
404420
.storageClassName(nameSuffix);
405421
}
406422

407-
createPVPVCAndVerify(v1pv,v1pvc, labelSelector, namespace);
423+
createPVPVCAndVerify(v1pv, v1pvc, labelSelector, namespace);
424+
if (nameSuffix.contains("grafana") || nameSuffix.contains("prometheus")) {
425+
String mountPath = "/data";
426+
if (nameSuffix.contains("grafana")) {
427+
mountPath = "/var/lib/grafana";
428+
}
429+
String argCommand = "chown -R 1000:1000 " + mountPath;
430+
if (OKE_CLUSTER) {
431+
argCommand = "chown 1000:1000 " + mountPath
432+
+ "/. && find "
433+
+ mountPath
434+
+ "/. -maxdepth 1 ! -name '.snapshot' ! -name '.' -print0 | xargs -r -0 chown -R 1000:1000";
435+
}
436+
createTestRepoSecret(namespace);
437+
createJobToChangePermissionsOnPvHostPath("pv-test" + nameSuffix,
438+
"pvc-" + nameSuffix, namespace,
439+
mountPath, argCommand);
440+
}
408441
}
409442
}

integration-tests/src/test/resources/exporter/promvalues.yaml

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,24 @@ server:
6666
type: NodePort
6767
nodePort: 30500
6868
securityContext:
69-
runAsGroup: 65534
7069
runAsNonRoot: true
7170
runAsUser: 1000
71+
initContainers:
72+
- command: [ "chown","-R","1000:1000","/data" ]
73+
image: busybox
74+
name: prometheus-data-permission-fix
75+
volumeMounts:
76+
- mountPath: /data
77+
name: storage-volume
78+
securityContext:
79+
runAsNonRoot: false
80+
runAsUser: 0
81+
runAsGroup: 0
82+
83+
volumes:
84+
- name: storage-volume
85+
persistentVolumeClaim:
86+
claimName: pvc-prometheus
7287

7388
global:
7489
evaluation_interval: 1m

0 commit comments

Comments
 (0)