Commit a634d60
authored
fix(memorystore): prevent infinite reconciliation drift loop by aligning connections list length (#11547)
### Why is this change necessary?
During E2E testing of network connectivity topologies, we observed that
`MemorystoreInstance` controllers can fall into an infinite
reconciliation loop due to false drift detection on the
`endpoints[i].connections` list.
Specifically:
- In the KRM spec (`desired`), a user defines the target VPC network(s)
under `spec.endpoints[i].connections` (typically 1 connection item
representing the intended PSC network target).
- Under the hood, GCP automatically allocates and returns **multiple**
server-generated connection entries per target network (e.g., one
connection per shard or node attachment).
- Because the GCP API returns an `actual` connections list that is
longer than the user's `desired` list, `tags.DiffForTopLevelFields`
flags the length mismatch as a drift. KCC repeatedly sends update
requests attempting to shrink the connections list, which GCP ignores,
resulting in an infinite reconciliation loop.
### What does this change do?
1. **Normalizes `Connections` list length before diffing
(`pkg/controller/direct/memorystore/memorystoreinstance_controller.go`)**:
Truncates the server-generated extra `Connections` in `maskedActual` to
match `len(desiredEndpoint.Connections)` before comparison
(`actualEndpoint.Connections =
actualEndpoint.Connections[:len(desiredEndpoint.Connections)]`).
- **Why truncating is correct and does not cause data loss**: Truncation
only applies to the temporary `maskedActual` copy used for drift
comparison against the user's `spec`. It does not discard any
user-configured target connections, nor does it affect the full observed
state reported in `status.endpoints`. It ensures we compare exactly the
user-declared intent (`desired`) against the corresponding actual
connection items without failing on extra server-created replica
entries.
2. **Prevents partial status overwrites
(`pkg/controller/direct/directbase/operations.go`)**:
Updates `directbase/operations.go` to prevent partial status updates
from overwriting existing status fields (such as `conditions` or
`externalRef`) with `nil`.
3. **Sorts HTTP logs in E2E tests**:
Aligns/sorts HTTP log entries for the `MemorystoreInstance` test
fixtures to prevent test flakiness.4 files changed
Lines changed: 537 additions & 516 deletions
File tree
- pkg
- controller/direct/memorystore
- test/resourcefixture/testdata/basic/memorystore/v1beta1/memorystoreinstance/fullmemorystoreinstance
Lines changed: 76 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
396 | 396 | | |
397 | 397 | | |
398 | 398 | | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
399 | 402 | | |
400 | 403 | | |
401 | 404 | | |
402 | 405 | | |
403 | 406 | | |
404 | 407 | | |
405 | 408 | | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
| 452 | + | |
| 453 | + | |
| 454 | + | |
| 455 | + | |
| 456 | + | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
| 464 | + | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
| 469 | + | |
| 470 | + | |
| 471 | + | |
| 472 | + | |
| 473 | + | |
| 474 | + | |
| 475 | + | |
| 476 | + | |
| 477 | + | |
| 478 | + | |
| 479 | + | |
| 480 | + | |
| 481 | + | |
406 | 482 | | |
407 | 483 | | |
408 | 484 | | |
| |||
0 commit comments