Skip to content

Commit

Permalink
feat: added mongodb in the default provisioners (#23)
Browse files Browse the repository at this point in the history
* feat(provisioners): add mongodb provisioner

Signed-off-by: Andrej Giesbrecht <[email protected]>

* fix: restore previous formatting of args in example provisioner

Signed-off-by: Andrej Giesbrecht <[email protected]>

* change provisioner type to mongodb

Co-authored-by: Ben Meier <[email protected]>
Signed-off-by: Andrej Giesbrecht <[email protected]>

* fix: remove db output and add connection output

Co-authored-by: Ben Meier <[email protected]>
Signed-off-by: Andrej Giesbrecht <[email protected]>

---------

Signed-off-by: Andrej Giesbrecht <[email protected]>
Signed-off-by: Andrej Giesbrecht <[email protected]>
Co-authored-by: Ben Meier <[email protected]>
  • Loading branch information
giesan and astromechza authored Aug 20, 2024
1 parent 7d72798 commit bbbdcdc
Showing 1 changed file with 130 additions and 6 deletions.
136 changes: 130 additions & 6 deletions internal/provisioners/default/zz-default.provisioners.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
- uri: template://default-provisioners/volume
type: volume
outputs: |
source:
source:
emptyDir: {}
# The default dns provisioner just outputs a random localhost domain because we don't know whether external-dns is
Expand Down Expand Up @@ -113,7 +113,7 @@
- {{ .Params.host | quote }}
rules:
- matches:
- path:
- path:
type: PathPrefix
value: {{ .Params.path | quote }}
backendRefs:
Expand Down Expand Up @@ -203,7 +203,7 @@
mountPath: /var/lib/postgresql/data
readinessProbe:
exec:
command:
command:
- pg_isready
- -U
- {{ .State.username | quote }}
Expand Down Expand Up @@ -317,7 +317,7 @@
mountPath: /usr/local/etc/redis
readinessProbe:
exec:
command:
command:
- redis-cli
- ping
periodSeconds: 3
Expand Down Expand Up @@ -453,7 +453,7 @@
mountPath: /var/lib/mysql
readinessProbe:
exec:
command:
command:
- mysqladmin
- ping
- -h
Expand Down Expand Up @@ -493,4 +493,128 @@
type: ClusterIP
ports:
- port: 3306
targetPort: 3306
targetPort: 3306
- uri: template://default-provisioners/mongo
type: mongodb
init: |
randomDatabase: db-{{ randAlpha 8 }}
randomUsername: user-{{ randAlpha 8 }}
randomPassword: {{ randAlphaNum 16 | quote }}
state: |
service: mongo-{{ .SourceWorkload }}-{{ substr 0 8 .Guid | lower }}
database: {{ dig "database" .Init.randomDatabase .State | quote }}
username: {{ dig "username" .Init.randomUsername .State | quote }}
password: {{ dig "password" .Init.randomPassword .State | quote }}
outputs: |
host: {{ .State.service }}
port: 27017
name: {{ .State.database }}
connection: "mongodb://{{ .State.username }}:{{ .State.password }}@{{ .State.service }}:27017/"
username: {{ .State.username }}
password: {{ encodeSecretRef .State.service "MONGO_INITDB_ROOT_PASSWORD" }}
manifests: |
- apiVersion: v1
kind: Secret
metadata:
name: {{ .State.service }}
annotations:
k8s.score.dev/source-workload: {{ .SourceWorkload }}
k8s.score.dev/resource-uid: {{ .Uid }}
k8s.score.dev/resource-guid: {{ .Guid }}
labels:
app.kubernetes.io/managed-by: score-k8s
app.kubernetes.io/name: {{ .State.service }}
app.kubernetes.io/instance: {{ .State.service }}
data:
MONGO_INITDB_ROOT_PASSWORD: {{ .State.password | b64enc }}
- apiVersion: apps/v1
kind: StatefulSet
metadata:
name: {{ .State.service }}
annotations:
k8s.score.dev/source-workload: {{ .SourceWorkload }}
k8s.score.dev/resource-uid: {{ .Uid }}
k8s.score.dev/resource-guid: {{ .Guid }}
labels:
app.kubernetes.io/managed-by: score-k8s
app.kubernetes.io/name: {{ .State.service }}
app.kubernetes.io/instance: {{ .State.service }}
spec:
replicas: 1
serviceName: {{ .State.service }}
selector:
matchLabels:
app.kubernetes.io/instance: {{ .State.service }}
template:
metadata:
labels:
app.kubernetes.io/managed-by: score-k8s
app.kubernetes.io/name: {{ .State.service }}
app.kubernetes.io/instance: {{ .State.service }}
annotations:
k8s.score.dev/source-workload: {{ .SourceWorkload }}
k8s.score.dev/resource-uid: {{ .Uid }}
k8s.score.dev/resource-guid: {{ .Guid }}
spec:
containers:
- name: mongo-db
image: mongo:latest
ports:
- name: mongo
containerPort: 27017
env:
- name: MONGO_INITDB_ROOT_USERNAME
value: {{ .State.username | quote }}
- name: MONGO_INITDB_ROOT_PASSWORD
valueFrom:
secretKeyRef:
name: {{ .State.service }}
key: MONGO_INITDB_ROOT_PASSWORD
livenessProbe:
exec:
command:
- /bin/sh
- -c
- echo 'db.runCommand("ping").ok' | mongosh -u $$MONGO_INITDB_ROOT_USERNAME -p $$MONGO_INITDB_ROOT_PASSWORD
initialDelaySeconds: 30
timeoutSeconds: 5
periodSeconds: 20
volumeMounts:
- name: data
mountPath: /var/db
volumeClaimTemplates:
- metadata:
name: data
annotations:
k8s.score.dev/source-workload: {{ .SourceWorkload }}
k8s.score.dev/resource-uid: {{ .Uid }}
k8s.score.dev/resource-guid: {{ .Guid }}
labels:
app.kubernetes.io/managed-by: score-k8s
app.kubernetes.io/name: {{ .State.service }}
app.kubernetes.io/instance: {{ .State.service }}
spec:
accessModes: ["ReadWriteOnce"]
resources:
requests:
storage: 1Gi
- apiVersion: v1
kind: Service
metadata:
name: {{ .State.service }}
annotations:
k8s.score.dev/source-workload: {{ .SourceWorkload }}
k8s.score.dev/resource-uid: {{ .Uid }}
k8s.score.dev/resource-guid: {{ .Guid }}
labels:
app.kubernetes.io/managed-by: score-k8s
app.kubernetes.io/name: {{ .State.service }}
app.kubernetes.io/instance: {{ .State.service }}
spec:
selector:
app.kubernetes.io/instance: {{ .State.service }}
type: ClusterIP
ports:
- port: 27017
targetPort: 27017

0 comments on commit bbbdcdc

Please sign in to comment.