From 8819d5f2bd34e1fa4f4c8ebdbed07759120f7540 Mon Sep 17 00:00:00 2001
From: groundhog2k <10630407+groundhog2k@users.noreply.github.com>
Date: Sun, 13 Dec 2020 15:11:45 +0100
Subject: [PATCH] Removed node selector and improved chart configuration (#130)

---
 charts/mongodb/Chart.yaml                 |  2 +-
 charts/mongodb/README.md                  | 18 +++++++++---------
 charts/mongodb/templates/service.yaml     |  6 ++++++
 charts/mongodb/templates/statefulset.yaml | 12 +++++++++---
 charts/mongodb/values.yaml                | 14 ++++++++------
 5 files changed, 33 insertions(+), 19 deletions(-)

diff --git a/charts/mongodb/Chart.yaml b/charts/mongodb/Chart.yaml
index 3cfddb94..55ac914a 100644
--- a/charts/mongodb/Chart.yaml
+++ b/charts/mongodb/Chart.yaml
@@ -7,6 +7,6 @@ type: application
 maintainers:
   - name: groundhog2k
 
-version: 0.2.0
+version: 0.2.1
 
 appVersion: 4.2.11
diff --git a/charts/mongodb/README.md b/charts/mongodb/README.md
index 132750c3..c3927f90 100644
--- a/charts/mongodb/README.md
+++ b/charts/mongodb/README.md
@@ -1,6 +1,6 @@
 # MongoDB
 
-![Version: 0.2.0](https://img.shields.io/badge/Version-0.2.0-informational?style=flat-square) ![Type: application](https://img.shields.io/badge/Type-application-informational?style=flat-square) ![AppVersion: 4.2.11](https://img.shields.io/badge/AppVersion-4.2.11-informational?style=flat-square)
+![Version: 0.2.1](https://img.shields.io/badge/Version-0.2.1-informational?style=flat-square) ![Type: application](https://img.shields.io/badge/Type-application-informational?style=flat-square) ![AppVersion: 4.2.11](https://img.shields.io/badge/AppVersion-4.2.11-informational?style=flat-square)
 
 A Helm chart for MongoDB on Kubernetes
 
@@ -57,12 +57,12 @@ $ helm uninstall my-release
 | livenessProbe | object | `see values.yaml` | Liveness probe configuration |
 | readinessProbe | object | `see values.yaml` | Readiness probe configuration |
 | resources | object | `{}` | Resource limits and requests |
-| nodeSelector."kubernetes.io/arch" | string | `"amd64"` | Deployment node selector |
+| nodeSelector | object | `{}` | Deployment node selector |
 | podAnnotations | object | `{}` | Additional pod annotations |
 | podSecurityContext | object | `see values.yaml` | Pod security context |
 | securityContext | object | `see values.yaml` | Container security context |
 | env | list | `[]` | Additional container environmment variables |
-| args | object | `{}` | Additional container command arguments |
+| args | object | `[]` | Additional container command arguments |
 | serviceAccount.annotations | object | `{}` | Additional service account annotations |
 | serviceAccount.create | bool | `false` | Enable service account creation |
 | serviceAccount.name | string | `""` | Name of the service account |
@@ -83,17 +83,17 @@ $ helm uninstall my-release
 | Key | Type | Default | Description |
 |-----|------|---------|-------------|
 | storage.accessModes[0] | string | `"ReadWriteOnce"` | Storage access mode |
-| storage.persistentVolumeClaimName | string | `""` | PVC name when existing storage volume should be used |
-| storage.requestedSize | string | `""` | Size for new PVC, when no existing PVC is used |
-| storage.className | string | `""` | Storage class name |
+| storage.persistentVolumeClaimName | string | `nil` | PVC name when existing storage volume should be used |
+| storage.requestedSize | string | `nil` | Size for new PVC, when no existing PVC is used |
+| storage.className | string | `nil` | Storage class name |
 
 ## MongoDB parameters
 
 | Key | Type | Default | Description |
 |-----|------|---------|-------------|
-| settings.customConfig | string | `""` | Custom MongoDB configuration block that will be mounted as file in /etc/mongo/custom.conf |
+| settings.customConfig | string | `nil` | Custom MongoDB configuration block that will be mounted as file in /etc/mongo/custom.conf |
 | settings.rootUsername | string | `admin` | The root username |
 | settings.rootPassword | string | `{}` | The root users password (Random value if not specified) |
 | initUserDatabase | object | `{}` | Optional user database initialization script support |
-| initUserDatabase.dbName | string | `""` | Name of the user database |
-| initUserDatabase.script | string | `""` | Javascript block to initialize the user database |
+| initUserDatabase.dbName | string | `nil` | Name of the user database |
+| initUserDatabase.script | string | `nil` | Javascript block to initialize the user database |
diff --git a/charts/mongodb/templates/service.yaml b/charts/mongodb/templates/service.yaml
index a276e455..45328e1b 100644
--- a/charts/mongodb/templates/service.yaml
+++ b/charts/mongodb/templates/service.yaml
@@ -11,5 +11,11 @@ spec:
       targetPort: mongodb
       protocol: TCP
       name: mongodb
+      {{- if and (eq .Values.service.type "NodePort") (.Values.service.nodePort) }}
+      nodePort: {{ .Values.service.nodePort }}
+      {{- end }}
+  {{- if and (eq .Values.service.type "LoadBalancer") (.Values.service.clusterIP) }}
+  clusterIP: {{ .Values.service.clusterIP }}
+  {{- end }}
   selector:
     {{- include "mongodb.selectorLabels" . | nindent 4 }}
diff --git a/charts/mongodb/templates/statefulset.yaml b/charts/mongodb/templates/statefulset.yaml
index 642ba391..12a17808 100644
--- a/charts/mongodb/templates/statefulset.yaml
+++ b/charts/mongodb/templates/statefulset.yaml
@@ -27,12 +27,16 @@ spec:
         {{- toYaml . | nindent 8 }}
       {{- end }}
       serviceAccountName: {{ include "mongodb.serviceAccountName" . }}
+      {{- with .Values.podSecurityContext }}
       securityContext:
-        {{- toYaml .Values.podSecurityContext | nindent 8 }}
+        {{- toYaml . | nindent 8 }}
+      {{- end }}
       containers:
         - name: {{ .Chart.Name }}
+          {{- with .Values.securityContext }}
           securityContext:
-            {{- toYaml .Values.securityContext | nindent 12 }}
+            {{- toYaml . | nindent 12 }}
+          {{- end }}
           image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
           imagePullPolicy: {{ .Values.image.pullPolicy }}
           ports:
@@ -65,8 +69,10 @@ spec:
             failureThreshold: {{ .Values.readinessProbe.failureThreshold }}
             successThreshold: {{ .Values.readinessProbe.successThreshold }}
           {{- end }}
+          {{- with .Values.resources }}
           resources:
-            {{- toYaml .Values.resources | nindent 12 }}
+            {{- toYaml . | nindent 12 }}
+          {{- end }}
           envFrom:
             - secretRef:
                 name: {{ include "mongodb.fullname" . }}            
diff --git a/charts/mongodb/values.yaml b/charts/mongodb/values.yaml
index 370e523f..e01c6d48 100644
--- a/charts/mongodb/values.yaml
+++ b/charts/mongodb/values.yaml
@@ -28,7 +28,7 @@ podAnnotations: {}
 podSecurityContext:
   fsGroup: 999
 
-## Don't touch - no other options supported in V0.1.0 of this chart
+## Don't touch - no other options supported in this chart version
 podManagementPolicy: OrderedReady
 updateStrategyType: RollingUpdate
 replicaCount: 1
@@ -45,6 +45,10 @@ securityContext:
 service:
   type: ClusterIP
   port: 27017
+  ## The node port (only relevant for type NodePort)
+  nodePort: {}
+  ## The cluster ip address (only relevant for type LoadBalancer)
+  clusterIP: {}
 
 ## Resource limits and requests
 resources: {}
@@ -73,10 +77,8 @@ readinessProbe:
   successThreshold: 1
   periodSeconds: 10
 
-## Default node type for the image
-## use arm64 for the arm64v8 image
-nodeSelector:
-  kubernetes.io/arch: amd64
+## Additional node selector
+nodeSelector: {}
 
 ## Pod tolerations
 tolerations: []
@@ -85,7 +87,7 @@ tolerations: []
 affinity: {}
 
 ## Additional arguments for the container entrypoint process
-args: {}
+args: []
 
 ## Additional environment variables
 env: []
-- 
GitLab