diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 0000000000000000000000000000000000000000..1afa27d2f7a20424aafe52aceffa0d0b1be98860 --- /dev/null +++ b/.gitlab-ci.yml @@ -0,0 +1,21 @@ +image: nexus.tech.vereign.com:6001/helm:3.5.3 + +include: + - project: 'gaiax/tsa/ci-helpers' + file: 'helm-package.yml' + +stages: + - lint + - package + +helm-lint: + extends: .helm-lint + stage: lint + tags: + - amd64-docker + +helm-package: + extends: .helm-package + stage: package + tags: + - amd64-docker diff --git a/Chart.yaml b/Chart.yaml new file mode 100644 index 0000000000000000000000000000000000000000..7215f975fd530d8564deecbff78e3926b517d6a3 --- /dev/null +++ b/Chart.yaml @@ -0,0 +1,5 @@ +apiVersion: v1 +appVersion: "v0.0.1" +name: mongodb +version: "0.0.1" + diff --git a/templates/_helpers.tpl b/templates/_helpers.tpl new file mode 100644 index 0000000000000000000000000000000000000000..aa9bae638ebf44e5086527b886426299ed7380a5 --- /dev/null +++ b/templates/_helpers.tpl @@ -0,0 +1,40 @@ +{{/* vim: set filetype=mustache: */}} +{{/* +Expand the name of the chart. +*/}} +{{- define "mongodb.name" -}} +{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" -}} +{{- end -}} + +{{/* +Create a default fully qualified app name. +We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec). +If release name contains chart name it will be used as a full name. +*/}} +{{- define "mongodb.fullname" -}} +{{- if .Values.fullnameOverride -}} +{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" -}} +{{- else -}} +{{- $name := default .Chart.Name .Values.nameOverride -}} +{{- if contains $name .Release.Name -}} +{{- .Release.Name | trunc 63 | trimSuffix "-" -}} +{{- else -}} +{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" -}} +{{- end -}} +{{- end -}} +{{- end -}} + +{{/* +Create chart name and version as used by the chart label. +*/}} +{{- define "mongodb.chart" -}} +{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}} +{{- end -}} + +{{- define "mongodb.metricsSecret" -}} + {{- if .Values.auth.existingMetricsSecret -}} + {{- .Values.auth.existingMetricsSecret -}} + {{- else -}} + {{- template "mongodb.fullname" . -}}-metrics + {{- end -}} +{{- end -}} \ No newline at end of file diff --git a/templates/mongodb-service.yaml b/templates/mongodb-service.yaml new file mode 100644 index 0000000000000000000000000000000000000000..5794ebfe07c42461b1bf31deecb985e2b13526ab --- /dev/null +++ b/templates/mongodb-service.yaml @@ -0,0 +1,23 @@ +apiVersion: v1 +kind: Service +metadata: + name: {{ template "mongodb.name" . }} + namespace: {{ template "mongodb.name" . }} + labels: + name: {{ template "mongodb.name" . }} +spec: + ports: + - protocol: TCP + port: {{ .Values.port }} + targetPort: {{ .Values.port }} + selector: + name: {{ template "mongodb.name" . }} + clusterIP: None + clusterIPs: + - None + type: ClusterIP + sessionAffinity: None + ipFamilies: + - IPv4 + ipFamilyPolicy: SingleStack + internalTrafficPolicy: Cluster diff --git a/templates/mongodb-statefulset.yaml b/templates/mongodb-statefulset.yaml new file mode 100644 index 0000000000000000000000000000000000000000..11b35b0c5c4752e4c983368c0e835974425e1418 --- /dev/null +++ b/templates/mongodb-statefulset.yaml @@ -0,0 +1,92 @@ +apiVersion: apps/v1 +kind: StatefulSet +metadata: + name: {{ template "mongodb.name" . }} + namespace: {{ template "mongodb.name" . }} +spec: + replicas: {{ .Values.replicas }} + selector: + matchLabels: + name: {{ template "mongodb.name" . }} + template: + metadata: + creationTimestamp: null + labels: + name: {{ template "mongodb.name" . }} + spec: + containers: + - name: {{ template "mongodb.name" . }} + image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}" + command: + - mongod + - '--port=27017' + - '--dbpath=/data/db' + - '--replSet=rs0' + - '--bind_ip_all' + ports: + - containerPort: {{ .Values.port }} + protocol: TCP + env: + - name: MONGO_INITDB_ROOT_USERNAME + value: {{ .Values.mongo.user }} + - name: MONGO_INITDB_ROOT_PASSWORD + value: {{ .Values.mongo.pass }} + - name: MONGO_REPLICA_SET_NAME + value: {{ .Values.mongo.replicaSetName }} + resources: {} + volumeMounts: + - name: mongo-persistent-storage + mountPath: /data/db + livenessProbe: + exec: + command: + - >- + test $(echo "rs.initiate().ok || rs.status().ok" | mongo -u + root -p root --quiet) -eq 1 + initialDelaySeconds: 10 + timeoutSeconds: 1 + periodSeconds: 30 + successThreshold: 1 + failureThreshold: 3 + terminationMessagePath: /dev/termination-log + terminationMessagePolicy: File + imagePullPolicy: Always + - name: {{ template "mongodb.name" . }}-sidecar + image: cvallance/mongo-k8s-sidecar + env: + - name: MONGO_SIDECAR_POD_LABELS + value: name=mongo + - name: KUBERNETES_MONGO_SERVICE_NAME + value: {{ template "mongodb.name" . }} + resources: {} + terminationMessagePath: /dev/termination-log + terminationMessagePolicy: File + imagePullPolicy: Always + restartPolicy: Always + terminationGracePeriodSeconds: 10 + dnsPolicy: ClusterFirst + serviceAccountName: {{ template "mongodb.name" . }} + serviceAccount: {{ template "mongodb.name" . }} + securityContext: {} + schedulerName: default-scheduler + volumeClaimTemplates: + - kind: PersistentVolumeClaim + apiVersion: v1 + metadata: + name: mongo-persistent-storage + creationTimestamp: null + spec: + accessModes: + - ReadWriteOnce + resources: + requests: + storage: {{ .Values.persistentVolume.size | quote }} + storageClassName: standard + volumeMode: Filesystem + serviceName: {{ template "mongodb.name" . }} + podManagementPolicy: OrderedReady + updateStrategy: + type: RollingUpdate + rollingUpdate: + partition: 0 + revisionHistoryLimit: 10 \ No newline at end of file diff --git a/values.yaml b/values.yaml new file mode 100644 index 0000000000000000000000000000000000000000..2d015484e40741cba13f5454109827b4a4adfcad --- /dev/null +++ b/values.yaml @@ -0,0 +1,20 @@ +# Mongo replica count +replicas: 1 + +# Mongo service port +port: 27017 + +# Mongo replSetName, user and pass +mongo: + replicaSetName: rs0 + user: "" + pass: "" + +# Specs for the MongoDB image +image: + repository: mongo + tag: 3.6 + +# Select desired volume size +persistentVolume: + size: 10Gi \ No newline at end of file