Move xos-db into it's own chart

Have it issue it's own PersistentVolumeClaim if required

Change-Id: I408559b2cf4481e011e47c310147fd36c8c284bc
diff --git a/.gitignore b/.gitignore
index f3aef51..54a5d81 100644
--- a/.gitignore
+++ b/.gitignore
@@ -8,7 +8,4 @@
 xos-core/charts
 voltha/charts
 xos-core/charts
-xos-profiles/rcord-lite/charts
-xos-profiles/mcord/charts
-xos-profiles/base-openstack/charts
-xos-profiles/container-vnf/charts
+xos-profiles/*/charts
diff --git a/xos-core/requirements.yaml b/xos-core/requirements.yaml
index 05b5a9e..62de4ca 100644
--- a/xos-core/requirements.yaml
+++ b/xos-core/requirements.yaml
@@ -14,6 +14,9 @@
 # limitations under the License.
 
 dependencies:
+- name: xos-db
+  version: 0.1.0-dev0
+  repository: file://../xos-db
 - name: xos-gui
   version: 1.0.1
   repository: file://../xos-gui
diff --git a/xos-core/values.yaml b/xos-core/values.yaml
index c6e5105..98b372f 100644
--- a/xos-core/values.yaml
+++ b/xos-core/values.yaml
@@ -18,10 +18,6 @@
 
 imagePullPolicy: 'Always'
 
-dbPvClaimName: db-pv-claim
-
-needDBPersistence: false
-
 # Docker images
 # YAML variable names can't contain `-`, so substituted with `_`
 xos_coreImage: 'xosproject/xos-core:{{ .Chart.Version }}'
@@ -29,7 +25,6 @@
 xos_toscaImage: 'xosproject/xos-tosca:1.0.1'
 xos_api_testerImage: 'xosproject/xos-api-tester:2.0.1'
 
-postgresImage: 'postgres:10.3-alpine'
 nodeImage: 'node:7.9.0'
 redisImage: 'redis:3.2'
 
@@ -46,11 +41,16 @@
 # CORD site names
 cordSiteName: mysite
 
-# Database name/username/password
+# Database name/username/password for XOS and the xos-db subchart
 xosDBName: 'xos'
 xosDBUser: 'postgres'
 xosDBPassword: 'password'
 
+xos-db:
+  xosDBName: 'xos'
+  xosDBUser: 'postgres'
+  xosDBPassword: 'password'
+
 ca_cert_chain: LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSUYyakNDQThLZ0F3SUJ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WdSaVdaYUMxdFFaYjFKWitmam5ECnVHZlJNM085WW9Lb0tKMHo1VW5WVk13TDl0K0JFbVp5TGNvYzRoVVgzTDJjT1VpM0VaaC9jeTEvREpGODg0UDcKQlgyY0lWcWM4ZU1rL1ZYbE5CY1d3RlpzVGM4Vk56SUprbExKYlJuOERQWmhxWHNlYjBCZXNlU1B6M0EvKzh4TApCZTJzbFBPK01KWVdLSGZPKzNvZmNibUFpUnMvNTkxOVpiMy9rVyt4c3ROQ1V3b0pBeTk1bXF2Ukg4TFo0Zz09Ci0tLS0tRU5EIENFUlRJRklDQVRFLS0tLS0=
 
 secrets:
diff --git a/local-persistent-volume/templates/persistent_volume_claim.yaml b/xos-db/Chart.yaml
similarity index 72%
rename from local-persistent-volume/templates/persistent_volume_claim.yaml
rename to xos-db/Chart.yaml
index 35af447..677cbc9 100644
--- a/local-persistent-volume/templates/persistent_volume_claim.yaml
+++ b/xos-db/Chart.yaml
@@ -13,15 +13,5 @@
 # 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
-
+name: xos-db
+version: 0.1.0-dev0
diff --git a/xos-db/templates/_helpers.tpl b/xos-db/templates/_helpers.tpl
new file mode 100644
index 0000000..ad2a2b5
--- /dev/null
+++ b/xos-db/templates/_helpers.tpl
@@ -0,0 +1,24 @@
+{{- /*
+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.
+*/ -}}
+
+{{- define "xos-db.release_labels" }}
+app: {{ printf "%s-%s" .Release.Name .Chart.Name | trunc 63 }}
+chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}
+release: {{ .Release.Name }}
+heritage: {{ .Release.Service }}
+version: {{ .Chart.Version }}
+{{- end }}
+
diff --git a/xos-db/templates/_persist.tpl b/xos-db/templates/_persist.tpl
new file mode 100644
index 0000000..ee6fb9b
--- /dev/null
+++ b/xos-db/templates/_persist.tpl
@@ -0,0 +1,30 @@
+{{- /*
+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.
+*/ -}}
+{{- define "xos-db.persistent-volume-claim" }}
+---
+kind: PersistentVolumeClaim
+apiVersion: v1
+metadata:
+  name: {{ .Values.pvClaimName }}
+spec:
+  accessModes:
+    - ReadWriteOnce
+  storageClassName: {{ .Values.storageClassName }}
+  resources:
+    requests:
+      storage: 1Gi
+{{- end }}
+
diff --git a/xos-core/templates/db-deployment.yaml b/xos-db/templates/db-deployment.yaml
similarity index 91%
rename from xos-core/templates/db-deployment.yaml
rename to xos-db/templates/db-deployment.yaml
index d2cb923..a3d3e91 100644
--- a/xos-core/templates/db-deployment.yaml
+++ b/xos-db/templates/db-deployment.yaml
@@ -45,12 +45,13 @@
                   key: password
             - name: PGDATA
               value: "/var/lib/postgresql/data/pgdata"
-      {{- if .Values.needDBPersistence }}
+{{- if .Values.needDBPersistence }}
           volumeMounts:
             - name: db-pv-storage
               mountPath: "/var/lib/postgresql/data"
       volumes:
         - name: db-pv-storage
           persistentVolumeClaim:
-            claimName: {{ .Values.dbPvClaimName }}
-      {{- end }}
+            claimName: {{ .Values.pvClaimName }}
+{{- include "xos-db.persistent-volume-claim" . }}
+{{- end }}
diff --git a/xos-core/templates/db-secrets.yaml b/xos-db/templates/db-secrets.yaml
similarity index 100%
rename from xos-core/templates/db-secrets.yaml
rename to xos-db/templates/db-secrets.yaml
diff --git a/xos-core/templates/db-service.yaml b/xos-db/templates/db-service.yaml
similarity index 92%
rename from xos-core/templates/db-service.yaml
rename to xos-db/templates/db-service.yaml
index 3a71aaa..fe8f3b7 100644
--- a/xos-core/templates/db-service.yaml
+++ b/xos-db/templates/db-service.yaml
@@ -18,7 +18,7 @@
 metadata:
   name: "xos-db"
   labels:
-    {{- include "xos-core.release_labels" . | indent 4 }}
+    {{- include "xos-db.release_labels" . | indent 4 }}
 spec:
   type: ClusterIP
   selector:
diff --git a/local-persistent-volume/templates/persistent_volume_claim.yaml b/xos-db/values.yaml
similarity index 64%
copy from local-persistent-volume/templates/persistent_volume_claim.yaml
copy to xos-db/values.yaml
index 35af447..35e2ca7 100644
--- a/local-persistent-volume/templates/persistent_volume_claim.yaml
+++ b/xos-db/values.yaml
@@ -13,15 +13,18 @@
 # 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
+# XOS Postgres database related values
+
+imagePullPolicy: 'Always'
+postgresImage: 'postgres:10.3-alpine'
+
+# Database name/username/password
+xosDBName: 'xos'
+xosDBUser: 'postgres'
+xosDBPassword: 'password'
+
+# DB persistence related vars
+needDBPersistence: false
+storageClassName: cord-block
+pvClaimName: xosdb-pv-claim