Commit 2c79c83
committed
feat(defaults): implement hybrid defaulting strategy with deep resource validation
This commit introduces a robust defaulting mechanism that strictly separates
Admission (Webhook) concerns from Reconciliation (Controller) concerns, aligned
with the v1alpha1 design.
Key Changes:
- **pkg/defaults**:
- Added `constants.go` with hardcoded safety defaults for Resources (CPU/Mem), Storage (1Gi), and Images (using GHCR main).
- Implemented `PopulateClusterDefaults` in `resolver.go` for the Webhook. This applies strictly *inline* defaults and static values without fetching external templates, adhering to the design's "Non-Goal".
- Implemented `Resolve...` methods (e.g., `ResolveGlobalTopo`) for the Controller. These actively fetch templates, merge them with inline specs, and apply "Level 4" operator defaults to guarantee valid, runnable configs (preventing nil-pointer crashes).
- Added `resolver_test.go` with 100% coverage, using table-driven tests and `go-cmp` to verify deep defaulting logic and error wrapping.
- **pkg/cluster-handler**:
- Updated `multigrescluster_controller.go` to call `PopulateClusterDefaults` at the start of reconciliation. This ensures the controller operates on a valid state even if the admission webhook is disabled.
- Simplified reconciliation logic by relying on the Resolver's guarantee of non-nil resource specs.
- Updated all tests to ensure they are 100% coverage.1 parent 4952cc9 commit 2c79c83
File tree
6 files changed
+653
-421
lines changed- pkg
- cluster-handler/controller/multigrescluster
- defaults
6 files changed
+653
-421
lines changedLines changed: 38 additions & 7 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
| 22 | + | |
22 | 23 | | |
23 | 24 | | |
24 | 25 | | |
| |||
124 | 125 | | |
125 | 126 | | |
126 | 127 | | |
127 | | - | |
128 | | - | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
129 | 132 | | |
130 | 133 | | |
131 | 134 | | |
| |||
149 | 152 | | |
150 | 153 | | |
151 | 154 | | |
152 | | - | |
153 | | - | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
154 | 158 | | |
155 | 159 | | |
156 | 160 | | |
| |||
278 | 282 | | |
279 | 283 | | |
280 | 284 | | |
281 | | - | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
282 | 313 | | |
283 | 314 | | |
284 | 315 | | |
285 | 316 | | |
286 | | - | |
| 317 | + | |
287 | 318 | | |
288 | 319 | | |
289 | 320 | | |
290 | 321 | | |
291 | 322 | | |
292 | | - | |
| 323 | + | |
293 | 324 | | |
294 | 325 | | |
295 | 326 | | |
| |||
Lines changed: 40 additions & 41 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
71 | 71 | | |
72 | 72 | | |
73 | 73 | | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
74 | 77 | | |
75 | 78 | | |
76 | 79 | | |
| |||
171 | 174 | | |
172 | 175 | | |
173 | 176 | | |
| 177 | + | |
| 178 | + | |
174 | 179 | | |
175 | 180 | | |
176 | 181 | | |
| |||
180 | 185 | | |
181 | 186 | | |
182 | 187 | | |
183 | | - | |
184 | | - | |
185 | | - | |
186 | | - | |
187 | | - | |
| 188 | + | |
188 | 189 | | |
189 | 190 | | |
190 | | - | |
| 191 | + | |
191 | 192 | | |
192 | 193 | | |
193 | 194 | | |
| |||
214 | 215 | | |
215 | 216 | | |
216 | 217 | | |
| 218 | + | |
217 | 219 | | |
218 | | - | |
219 | | - | |
220 | | - | |
221 | | - | |
222 | | - | |
223 | | - | |
224 | | - | |
225 | | - | |
226 | | - | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
227 | 228 | | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
228 | 236 | | |
229 | | - | |
230 | | - | |
231 | | - | |
232 | | - | |
233 | | - | |
234 | | - | |
235 | | - | |
236 | | - | |
237 | | - | |
238 | | - | |
239 | | - | |
240 | | - | |
241 | | - | |
242 | | - | |
243 | | - | |
244 | | - | |
245 | | - | |
246 | | - | |
247 | | - | |
248 | | - | |
249 | | - | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
250 | 248 | | |
251 | | - | |
252 | 249 | | |
253 | | - | |
254 | | - | |
255 | | - | |
256 | | - | |
| 250 | + | |
| 251 | + | |
257 | 252 | | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
258 | 256 | | |
| 257 | + | |
259 | 258 | | |
260 | 259 | | |
261 | 260 | | |
| |||
0 commit comments