fix: address review findings on the conventions branch

- ci: reject a manual dispatch with tag "latest"; concurrency group per tag
- Dockerfile: declare GIT_COMMIT after the module download layer
- Makefile: docker-build targets linux/amd64 by default
- patch.go: no shared package-level pointers; main.go: no init()
- tests: assert that merge replaces managed listener content
- docs: flows.md startup section matches main.go; review saved to docs/reviews

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-08 20:43:02 +02:00
co-authored by Claude Opus 5.5
parent 8c074288c6
commit 60360ca5b9
10 changed files with 138 additions and 40 deletions
+22 -14
View File
@@ -35,27 +35,35 @@ Executed once at process start (`main.go`):
```
process start
│
├─ init() [main.go:22-26]
│ ├─ clientgoscheme.AddToScheme(scheme) # core/v1: Secrets, Events, …
│ ├─ cmv1.AddToScheme(scheme) # cert-manager.io/v1 Certificate
│ └─ gwapiv1.Install(scheme) # gateway.networking.k8s.io/v1 Gateway
│
└─ main() [main.go:28]
└─ main() [main.go:24]
│
├─ flag.StringVar --metrics-bind-address default ":8080" [main.go:32]
├─ flag.StringVar --health-probe-bind-address default ":8081" [main.go:33]
├─ flag.StringVar --metrics-bind-address default ":8080" [main.go:29]
├─ flag.StringVar --health-probe-bind-address default ":8081" [main.go:30]
├─ flag.BoolVar --version [main.go:31]
├─ zap.Options{Development: true, AddCaller}.BindFlags [main.go:32-33]
│ adds --zap-devel, --zap-encoder, --zap-log-level, …
├─ flag.Parse() [main.go:34]
│
├─ ctrl.SetLogger(zap, UseDevMode=true, AddCaller) [main.go:36-41]
│ dev-mode console logger with file:line call site
├─ --version ──► print version.Resolve(), return [main.go:36-39]
│ before any logger or cluster access
│
├─ scheme := runtime.NewScheme() [main.go:41-44]
│ ├─ clientgoscheme.AddToScheme(scheme) # core/v1: Secrets, Events, …
│ ├─ cmv1.AddToScheme(scheme) # cert-manager.io/v1 Certificate
│ └─ gwapiv1.Install(scheme) # gateway.networking.k8s.io/v1 Gateway
│
├─ ctrl.SetLogger(zap.New(zap.UseFlagOptions(&opts))) [main.go:46]
│ dev-mode console logger with file:line call site unless
│ --zap-devel=false is passed
├─ log "starting gateway-cert-operator" commit=… goVersion=… [main.go:48]
│
├─ ctrl.GetConfigOrDie() # KUBECONFIG or in-cluster config
│ on err ──► os.Exit(1)
│
├─ ctrl.NewManager(cfg, Options{Scheme, Metrics, HealthProbeBindAddress})
│ on err ──► log + os.Exit(1) [main.go:44-47]
│ on err ──► log + os.Exit(1) [main.go:50-54]
│
├─ controller.SetupCertificateReconciler(mgr) [main.go:53]
├─ controller.SetupCertificateReconciler(mgr) [main.go:60]
│ registers field index + watches (see §3)
│ on err ──► log + os.Exit(1)
│
@@ -63,7 +71,7 @@ process start
├─ mgr.AddReadyzCheck("readyz", healthz.Ping) → GET /readyz:8081
│ on err ──► log + os.Exit(1)
│
└─ mgr.Start(ctrl.SetupSignalHandler()) [main.go:68]
└─ mgr.Start(ctrl.SetupSignalHandler()) [main.go:75]
SetupSignalHandler installs SIGINT / SIGTERM cancel
mgr.Start blocks; on shutdown → graceful stop
on err ──► log + os.Exit(1)
@@ -479,7 +487,7 @@ Described in §6c. Drift in `Protocol`, `AllowedRoutes`, `TLS.Options`, or any `
Branch (F) of Reconcile treats all Gateway `Get` errors the same (including `NotFound`) and returns them as re-queue-able errors. A Certificate with a typo'd `gateway-name` annotation will retry with rate-limited backoff indefinitely, generating log noise and API load. There is no terminal failure path.
**6. No leader election**
`ctrl.NewManager` at `main.go:44` does not set `LeaderElection: true`. The `deploy/deployment_gateway-cert-operator.yaml` runs `replicas: 1` which makes this safe today. Scaling to multiple replicas without enabling leader election would result in concurrent Gateway patches.
`ctrl.NewManager` at `main.go:50` does not set `LeaderElection: true`. The `deploy/deployment_gateway-cert-operator.yaml` runs `replicas: 1` which makes this safe today. Scaling to multiple replicas without enabling leader election would result in concurrent Gateway patches.
**7. `listenerNameFor` edge cases**
- **Wildcard hostnames**: `*.example.com` produces `SectionName` `auto-…-*-example-com`. The `*` character is not valid in an RFC 1123 label; the Gateway API server will reject the Patch, causing an error-retry loop.
@@ -141,3 +141,15 @@ things could differ from egress on this repo's runner: `actions/setup-go@v5` (uh
had to install Go with curl instead), and lint is not part of the `check` job, same
as egress. The unused `GIT_TAG` and `BUILD_DATE` build args are gone;
`kubernetes-deploy.yaml` is untouched.
## Step 7 — Close out (review)
Ran both reviewer agents on `main...HEAD`; findings and their status are in
`docs/reviews/2026-10-08-2040-house-conventions.md`. Ten items fixed on the branch, four new
bugs deferred to the bug-fix phase, one test simplification declined.
Worth noting: the reviewer agents were not registered as agent types when the review
started (they were added in this session), so they were run as general-purpose
agents told to follow the agent files. The `:latest` dispatch hole came in with the
workflow copied from egress and is still open there. Step 7 stays unchecked until
the branch is pushed and the MR is open.
@@ -0,0 +1,56 @@
# Review: house conventions port
**Created:** 2026-10-08 20:40 CEST
**Scope:** `main...feat/house-conventions` at `8c07428` (7 commits)
**Reviewers:** `operator-reviewer`, `go-operator-reviewer`
Both reviewers ran `make check` and `go test -race ./...` (green) and confirmed the
branch changes no reconcile behaviour. No merge-blockers.
## Worth fixing
- [x] `build.yaml`: a manual dispatch with the default `tag: latest` overwrote
`:latest`, the tag the Deployment runs. Default removed; `latest` is rejected.
(Inherited from the egress workflow, which still has it.)
- [x] `Dockerfile`: `ARG GIT_COMMIT` sat above `go mod download`, so every commit
re-downloaded all modules. Moved to just above the build.
- [x] `patch_test.go`: `TestMergeListeners_ownership` compared names only; a
mutation that kept stale listener content passed. Added
`TestMergeListeners_replacesManagedContent`.
- [x] `make docker-build` followed the host architecture (arm64 on this Mac, where
the Dockerfile used to hard-code amd64). Now builds `linux/amd64` by default.
- [x] `docs/flows.md` §2 described the old `main.go` (line refs, hardcoded dev
logger, no `--version`). Rewritten against the current file.
- [x] `CLAUDE.md` overstated the reverse watch. Reworded.
- [x] `build.yaml`: two dispatches from the same ref shared a concurrency group and
cancelled each other. Group now includes the tag input.
## Simplifications
- [x] `patch.go`: package-level `tlsModeTerminate` / `namespacesFromAll` were shared
by address across every listener. Replaced with `ptrTo(...)`; `defaultPort` is a
const.
- [x] `main.go`: `init()` removed, scheme built in `main()` (CLAUDE.md says no
`init()`).
- [x] `Makefile` comment claimed the lint toolchain pin "matches CI"; CI does not
lint. Claim dropped.
- [ ] `TestListenerNameFor_sanitizesDots` tests an unexported helper and overlaps the
names table. Kept as the home for truncation and collision cases in the bug-fix
phase.
## Deferred to the bug-fix phase (new, not in the plan's backlog)
- [ ] Empty desired set: when a Gateway has only `auto-*` listeners and no cert
yields any, `MergeListeners` returns nil and the patch sends `listeners: null`,
which the API server rejects (`MinItems=1`). Permanent error requeue. Any fix for
"last cert deleted" runs straight into this. `patch.go` `MergeListeners`,
`certificate_controller.go:119-120`.
- [ ] Listeners are added before the Certificate is Ready, so they reference a
Secret that may not exist yet.
- [ ] ClusterRole grants `events` create/patch; nothing records events.
- [ ] CI `check` job has no golangci-lint and no `-race`. Needs a linter install
step on the runner (uh-cli does it from a pinned tarball).
## Nice-to-have
- [x] Assert the secret ref `Group` in `TestBuildListenersFromCertificates_listenerFields`.