Skip to content

Commit 6ba522d

Browse files
ankediarjeberhard
authored andcommitted
Allow using NFS in persistent volume spec as part of the initializeDomainOnPV.
1 parent 755be92 commit 6ba522d

File tree

7 files changed

+62
-12
lines changed

7 files changed

+62
-12
lines changed

documentation/domains/Domain.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -885,6 +885,10 @@
885885
"description": "StorageClassName is the name of StorageClass to which this persistent volume belongs. Empty value means that this volume does not belong to any StorageClass.",
886886
"type": "string"
887887
},
888+
"nfs": {
889+
"description": "nfs represents an NFS mount on the host. Provisioned by an admin. More info:\nhttps://kubernetes.io/docs/concepts/storage/volumes#nfs\nRepresents an NFS mount that lasts the lifetime of a pod. NFS volumes do not support ownership management or SELinux relabeling.",
890+
"$ref": "https://github.com/garethr/kubernetes-json-schema/blob/master/v1.13.5/_definitions.json#/definitions/io.k8s.api.core.v1.NFSVolumeSource"
891+
},
888892
"persistentVolumeReclaimPolicy": {
889893
"description": "PersistentVolumeReclaimPolicy defines what happens to a persistent volume when released from its claim. Valid options are Retain (default for manually created PersistentVolumes), Delete (default for dynamically provisioned PersistentVolumes), and Recycle (deprecated). Recycle must be supported by the volume plugin underlying this PersistentVolume. More info: https://kubernetes.io/docs/concepts/storage/persistent-volumes#reclaiming ",
890894
"type": "string"

documentation/domains/Domain.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,7 @@ The current status of the operation of the WebLogic domain. Updated automaticall
362362
| --- | --- | --- |
363363
| `capacity` | Map | Capacity is the description of the persistent volume's resources and capacity. More info: https://kubernetes.io/docs/concepts/storage/persistent-volumes#capacity |
364364
| `hostPath` | [Host Path Volume Source](k8s1.13.5.md#host-path-volume-source) | HostPath represents a directory on the host. Provisioned by a developer or tester. This is useful for single-node development and testing only! On-host storage is not supported in any way and WILL NOT WORK in a multi-node cluster. More info:<br/> https://kubernetes.io/docs/concepts/storage/volumes#hostpath<br/>Represents a host path mapped into a pod. Host path volumes do not support ownership management or SELinux relabeling. |
365+
| `nfs` | [NFS Volume Source](k8s1.13.5.md#nfs-volume-source) | nfs represents an NFS mount on the host. Provisioned by an admin. More info:<br/>https://kubernetes.io/docs/concepts/storage/volumes#nfs<br/>Represents an NFS mount that lasts the lifetime of a pod. NFS volumes do not support ownership management or SELinux relabeling. |
365366
| `persistentVolumeReclaimPolicy` | string | PersistentVolumeReclaimPolicy defines what happens to a persistent volume when released from its claim. Valid options are Retain (default for manually created PersistentVolumes), Delete (default for dynamically provisioned PersistentVolumes), and Recycle (deprecated). Recycle must be supported by the volume plugin underlying this PersistentVolume. More info: https://kubernetes.io/docs/concepts/storage/persistent-volumes#reclaiming |
366367
| `storageClassName` | string | StorageClassName is the name of StorageClass to which this persistent volume belongs. Empty value means that this volume does not belong to any StorageClass. |
367368
| `volumeMode` | string | VolumeMode defines if a volume is intended to be used with a formatted filesystem or to remain in raw block state. Value of Filesystem is implied when not included in spec. |

kubernetes/crd/domain-crd.yaml

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ apiVersion: apiextensions.k8s.io/v1
55
kind: CustomResourceDefinition
66
metadata:
77
annotations:
8-
weblogic.sha256: f276330d4f124e1c8828a6183c3232d15a7ab68cda30d3cdf8d1e008e3c726e2
8+
weblogic.sha256: 74446d3b1c48a2baabc56f1240b28e5a2d1e8a6e8f656295532ad83de1517552
99
name: domains.weblogic.oracle
1010
spec:
1111
group: weblogic.oracle
@@ -206,6 +206,22 @@ spec:
206206
to which this persistent volume belongs. Empty value
207207
means that this volume does not belong to any StorageClass.
208208
type: string
209+
nfs:
210+
description: |-
211+
nfs represents an NFS mount on the host. Provisioned by an admin. More info:
212+
https://kubernetes.io/docs/concepts/storage/volumes#nfs
213+
Represents an NFS mount that lasts the lifetime of a pod. NFS volumes do not support ownership management or SELinux relabeling.
214+
properties:
215+
path:
216+
type: string
217+
server:
218+
type: string
219+
readOnly:
220+
type: boolean
221+
required:
222+
- path
223+
- server
224+
type: object
209225
persistentVolumeReclaimPolicy:
210226
description: 'PersistentVolumeReclaimPolicy defines
211227
what happens to a persistent volume when released

operator/src/main/java/oracle/kubernetes/operator/helpers/PersistentVolumeHelper.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,8 @@ private V1PersistentVolumeSpec createSpec(PersistentVolumeSpec spec) {
223223
return new V1PersistentVolumeSpec().accessModes(Collections.singletonList(READ_WRITE_MANY))
224224
.storageClassName(spec.getStorageClassName())
225225
.capacity(spec.getCapacity()).persistentVolumeReclaimPolicy(spec.getPersistentVolumeReclaimPolicy())
226-
.hostPath(spec.getHostPath());
226+
.hostPath(spec.getHostPath())
227+
.nfs(spec.getNfs());
227228
}
228229

229230

operator/src/main/java/oracle/kubernetes/weblogic/domain/model/PersistentVolumeSpec.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
import io.kubernetes.client.custom.Quantity;
99
import io.kubernetes.client.openapi.models.V1HostPathVolumeSource;
10+
import io.kubernetes.client.openapi.models.V1NFSVolumeSource;
1011
import oracle.kubernetes.json.Description;
1112
import org.apache.commons.lang3.builder.EqualsBuilder;
1213
import org.apache.commons.lang3.builder.HashCodeBuilder;
@@ -26,6 +27,12 @@ public class PersistentVolumeSpec {
2627
+ " or SELinux relabeling.")
2728
private V1HostPathVolumeSource hostPath;
2829

30+
@Description("nfs represents an NFS mount on the host. Provisioned by an admin. More info:\n"
31+
+ "https://kubernetes.io/docs/concepts/storage/volumes#nfs\n"
32+
+ "Represents an NFS mount that lasts the lifetime of a pod. NFS volumes do"
33+
+ " not support ownership management or SELinux relabeling.")
34+
private V1NFSVolumeSource nfs;
35+
2936
@Description("PersistentVolumeReclaimPolicy defines what happens to a persistent volume when released from"
3037
+ " its claim. Valid options are Retain (default for manually created PersistentVolumes),"
3138
+ " Delete (default for dynamically provisioned PersistentVolumes), and Recycle (deprecated)."
@@ -59,6 +66,15 @@ public PersistentVolumeSpec hostPath(V1HostPathVolumeSource hostPath) {
5966
return this;
6067
}
6168

69+
public V1NFSVolumeSource getNfs() {
70+
return nfs;
71+
}
72+
73+
public PersistentVolumeSpec nfs(V1NFSVolumeSource nfs) {
74+
this.nfs = nfs;
75+
return this;
76+
}
77+
6278
public String getPersistentVolumeReclaimPolicy() {
6379
return persistentVolumeReclaimPolicy;
6480
}
@@ -91,6 +107,7 @@ public String toString() {
91107
new ToStringBuilder(this)
92108
.append("capacity", capacity)
93109
.append("hostPath", hostPath)
110+
.append("nfs", nfs)
94111
.append("persistentVolumeReclaimPolicy", persistentVolumeReclaimPolicy)
95112
.append("storageClassName", storageClassName)
96113
.append("volumeMode", volumeMode);
@@ -103,6 +120,7 @@ public int hashCode() {
103120
HashCodeBuilder builder = new HashCodeBuilder()
104121
.append(capacity)
105122
.append(hostPath)
123+
.append(nfs)
106124
.append(persistentVolumeReclaimPolicy)
107125
.append(storageClassName)
108126
.append(volumeMode);
@@ -123,6 +141,7 @@ public boolean equals(Object other) {
123141
new EqualsBuilder()
124142
.append(capacity, rhs.capacity)
125143
.append(hostPath, rhs.hostPath)
144+
.append(nfs, rhs.nfs)
126145
.append(persistentVolumeReclaimPolicy, rhs.persistentVolumeReclaimPolicy)
127146
.append(storageClassName, rhs.storageClassName)
128147
.append(volumeMode, rhs.volumeMode);

operator/src/test/java/oracle/kubernetes/operator/helpers/DomainIntrospectorJobTest.java

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
import io.kubernetes.client.openapi.models.V1ContainerStateWaiting;
3232
import io.kubernetes.client.openapi.models.V1ContainerStatus;
3333
import io.kubernetes.client.openapi.models.V1EmptyDirVolumeSource;
34-
import io.kubernetes.client.openapi.models.V1HostPathVolumeSource;
3534
import io.kubernetes.client.openapi.models.V1Job;
3635
import io.kubernetes.client.openapi.models.V1JobCondition;
3736
import io.kubernetes.client.openapi.models.V1JobSpec;
@@ -84,8 +83,6 @@
8483
import oracle.kubernetes.weblogic.domain.model.InitializeDomainOnPV;
8584
import oracle.kubernetes.weblogic.domain.model.Model;
8685
import oracle.kubernetes.weblogic.domain.model.Opss;
87-
import oracle.kubernetes.weblogic.domain.model.PersistentVolume;
88-
import oracle.kubernetes.weblogic.domain.model.PersistentVolumeSpec;
8986
import org.junit.jupiter.api.AfterEach;
9087
import org.junit.jupiter.api.BeforeEach;
9188
import org.junit.jupiter.api.Test;
@@ -560,13 +557,6 @@ private Opss getOpss() {
560557
return opss;
561558
}
562559

563-
private PersistentVolume createPv() {
564-
return new PersistentVolume().metadata(new V1ObjectMeta().name("test-pv"))
565-
.spec(new PersistentVolumeSpec().storageClassName("oke-pv")
566-
.capacity(Collections.singletonMap("storage", new Quantity("500Gi")))
567-
.hostPath(new V1HostPathVolumeSource().path("/shared")));
568-
}
569-
570560
private List<V1Container> getCreatedPodSpecContainers(List<V1Job> jobs) {
571561
return getJobPodSpec(jobs.get(0)).getContainers();
572562
}

operator/src/test/java/oracle/kubernetes/weblogic/domain/model/DomainV2Test.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import io.kubernetes.client.openapi.models.V1Container;
1515
import io.kubernetes.client.openapi.models.V1EnvVar;
1616
import io.kubernetes.client.openapi.models.V1HostPathVolumeSource;
17+
import io.kubernetes.client.openapi.models.V1NFSVolumeSource;
1718
import io.kubernetes.client.openapi.models.V1ObjectMeta;
1819
import io.kubernetes.client.openapi.models.V1PodSecurityContext;
1920
import io.kubernetes.client.openapi.models.V1ResourceRequirements;
@@ -1722,6 +1723,24 @@ private PersistentVolume createPv() {
17221723
.volumeMode("Block"));
17231724
}
17241725

1726+
@Test
1727+
void whenPersistentVolumeConfiguredWithNfs_useConfiguredValues() {
1728+
configureDomain(domain).withInitializeDomainOnPv(new InitializeDomainOnPV().persistentVolume(createNfsPv()));
1729+
1730+
assertThat(getPersistentVolume(domain), equalTo(createNfsPv()));
1731+
assertThat(getPersistentVolume(domain).getSpec().getStorageClassName(), equalTo("oke-pv"));
1732+
assertThat(getPersistentVolume(domain).getSpec().getCapacity(), notNullValue());
1733+
assertThat(getPersistentVolume(domain).getSpec().getNfs().getPath(), equalTo("/shared"));
1734+
}
1735+
1736+
private PersistentVolume createNfsPv() {
1737+
return new PersistentVolume().metadata(new V1ObjectMeta().name("test-pv"))
1738+
.spec(new PersistentVolumeSpec().storageClassName("oke-pv")
1739+
.capacity(Collections.singletonMap("storage", new Quantity("500Gi")))
1740+
.nfs(new V1NFSVolumeSource().path("/shared")
1741+
.server("10.0.3.9")));
1742+
}
1743+
17251744
@Test
17261745
void whenPersistentVolumeClaimConfigured_useConfiguredValues() {
17271746
configureDomain(domain).withInitializeDomainOnPv(new InitializeDomainOnPV().persistentVolumeClaim(createPvc()));

0 commit comments

Comments
 (0)