Skip to content

Commit

Permalink
feat: add the common chart
Browse files Browse the repository at this point in the history
  • Loading branch information
PhilippeVienne committed Aug 12, 2024
1 parent 1f0b4c7 commit 868be42
Show file tree
Hide file tree
Showing 19 changed files with 1,058 additions and 0 deletions.
23 changes: 23 additions & 0 deletions charts/common/.helmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Patterns to ignore when building packages.
# This supports shell glob matching, relative path matching, and
# negation (prefixed with !). Only one pattern per line.
.DS_Store
# Common VCS dirs
.git/
.gitignore
.bzr/
.bzrignore
.hg/
.hgignore
.svn/
# Common backup files
*.swp
*.bak
*.tmp
*.orig
*~
# Various IDEs
.project
.idea/
*.tmproj
.vscode/
6 changes: 6 additions & 0 deletions charts/common/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
apiVersion: v2
name: common
description: Opinated Helm chart for deploying applications to Kubernetes
type: application
version: 1.0.17
appVersion: "v0.1.0"
30 changes: 30 additions & 0 deletions charts/common/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Common Helm Chart

The Common Helm Chart is an opinionated framework for deploying applications to Kubernetes. It provides a standardized structure and configuration options to streamline the deployment process.

## Features

- **Modularity**: The Common Helm Chart is designed to be modular, allowing you to easily add or remove components based on your application's requirements.
- **Configuration Management**: It provides a centralized configuration management system, allowing you to easily manage and override application-specific configurations.
- **Scalability**: The Common Helm Chart is built with scalability in mind, enabling you to effortlessly scale your application as your needs evolve.
- **Monitoring and Logging**: It includes built-in support for monitoring and logging, ensuring that you have visibility into the health and performance of your application.
- **Security**: The Common Helm Chart follows best practices for securing your application, including the use of secrets and RBAC (Role-Based Access Control).

## Getting Started

To get started with the Common Helm Chart, follow these steps:

1. Clone the repository: `git clone https://github.com/skyloud/helm-charts.git`
2. Customize the configuration: Modify the values in the `values.yaml` file to match your application's requirements.
3. Deploy the chart: Run `helm install common-chart charts/common` to deploy your application to Kubernetes.

For more detailed instructions and examples, please refer to the [documentation](https://github.com/skyloud/helm-charts).

## Contributing

We welcome contributions from the community! If you have any suggestions, bug reports, or feature requests, please open an issue or submit a pull request on our [GitHub repository](https://github.com/skyloud/helm-charts).

## License

The Common Helm Chart is released under the [Apache 2.0 License](https://www.apache.org/licenses/LICENSE-2.0). Please refer to the [LICENSE](https://github.com/skyloud/helm-charts/blob/main/LICENSE.md) file for more information.

22 changes: 22 additions & 0 deletions charts/common/templates/NOTES.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
1. Get the application URL by running these commands:
{{- if .Values.ingress.enabled }}
{{- range $host := .Values.ingress.hosts }}
{{- range .paths }}
http{{ if $.Values.ingress.tls }}s{{ end }}://{{ $host.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 "common.fullname" . }})
export NODE_IP=$(kubectl get nodes --namespace {{ .Release.Namespace }} -o jsonpath="{.items[0].status.addresses[0].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 "common.fullname" . }}'
export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ include "common.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 "common.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
{{- end }}
71 changes: 71 additions & 0 deletions charts/common/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
{{/*
Expand the name of the chart.
*/}}
{{- define "common.name" -}}
{{- default .Chart.Name .Values.nameOverride | trunc 63 | 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 "common.fullname" -}}
{{- if .Values.fullnameOverride }}
{{- .Values.fullnameOverride | trunc 63 | 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 }}

{{/*
Create chart name and version as used by the chart label.
*/}}
{{- define "common.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
{{- end }}

{{/*
Common labels
*/}}
{{- define "common.labels" -}}
helm.sh/chart: {{ include "common.chart" . }}
{{ include "common.selectorLabels" . }}
{{- if .Chart.AppVersion }}
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
{{- end }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- end }}

{{/*
Selector labels
*/}}
{{- define "common.selectorLabels" -}}
app.kubernetes.io/name: {{ include "common.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end }}

{{/*
Return the proper Common image
*/}}
{{- define "common.image" -}}
{{- $repositoryName := .Values.image.repository -}}
{{- $separator := ":" -}}
{{- $tag := .Values.image.tag | default .Chart.AppVersion | toString -}}
{{- if .Values.global }}
{{- if .Values.global.image }}
{{- if .Values.global.image.repository }}
{{- $repositoryName = .Values.global.image.repository | toString -}}
{{- end -}}
{{- if .Values.global.image.tag }}
{{- $tag = .Values.global.image.tag | toString -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- printf "%s%s%s" $repositoryName $separator $tag -}}
{{- end -}}
89 changes: 89 additions & 0 deletions charts/common/templates/cronjob.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
{{- $imagePullSecrets := .Values.image.pullSecrets -}}

{{- range .Values.cronJobs }}
---
apiVersion: batch/v1
kind: CronJob
metadata:
name: {{ .name }}
spec:
concurrencyPolicy: {{ .concurrencyPolicy | default "Allow" }}
failedJobsHistoryLimit: {{ .failedJobsHistoryLimit | default 1 }}
schedule: {{ .schedule | quote }}
jobTemplate:
metadata:
name: {{ .name }}
spec:
template:
spec:
containers:
- name: {{ .name }}
imagePullPolicy: {{ .imagePullPolicy | default "IfNotPresent"}}
{{- if and (.image).tag .image.repository }}
image: "{{ .image.repository }}:{{ .image.tag }}"
{{- else }}
image: {{ include "common.image" $ }}
{{- end }}
{{- with .resources }}
resources:
{{- toYaml . | nindent 16 }}
{{- end }}
{{- with .command }}
command:
{{- toYaml . | nindent 16 }}
{{- end }}
{{- with .args }}
args:
{{- toYaml . | nindent 16 }}
{{- end }}
{{- with .env }}
env:
{{- toYaml . | nindent 16 }}
{{- end }}
{{- with .envFrom }}
envFrom:
{{- toYaml . | nindent 16 }}
{{- end }}
{{- with .securityContext }}
securityContext:
{{- toYaml . | nindent 16 }}
{{- end }}
{{- with .volumeMounts }}
volumeMounts:
{{- toYaml . | nindent 16 }}
{{- end }}
{{- with $imagePullSecrets }}
imagePullSecrets:
{{- toYaml . | nindent 12 }}
{{- end }}
restartPolicy: {{ .restartPolicy | default "OnFailure" }}
{{- with .podSecurityContext }}
securityContext:
{{- toYaml . | nindent 12 }}
{{- end }}
{{- with .volumes }}
volumes:
{{- toYaml . | nindent 12 }}
{{- end }}
{{- with .affinity }}
affinity:
{{- toYaml . | nindent 12 }}
{{- end }}
{{- with .nodeSelector }}
nodeSelector:
{{- toYaml . | nindent 12 }}
{{- end }}
{{- with .tolerations }}
tolerations:
{{- toYaml . | nindent 12 }}
{{- end }}
{{- with .priorityClassName }}
priorityClassName: {{ . }}
{{- end }}
{{- with .schedulerName }}
schedulerName: {{ . }}
{{- end }}
terminationGracePeriodSeconds: {{ .terminationGracePeriodSeconds | default 30 }}
backoffLimit: 3
successfulJobsHistoryLimit: {{ .successfulJobsHistoryLimit | default 2 }}
{{- end }}
111 changes: 111 additions & 0 deletions charts/common/templates/deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ include "common.fullname" . }}
labels:
{{- include "common.labels" . | nindent 4 }}
{{- with .Values.annotations }}
annotations:
{{- toYaml . | nindent 4 }}
{{- end }}
spec:
{{- with .Values.strategy }}
strategy:
{{- toYaml .| nindent 4 }}
{{- end }}
revisionHistoryLimit: {{ .Values.revisionHistoryLimit | default 2 }}
{{- if not .Values.autoscaling.enabled }}
replicas: {{ .Values.replicaCount }}
{{- end }}
selector:
matchLabels:
{{- include "common.selectorLabels" . | nindent 6 }}
template:
metadata:
{{- with .Values.podAnnotations }}
annotations:
{{- toYaml . | nindent 8 }}
{{- end }}
labels:
{{- include "common.selectorLabels" $ | nindent 8 }}
spec:
{{- with .Values.image.pullSecrets }}
imagePullSecrets:
{{- toYaml . | nindent 8 }}
{{- end }}
serviceAccountName: {{ include "common.fullname" . }}
securityContext:
{{- toYaml .Values.podSecurityContext | nindent 8 }}
containers:
- name: {{ .Values.containerName | default .Chart.Name }}
securityContext:
{{- toYaml .Values.securityContext | nindent 12 }}
image: {{ include "common.image" . }}
imagePullPolicy: {{ .Values.image.pullPolicy }}
{{- with .Values.env }}
env:
{{- toYaml . | nindent 12 }}
{{- end }}
{{- with .Values.envFrom }}
envFrom:
{{- toYaml . | nindent 12 }}
{{- end }}
{{- with .Values.args }}
args:
{{- toYaml . | nindent 12 }}
{{- end }}
{{- if and .Values.service.enabled .Values.containerPort }}
ports:
- name: http
containerPort: {{ .Values.containerPort }}
protocol: {{ .Values.service.protocol }}
{{- end }}
{{- with .Values.livenessProbe }}
livenessProbe:
{{- toYaml . | nindent 12 }}
{{- end }}
{{- with .Values.readinessProbe }}
readinessProbe:
{{- toYaml . | nindent 12 }}
{{- end }}
{{- with .Values.startupProbe }}
startupProbe:
{{- toYaml . | nindent 12 }}
{{- end }}
resources:
{{- toYaml .Values.resources | nindent 12 }}
{{- with .Values.command }}
command:
{{- toYaml . | nindent 12 }}
{{- end }}
{{- with .Values.lifecycleHooks }}
lifecycle:
{{- toYaml . | nindent 12 }}
{{- end }}
{{- with .Values.volumeMounts }}
volumeMounts:
{{- toYaml . | nindent 12 }}
{{- end }}
{{- with .Values.sidecars }}
{{- toYaml . | nindent 8 }}
{{- end }}
{{- if .Values.volumes }}
volumes:
{{- toYaml .Values.volumes | nindent 8 }}
{{- end }}
{{- with .Values.nodeSelector }}
nodeSelector:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.affinity }}
affinity:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.tolerations }}
tolerations:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.initContainers }}
initContainers:
{{- toYaml . | nindent 8 }}
{{- end }}
32 changes: 32 additions & 0 deletions charts/common/templates/hpa.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{{- if .Values.autoscaling.enabled }}
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
name: {{ include "common.fullname" . }}
labels:
{{- include "common.labels" . | nindent 4 }}
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: {{ include "common.fullname" . }}
minReplicas: {{ .Values.autoscaling.minReplicas }}
maxReplicas: {{ .Values.autoscaling.maxReplicas }}
metrics:
{{- if .Values.autoscaling.targetCPUUtilizationPercentage }}
- type: Resource
resource:
name: cpu
target:
type: Utilization
averageUtilization: {{ .Values.autoscaling.targetCPUUtilizationPercentage }}
{{- end }}
{{- if .Values.autoscaling.targetMemoryUtilizationPercentage }}
- type: Resource
resource:
name: memory
target:
type: Utilization
averageUtilization: {{ .Values.autoscaling.targetMemoryUtilizationPercentage }}
{{- end }}
{{- end }}
Loading

0 comments on commit 868be42

Please sign in to comment.