Skip to content

Commit

Permalink
chore: Update pokeshop chart to provide easy installation (#19)
Browse files Browse the repository at this point in the history
Co-authored-by: Matheus Nogueira <[email protected]>
  • Loading branch information
danielbdias and mathnogueira authored Sep 5, 2024
1 parent 726a80f commit b733921
Show file tree
Hide file tree
Showing 11 changed files with 101 additions and 36 deletions.
2 changes: 1 addition & 1 deletion charts/pokeshop-demo/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ 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: v1.1.0
version: v1.2.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
Expand Down
10 changes: 5 additions & 5 deletions charts/pokeshop-demo/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -71,21 +71,21 @@ app.kubernetes.io/instance: {{ .Release.Name }}
{{- end }}

{{/*
Common labels (Worker)
Common labels (Queue Worker)
*/}}
{{- define "pokeshop-demo.worker.labels" -}}
{{- define "pokeshop-demo.queueworker.labels" -}}
helm.sh/chart: {{ include "pokeshop-demo.chart" . }}
{{ include "pokeshop-demo.worker.selectorLabels" . }}
{{ include "pokeshop-demo.queueworker.selectorLabels" . }}
{{- if .Chart.AppVersion }}
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
{{- end }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- end }}

{{/*
Selector labels (Worker)
Selector labels (Queue Worker)
*/}}
{{- define "pokeshop-demo.worker.selectorLabels" -}}
{{- define "pokeshop-demo.queueworker.selectorLabels" -}}
app.kubernetes.io/name: {{ include "pokeshop-demo.name" . }}-worker
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end }}
Expand Down
6 changes: 3 additions & 3 deletions charts/pokeshop-demo/templates/deployment.api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ metadata:
labels:
{{- include "pokeshop-demo.api.labels" . | nindent 4 }}
spec:
replicas: {{ .Values.pokeshop.replicaCount }}
replicas: {{ .Values.pokeshop.api.replicaCount }}
selector:
matchLabels:
{{- include "pokeshop-demo.api.selectorLabels" . | nindent 6 }}
Expand All @@ -23,7 +23,7 @@ spec:
containerPort: 80
protocol: TCP
resources:
{{- toYaml .Values.pokeshop.resources | nindent 12 }}
{{- toYaml .Values.pokeshop.api.resources | nindent 12 }}
env:
- name: NPM_RUN_COMMAND
value: api
Expand All @@ -39,7 +39,7 @@ spec:
containerPort: {{ .Values.pokeshop.service.rpcPort }}
protocol: TCP
resources:
{{- toYaml .Values.pokeshop.resources | nindent 12 }}
{{- toYaml .Values.pokeshop.api.resources | nindent 12 }}
env:
- name: NPM_RUN_COMMAND
value: rpc
Expand Down
10 changes: 5 additions & 5 deletions charts/pokeshop-demo/templates/deployment.queueworker.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@ kind: Deployment
metadata:
name: {{ include "pokeshop-demo.fullname" . }}-queueworker
labels:
{{- include "pokeshop-demo.worker.labels" . | nindent 4 }}
{{- include "pokeshop-demo.queueworker.labels" . | nindent 4 }}
spec:
replicas: {{ .Values.pokeshop.replicaCount }}
replicas: {{ .Values.pokeshop.queueworker.replicaCount }}
selector:
matchLabels:
{{- include "pokeshop-demo.worker.selectorLabels" . | nindent 6 }}
{{- include "pokeshop-demo.queueworker.selectorLabels" . | nindent 6 }}
template:
metadata:
labels:
{{- include "pokeshop-demo.worker.selectorLabels" . | nindent 8 }}
{{- include "pokeshop-demo.queueworker.selectorLabels" . | nindent 8 }}
spec:
containers:
- name: pokeshop-worker
Expand All @@ -23,7 +23,7 @@ spec:
containerPort: 80
protocol: TCP
resources:
{{- toYaml .Values.pokeshop.resources | nindent 12 }}
{{- toYaml .Values.pokeshop.queueworker.resources | nindent 12 }}
env:
- name: NPM_RUN_COMMAND
value: worker
Expand Down
4 changes: 2 additions & 2 deletions charts/pokeshop-demo/templates/deployment.stream.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ metadata:
labels:
{{- include "pokeshop-demo.stream.labels" . | nindent 4 }}
spec:
replicas: {{ .Values.pokeshop.replicaCount }}
replicas: {{ .Values.pokeshop.stream.replicaCount }}
selector:
matchLabels:
{{- include "pokeshop-demo.stream.selectorLabels" . | nindent 6 }}
Expand All @@ -26,7 +26,7 @@ spec:
name: controller
protocol: TCP
resources:
{{- toYaml .Values.pokeshop.resources | nindent 12 }}
{{- toYaml .Values.pokeshop.stream.resources | nindent 12 }}
env:
- name: KAFKA_ADVERTISED_LISTENERS
value: PLAINTEXT://stream.{{ .Release.Namespace }}:9092
Expand Down
36 changes: 36 additions & 0 deletions charts/pokeshop-demo/templates/deployment.streamworker.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ include "pokeshop-demo.fullname" . }}-streamworker
labels:
{{- include "pokeshop-demo.streamworker.labels" . | nindent 4 }}
spec:
replicas: {{ .Values.pokeshop.streamworker.replicaCount }}
selector:
matchLabels:
{{- include "pokeshop-demo.streamworker.selectorLabels" . | nindent 6 }}
template:
metadata:
labels:
{{- include "pokeshop-demo.streamworker.selectorLabels" . | nindent 8 }}
spec:
containers:
- name: pokeshop-stream-worker
image: "{{ .Values.pokeshop.image.repository }}:{{ .Values.pokeshop.image.tag }}"
imagePullPolicy: {{ .Values.pokeshop.image.pullPolicy }}
ports:
- name: http
containerPort: 80
protocol: TCP
resources:
{{- toYaml .Values.pokeshop.streamworker.resources | nindent 12 }}
env:
- name: NPM_RUN_COMMAND
value: stream-worker
- name: SERVICE_NAME
value: pokeshop-stream-worker
- name: KAFKA_BROKER
value: stream:9092
- name: KAFKA_TOPIC
value: pokeshop
{{- toYaml .Values.pokeshop.env | nindent 12 }}
6 changes: 4 additions & 2 deletions charts/pokeshop-demo/templates/ingressroute.api.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{{- if .Values.pokeshop.ingress.enabled -}}
---
apiVersion: traefik.io/v1alpha1
kind: IngressRoute
Expand All @@ -8,7 +9,7 @@ spec:
- websecure
routes:
- kind: Rule
match: Host(`{{ .Values.hostname }}`)
match: Host(`{{ .Values.pokeshop.ingress.hostname }}`)
services:
- kind: Service
name: {{ include "pokeshop-demo.fullname" . }}-api
Expand All @@ -24,10 +25,11 @@ spec:
- websecure
routes:
- kind: Rule
match: Host(`{{ .Values.hostname }}`) && Headers(`Content-Type`, `application/grpc`)
match: Host(`{{ .Values.pokeshop.ingress.hostname }}`) && Headers(`Content-Type`, `application/grpc`)
services:
- kind: Service
name: {{ include "pokeshop-demo.fullname" . }}-api
passHostHeader: true
port: grpc
scheme: h2c
{{- end }}
16 changes: 3 additions & 13 deletions charts/pokeshop-demo/templates/ingressroute.collector.yaml
Original file line number Diff line number Diff line change
@@ -1,13 +1,4 @@
# ---
# apiVersion: traefik.io/v1alpha1
# kind: Middleware
# metadata:
# name: {{ include "pokeshop-demo.fullname" . }}-otel-collector-stripprefix
# spec:
# stripPrefix:
# prefixes:
# - /otc
# ---
{{- if .Values.pokeshop.ingress.enabled -}}
apiVersion: traefik.io/v1alpha1
kind: IngressRoute
metadata:
Expand All @@ -17,11 +8,10 @@ spec:
- websecure
routes:
- kind: Rule
match: Host(`{{ .Values.hostname }}`) && PathPrefix(`/v1/traces`)
match: Host(`{{ .Values.pokeshop.ingress.hostname }}`) && PathPrefix(`/v1/traces`)
services:
- kind: Service
name: {{ .Release.Name }}-opentelemetry-collector
passHostHeader: true
port: otlp-http
# middlewares:
# - name: {{ include "pokeshop-demo.fullname" . }}-otel-collector-stripprefix
{{- end }}
25 changes: 20 additions & 5 deletions charts/pokeshop-demo/values.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
hostname: pokeshop.localdev

pokeshop:
image:
repository: kubeshop/demo-pokemon-api
Expand All @@ -11,7 +9,25 @@ pokeshop:
port: 80
rpcPort: 8082

replicaCount: 1
# This chart requires Traefik to be installed on the cluster. If you don't have Traefik installed
# and don't want to install it, make sure to set `ingress.enabled` as `false`. Otherwise, the installation
# will fail.
ingress:
enabled: false
hostname: pokeshop.localdev

api:
resources: {}
replicaCount: 1
queueworker:
resources: {}
replicaCount: 1
stream:
resources: {}
replicaCount: 1
streamworker:
resources: {}
replicaCount: 1

env:
- name: COLLECTOR_ENDPOINT
Expand Down Expand Up @@ -65,7 +81,6 @@ opentelemetry-collector:
image:
repository: "otel/opentelemetry-collector-contrib"


ports:
otlp:
enabled: true
Expand Down Expand Up @@ -96,7 +111,7 @@ opentelemetry-collector:
http:
cors:
allowed_origins:
- "https://*.tracetest.io"
- "*"

processors:
batch:
Expand Down
18 changes: 18 additions & 0 deletions scripts/setup_demo_on_kind_cluster.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/usr/bin/env bash

set -e

export KUBECONFIG=$KUBECONFIG:$(pwd)/tracetest.kubeconfig
kubectl config use-context kind-tracetest

PROJECT_ROOT=$(dirname "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)")

printf "\n\e[42m\e[1mInstalling Pokeshop demo\e[0m\e[0m\n"
helm upgrade --install ttdemo -n demo --create-namespace $PROJECT_ROOT/charts/pokeshop-demo -f $PROJECT_ROOT/values-kind-demo.yaml

printf "\n\e[42m\e[1mConfiguring CoreDNS\e[0m\e[0m\n"
hosts=(tracetest.localdev)
hosts+=(pokeshop.localdev)

$PROJECT_ROOT/scripts/coredns_config.sh ttdeps-traefik.default.svc.cluster.local "${hosts[@]}"
printf "\n"
4 changes: 4 additions & 0 deletions values-kind-demo.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
pokeshop:
ingress:
enabled: true

opentelemetry-collector:
config:
receivers:
Expand Down

0 comments on commit b733921

Please sign in to comment.