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

---
 charts/rabbitmq/Chart.yaml                 |  4 +---
 charts/rabbitmq/README.md                  | 17 +++++++++++------
 charts/rabbitmq/templates/service.yaml     |  9 +++++++++
 charts/rabbitmq/templates/statefulset.yaml | 18 +++++++++++++++---
 charts/rabbitmq/values.yaml                | 22 +++++++++++++++-------
 5 files changed, 51 insertions(+), 19 deletions(-)

diff --git a/charts/rabbitmq/Chart.yaml b/charts/rabbitmq/Chart.yaml
index 96a53f66..7ecd3c32 100644
--- a/charts/rabbitmq/Chart.yaml
+++ b/charts/rabbitmq/Chart.yaml
@@ -7,8 +7,6 @@ type: application
 maintainers:
   - name: groundhog2k
 
-# This is the chart version.
-version: 0.2.0
+version: 0.2.1
 
-# This is the version number of the application being deployed.
 appVersion: 3.8.9
diff --git a/charts/rabbitmq/README.md b/charts/rabbitmq/README.md
index 740e4051..70453544 100644
--- a/charts/rabbitmq/README.md
+++ b/charts/rabbitmq/README.md
@@ -1,6 +1,6 @@
 # RabbitMQ
 
-![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: 3.8.9](https://img.shields.io/badge/AppVersion-3.8.9-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: 3.8.9](https://img.shields.io/badge/AppVersion-3.8.9-informational?style=flat-square)
 
 A Helm chart for a RabbitMQ cluster on Kubernetes
 
@@ -15,7 +15,7 @@ $ helm install my-release groundhog2k/rabbitmq
 
 This chart uses the original [RabbitMQ image from Docker Hub](https://hub.docker.com/_/rabbitmq) to deploy a stateful RabbitMQ cluster in Kubernetes.
 
-It fully supports deployment of arm64v8 and amd64 multi-architecture docker image. Just set the `nodeSelector` value to `kubernetes.io/arch: "arm64"` (default is `"amd64"`)
+It fully supports deployment of the multi-architecture docker image.
 
 ## Prerequisites
 
@@ -57,11 +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 | `{}` | Pod security context |
 | securityContext | object | `see values.yaml` | Container security context |
 | env | list | `[]` | Additional container environmment variables |
+| args | list | `[]` | Additional container command arguments |
 | rbac.create | bool | `true` | Enable creation of RBAC |
 | serviceAccount.create | bool | `false` | Enable service account creation |
 | serviceAccount.name | string | `""` | Optional name of the service account |
@@ -75,17 +76,21 @@ $ helm uninstall my-release
 
 | Key | Type | Default | Description |
 |-----|------|---------|-------------|
+| service.type | string | `"ClusterIP"` | Service type |
+| service.clusterIP | string | `nil` | Service cluster IP (only relevant for type LoadBalancer) |
 | service.amqp.port | int | `5672` | AMQP port |
+| service.amqp.nodePort | int | `nil` | Service node port (only relevant for type NodePort) |
 | service.mgmt.port | int | `15672` | Management UI port |
+| service.mgmt.nodePort | int | `nil` | Service node port (only relevant for type NodePort) |
 
 ## Storage parameters
 
 | 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 |
 
 ## Ingress parameters
 
diff --git a/charts/rabbitmq/templates/service.yaml b/charts/rabbitmq/templates/service.yaml
index 88437005..e3fc63b2 100644
--- a/charts/rabbitmq/templates/service.yaml
+++ b/charts/rabbitmq/templates/service.yaml
@@ -10,8 +10,17 @@ spec:
     - port: {{ .Values.service.amqp.port }}
       targetPort: amqp
       name: amqp
+      {{- if and (eq .Values.service.type "NodePort") (.Values.service.amqp.nodePort) }}
+      nodePort: {{ .Values.service.amqp.nodePort }}
+      {{- end }}
     - port: {{ .Values.service.mgmt.port }}
       targetPort: mgmt
       name: mgmt
+      {{- if and (eq .Values.service.type "NodePort") (.Values.service.mgmt.nodePort) }}
+      nodePort: {{ .Values.service.mgmt.nodePort }}
+      {{- end }}
+  {{- if and (eq .Values.service.type "LoadBalancer") (.Values.service.clusterIP) }}
+  clusterIP: {{ .Values.service.clusterIP }}
+  {{- end }}      
   selector:
     {{- include "rabbitmq.selectorLabels" . | nindent 4 }}
diff --git a/charts/rabbitmq/templates/statefulset.yaml b/charts/rabbitmq/templates/statefulset.yaml
index ff53aa04..d7fd47e2 100644
--- a/charts/rabbitmq/templates/statefulset.yaml
+++ b/charts/rabbitmq/templates/statefulset.yaml
@@ -27,12 +27,16 @@ spec:
       imagePullSecrets:
         {{- toYaml . | nindent 8 }}
       {{- end }}
+      {{- 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:
@@ -70,8 +74,10 @@ spec:
             successThreshold: {{ .Values.readinessProbe.successThreshold }}
             failureThreshold: {{ .Values.readinessProbe.failureThreshold }}
           {{- end }}
+          {{- with .Values.resources }}
           resources:
-            {{- toYaml .Values.resources | nindent 12 }}
+            {{- toYaml . | nindent 12 }}
+          {{- end }}
           lifecycle:
           {{- if and .Values.clustering.rebalance (gt (.Values.replicaCount | int) 1) }}
             postStart:
@@ -112,6 +118,12 @@ spec:
           envFrom:
             - secretRef:
                 name: {{ include "rabbitmq.fullname" . }}
+          {{- if .Values.args }}
+          args:
+            {{- range .Values.args }}
+            - {{ . }}
+            {{- end }}
+          {{- end }}                
           volumeMounts:
             - name: logs
               mountPath: /var/log/rabbitmq
diff --git a/charts/rabbitmq/values.yaml b/charts/rabbitmq/values.yaml
index 31186e91..d706904e 100644
--- a/charts/rabbitmq/values.yaml
+++ b/charts/rabbitmq/values.yaml
@@ -36,10 +36,17 @@ securityContext:
 
 ## Default RabbitMq service ports (default: AMQP port 5672, Management UI port 15672)
 service:
+  type: ClusterIP
   amqp:
     port: 5672
+    ## The node port (only relevant for type NodePort)
+    nodePort: {}
   mgmt:
     port: 15672
+    ## The node port (only relevant for type NodePort)
+    nodePort: {}
+  ## The cluster ip address (only relevant for type LoadBalancer)
+  clusterIP: {}
 
 ## Ingress configuration
 ingress:
@@ -68,10 +75,8 @@ resources: {}
 #    cpu: 100m
 #    memory: 128Mi
 
-## Default node type for the image
-## use arm64 for the arm64v8 image
-nodeSelector:
-  kubernetes.io/arch: amd64
+## Additional node selector
+nodeSelector: {}
 
 tolerations: []
 affinity: {}
@@ -107,6 +112,9 @@ rbac:
 ## Additional environment variables
 env: []
 
+## Arguments for the container entrypoint process
+args: []
+
 ## Default Kubernetes cluster domain
 clusterDomain: cluster.local
 
@@ -144,13 +152,13 @@ clustering:
 ## Storage parameters
 storage:
   ## Set persistentVolumenClaimName to reference an existing PVC
-  # persistentVolumeClaimName: <own-pvc-name>
+  persistentVolumeClaimName: {}
 
   ## Alternative set requestedSize to define a size for a dynamically created PVC
-  # requestedSize: <volume-size>
+  requestedSize: {}
 
   ## the storage class name
-  # className:
+  className: {}
 
   ## Default access mode (ReadWriteOnce)
   accessModes:
-- 
GitLab