Mini Project: A Golden Path for linkly-style Services
The course's milestone project: a golden-path template that creates a new linkly-style service with its pipeline, chart, GitOps entry, dashboards and SLOs, plus the scaffolder that runs it and the template's own CI that proves the result works. It packages what the Capstone built by hand for one service, so the next service takes minutes.
Requirements
- Inputs are few and validated: name (a DNS label), owner (an existing team), SLO target in [90, 100), plus description, system, port and cost center (Rendering a Golden Path).
- One run produces:
- a service repository with
catalog-info.yaml(owner, system, TechDocs, golden-path version), a CI workflow that calls the platform's reusable workflow, a Helm chart (Deployment with probes and a hardened security context, Service, Gateway API HTTPRoute, PodDisruptionBudget, ServiceMonitor, PrometheusRule with SLO recording rules and a burn-rate alert), a RED dashboard, TechDocs pages (overview and a runbook entry for the alert) and.golden-path.yaml; - a GitOps entry: Argo CD Applications for staging and production on a branch of
platform-deploy, to be opened as a pull request (GitOps: promotion).
- a service repository with
- Derived values are computed once in the scaffolder (the alert name prefix, the fast-burn threshold
14.4 × (1 − SLO), see SRE: multiwindow alerts), so templates stay free of logic. - Pods carry cost labels (
team,cost-center) through a Helm helper (OpenCost). - The template is tested: render it with sample answers and check no placeholders are left,
helm lint, kubeconform in strict mode for the chart (including the Gateway API and Prometheus Operator kinds) and the Argo CD Applications, the dashboard JSON, the catalog owner, the cost labels and the docs navigation.
Try building it yourself first. The session below is one complete solution, in three parts: the template repository, the scaffolder, and the template's CI.
The template
text
golden-go-service/ (tag v1.0.0)
├── render.sh ${{ values.x }} in contents and paths
└── skeleton/
├── catalog-info.yaml
├── .github/workflows/ci.yaml calls acme/platform-workflows/...@v4
├── mkdocs.yml, docs/{index,runbook}.md
├── monitoring/dashboard.json
├── chart/${{ values.name }}/ Chart, values, _helpers, deployment, service (+route, PDB), monitoring
└── gitops/apps/${{ values.name }}/{staging,production}/application.yamlThe session
bash · try it yourself
# ============ 1. the template repository (owned by the platform team) ============
T=golden-go-service/skeleton
mkdir -p $T/.github/workflows $T/docs $T/monitoring "$T/chart/\${{ values.name }}/templates" \
"$T/gitops/apps/\${{ values.name }}"/{staging,production}
cat > $T/catalog-info.yaml <<'EOF'
apiVersion: backstage.io/v1alpha1
kind: Component
metadata:
name: ${{ values.name }}
description: ${{ values.description }}
annotations:
github.com/project-slug: acme/${{ values.name }}
backstage.io/techdocs-ref: dir:.
acme.io/golden-path: go-service@${{ values.templateVersion }}
spec:
type: service
lifecycle: experimental
owner: group:${{ values.owner }}
system: ${{ values.system }}
EOF
cat > $T/.github/workflows/ci.yaml <<'EOF'
name: ci
on:
push: {branches: [main]}
pull_request:
permissions: {contents: read, id-token: write, packages: write}
jobs:
go-service:
uses: acme/platform-workflows/.github/workflows/go-service.yaml@v4
with:
image: ghcr.io/acme/${{ values.name }}
chart: chart/${{ values.name }}
gitops-path: apps/${{ values.name }}/staging
tag: ${{ github.sha }}
EOF
cat > $T/mkdocs.yml <<'EOF'
site_name: ${{ values.name }}
nav: [{Overview: index.md}, {Runbook: runbook.md}]
plugins: [techdocs-core]
EOF
printf '# ${{ values.name }}\n\n${{ values.description }}\n\nOwner: ${{ values.owner }}. SLO: ${{ values.sloTarget }}%% of requests succeed over 30 days.\n' > $T/docs/index.md
printf '# Runbook\n\n## ${{ values.alertPrefix }}ErrorBudgetBurn\n\nThe service is burning its error budget too fast. Check the dashboard, recent deploys (Argo CD), then dependencies.\n' > $T/docs/runbook.md
C="$T/chart/\${{ values.name }}"
cat > "$C/Chart.yaml" <<'EOF'
apiVersion: v2
name: ${{ values.name }}
description: ${{ values.description }}
version: 0.1.0
appVersion: "0.1.0"
EOF
cat > "$C/values.yaml" <<'EOF'
image: {repository: ghcr.io/acme/${{ values.name }}, tag: ""}
replicaCount: 2
port: ${{ values.port }}
host: ${{ values.name }}.example.com
resources:
requests: {cpu: 50m, memory: 64Mi}
limits: {memory: 128Mi}
labels: {team: ${{ values.owner }}, cost-center: ${{ values.costCenter }}}
slo: {target: ${{ values.sloTarget }}}
EOF
cat > "$C/templates/_helpers.tpl" <<'EOF'
{{- define "svc.selector" -}}
app.kubernetes.io/name: {{ .Chart.Name }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end }}
{{- define "svc.labels" -}}
{{ include "svc.selector" . }}
app.kubernetes.io/version: {{ .Values.image.tag | default .Chart.AppVersion | quote }}
{{- range $k, $v := .Values.labels }}
{{ $k }}: {{ $v }}
{{- end }}
{{- end }}
EOF
cat > "$C/templates/deployment.yaml" <<'EOF'
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ .Release.Name }}
labels: {{- include "svc.labels" . | nindent 4 }}
spec:
replicas: {{ .Values.replicaCount }}
selector:
matchLabels: {{- include "svc.selector" . | nindent 6 }}
template:
metadata:
labels: {{- include "svc.labels" . | nindent 8 }}
spec:
securityContext: {runAsNonRoot: true, seccompProfile: {type: RuntimeDefault}}
containers:
- name: app
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
ports: [{name: http, containerPort: {{ .Values.port }}}]
readinessProbe: {httpGet: {path: /readyz, port: http}}
livenessProbe: {httpGet: {path: /healthz, port: http}}
resources: {{- toYaml .Values.resources | nindent 12 }}
securityContext: {allowPrivilegeEscalation: false, readOnlyRootFilesystem: true, capabilities: {drop: [ALL]}}
EOF
cat > "$C/templates/service.yaml" <<'EOF'
apiVersion: v1
kind: Service
metadata:
name: {{ .Release.Name }}
labels: {{- include "svc.labels" . | nindent 4 }}
spec:
selector: {{- include "svc.selector" . | nindent 4 }}
ports: [{name: http, port: 80, targetPort: http}]
---
apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
name: {{ .Release.Name }}
labels: {{- include "svc.labels" . | nindent 4 }}
spec:
parentRefs: [{name: public, namespace: gateway-system}]
hostnames: [{{ .Values.host }}]
rules: [{backendRefs: [{name: {{ .Release.Name }}, port: 80}]}]
---
apiVersion: policy/v1
kind: PodDisruptionBudget
metadata:
name: {{ .Release.Name }}
labels: {{- include "svc.labels" . | nindent 4 }}
spec:
maxUnavailable: 1
selector:
matchLabels: {{- include "svc.selector" . | nindent 6 }}
EOF
cat > "$C/templates/monitoring.yaml" <<'EOF'
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
name: {{ .Release.Name }}
labels: {{- include "svc.labels" . | nindent 4 }}
spec:
selector:
matchLabels: {{- include "svc.selector" . | nindent 6 }}
endpoints: [{port: http, path: /metrics}]
---
apiVersion: monitoring.coreos.com/v1
kind: PrometheusRule
metadata:
name: {{ .Release.Name }}-slo
labels: {{- include "svc.labels" . | nindent 4 }}
spec:
groups:
- name: {{ .Release.Name }}-slo
rules:
- record: job:slo_errors_per_request:ratio_rate5m
expr: sum by (job) (rate(http_requests_total{job="{{ .Release.Name }}",code=~"5.."}[5m])) / sum by (job) (rate(http_requests_total{job="{{ .Release.Name }}"}[5m]))
- record: job:slo_errors_per_request:ratio_rate1h
expr: sum by (job) (rate(http_requests_total{job="{{ .Release.Name }}",code=~"5.."}[1h])) / sum by (job) (rate(http_requests_total{job="{{ .Release.Name }}"}[1h]))
- alert: ${{ values.alertPrefix }}ErrorBudgetBurn
expr: job:slo_errors_per_request:ratio_rate1h{job="{{ .Release.Name }}"} > ${{ values.fastBurnThreshold }} and job:slo_errors_per_request:ratio_rate5m{job="{{ .Release.Name }}"} > ${{ values.fastBurnThreshold }}
labels: {severity: page, team: ${{ values.owner }}}
annotations:
summary: {{ .Release.Name }} is burning its {{ .Values.slo.target }}% error budget 14.4x too fast
runbook_url: https://backstage.example.com/docs/default/component/{{ .Chart.Name }}/runbook/
EOF
cat > $T/monitoring/dashboard.json <<'EOF'
{
"title": "${{ values.name }} (RED)",
"uid": "${{ values.name }}-red",
"tags": ["golden-path", "${{ values.owner }}"],
"panels": [
{"type": "timeseries", "title": "Requests/s",
"targets": [{"expr": "sum(rate(http_requests_total{job=\"${{ values.name }}\"}[5m]))"}]},
{"type": "timeseries", "title": "Error ratio",
"targets": [{"expr": "job:slo_errors_per_request:ratio_rate5m{job=\"${{ values.name }}\"}"}]},
{"type": "timeseries", "title": "p99 latency",
"targets": [{"expr": "histogram_quantile(0.99, sum by (le) (rate(http_request_duration_seconds_bucket{job=\"${{ values.name }}\"}[5m])))"}]}
]
}
EOF
G="$T/gitops/apps/\${{ values.name }}"
for env in staging production; do
cat > "$G/$env/application.yaml" <<'EOF'
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
name: ${{ values.name }}-ENV
namespace: argocd
labels: {team: ${{ values.owner }}}
spec:
project: ${{ values.owner }}
source:
repoURL: https://github.com/acme/${{ values.name }}.git
targetRevision: main
path: chart/${{ values.name }}
helm:
valueFiles: [values.yaml]
parameters: [{name: image.tag, value: "0.1.0"}]
destination:
server: https://kubernetes.default.svc
namespace: ${{ values.owner }}
syncPolicy:
automated: {prune: true, selfHeal: true}
EOF
sed -i "s/-ENV/-$env/" "$G/$env/application.yaml"
done
cat > golden-go-service/render.sh <<'EOF'
#!/bin/bash
# usage: render.sh <skeleton-dir> <values.yaml> <out-dir>: replaces ${{ values.x }} in file contents and paths
set -euo pipefail
script=$(mktemp)
yq -o=props "$2" | sed -E 's/^([^ ]+) = (.*)$/s|\\$\\{\\{ values.\1 \\}\\}|\2|g/' > "$script"
(cd "$1" && find . -type f) | sort | while read -r f; do
out="$3/$(echo "$f" | sed -E -f "$script")"
mkdir -p "$(dirname "$out")" && sed -E -f "$script" "$1/$f" > "$out"
done
rm "$script"
EOF
chmod +x golden-go-service/render.sh
(cd golden-go-service && git init -q && git add . && git commit -qm "go-service golden path" && git tag v1.0.0)
git init -q platform-deploy && mkdir platform-deploy/apps && touch platform-deploy/apps/.keep
(cd platform-deploy && git add . && git commit -qm "platform-deploy")
# ============ 2. the scaffolder (what the portal's Create button runs) ============
cat > golden-path.sh <<'EOF'
#!/bin/bash
# usage: golden-path.sh <answers.yaml>
set -euo pipefail
a=$1 version=v1.0.0 fail=0
err() { echo " invalid: $1"; fail=1; }
name=$(yq '.name' "$a") owner=$(yq '.owner' "$a") slo=$(yq '.sloTarget' "$a")
[[ $name =~ ^[a-z][a-z0-9-]{1,28}[a-z0-9]$ ]] || err "name '$name' is not a lowercase DNS label"
grep -qx "$owner" teams.txt || err "owner '$owner' is not a team"
awk -v s="$slo" 'BEGIN { exit !(s >= 90 && s < 100) }' || err "sloTarget '$slo' must be in [90, 100)"
if [ $fail -ne 0 ]; then echo "rejected $a"; exit 1; fi
# derived values, computed once so the templates stay simple
work=$(mktemp -d)
prefix=$(echo "$name" | sed -E 's/(^|-)([a-z])/\U\2/g')
burn=$(awk -v s="$slo" 'BEGIN { printf "%g", 14.4 * (100 - s) / 100 }')
yq ". + {\"templateVersion\": \"$version\", \"alertPrefix\": \"$prefix\", \"fastBurnThreshold\": \"$burn\"}" "$a" > "$work/values.yaml"
git clone -q --depth 1 --branch "$version" "file://$PWD/golden-go-service" "$work/tpl"
"$work/tpl/render.sh" "$work/tpl/skeleton" "$work/values.yaml" "$work/out"
# the service repository: everything except gitops/
mkdir "$name"
(cd "$work/out" && tar --exclude=./gitops -cf - .) | tar -xf - -C "$name"
{ printf 'template: golden-go-service\nversion: %s\nanswers:\n' "$version"; sed 's/^/ /' "$a"; } > "$name/.golden-path.yaml"
git -C "$name" init -q && git -C "$name" add . && git -C "$name" commit -qm "Scaffold $name from golden-go-service $version"
# the GitOps entry: a branch in platform-deploy, opened as a pull request
git -C platform-deploy switch -q -c "add-$name"
cp -r "$work/out/gitops/apps/$name" platform-deploy/apps/
git -C platform-deploy add . && git -C platform-deploy commit -qm "Add $name to staging and production"
git -C platform-deploy switch -q main
rm -rf "$work"
echo "created $name (alerts: ${prefix}ErrorBudgetBurn at error ratio > $burn)"
EOF
chmod +x golden-path.sh
printf 'team-growth\nteam-links\n' > teams.txt
cat > bad.yaml <<'EOF'
name: Short_Links
owner: growth
sloTarget: 100
EOF
cat > shortlinks.yaml <<'EOF'
name: shortlinks
description: Short links for marketing campaigns
owner: team-growth
system: links
costCenter: cc-4410
port: 8080
sloTarget: 99.9
EOF
./golden-path.sh bad.yaml || true
./golden-path.sh shortlinks.yaml
printf 'name: url-checker
owner: team-links
system: links
description: Checks short-link targets
costCenter: cc-4420
port: 8080
sloTarget: 99.5
' > url-checker.yaml
./golden-path.sh url-checker.yaml
tree -a --noreport -I .git shortlinks
git -C shortlinks log --oneline
git -C platform-deploy log --oneline add-shortlinks
git -C platform-deploy branch --list
git -C platform-deploy diff --stat main add-shortlinks
# ============ 3. the template's own CI: is the result a working service? ============
check() {
if out=$(bash -c "$2" 2>&1); then echo "PASS $1${out:+: $out}"; else echo "FAIL $1"; echo "$out" | sed 's/^/ /'; fi
}
git -C platform-deploy switch -q add-shortlinks
check "no placeholders left" "! grep -rn '\${{ values' shortlinks platform-deploy/apps"
check "helm lint" "helm lint shortlinks/chart/shortlinks > /dev/null"
check "chart manifests (strict)" "helm template shortlinks shortlinks/chart/shortlinks --set image.tag=0.1.0 | kubeconform -n 1 -strict -summary"
check "Argo CD Applications" "kubeconform -n 1 -strict -summary platform-deploy/apps/shortlinks/*/application.yaml"
check "dashboard" "jq -er '.panels | length | tostring + \" panels\"' shortlinks/monitoring/dashboard.json"
check "catalog owner" "yq -e '.spec.owner' shortlinks/catalog-info.yaml"
check "cost labels on Pods" "helm template shortlinks shortlinks/chart/shortlinks | yq -e 'select(.kind == \"Deployment\") | .spec.template.metadata.labels | (has(\"team\") and has(\"cost-center\"))'"
check "docs nav" "for p in \$(yq '.nav[] | .[]' shortlinks/mkdocs.yml); do test -f shortlinks/docs/\$p || { echo missing \$p; exit 1; }; done"
echo "--- the SLO alert, as rendered:"
helm template shortlinks shortlinks/chart/shortlinks | yq 'select(.kind == "PrometheusRule") | .spec.groups[0].rules[2] | {"alert": .alert, "expr": .expr, "summary": .annotations.summary}' invalid: name 'Short_Links' is not a lowercase DNS label
invalid: owner 'growth' is not a team
invalid: sloTarget '100' must be in [90, 100)
rejected bad.yaml
created shortlinks (alerts: ShortlinksErrorBudgetBurn at error ratio > 0.0144)
created url-checker (alerts: UrlCheckerErrorBudgetBurn at error ratio > 0.072)
shortlinks
├── .github
│ └── workflows
│ └── ci.yaml
├── .golden-path.yaml
├── catalog-info.yaml
├── chart
│ └── shortlinks
│ ├── Chart.yaml
│ ├── templates
│ │ ├── _helpers.tpl
│ │ ├── deployment.yaml
│ │ ├── monitoring.yaml
│ │ └── service.yaml
│ └── values.yaml
├── docs
│ ├── index.md
│ └── runbook.md
├── mkdocs.yml
└── monitoring
└── dashboard.json
699e202 Scaffold shortlinks from golden-go-service v1.0.0
959398b Add shortlinks to staging and production
a0a91b0 platform-deploy
add-shortlinks
add-url-checker
* main
apps/shortlinks/production/application.yaml | 20 ++++++++++++++++++++
apps/shortlinks/staging/application.yaml | 20 ++++++++++++++++++++
2 files changed, 40 insertions(+)
PASS no placeholders left
PASS helm lint
PASS chart manifests (strict): Summary: 6 resources found parsing stdin - Valid: 6, Invalid: 0, Errors: 0, Skipped: 0
PASS Argo CD Applications: Summary: 2 resources found in 2 files - Valid: 2, Invalid: 0, Errors: 0, Skipped: 0
PASS dashboard: 3 panels
PASS catalog owner: group:team-growth
PASS cost labels on Pods: true
PASS docs nav
--- the SLO alert, as rendered:
alert: ShortlinksErrorBudgetBurn
expr: job:slo_errors_per_request:ratio_rate1h{job="shortlinks"} > 0.0144 and job:slo_errors_per_request:ratio_rate5m{job="shortlinks"} > 0.0144
summary: shortlinks is burning its 99.9% error budget 14.4x too fast
Walkthrough
- Validation first. The bad answers file fails on all three rules at once (the scaffolder collects errors instead of stopping at the first), and nothing is created.
- Derived values.
ShortlinksErrorBudgetBurnandUrlCheckerErrorBudgetBurncome from the names; the thresholds0.0144(99.9%) and0.072(99.5%) are14.4 × error budget, the 1-hour fast-burn rate from the SRE course. Teams never type a threshold. - Two repositories touched, one per concern. The service repo gets one commit with everything it needs;
platform-deploygets a branch per service, ready to be a pull request that the platform's policies and reviewers check before Argo CD creates the Applications. - Three template languages, no collisions.
${{ values.* }}was replaced at scaffold time; Helm's{{ .Release.Name }}stayed for deploy time; GitHub's${{ github.sha }}stayed for CI time. The placeholder check looks only for${{ values. - The checks are the template's CI. Run them on every change to the template, with a few sample answer files (a short name, a long one, the strictest SLO), and the template can't ship a broken chart. Add a real
helm installinto an ephemeral cluster (kind, vcluster) when you have one.
Making it real
| Session piece | In production |
|---|---|
golden-path.sh |
a Backstage template: parameters with the same rules, fetch:template for ./skeleton, publish:github, publish:github:pull-request for gitops/, catalog:register (Software Templates); or the same script as a workflow_dispatch job |
teams.txt |
groups from the catalog (OwnerPicker) or the identity provider |
a branch in platform-deploy |
a pull request with an AppProject-scoped Application, checked by policy (Secrets & Policy) |
sed rendering |
Nunjucks in Backstage, or Copier/cookiecutter (Jinja2) |
.golden-path.yaml |
the base for automated update PRs (Keeping Services in Step) |
Extensions
- Add a database option. A
database: none|postgresanswer that adds aDatabaserequest (the XR from XRDs & Compositions) to the GitOps entry and an External Secret reference to the chart. - Ship v1.1.0 of the template (say, a NetworkPolicy and a latency SLO) and update
shortlinkswith the three-way merge from Keeping Services in Step. - Scorecard the result. Run the scorecards fact collector on the generated service: it should pass most checks on day one. The ones it fails (an on-call annotation, a real runbook) are the ones only the team can add, so the template's docs should say so.
- Measure it. Record each run's duration and the time to the first healthy deploy, and put both on the platform's KPI page (Platform KPIs).
Test yourself
Why does the scaffolder compute the burn-rate threshold instead of asking the team for it?
- Teams can't do arithmetic
- It is derived from the SLO target by a fixed rule; computing it once keeps the templates free of logic and the alerts consistent
- Helm can't render numbers
- Prometheus requires it
Why does the GitOps entry go to a branch of platform-deploy rather than straight to main?
- Git requires branches
- It becomes a pull request that reviewers and policy checks approve before Argo CD creates the Applications
- Argo CD only reads branches
- To save space
Which placeholders are left in the generated files on purpose?
- None
- Helm's
{{ .Release.Name }}and GitHub Actions'${{ github.sha }} ${{ values.name }}- All of them