Skip to content

Commit

Permalink
Merge pull request #22 from truefoundry/tfy-agent
Browse files Browse the repository at this point in the history
  • Loading branch information
srihari-tf authored May 17, 2023
2 parents 7089d99 + b099f84 commit 0da9c81
Show file tree
Hide file tree
Showing 10 changed files with 465 additions and 0 deletions.
6 changes: 6 additions & 0 deletions charts/tfy-agent/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
apiVersion: v2
name: tfy-agent
version: 0.1.0
description: "Truefoundry agent for kubernetes clusters"
maintainers:
- name: truefoundry
129 changes: 129 additions & 0 deletions charts/tfy-agent/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
{{/*
Expand the name of the chart.
*/}}
{{- define "app.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 "app.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 }}

{{/*
Define full name for tfy-agent-proxy
*/}}
{{- define "app.tfyAgentProxy.fullname" -}}
{{- include "app.fullname" . | trunc 57 | trimSuffix "-" }}-proxy
{{- end }}

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

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

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

{{/*
Create the name of the service account to use
*/}}
{{- define "app.serviceAccountName" -}}
{{- if .Values.serviceAccount.create }}
{{- default (include "app.fullname" .) .Values.serviceAccount.name }}
{{- else }}
{{- default "default" .Values.serviceAccount.name }}
{{- end }}
{{- end }}

{{/*
Parse env from template
*/}}
{{- define "app.parseEnv" -}}
{{ tpl (.Values.env | toYaml) . }}
{{- end }}


{{/*
Create the env file
*/}}
{{- define "app.env" }}
{{- range $key, $val := (include "app.parseEnv" .) | fromYaml }}
{{- if and $val (contains "${k8s-secret" ($val | toString)) }}
- name: {{ $key }}
valueFrom:
secretKeyRef:
name: {{ $.Values.envSecretName }}
key: {{ $val | trimPrefix "${k8s-secret/" | trimSuffix "}" }}
{{- else }}
- name: {{ $key }}
value: {{ $val | quote }}
{{- end }}
{{- end }}
{{- end }}

{{/*
Parse env from template
*/}}
{{- define "app.tfyAgentProxy.parseEnv" -}}
{{ tpl (.Values.tfyAgentProxy.env | toYaml) . }}
{{- end }}

{{/*
Create the env file
*/}}
{{- define "app.tfyAgentProxy.env" }}
{{- range $key, $val := (include "app.tfyAgentProxy.parseEnv" .) | fromYaml }}
{{- if and $val (contains "${k8s-secret" ($val | toString)) }}
- name: {{ $key }}
valueFrom:
secretKeyRef:
name: {{ $.Values.envSecretName }}
key: {{ $val | trimPrefix "${k8s-secret/" | trimSuffix "}" }}
{{- else }}
- name: {{ $key }}
value: {{ $val | quote }}
{{- end }}
{{- end }}
{{- end }}

# {{- define "app.imagePullSecrets" }}
# {{- if (tpl .Values.imagePullCredentials .) }}
# - name: {{ include "app.fullname" . }}-image-pull-secret
# {{- end }}
# {{- if (tpl .Values.imagePullSecretName .) }}
# - name: {{ tpl .Values.imagePullSecretName . }}
# {{- end }}
# {{- end }}
14 changes: 14 additions & 0 deletions charts/tfy-agent/templates/clusterrolebinding.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{{- if .Values.rbac.enabled -}}
kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: {{ include "app.fullname" . }}-admin-rbac
subjects:
- kind: ServiceAccount
name: {{ include "app.serviceAccountName" . }}
namespace: {{ .Release.Namespace }}
roleRef:
kind: ClusterRole
name: cluster-admin
apiGroup: rbac.authorization.k8s.io
{{- end }}
30 changes: 30 additions & 0 deletions charts/tfy-agent/templates/deployment-tfy-agent-proxy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{{- if .Values.tfyAgentProxy.enabled }}
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ include "app.tfyAgentProxy.fullname" . }}
labels:
app.kubernetes.io/version: {{ .Values.tfyAgentProxy.imageTag | quote }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
helm.sh/chart: {{ include "app.chart" . }}
app.kubernetes.io/name: tfy-agent-proxy
spec:
replicas: 1
selector:
matchLabels:
app.kubernetes.io/name: {{ include "app.tfyAgentProxy.fullname" . }}
template:
metadata:
labels:
app.kubernetes.io/name: {{ include "app.tfyAgentProxy.fullname" . }}
spec:
serviceAccountName: {{ include "app.serviceAccountName" . }}
containers:
- name: tfy-agent-proxy
env:
{{- include "app.tfyAgentProxy.env" . | trim | nindent 12 }}
image: "{{ .Values.tfyAgentProxy.imageRepository }}:{{ .Values.tfyAgentProxy.imageTag }}"
imagePullPolicy: IfNotPresent
resources:
{{- toYaml .Values.tfyAgentProxy.resources | nindent 12 }}
{{- end }}
63 changes: 63 additions & 0 deletions charts/tfy-agent/templates/deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ include "app.fullname" . }}
labels:
{{- include "app.labels" . | nindent 4 }}
spec:
replicas: 1
selector:
matchLabels:
{{- include "app.selectorLabels" . | nindent 6 }}
template:
metadata:
{{- with .Values.podAnnotations }}
annotations:
{{- toYaml . | nindent 8 }}
{{- end }}
labels:
{{- include "app.selectorLabels" . | nindent 8 }}
spec:
{{- with .Values.imagePullSecrets }}
imagePullSecrets:
{{- toYaml . | nindent 8 }}
{{- end }}
serviceAccountName: {{ include "app.serviceAccountName" . }}
securityContext:
{{- toYaml .Values.podSecurityContext | nindent 8 }}
containers:
- name: {{ .Chart.Name }}
securityContext:
{{- toYaml .Values.securityContext | nindent 12 }}
env:
{{- include "app.env" . | trim | nindent 12 }}
image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
ports:
- name: http
containerPort: {{ .Values.service.port }}
protocol: TCP
resources:
{{- toYaml .Values.resources | nindent 12 }}
{{- if .Values.healthcheck.enabled }}
livenessProbe:
httpGet:
path: {{ .Values.healthcheck.liveness.path }}
port: {{ .Values.healthcheck.liveness.port }}
readinessProbe:
httpGet:
path: {{ .Values.healthcheck.readiness.path }}
port: {{ .Values.healthcheck.liveness.port }}
{{- 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 }}
39 changes: 39 additions & 0 deletions charts/tfy-agent/templates/ingress.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{{- if .Values.ingress.enabled -}}
{{- $serviceName := include "app.fullname" . -}}
{{- $servicePort := .Values.service.port -}}
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
{{- if .Values.ingress.annotations }}
annotations:
{{- range $key, $value := .Values.ingress.annotations }}
{{ $key }}: {{ $value | quote }}
{{- end }}
{{- end }}
name: {{ include "app.fullname" . }}
labels:
{{- include "app.labels" . | nindent 4 }}
{{- if .Values.ingress.labels }}
{{- toYaml .Values.ingress.labels | nindent 4 }}
{{- end }}
spec:
ingressClassName: {{ .Values.ingress.ingressClassName }}
rules:
{{- range $host := .Values.ingress.hosts }}
- host: {{ $host }}
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: {{ $serviceName }}
port:
number: {{ $servicePort }}

{{- end -}}
{{- if .Values.ingress.tls }}
tls:
{{- toYaml .Values.ingress.tls | nindent 4 }}
{{- end -}}
{{- end -}}
15 changes: 15 additions & 0 deletions charts/tfy-agent/templates/service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
apiVersion: v1
kind: Service
metadata:
name: {{ include "app.fullname" . }}
labels:
{{- include "app.labels" . | nindent 4 }}
spec:
type: {{ .Values.service.type }}
ports:
- port: {{ .Values.service.port }}
targetPort: {{ .Values.service.port }}
protocol: TCP
name: http
selector:
{{- include "app.selectorLabels" . | nindent 4 }}
12 changes: 12 additions & 0 deletions charts/tfy-agent/templates/serviceaccount.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{{- if .Values.serviceAccount.create -}}
apiVersion: v1
kind: ServiceAccount
metadata:
name: {{ include "app.serviceAccountName" . }}
labels:
{{- include "app.labels" . | nindent 4 }}
{{- with .Values.serviceAccount.annotations }}
annotations:
{{ tpl (toYaml . | indent 4) $ }}
{{- end }}
{{- end }}
32 changes: 32 additions & 0 deletions charts/tfy-agent/templates/virtualservice.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{{- if .Values.istio.virtualservice.enabled -}}
{{- $serviceName := include "app.fullname" . -}}
{{- $servicePort := .Values.service.port -}}
apiVersion: networking.istio.io/v1beta1
kind: VirtualService
metadata:
name: {{ include "app.fullname" . }}
labels:
{{- include "app.labels" . | nindent 4 }}
{{- if .Values.istio.virtualservice.annotations }}
annotations:
{{- range $key, $value := .Values.istio.virtualservice.annotations }}
{{ $key }}: {{ $value | quote }}
{{- end }}
{{- end }}
namespace: {{ .Release.Namespace }}
spec:
gateways:
{{- range .Values.istio.virtualservice.gateways}}
- {{ . }}
{{- end }}
hosts:
{{- range .Values.istio.virtualservice.hosts}}
- {{ . }}
{{- end }}
http:
- route:
- destination:
host: {{ include "app.fullname" . }}.{{ .Release.Namespace }}.svc.cluster.local
port:
number: {{ .Values.service.port }}
{{- end }}
Loading

0 comments on commit 0da9c81

Please # to comment.