Skip to content
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

Ms helper tpl #202

Merged
merged 8 commits into from
Jul 2, 2024
Merged
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
8 changes: 5 additions & 3 deletions charts/microservice/Chart.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
---
apiVersion: v2
name: microservice
description: A Helm chart for a microservice in Kubernetes

type: application
version: 0.1.0
appVersion: "1.0"
version: 0.1.2
appVersion: "0.1.2"
maintainers:
- name: Opstree Solutions
60 changes: 60 additions & 0 deletions charts/microservice/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
{{/* vim: set filetype=mustache: */}}

{{/*
Create a defautl fully qualified app name
It will use the release name to give the app name
*/}}

{{- define "app.name" -}}
{{- default .Chart.Name .Values.nameOverride | trunc 60 | 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 "app.tempname" -}}
{{- if .Values.fullnameOverride }}
{{- .Values.fullnameOverride | trunc 60 | 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 }}

{{- define "app.fullname" -}}
{{- printf "%s-%s" ( include "app.tempname" . ) "app" | trunc 63 | trimSuffix "-" }}
{{- end }}

{{/*
Common labels
*/}}
{{- define "app.labels" -}}
app: {{ include "app.tempname" . }}
{{- end }}

{{/*
Selector labels
*/}}
{{- define "app.selectorLabels" -}}
app: {{ include "app.tempname" . }}
{{- end }}%

{{/*
service name
*/}}
{{- define "app.servicename" -}}
{{- printf "%s-%s" ( include "app.tempname" . ) "svc" | trunc 63 | trimSuffix "-" }}
{{- end }}%

{{/*
configmap name
*/}}
{{- define "app.configmapname" -}}
{{- printf "%s-%s" ( include "app.tempname" . ) "cm" | trunc 63 | trimSuffix "-" }}
{{- end }}%
8 changes: 4 additions & 4 deletions charts/microservice/templates/deployment.yaml
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ include "microservice.fullname" . }}
name: {{ include "app.fullname" . }}
labels:
{{- include "microservice.labels" . | nindent 4 }}
{{- include "app.labels" . | nindent 4 }}
spec:
replicas: {{ .Values.replicaCount }}
selector:
matchLabels:
{{- include "microservice.selectorLabels" . | nindent 6 }}
{{- include "app.selectorLabels" . | nindent 6 }}
template:
metadata:
labels:
{{- include "microservice.selectorLabels" . | nindent 8 }}
{{- include "app.selectorLabels" . | nindent 8 }}
spec:
containers:
- name: {{ .Chart.Name }}
Expand Down
6 changes: 3 additions & 3 deletions charts/microservice/templates/service.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
apiVersion: v1
kind: Service
metadata:
name: {{ include "microservice.fullname" . }}
name: {{ include "app.servicename" . }}
labels:
{{- include "microservice.labels" . | nindent 4 }}
{{- include "app.labels" . | nindent 4 }}
spec:
type: {{ .Values.service.type }}
ports:
Expand All @@ -12,4 +12,4 @@ spec:
protocol: TCP
name: http
selector:
{{- include "microservice.selectorLabels" . | nindent 4 }}
{{- include "app.selectorLabels" . | nindent 4 }}
6 changes: 4 additions & 2 deletions charts/microservice/values.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
replicaCount: 1

fullnameOverride: "nginx"
nameOverride: ""
image:
repository: nginx # your microservice image name
repository: nginx
pullPolicy: IfNotPresent
tag: "latest" # your microservice image tag
tag: "latest"

service:
type: ClusterIP
Expand Down
Loading