Skip to content

Commit

Permalink
GEMPT-2322 grpc-gateway chart
Browse files Browse the repository at this point in the history
  • Loading branch information
etessari committed Jun 20, 2024
1 parent 89abcc8 commit fdeeb70
Show file tree
Hide file tree
Showing 11 changed files with 280 additions and 0 deletions.
25 changes: 25 additions & 0 deletions charts/grpc-gateway/.helmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# 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/

unittests/
24 changes: 24 additions & 0 deletions charts/grpc-gateway/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
apiVersion: v2
name: grpc-gateway
description: A Helm chart 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.1.0

# 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.1.0"
3 changes: 3 additions & 0 deletions charts/grpc-gateway/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# gRPC gateway helm chart

Helm chart that deploys [grpc-gateway](https://github.com/grpc-ecosystem/grpc-gateway) to a Kubernetes cluster.
8 changes: 8 additions & 0 deletions charts/grpc-gateway/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{{- define "pdb.formatValue" }}
{{- $valueToFormat := . | toString }}
{{- if contains "%" $valueToFormat }}
{{- print $valueToFormat | quote }}
{{- else }}
{{- print $valueToFormat }}
{{- end }}
{{- end }}
70 changes: 70 additions & 0 deletions charts/grpc-gateway/templates/deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{.Values.name }}
namespace: {{.Values.namespace | quote}}
labels:
app: {{.Values.name}}
spec:
selector:
matchLabels:
app: {{.Values.name}}
template:
metadata:
labels:
app: {{.Values.name}}
annotations:
{{- if .Values.deployment.annotations }}
{{ toYaml .Values.deployment.annotations | indent 8 }}
{{ end }}
spec:
serviceAccountName: {{ .Values.service.serviceAccount }}
{{- if .Values.spc.enabled }}
volumes:
- name: secrets-store-inline
csi:
driver: secrets-store.csi.k8s.io
readOnly: true
volumeAttributes:
secretProviderClass: spc-{{.Values.name}}
{{- end }}
containers:
- name: {{ .Values.name }}
image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
{{- if .Values.deployment.resources }}
resources:
{{ toYaml .Values.deployment.resources | indent 12 }}
{{- end }}
readinessProbe:
tcpSocket:
port: {{.Values.http.containerPort}}
initialDelaySeconds: 5
livenessProbe:
tcpSocket:
port: {{.Values.http.containerPort}}
initialDelaySeconds: 10
ports:
- name: http
containerPort: {{.Values.http.containerPort}}
protocol: TCP
{{- if .Values.spc.enabled }}
volumeMounts:
- name: secrets-store-inline
mountPath: {{ .Values.deployment.secretsPath }}
readOnly: true
{{- end }}
env:
- name: ENVIRONMENT
value: {{.Values.environment | quote}}
- name: HTTP_LISTEN_HOST
value: {{.Values.http.host | quote}}
- name: HTTP_LISTEN_PORT
value: {{.Values.http.port | quote}}
- name: GRPC_LISTEN_HOST
value: {{.Values.grpc.host | quote}}
- name: GRPC_LISTEN_PORT
value: {{.Values.grpc.port | quote}}
{{- if .Values.deployment.env }}
{{ toYaml .Values.deployment.env | indent 12 }}
{{- end }}
25 changes: 25 additions & 0 deletions charts/grpc-gateway/templates/hpa.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{{- if .Values.hpa.enabled }}
apiVersion: {{ ternary "autoscaling/v2" "autoscaling/v2beta2" (semverCompare ">=1.23" .Capabilities.KubeVersion.Version) }}
kind: HorizontalPodAutoscaler
metadata:
name: {{ .Values.name }}
namespace: {{ .Values.namespace }}
labels:
app: {{.Values.name}}
spec:
maxReplicas: {{ .Values.hpa.maxReplicas }}
metrics:
{{- range $index, $val := .Values.hpa.metrics }}
- resource:
name: {{ $val.name }}
target:
averageUtilization: {{ $val.target.averageUtilization }}
type: {{ $val.target.type }}
type: {{ $val.type }}
{{- end }}
minReplicas: {{ .Values.hpa.minReplicas }}
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: {{ .Values.name }}
{{- end }}
21 changes: 21 additions & 0 deletions charts/grpc-gateway/templates/pdb.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
apiVersion: {{ ternary "policy/v1" "policy/v1beta1" (semverCompare ">=1.9" .Capabilities.KubeVersion.Version) }}
kind: PodDisruptionBudget
metadata:
name: {{.Values.name }}
namespace: {{ .Values.namespace | quote }}
spec:
{{- if and (.Values.pdb.enabled) (.Values.hpa.enabled) (gt .Values.hpa.minReplicas 1.0) (gt .Values.hpa.maxReplicas 1.0) }}
{{- if .Values.pdb.maxUnavailable }}
{{- $formattedValue := include "pdb.formatValue" .Values.pdb.maxUnavailable }}
maxUnavailable: {{ $formattedValue }}
{{- end }}
{{- if .Values.pdb.minAvailable }}
{{- $formattedValue := include "pdb.formatValue" .Values.pdb.minAvailable }}
minAvailable: {{ $formattedValue }}
{{- end }}
{{- else }}
minAvailable: 0
{{- end }}
selector:
matchLabels:
app: {{ .Values.name }}
14 changes: 14 additions & 0 deletions charts/grpc-gateway/templates/service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
apiVersion: v1
kind: Service
metadata:
name: {{ .Values.name }}-internal-server
namespace: {{ .Values.namespace | quote }}
spec:
selector:
app: {{ .Values.name }}
type: ClusterIP
ports:
- name: http
protocol: TCP
port: {{.Values.http.port}}
targetPort: http
15 changes: 15 additions & 0 deletions charts/grpc-gateway/templates/spc-aws-parameter.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{{- if .Values.spc.enabled }}
apiVersion: secrets-store.csi.x-k8s.io/v1alpha1
kind: SecretProviderClass
metadata:
name: spc-{{ .Values.name }}
namespace: {{ .Values.namespace }}
spec:
provider: aws
{{- if .Values.spc.secretObjects }}
secretObjects: {{ .Values.spc.secretObjects }}
{{- end }}
{{- if .Values.spc.parameters }}
parameters: {{ .Values.spc.parameters }}
{{- end }}
{{- end }}
28 changes: 28 additions & 0 deletions charts/grpc-gateway/templates/virtual-service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{{- if .Values.virtualService.enabled }}
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
name: {{ .Values.name }}
namespace: {{ .Values.virtualService.namespace }}
spec:
hosts:
- {{ .Values.host }}
gateways:
- {{ .Values.gateway }}
http:
{{- range $key, $value := .Values.http.routes }}
- route:
- destination:
port:
number: {{ $.Values.http.port }}
host: {{ $.Values.name }}-internal-server.{{ $.Values.namespace }}.svc.cluster.local
match:
{{- range $value.matchPrefix }}
- uri:
prefix: {{ . | quote }}
{{- end }}
{{- if $value.timeout }}
timeout: {{ $value.timeout }}
{{- end }}
{{- end }}
{{- end }}
47 changes: 47 additions & 0 deletions charts/grpc-gateway/values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name:
namespace:
environment:
host:
gateway:
service:
serviceAccount:
virtualService:
enabled: false
namespace: "default"
deployment:
annotations: {}
resources: {}
secretsPath: "/mnt/secrets-store"
env: {}
spc:
enabled: false
secretObjects:
parameters:
image:
repository:
pullPolicy: IfNotPresent
grpc:
host:
port:
http:
host: # if not empty only specified domain will be proxied
port:
containerPort:
routes:
- timeout:
matchPrefix:
- "/"
hpa:
enabled: false
minReplicas: 1
maxReplicas: 2
metrics:
- name: memory
type: Resource
target:
averageUtilization: 60
type: Utilization
pdb:
enabled: false
minAvailable:
maxUnavailable:

0 comments on commit fdeeb70

Please sign in to comment.