Local persistent store for Postgres

Change-Id: I6af6402a5826300352cf24e268dd043771541446
diff --git a/local-persistent-volume/Chart.yaml b/local-persistent-volume/Chart.yaml
new file mode 100644
index 0000000..bacf6f2
--- /dev/null
+++ b/local-persistent-volume/Chart.yaml
@@ -0,0 +1,17 @@
+---
+# Copyright 2017-present Open Networking Foundation
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+name: local-persistent-volume
+version: 1.0.0
diff --git a/local-persistent-volume/templates/persistent-volume.yaml b/local-persistent-volume/templates/persistent-volume.yaml
new file mode 100644
index 0000000..c012f6f
--- /dev/null
+++ b/local-persistent-volume/templates/persistent-volume.yaml
@@ -0,0 +1,37 @@
+---
+# Copyright 2017-present Open Networking Foundation
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+apiVersion: v1
+kind: PersistentVolume
+metadata:
+  name: {{ .Values.persistentVolumeName }}
+spec:
+  capacity:
+    storage: {{ .Values.pvStorageCapacity }}
+  accessModes:
+  - ReadWriteOnce
+  persistentVolumeReclaimPolicy: Retain
+  storageClassName: {{ .Values.storageClassName }}
+  local:
+    path: {{ .Values.hostLocalPath }}
+  nodeAffinity:
+    required:
+      nodeSelectorTerms:
+      - matchExpressions:
+        - key: kubernetes.io/hostname
+          operator: In
+          values:
+          - {{ .Values.volumeHostName }}
+
diff --git a/local-persistent-volume/templates/persistent_volume_claim.yaml b/local-persistent-volume/templates/persistent_volume_claim.yaml
new file mode 100644
index 0000000..35af447
--- /dev/null
+++ b/local-persistent-volume/templates/persistent_volume_claim.yaml
@@ -0,0 +1,27 @@
+---
+# Copyright 2017-present Open Networking Foundation
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+kind: PersistentVolumeClaim
+apiVersion: v1
+metadata:
+  name: {{ .Values.pvClaimName }}
+spec:
+  accessModes:
+  - ReadWriteOnce
+  storageClassName: {{ .Values.storageClassName }}
+  resources:
+    requests:
+      storage: 1Gi
+
diff --git a/local-persistent-volume/templates/storage-class.yaml b/local-persistent-volume/templates/storage-class.yaml
new file mode 100644
index 0000000..32cea67
--- /dev/null
+++ b/local-persistent-volume/templates/storage-class.yaml
@@ -0,0 +1,22 @@
+---
+# Copyright 2017-present Open Networking Foundation
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+kind: StorageClass
+apiVersion: storage.k8s.io/v1
+metadata:
+  name: {{ .Values.storageClassName }}
+provisioner: kubernetes.io/no-provisioner
+volumeBindingMode: WaitForFirstConsumer
+
diff --git a/local-persistent-volume/values.yaml b/local-persistent-volume/values.yaml
new file mode 100644
index 0000000..5c24c03
--- /dev/null
+++ b/local-persistent-volume/values.yaml
@@ -0,0 +1,21 @@
+---
+# Copyright 2017-present Open Networking Foundation
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+storageClassName: db-local-storage
+persistentVolumeName: db-pv
+pvClaimName: db-pv-claim
+volumeHostName: k8s-01
+hostLocalPath: /var/local/vol1
+pvStorageCapacity: 10Gi
\ No newline at end of file
diff --git a/xos-core/templates/db-deployment.yaml b/xos-core/templates/db-deployment.yaml
index d508962..82f1507 100644
--- a/xos-core/templates/db-deployment.yaml
+++ b/xos-core/templates/db-deployment.yaml
@@ -43,3 +43,12 @@
                 secretKeyRef:
                   name: xos-db-secrets
                   key: password
+      {{- if .Values.needDBPersistence }}
+          volumeMounts:
+            - name: db-pv-storage
+              mountPath: "/var/lib/postgresql/data"
+      volumes:
+        - name: db-pv-storage
+          persistentVolumeClaim:
+            claimName: {{ .Values.dbPvClaimName }}
+      {{- end }}
diff --git a/xos-core/values.yaml b/xos-core/values.yaml
index a2fc5ff..6cb8a46 100644
--- a/xos-core/values.yaml
+++ b/xos-core/values.yaml
@@ -18,6 +18,10 @@
 
 imagePullPolicy: 'Always'
 
+dbPvClaimName: db-pv-claim
+
+needDBPersistence: false
+
 # Docker images
 # YAML variable names can't contain `-`, so substituted with `_`
 xos_coreImage: 'xosproject/xos-core:master'