Skip to content

Commit

Permalink
✨ feat: helm chart
Browse files Browse the repository at this point in the history
Signed-off-by: Muhammed Hussein Karimi <[email protected]>
  • Loading branch information
mhkarimi1383 committed Jul 8, 2023
1 parent d5cd1f8 commit 13b4089
Show file tree
Hide file tree
Showing 15 changed files with 444 additions and 0 deletions.
23 changes: 23 additions & 0 deletions charts/reflector/.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/
24 changes: 24 additions & 0 deletions charts/reflector/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
apiVersion: v2
name: reflector
description: Reflector operator for Kubernetes

# A chart can be either an 'application' or a 'library' chart.
#
# Application charts are a collection of templates that can be packaged into versioned archives
# to be deployed.
#
# Library charts provide useful utilities or functions for the chart developer. They're included as
# a dependency of application charts to inject those utilities and functions into the rendering
# pipeline. Library charts do not define any templates and therefore cannot be deployed.
type: application

# This is the chart version. This version number should be incremented each time you make changes
# to the chart and its templates, including the app version.
# Versions are expected to follow Semantic Versioning (https://semver.org/)
version: 0.0.1

# This is the version number of the application being deployed. This version number should be
# incremented each time you make changes to the application. Versions are not expected to
# follow Semantic Versioning. They should reflect the version the application is using.
# It is recommended to use it with quotes.
appVersion: "0.0.1"
Empty file.
58 changes: 58 additions & 0 deletions charts/reflector/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
{{/*
Expand the name of the chart.
*/}}
{{- define "reflector.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 "reflector.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 "reflector.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
{{- end }}

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

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

{{/*
Create the name of the service account to use
*/}}
{{- define "reflector.serviceAccountName" -}}
{{- default (include "reflector.fullname" .) .Values.serviceAccount.name }}
{{- end }}
33 changes: 33 additions & 0 deletions charts/reflector/templates/certgen-job.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
apiVersion: batch/v1
kind: Job
metadata:
name: {{ include "reflector.fullname" . }}-certgen
namespace: {{ .Release.Namespace }}
annotations:
"helm.sh/hook": pre-install,pre-upgrade
"helm.sh/hook-delete-policy": before-hook-creation,hook-succeeded
"helm.sh/hook-weight": "4"
labels:
{{- include "reflector.labels" . | nindent 4 }}
spec:
template:
metadata:
name: {{ include "reflector.fullname" . }}-certgen
labels:
{{- include "reflector.labels" . | nindent 8 }}
spec:
containers:
- name: create
image: {{ .Values.certGen.image.repository }}:{{ .Values.certGen.image.tag }}
imagePullPolicy: {{ .Values.certGen.image.pullPolicy }}
args:
- create
- --host={{ include "reflector.fullname" . }}-validating-webhook,{{ include "reflector.fullname" . }}-validating-webhook.{{ .Release.Namespace }}.svc,{{ include "reflector.fullname" . }}-validating-webhook.{{ .Release.Namespace }}.svc.cluster,{{ include "reflector.fullname" . }}-validating-webhook.{{ .Release.Namespace }}.svc.cluster.local
- --namespace={{ .Release.Namespace }}
- --secret-name={{ include "reflector.fullname" . }}-webhook-tls
restartPolicy: OnFailure
serviceAccountName: {{ include "reflector.fullname" . }}-certgen
securityContext:
runAsGroup: 2000
runAsNonRoot: true
runAsUser: 2000
11 changes: 11 additions & 0 deletions charts/reflector/templates/certgen-role.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
name: {{ include "reflector.fullname" . }}-certgen
annotations:
"helm.sh/hook": pre-install,pre-upgrade
"helm.sh/hook-weight": "1"
rules:
- apiGroups: [""]
resources: ["secrets"]
verbs: ["get", "list", "watch", "create", "update", "patch", "delete"]
15 changes: 15 additions & 0 deletions charts/reflector/templates/certgen-rolebinding.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: {{ include "reflector.fullname" . }}-certgen
annotations:
"helm.sh/hook": pre-install,pre-upgrade
"helm.sh/hook-weight": "3"
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: Role
name: {{ include "reflector.fullname" . }}-certgen
subjects:
- kind: ServiceAccount
name: {{ include "reflector.fullname" . }}-certgen
namespace: {{ .Release.Namespace }}
9 changes: 9 additions & 0 deletions charts/reflector/templates/certgen-serviceaccount.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
apiVersion: v1
kind: ServiceAccount
metadata:
name: {{ include "reflector.fullname" . }}-certgen
annotations:
"helm.sh/hook": pre-install,pre-upgrade
"helm.sh/hook-weight": "2"
labels:
{{- include "reflector.labels" . | nindent 4 }}
12 changes: 12 additions & 0 deletions charts/reflector/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: {{ include "reflector.fullname" . }}
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: {{ .Values.role.clusterRoleName | quote }}
subjects:
- kind: ServiceAccount
name: {{ include "reflector.serviceAccountName" . }}
namespace: {{ .Release.Namespace }}
41 changes: 41 additions & 0 deletions charts/reflector/templates/crd.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{{ if eq .Values.crd.install true }}
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
name: reflects.k8s.karimi.dev
spec:
scope: Namespaced
versions:
- name: v1
served: true
storage: true
schema:
openAPIV3Schema:
type: object
properties:
spec:
type: object
properties:
namespaces:
type: array
items:
type: string
items:
type: array
items:
type: object
x-kubernetes-embedded-resource: true
x-kubernetes-preserve-unknown-fields: true
group: k8s.karimi.dev
names:
plural: reflects
kind: Reflect
singular: reflect
shortNames:
- ref
- rf
- rfl
- rfct
- rft
# preserveUnknownFields: false
{{ end }}
84 changes: 84 additions & 0 deletions charts/reflector/templates/deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ include "reflector.fullname" . }}
labels:
{{- include "reflector.labels" . | nindent 4 }}
spec:
{{- if not .Values.autoscaling.enabled }}
replicas: {{ .Values.replicaCount }}
{{- end }}
selector:
matchLabels:
{{- include "reflector.selectorLabels" . | nindent 6 }}
template:
metadata:
{{- with .Values.podAnnotations }}
annotations:
{{- toYaml . | nindent 8 }}
{{- end }}
labels:
{{- include "reflector.selectorLabels" . | nindent 8 }}
spec:
{{- with .Values.imagePullSecrets }}
imagePullSecrets:
{{- toYaml . | nindent 8 }}
{{- end }}
serviceAccountName: {{ include "reflector.serviceAccountName" . }}
securityContext:
{{- toYaml .Values.podSecurityContext | nindent 8 }}
containers:
- name: {{ .Chart.Name }}
securityContext:
{{- toYaml .Values.securityContext | nindent 12 }}
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
imagePullPolicy: {{ .Values.image.pullPolicy | quote }}
env:
- name: "SHELL_OPERATOR_NAMESPACE"
value: {{ .Release.Namespace | quote }}
- name: "VALIDATING_WEBHOOK_SERVICE_NAME"
value: "{{ include "reflector.fullname" . }}-validating-webhook"
- name: "VALIDATING_WEBHOOK_CONFIGURATION_NAME"
value: {{ include "reflector.fullname" . | quote }}
- name: "LOG_LEVEL"
value: {{ .Values.logLevel | quote }}
- name: "LOG_TYPE"
value: {{ .Values.logType | quote }}
- name: "VALIDATING_WEBHOOK_CA"
value: "/validating-certs/ca"
- name: "VALIDATING_WEBHOOK_SERVER_KEY"
value: "/validating-certs/key"
- name: "VALIDATING_WEBHOOK_SERVER_CERT"
value: "/validating-certs/cert"
{{- range .Values.extraEnv }}
- name: {{ .name | quote }}
value: {{ toYaml .value | quote }}
{{- end }}
readinessProbe:
httpGet:
path: /healthz
port: 9680
scheme: HTTPS
volumeMounts:
- mountPath: /validating-certs/
name: validating-certs
readOnly: true
resources:
{{- toYaml .Values.resources | nindent 12 }}
volumes:
- name: validating-certs
secret:
defaultMode: 420
secretName: {{ include "reflector.fullname" . }}-webhook-tls
{{- with .Values.nodeSelector }}
nodeSelector:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.affinity }}
affinity:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.tolerations }}
tolerations:
{{- toYaml . | nindent 8 }}
{{- end }}
28 changes: 28 additions & 0 deletions charts/reflector/templates/hpa.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{{- if .Values.autoscaling.enabled }}
apiVersion: autoscaling/v2beta1
kind: HorizontalPodAutoscaler
metadata:
name: {{ include "reflector.fullname" . }}
labels:
{{- include "reflector.labels" . | nindent 4 }}
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: {{ include "reflector.fullname" . }}
minReplicas: {{ .Values.autoscaling.minReplicas }}
maxReplicas: {{ .Values.autoscaling.maxReplicas }}
metrics:
{{- if .Values.autoscaling.targetCPUUtilizationPercentage }}
- type: Resource
resource:
name: cpu
targetAverageUtilization: {{ .Values.autoscaling.targetCPUUtilizationPercentage }}
{{- end }}
{{- if .Values.autoscaling.targetMemoryUtilizationPercentage }}
- type: Resource
resource:
name: memory
targetAverageUtilization: {{ .Values.autoscaling.targetMemoryUtilizationPercentage }}
{{- end }}
{{- end }}
15 changes: 15 additions & 0 deletions charts/reflector/templates/service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
apiVersion: v1
kind: Service
metadata:
name: {{ include "reflector.fullname" . }}-validating-webhook
labels:
{{- include "reflector.labels" . | nindent 4 }}
spec:
type: {{ .Values.service.type }}
ports:
- port: {{ .Values.service.port }}
targetPort: 9680
protocol: TCP
name: validating-webhook
selector:
{{- include "reflector.selectorLabels" . | nindent 4 }}
10 changes: 10 additions & 0 deletions charts/reflector/templates/serviceaccount.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
apiVersion: v1
kind: ServiceAccount
metadata:
name: {{ include "reflector.serviceAccountName" . }}
labels:
{{- include "reflector.labels" . | nindent 4 }}
{{- with .Values.serviceAccount.annotations }}
annotations:
{{- toYaml . | nindent 4 }}
{{- end }}
Loading

0 comments on commit 13b4089

Please sign in to comment.