Skip to content

Commit

Permalink
[MOSIP-30647] added deployment info helm chart
Browse files Browse the repository at this point in the history
  • Loading branch information
Rakshithb1 committed Jul 24, 2024
1 parent f54d415 commit b4fb3e7
Show file tree
Hide file tree
Showing 13 changed files with 307 additions and 0 deletions.
1 change: 1 addition & 0 deletions charts/deployment-info/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
charts/
23 changes: 23 additions & 0 deletions charts/deployment-info/.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/
13 changes: 13 additions & 0 deletions charts/deployment-info/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
apiVersion: v2
name: deployment-info
description: A Helm chart to get deployment information
type: application
version: 0.0.1-develop
appVersion: ""
home: https://mosip.io
keywords:
- mosip
- deployment-info
maintainers:
- email: [email protected]
name: MOSIP

Check failure on line 13 in charts/deployment-info/Chart.yaml

View workflow job for this annotation

GitHub Actions / chart-lint-publish / chart-lint-publish

13:16 [new-line-at-end-of-file] no new line character at the end of file
11 changes: 11 additions & 0 deletions charts/deployment-info/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Deployment Information Helm Chart

This Helm chart deploys an NGINX server along with a script to fetch Kubernetes deployment information.

## TL;DR

```console
$ helm repo add mosip https://mosip.github.io
$ helm install my-release mosip/deployment-info
```

62 changes: 62 additions & 0 deletions charts/deployment-info/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
{{/*
Expand the name of the chart.
*/}}
{{- define "deployment-info.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 "deployment-info.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 "deployment-info.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
{{- end }}

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

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

{{/*
Create the name of the service account to use
*/}}
{{- define "deployment-info.serviceAccountName" -}}
{{- if .Values.serviceAccount.create }}
{{- default (include "deployment-info.fullname" .) .Values.serviceAccount.name }}
{{- else }}
{{- default "default" .Values.serviceAccount.name }}
{{- end }}
{{- end }}
30 changes: 30 additions & 0 deletions charts/deployment-info/templates/clusterrole.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: {{ .Release.Name }}
namespace: {{ .Release.Namespace }}
rules:
- apiGroups:
- ""
resources:
- namespaces
- pods
verbs:
- get
- list
- apiGroups:
- apps
resources:
- deployments
- statefulsets
verbs:
- get
- list
- apiGroups:
- batch
resources:
- jobs
- cronjobs
verbs:
- get
- list
12 changes: 12 additions & 0 deletions charts/deployment-info/templates/clusterrolebinding.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: {{ .Release.Name }}
subjects:
- kind: ServiceAccount
name: {{ .Release.Name }}
namespace: {{ .Release.Namespace }}
roleRef:
kind: ClusterRole
name: {{ .Release.Name }}
apiGroup: rbac.authorization.k8s.io
31 changes: 31 additions & 0 deletions charts/deployment-info/templates/configmap.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ .Release.Name }}-script-config
namespace: {{ .Release.Namespace }}
data:
fetch-deployment-info.sh: |
#!/bin/sh
# Clear existing deployment_info.txt or create if not exists
> /usr/share/nginx/html/deployment_info.txt
kubectl get namespaces | awk 'NR>1 {print $1}' | while read namespace; do
echo "Namespace: $namespace" >> /usr/share/nginx/html/deployment_info.txt
# Get deployments
kubectl get deployments -n $namespace -o json | jq -r '.items[] | "Deployment: \(.metadata.name), Image: \(.spec.template.spec.containers[].image), Helm Chart Version: \(.metadata.labels["helm.sh/chart"])"' >> /usr/share/nginx/html/deployment_info.txt
# Get statefulsets
kubectl get statefulsets -n $namespace -o json | jq -r '.items[] | "StatefulSet: \(.metadata.name), Image: \(.spec.template.spec.containers[].image), Helm Chart Version: \(.metadata.labels["helm.sh/chart"])"' >> /usr/share/nginx/html/deployment_info.txt
# Get cronjobs
kubectl get cronjobs -n $namespace -o json | jq -r '.items[] | "CronJob: \(.metadata.name), Image: \(.spec.jobTemplate.spec.template.spec.containers[].image), Helm Chart Version: \(.metadata.labels["helm.sh/chart"])"' >> /usr/share/nginx/html/deployment_info.txt
# Get jobs
kubectl get jobs -n $namespace -o json | jq -r '.items[] | "Job: \(.metadata.name), Image: \(.spec.template.spec.containers[].image), Helm Chart Version: \(.metadata.labels["helm.sh/chart"])"' >> /usr/share/nginx/html/deployment_info.txt
echo "" >> /usr/share/nginx/html/deployment_info.txt
done
echo "Script executed at $(date)" >> /usr/share/nginx/html/deployment_info.txt
63 changes: 63 additions & 0 deletions charts/deployment-info/templates/deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ .Release.Name }}
namespace: {{ .Release.Namespace }}
labels:
{{- include "deployment-info.labels" . | nindent 4 }}
spec:
replicas: {{ .Values.replicaCount }}
selector:
matchLabels:
app: deployment-info
template:
metadata:
labels:
app: deployment-info
spec:
serviceAccountName: {{ .Release.Name }}
containers:
- name: nginx
image: {{ .Values.nginx.image }}
imagePullPolicy: {{ .Values.nginx.imagePullPolicy }}
ports:
- containerPort: 80
volumeMounts:
- name: result-file
mountPath: /usr/share/nginx/html
- name: script-runner
image: {{ .Values.scriptRunner.image }}
imagePullPolicy: {{ .Values.nginx.imagePullPolicy }}
command:
- /bin/sh
- -c
- |
apk add --no-cache bash curl bind-tools jq
curl -LO "https://dl.k8s.io/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl"
chmod +x kubectl
mv kubectl /usr/local/bin/
cp /fetch-deployment-info.sh /tmp/fetch-deployment-info.sh
chmod +x /tmp/fetch-deployment-info.sh
/tmp/fetch-deployment-info.sh
echo "0 2 * * * /tmp/fetch-deployment-info.sh" > /etc/crontabs/root
crond -f
volumeMounts:
- name: script-file
mountPath: /fetch-deployment-info.sh
subPath: fetch-deployment-info.sh
- name: result-file
mountPath: /usr/share/nginx/html
volumes:
- name: script-file
configMap:
name: {{ .Release.Name }}-script-config
- name: result-file
emptyDir: {}
13 changes: 13 additions & 0 deletions charts/deployment-info/templates/service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
apiVersion: v1
kind: Service
metadata:
name: {{ .Release.Name }}
namespace: {{ .Release.Namespace }}
spec:
selector:
app: deployment-info
ports:
- protocol: TCP
port: 80
targetPort: 80
type: ClusterIP
5 changes: 5 additions & 0 deletions charts/deployment-info/templates/serviceaccount.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
apiVersion: v1
kind: ServiceAccount
metadata:
name: {{ .Release.Name }}
namespace: {{ .Release.Namespace }}
27 changes: 27 additions & 0 deletions charts/deployment-info/templates/virtualservice.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
name: {{ .Release.Name }}
namespace: {{ .Release.Namespace }}
spec:
hosts:
- "*"
gateways:
{{- if .Values.istio.gateways }}
{{- range .Values.istio.gateways }}
- {{ . }}
{{- end }}
{{- end }}
http:
- match:
- uri:
prefix: {{ .Values.istio.prefix }}
route:
- destination:
host: {{ .Release.Name }}
port:
number: 80
headers:
request:
set:
x-forwarded-proto: https
16 changes: 16 additions & 0 deletions charts/deployment-info/values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
replicaCount: 1

nginx:
image: nginx:latest
imagePullPolicy: IfNotPresent

scriptRunner:
image: alpine:latest
imagePullPolicy: IfNotPresent


istio:
enabled: true
gateways:
- istio-system/internal
prefix: /deployment_info.txt

0 comments on commit b4fb3e7

Please sign in to comment.