Skip to content

Commit

Permalink
Merge pull request #202 from OT-CONTAINER-KIT/ms-helper-tpl
Browse files Browse the repository at this point in the history
Ms helper tpl
  • Loading branch information
ashwani-opstree authored Jul 2, 2024
2 parents b28e579 + 8195e90 commit d8d2508
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 12 deletions.
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

0 comments on commit d8d2508

Please sign in to comment.