Skip to content

feat: support multiple ConfigMap objects #62

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions charts/helmchart/config/override-values-v2.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
service:
service1:
type: ClusterIP
port: 80
containerPort: 8080
targetPort: 8080
configmaps:
enabled: true
config:
- name: config1
data:
key1: "value1"
key2: "value2"
- name: config2
data:
keyA: "valueA"
keyB: "valueB"
38 changes: 23 additions & 15 deletions charts/helmchart/templates/NOTES.txt
Original file line number Diff line number Diff line change
@@ -1,22 +1,30 @@
1. Get the application URL by running these commands:
{{- if .Values.ingress.enabled }}
{{- range $host := .Values.ingress.hosts }}
{{- range .Values.ingress.hosts }}
{{- range .paths }}
http{{ if $.Values.ingress.tls }}s{{ end }}://{{ $host.host }}{{ .path }}
http{{ if $.Values.ingress.tls }}s{{ end }}://{{ $.host }}{{ .path }}
{{- end }}
{{- end }}
{{- else if contains "NodePort" .Values.service.type }}
export NODE_PORT=$(kubectl get --namespace {{ .Release.Namespace }} -o jsonpath="{.spec.ports[0].nodePort}" services {{ include "helmchart.fullname" . }})
export NODE_IP=$(kubectl get nodes --namespace {{ .Release.Namespace }} -o jsonpath="{.items[0].status.addresses[0].address}")
{{- end }}

{{- range $name, $service := .Values.service }}
{{- if eq $service.type "NodePort" }}
export NODE_PORT=$(kubectl get --namespace {{ $.Release.Namespace }} -o jsonpath='{.spec.ports[0].nodePort}' services {{ include "helmchart.fullname" $ }})
export NODE_IP=$(kubectl get nodes --namespace {{ $.Release.Namespace }} -o jsonpath='{.items[0].status.addresses[?(@.type=="ExternalIP")].address}')
echo http://$NODE_IP:$NODE_PORT
{{- else if contains "LoadBalancer" .Values.service.type }}
NOTE: It may take a few minutes for the LoadBalancer IP to be available.
You can watch the status of by running 'kubectl get --namespace {{ .Release.Namespace }} svc -w {{ include "helmchart.fullname" . }}'
export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ include "helmchart.fullname" . }} --template "{{"{{ range (index .status.loadBalancer.ingress 0) }}{{.}}{{ end }}"}}")
echo http://$SERVICE_IP:{{ .Values.service.port }}
{{- else if contains "ClusterIP" .Values.service.type }}
export POD_NAME=$(kubectl get pods --namespace {{ .Release.Namespace }} -l "app.kubernetes.io/name={{ include "helmchart.name" . }},app.kubernetes.io/instance={{ .Release.Name }}" -o jsonpath="{.items[0].metadata.name}")
export CONTAINER_PORT=$(kubectl get pod --namespace {{ .Release.Namespace }} $POD_NAME -o jsonpath="{.spec.containers[0].ports[0].containerPort}")
{{- end }}

{{- if eq $service.type "LoadBalancer" }}
echo "NOTE: It may take a few minutes for the LoadBalancer IP to be available."
echo "You can watch the status by running:"
echo "kubectl get --namespace {{ $.Release.Namespace }} svc -w {{ include "helmchart.fullname" $ }}"
export SERVICE_IP=$(kubectl get svc --namespace {{ $.Release.Namespace }} {{ include "helmchart.fullname" $ }} -o jsonpath='{.status.loadBalancer.ingress[0].ip}')
echo http://$SERVICE_IP:{{ $service.port }}
{{- end }}

{{- if eq $service.type "ClusterIP" }}
export POD_NAME=$(kubectl get pods --namespace {{ $.Release.Namespace }} -l "app.kubernetes.io/name={{ include "helmchart.name" $ }},app.kubernetes.io/instance={{ $.Release.Name }}" -o jsonpath='{.items[0].metadata.name}')
export CONTAINER_PORT=$(kubectl get pod --namespace {{ $.Release.Namespace }} $POD_NAME -o jsonpath='{.spec.containers[0].ports[0].containerPort}')
echo "Visit http://127.0.0.1:8080 to use your application"
kubectl --namespace {{ .Release.Namespace }} port-forward $POD_NAME 8080:$CONTAINER_PORT
kubectl --namespace {{ $.Release.Namespace }} port-forward $POD_NAME 8080:$CONTAINER_PORT
{{- end }}
{{- end }}
19 changes: 11 additions & 8 deletions charts/helmchart/templates/configmap.yaml
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
{{- if .Values.configmap.enabled }}
{{- if .Values.configmaps.enabled }}
{{- range .Values.configmaps.config}}
---
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ include "helmchart.fullname" . }}-config
namespace: {{ include "helmchart.namespace" . }}
name: {{ include "helmchart.fullname" $ }}-{{.name}}-config
namespace: {{ include "helmchart.namespace" $ }}
labels:
{{- include "helmchart.labels" $ | nindent 4 }}
annotations:
"helm.sh/hook-weight": "4"
"helm.sh/hook-weight": "4"
data:
{{- with .Values.configmap.configs }}
{{- toYaml . | nindent 2 -}}
{{- end}}
{{- end}}
{{- range $key, $val := .data }}
{{ $key }}: {{ $val | quote }}
{{- end }}
{{- end }}
{{- end }}
10 changes: 7 additions & 3 deletions charts/helmchart/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,21 @@ spec:
{{- end }}
imagePullPolicy: {{ .Values.image.pullPolicy }}
ports:
{{- range $key, $value := .Values.service}}
- name: http
containerPort: {{ .Values.service.containerPort | default .Values.service.port }}
containerPort: {{ $value.containerPort | default $value.port }}
protocol: TCP
{{- end }}
{{- if .Values.commands }}
command:
{{- toYaml .Values.commands | nindent 12 }}
{{- end }}
envFrom:
{{- if .Values.configmap.enabled }}
{{- if .Values.configmaps.enabled }}
{{- range .Values.configmaps.config }}
- configMapRef:
name: {{ include "helmchart.fullname" . }}-config
name: {{ include "helmchart.fullname" $ }}-{{ .name }}-config
{{- end }}
{{- end }}
{{- if .Values.secret.enabled }}
- secretRef:
Expand Down