feat(kubernetes): define resource templates #138
No reviewers
Labels
No labels
Compat/Breaking
Kind/Bug
Kind/Documentation
Kind/Enhancement
Kind/Feature
Kind/Security
Kind/Testing
Priority
Critical
Priority
High
Priority
Low
Priority
Medium
Reviewed
Confirmed
Reviewed
Duplicate
Reviewed
Invalid
Reviewed
Won't Fix
Status
Abandoned
Status
Blocked
Status
Need More Info
No milestone
No project
No assignees
3 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
thwap/thwap-pagesd!138
Loading…
Reference in a new issue
No description provided.
Delete branch "feat/k8s-resource-templates"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
What
Define the Kubernetes resource templates in
internal/kubernetes/templates.go:nginx:alpineby default, configurable via newkubernetes.static_imageconfig) serving content from a shared volume mounted at/var/www/site. UsesemptyDiras the volume source for now; the storage task (#58) formalizes PVC and the production-version symlink.templates.go.app.kubernetes.io/name/app.kubernetes.io/instancelabels (also addresses the earlier review suggestion).Implements
PublishSite— creates or updates the Deployment, Service, and Ingress for a production site via generic upsert helpers (Deployment/Service now share the ingress create-or-update pattern).Config: added
kubernetes.static_image(defaultnginx:alpine).Tests: fake-clientset coverage for
PublishSite(image, port, mount path, service selector/port, ingress host), idempotent re-publish, and Deployment/Service template label/selector shapes.Why
Phase 4 task #55 — completes the Kubernetes integration layer;
PublishSiteis what the webhook receiver (#73) and site registration (#67) call.Testing
go build ./...go vet ./...go test -race ./internal/kubernetes/— 16 tests passgofmt -l ./cmd ./internal ./pkgcleangolangci-lint run— 0 issuesBreaking Changes
None.
Notes
emptyDirfor now; the storage task (#58) will wire PVC and the/var/www/sitesymlink.Closes #52
Closes #53
Closes #54
Closes #55
Review Summary
Verified locally on the PR head (
3b5e166):go build,go vet,go mod verify,gofmt(incl../pkg),golangci-lint runall clean; all 16 kubernetes tests pass with-race.The refactor is solid — generic
upsertDeployment/upsertServicemirror the ingress pattern,PublishSitecorrectly orders Deployment → Service → Ingress, selector/label wiring is consistent (service selector matches pod labels, deployment selector matches template labels), and thestatic_imageconfig is wired through with updated tests.Blocking Issue
internal/kubernetes/templates.go— the Deployment template mounts site content at/var/www/sitebut the default imagenginx:alpineserves its stock docroot/usr/share/nginx/html. The container spec has nocommand/argsand no ConfigMap mount to override the nginx config, so a site published with the default configuration will serve nginx's welcome page, not the site content. The mount path and the image's docroot simply don't line up.Fix options (one is enough):
/usr/share/nginx/htmlinstead of/var/www/site(if keeping stocknginx:alpine), orcommand) pointingrootat/var/www/site, orstatic_imagedefault to an image that serves/var/www/siteand document the contract.Task #52 is "Deployment template (static file server)" — with the default config this template doesn't actually serve the mounted content. If this serving arrangement is intentionally deferred to the storage task (#58), the mount path should at least match what the default image serves today.
Non-blocking Suggestions
tcpSocketon 80 would do.replicas: 1is hardcoded — already tracked by task #113 (configurable replicas). Fine for now.The blocking item is a small change to align the mount path with what the default image serves (or vice versa).
Review changes addressed in
6d71488:Blocking issue — the Deployment now ships an nginx ConfigMap (
nginxServerConfig) that pointsroot /var/www/site, mounted read-only over/etc/nginx/conf.d/default.confwithSubPath: default.conf.PublishSiteupserts the ConfigMap before the Deployment. Kept the/var/www/sitemount path per roadmap #57 (production-version symlink contract). Test extended to verify the ConfigMap data references the mount path and the config mount exists.Non-blocking #1 — added readiness and liveness
tcpSocketprobes on port 80 to the static container.Verified:
go build,go vet,gofmt,golangci-lint runclean; all 16 kubernetes tests pass with-race.Review Summary
The blocking issue from the previous review is resolved.
PublishSitenow upserts aConfigMap(nginxConfigMapTemplate) holding a server config withroot /var/www/site;andtry_files $uri $uri/ /index.html;, mounted over nginx's stock/etc/nginx/conf.d/default.conf(viaSubPath, read-only). The Deployment mount path now matches what the server actually serves, so a site published with the defaultnginx:alpineconfig will serve the site content.TestPublishSiteasserts the config references the mount path and that both the config volume and probes are wired.tcpSocketprobes on port 80, addressing the earlier suggestion.Verified locally on the PR head (
6d71488):go build,go vet,go mod verify,gofmt,golangci-lint runall clean; all 16 kubernetes tests pass with-race.No blocking issues.
Non-blocking observations:
SubPathmounts, so config changes won't hot-reload into running pods (requires a pod restart). Fine for a per-site static config, but worth knowing when the config becomes dynamic.Approving.