-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #52 from MadWorldNL/Feature/48-Postgresql
Feature: Add Database to save data
- Loading branch information
Showing
42 changed files
with
860 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
{{- $pgadminSecrets := (lookup "v1" "Secret" .Values.namespace .Values.pgadmin.name ) -}} | ||
apiVersion: v1 | ||
kind: Secret | ||
metadata: | ||
name: {{ .Values.pgadmin.secret.name }} | ||
namespace: {{ .Values.namespace }} | ||
type: kubernetes.io/basic-auth | ||
data: | ||
username: {{ .Values.pgadmin.username | b64enc }} | ||
{{- if and $pgadminSecrets $pgadminSecrets.data }} | ||
{{- if $pgadminSecrets.data.password }} | ||
password: {{ $pgadminSecrets.data.password }} | ||
{{- else }} | ||
password: {{ "nonExistingKey1234" | b64enc }} | ||
{{- end }} | ||
{{- else }} | ||
password: {{ "nonExistingKey1234" | b64enc }} | ||
{{- end }} | ||
--- | ||
kind: PersistentVolume | ||
apiVersion: v1 | ||
metadata: | ||
name: pgadmin-pv-volume | ||
namespace: {{ .Values.namespace }} | ||
labels: | ||
type: local | ||
app: {{ .Values.pgadmin.app }} | ||
spec: | ||
storageClassName: manual | ||
capacity: | ||
storage: 5Gi | ||
volumeMode: Filesystem | ||
accessModes: | ||
- ReadWriteOnce | ||
hostPath: | ||
path: "/MantaRayPlan/Pgadmin" | ||
--- | ||
kind: PersistentVolumeClaim | ||
apiVersion: v1 | ||
metadata: | ||
name: pgadmin-pv-claim | ||
namespace: {{ .Values.namespace }} | ||
labels: | ||
app: {{ .Values.pgadmin.app }} | ||
spec: | ||
storageClassName: manual | ||
accessModes: | ||
- ReadWriteOnce | ||
resources: | ||
requests: | ||
storage: 5Gi | ||
--- | ||
apiVersion: apps/v1 | ||
kind: Deployment | ||
metadata: | ||
name: {{ .Values.pgadmin.deployment }} | ||
namespace: {{ .Values.namespace }} | ||
labels: | ||
app: {{ .Values.pgadmin.app }} | ||
name: {{ .Values.pgadmin.name }} | ||
spec: | ||
replicas: 1 | ||
selector: | ||
matchLabels: | ||
app: {{ .Values.pgadmin.app }} | ||
task: {{ .Values.pgadmin.name }} | ||
template: | ||
metadata: | ||
labels: | ||
app: {{ .Values.pgadmin.app }} | ||
task: {{ .Values.pgadmin.name }} | ||
spec: | ||
containers: | ||
- name: {{ .Values.pgadmin.app }} | ||
image: "dpage/pgadmin4:latest" | ||
imagePullPolicy: Always | ||
securityContext: | ||
runAsUser: 0 | ||
runAsGroup: 0 | ||
env: | ||
- name: PGADMIN_DEFAULT_EMAIL | ||
valueFrom: | ||
secretKeyRef: | ||
name: {{ .Values.pgadmin.secret.name }} | ||
key: username | ||
- name: PGADMIN_DEFAULT_PASSWORD | ||
valueFrom: | ||
secretKeyRef: | ||
name: {{ .Values.pgadmin.secret.name }} | ||
key: password | ||
ports: | ||
- containerPort: 80 | ||
volumeMounts: | ||
- mountPath: "/var/lib/pgadmin" | ||
name: pgadminvolume | ||
volumes: | ||
- name: pgadminvolume | ||
persistentVolumeClaim: | ||
claimName: pgadmin-pv-claim | ||
--- | ||
apiVersion: v1 | ||
kind: Service | ||
metadata: | ||
name: {{ .Values.pgadmin.loadBalancer }} | ||
namespace: {{ .Values.namespace }} | ||
spec: | ||
selector: | ||
app: {{ .Values.pgadmin.app }} | ||
task: {{ .Values.pgadmin.name }} | ||
ports: | ||
- protocol: TCP | ||
name: http | ||
port: 80 | ||
targetPort: 80 | ||
type: LoadBalancer |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
{{- $postgresSecrets := (lookup "v1" "Secret" .Values.namespace .Values.database.name ) -}} | ||
apiVersion: v1 | ||
kind: Secret | ||
metadata: | ||
name: {{ .Values.database.secret.name }} | ||
namespace: {{ .Values.namespace }} | ||
type: kubernetes.io/basic-auth | ||
data: | ||
username: {{ "app" | b64enc }} | ||
{{- if and $postgresSecrets $postgresSecrets.data }} | ||
{{- if $postgresSecrets.data.password }} | ||
password: {{ $postgresSecrets.data.password }} | ||
{{- else }} | ||
password: {{ "nonExistingKey1234" | b64enc }} | ||
{{- end }} | ||
{{- else }} | ||
password: {{ "nonExistingKey1234" | b64enc }} | ||
{{- end }} | ||
--- | ||
apiVersion: hostpathprovisioner.kubevirt.io/v1beta1 | ||
kind: HostPathProvisioner | ||
metadata: | ||
name: hostpath-provisioner | ||
namespace: hostpath-provisioner | ||
spec: | ||
imagePullPolicy: Always | ||
storagePools: | ||
- name: "postgres-pool" | ||
pvcTemplate: | ||
accessModes: | ||
- ReadWriteOnce | ||
resources: | ||
requests: | ||
storage: {{ .Values.database.size.combined }} | ||
path: "/MantaRayPlan/Postgres" | ||
workload: | ||
nodeSelector: | ||
kubernetes.io/os: linux | ||
--- | ||
apiVersion: storage.k8s.io/v1 | ||
kind: StorageClass | ||
metadata: | ||
name: postgres-csi | ||
namespace: hostpath-provisioner | ||
provisioner: kubevirt.io.hostpath-provisioner | ||
reclaimPolicy: Delete | ||
volumeBindingMode: WaitForFirstConsumer | ||
parameters: | ||
storagePool: postgres-pool | ||
--- | ||
{{- if .Values.database.enabled }} | ||
apiVersion: postgresql.cnpg.io/v1 | ||
kind: Cluster | ||
metadata: | ||
name: {{ .Values.database.name }} | ||
namespace: {{ .Values.namespace }} | ||
spec: | ||
instances: 3 | ||
primaryUpdateStrategy: unsupervised | ||
bootstrap: | ||
initdb: | ||
database: maintenance | ||
owner: app | ||
secret: | ||
name: postgres-secret | ||
storage: | ||
size: {{ .Values.database.size.single }} | ||
pvcTemplate: | ||
accessModes: | ||
- ReadWriteOnce | ||
resources: | ||
requests: | ||
storage: {{ .Values.database.size.single }} | ||
storageClassName: postgres-csi | ||
{{ end }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# Dotnet Database | ||
## Pre-requisites | ||
```bash | ||
dotnet tool install --global dotnet-ef | ||
# If already installed | ||
dotnet tool update --global dotnet-ef | ||
``` | ||
## Migrations | ||
### Create Migration | ||
Default add migrations command: | ||
```bash | ||
dotnet ef migrations add InitialCreate | ||
``` | ||
|
||
When the migrations is saved in another project: | ||
```bash | ||
dotnet ef migrations add InitialCreate --context MantaRayPlanDbContext --project ../Server.DataAccess.Database -o ../Server.DataAccess.Database/Migrations | ||
``` | ||
### Remove Migration | ||
```bash | ||
dotnet ef migrations remove | ||
``` |
Oops, something went wrong.