Commit c864ea3
feat: Deco CRD and BuildReconciler for cfworkers (#5)
* feat: add DecoBuild CRD and BuildReconciler for cfworkers builds
- DecoBuild CRD: represents a cfworkers build request; operator creates K8s Jobs
- BuildReconciler: watches DecoBuild, generates S3 presigned URLs, creates Job
- build/job.go: Job spec builder (cfworkers-builder image, env vars, TTL 24h)
- build/s3presign.go: generates presigned URLs for logs/cache using aws-sdk-go-v2
- RBAC: batch/jobs + deco.sites/decobuilds permissions
- Chart bumped to v0.3.0; cfworkers env vars injected from ExternalSecret
* chore: go mod tidy — add aws-sdk-go-v2 go.sum entries
* fix: gofmt formatting in build/job.go constants
* fix: wire DecoBuild CRD and cfworkers env vars into Helm generator
- Add deco.sites_decobuilds.yaml to config/crd/kustomization.yaml so helm-generator picks it up
- Add cfworkers env vars block to helm-generator addEnvVarsToDeployment
- Regenerate chart templates via make manifests helm
* feat: replace DecoBuild CRD with Deco CR for cfworkers builds and previews
Replaces the per-build DecoBuild CRD with a site-scoped Deco CR that owns
both production and preview builds. The operator reconciles spec.build.source
for production deploys and spec.previews.active[] for concurrent PR previews,
fixing the concurrent PR overwrite bug.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
* fix: also set WORKER_NAME env var for backwards compat with existing builder images
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
* revert: remove WORKER_NAME backwards compat, use DECO_SITE_NAME only
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
* chore: remove DecoBuild CRD — using Deco CR directly for cfworkers builds
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
* refactor(operator): decouple reconciler from cfworkers via JobFactory
The DecoReconciler no longer holds cfworkers-specific credentials
(CfApiToken, CfAccountId, S3Config). A JobFactory function type is
injected at startup, keeping the reconciler platform-agnostic. Future
serving types just need a new factory wired in main.go.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
* refactor(operator): move platform-specific constants into JobFactory
BuilderImage, TTLSeconds, LogsBucket and CacheBucket are now fields on
JobOpts/S3Config instead of hardcoded constants. The cfworkers factory in
main.go owns these values. spec.build.builder in the CR still takes
precedence over the platform default for BuilderImage.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
* refactor(operator): support multiple serving types via factory registry
Replace single JobFactory field with Factories map[string]JobFactory keyed
by spec.serving.type. createJob looks up the factory by type and returns an
error for unknown types. A new platform just registers its factory in main.go.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
* rename: JobOpts → CfWorkersJobOpts, NewJob → NewCfWorkersJob
Makes the cfworkers-specific types explicit in the build package so future
platforms can add their own types alongside without ambiguity.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
* refactor(operator): introduce build.Registry for platform dispatch
Move serving-type dispatch out of the controller into build.Registry.
The controller now holds a *build.Registry and calls registry.NewJob()
without knowing about platforms. New platforms register via registry.Register()
in main.go.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
* rename: build/job.go → build/cfworkers.go
Clarifies that this file is cfworkers-specific. Generic build helpers
(registry, s3presign) stay at the package level; platform-specific
implementations get their own file.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
* chore: bump version to 0.2.7
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
* chore: revert version to 0.2.6
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
* chore: move s3Region from values to secret
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
* feat: add cfworkers build duration and count metrics
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
* fix: address CI lint failures and move S3_REGION to secretKeyRef
- Fix goconst: extract Succeeded/Failed as constants
- Fix prealloc: pre-allocate newStatuses slice
- Fix lll: break long factory func signature in cmd/main.go
- Fix helm-generator to emit S3_REGION as secretKeyRef (key: s3-region)
- Regenerate CRD template (alphabetical field ordering from controller-gen)
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
* fix: pin CRD plural to 'decos' via +kubebuilder:resource:path=decos
Without this annotation controller-gen auto-pluralises 'Deco' as 'decoes',
creating a second deco.sites_decoes.yaml alongside the committed
deco.sites_decos.yaml. envtest loads every yaml in config/crd/bases/ so
both CRDs were registered, causing the BeforeSuite context deadline timeout.
Also regenerates deco.sites_decos.yaml from current types (updated schema,
alphabetical field ordering, adds previews/branchRef fields).
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
* chore: regenerate helm chart CRD template from updated deco.sites_decos.yaml
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
* refactor(build): replace Factory func type with Builder interface
* feat(build): add CfWorkersConfig, cfWorkersBuilder, NewCloudflareFactory
* refactor(controller): hold build.Builder interface; update default bucket names
* refactor(main): remove CF/S3 specifics — wire via build.NewCloudflareFactory
* refactor(build): unexport internal types NewCfWorkersJob, CfWorkersJobOpts, PresignedURLs, GeneratePresignedURLs
* refactor(build): remove defaults test — buckets are env-configurable
* chore: remove cfworkers_test.go — follow-up PR
* refactor(build): remove hardcoded default bucket/image names — repo is public
* feat(helm): move S3_REGION to values; add builderImage, s3LogsBucket, s3CacheBucket as plain values
* refactor(helm): split S3 into dedicated s3.existingSecret — shared across build platforms
* refactor(build): rename Registry to BuilderRegistry for clarity
* fix(build): update compile-time check to BuilderRegistry after rename
* feat(crd): add envs and secrets fields to DecoSpecBuild for custom Job env injection
* refactor(build): read envs/secrets directly from Deco spec in newCfWorkersJob
* fix(build): prealloc envFrom, make TTLSecondsAfterFinished configurable via CRD (default 10m)
* fix(build): fix prealloc lint — use make+index instead of make+append for envFrom
* refactor(s3): rename cacheBucket to artifactsBucket — build artifacts not just npm cache
* chore: remove values-local.yaml from .gitignore
* refactor: move artifactsBucket from s3 to cfworkers in chart values
artifactsBucket is platform-specific (Cloudflare Workers), not shared S3
infrastructure, so it belongs under the cfworkers section.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
* fix: use Status().Patch() to avoid optimistic concurrency conflicts on status update
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
* fix: resolve helm-verify and lint CI failures
- Regenerate CRDs with controller-gen v0.18.0 to match Makefile pin
- Fix gofmt: remove extra alignment spaces in cfworkers.go
- Add phaseRunning constant; replace all "Running" literals in deco_controller
- Add condTypePodsNotified constant in decofile_controller
- Add metricsNamespace/metricsSubsystemValkey constants in metrics.go
- Add valkeyReservedDefault constant in namespace_controller
- Exclude test files from goconst in .golangci.yml
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
---------
Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>1 parent 99217c4 commit c864ea3
23 files changed
Lines changed: 1992 additions & 28 deletions
File tree
- api/v1alpha1
- chart
- templates
- cmd
- config
- crd
- bases
- rbac
- hack/helm-generator
- internal
- build
- controller
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
22 | 22 | | |
23 | 23 | | |
24 | 24 | | |
| 25 | + | |
| 26 | + | |
25 | 27 | | |
26 | 28 | | |
27 | 29 | | |
| |||
36 | 38 | | |
37 | 39 | | |
38 | 40 | | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
39 | 44 | | |
40 | 45 | | |
41 | 46 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
0 commit comments