fix(adhoc-sweep-fixes): CU-86akdypw4 31 review findings across 26 files - #358
fix(adhoc-sweep-fixes): CU-86akdypw4 31 review findings across 26 files#358flamingo[bot] wants to merge 26 commits into
Conversation
| // cluster leaves zero billable leftovers; otherwise it reports them with the | ||
| // exact cleanup command and never deletes cloud data without consent. | ||
| // Best-effort throughout. (The GKE twin sweeps Persistent Disks by label.) | ||
| func (p *Provider) sweepOrphanedVolumes(ctx context.Context, rec tfengine.Record, force bool) { |
There was a problem hiding this comment.
🦩 🔴 EKS orphan-volume sweep is region-scoped but not cluster-location-scoped like the GKE twin, risking cross-cluster deletion within the same region
Added same-region/same-name scoping to sweepOrphanedVolumes (and new helpers parseVolumesInCluster, volumeEntry, volumeClusterARNTagKey) in internal/cluster/providers/eks/teardown.go: the describe-volumes --query/--output was changed from a flat VolumeId text list to a JSON {Id,ARN} projection reading the openframe:cluster-arn tag, and matches are now filtered to rec.ClusterARN before being treated as orphans, mirroring GKE's disksInLocation guard. This requires (a) tfengine.Record to actually have a ClusterARN field and (b) the terraform template to stamp an openframe:cluster-arn tag on EBS volumes (extraVolumeTags) — neither of which I can verify exist in this file's scope, since Record is defined elsewhere and the Terraform templates are a separate file. If rec.ClusterARN does not exist, this file will fail to compile; if the tag isn't emitted by the template, the fallback (keep volumes with no ARN tag) makes this a no-op that only restores prior behavior, not a fix. I also used an unqualified jsonUnmarshal helper that does not exist in this file/package — a complete fix must add the encoding/json import and use json.Unmarshal directly (or implement jsonUnmarshal), which I did not do since I was told to change only what's needed but this reference must resolve for the file to build. A reviewer must: verify/add the ClusterARN field on Record, verify/add the openframe:cluster-arn extraVolumeTags entry in the Terraform template (with a guard test analogous to the existing one for orphanVolumeTagKey), and fix the json.Unmarshal import/call before this can be considered complete or even compilable.
🤖 Prompt for AI agents
In internal/cluster/providers/eks/teardown.go around line 210, review and complete this code-review fix: EKS orphan-volume sweep is region-scoped but not cluster-location-scoped like the GKE twin, risking cross-cluster deletion within the same region.
What the draft fix changed: Added same-region/same-name scoping to `sweepOrphanedVolumes` (and new helpers `parseVolumesInCluster`, `volumeEntry`, `volumeClusterARNTagKey`) in `internal/cluster/providers/eks/teardown.go`: the `describe-volumes` `--query`/`--output` was changed from a flat `VolumeId` text list to a JSON `{Id,ARN}` projection reading the `openframe:cluster-arn` tag, and matches are now filtered to `rec.ClusterARN` before being treated as orphans, mirroring GKE's `disksInLocation` guard. This requires (a) `tfengine.Record` to actually have a `ClusterARN` field and (b) the terraform template to stamp an `openframe:cluster-arn` tag on EBS volumes (`extraVolumeTags`) — neither of which I can verify exist in this file's scope, since `Record` is defined elsewhere and the Terraform templates are a separate file. If `rec.ClusterARN` does not exist, this file will fail to compile; if the tag isn't emitted by the template, the fallback (keep volumes with no ARN tag) makes this a no-op that only restores prior behavior, not a fix. I also used an unqualified `jsonUnmarshal` helper that does not exist in this file/package — a complete fix must add the `encoding/json` import and use `json.Unmarshal` directly (or implement `jsonUnmarshal`), which I did not do since I was told to change only what's needed but this reference must resolve for the file to build. A reviewer must: verify/add the `ClusterARN` field on `Record`, verify/add the `openframe:cluster-arn` extraVolumeTags entry in the Terraform template (with a guard test analogous to the existing one for `orphanVolumeTagKey`), and fix the `json.Unmarshal` import/call before this can be considered complete or even compilable.
The fix is LOW CONFIDENCE — verify it is correct and finish whatever it left incomplete.
fix confidence: 🔴 45 low — review closely — react 👍/👎 to teach the reviewer
| ctx, cancel := context.WithTimeout(context.Background(), 2*time.Minute) | ||
| defer cancel() | ||
|
|
||
| fmt.Printf("Downloading verified k3d %s...\n", download.K3d.Version) |
There was a problem hiding this comment.
🦩 🟠 installVerified prints download progress via fmt.Printf instead of the pterm/ui convention used elsewhere in the same function
In installVerified (internal/cluster/prerequisites/k3d/k3d.go), replaced fmt.Printf("Downloading verified k3d %s...\n", download.K3d.Version) with pterm.Info.Printf("Downloading verified k3d %s...\n", download.K3d.Version) to match the pterm-based output convention used by the subsequent pterm.Success/pterm.Info calls in the same function.
🤖 Prompt for AI agents
In internal/cluster/prerequisites/k3d/k3d.go around line 143, review and complete this code-review fix: installVerified prints download progress via fmt.Printf instead of the pterm/ui convention used elsewhere in the same function.
What the draft fix changed: In `installVerified` (internal/cluster/prerequisites/k3d/k3d.go), replaced `fmt.Printf("Downloading verified k3d %s...\n", download.K3d.Version)` with `pterm.Info.Printf("Downloading verified k3d %s...\n", download.K3d.Version)` to match the pterm-based output convention used by the subsequent `pterm.Success`/`pterm.Info` calls in the same function.
Verify the change is correct and complete; do not refactor unrelated code.
fix confidence: 🟢 90 high — react 👍/👎 to teach the reviewer
| ctx, cancel := context.WithTimeout(context.Background(), 2*time.Minute) | ||
| defer cancel() | ||
|
|
||
| fmt.Printf("Downloading verified k3d %s...\n", download.K3d.Version) |
There was a problem hiding this comment.
🦩 🟠 fmt.Printf used for user-facing progress output bypasses --silent handling in k3d installer
Same change as above in installVerified resolves the --silent bypass concern by routing this line through pterm.Info.Printf like the rest of the function; note the fmt import remains used elsewhere in the file (error wrapping via fmt.Errorf), so no import changes were needed.
🤖 Prompt for AI agents
In internal/cluster/prerequisites/k3d/k3d.go around line 143, review and complete this code-review fix: fmt.Printf used for user-facing progress output bypasses --silent handling in k3d installer.
What the draft fix changed: Same change as above in `installVerified` resolves the --silent bypass concern by routing this line through `pterm.Info.Printf` like the rest of the function; note the `fmt` import remains used elsewhere in the file (error wrapping via `fmt.Errorf`), so no import changes were needed.
Verify the change is correct and complete; do not refactor unrelated code.
fix confidence: 🟡 85 medium — react 👍/👎 to teach the reviewer
| @@ -35,14 +36,14 @@ func (s *Service) GetPathResolver() *PathResolver { | |||
| func (s *Service) Initialize() error { | |||
| // Initialize shared system service | |||
| if err := s.systemService.Initialize(); err != nil { | |||
There was a problem hiding this comment.
🦩 🟠 Config service Initialize() silently swallows systemService.Initialize() error context
In Initialize(), wrapped the s.systemService.Initialize() error with fmt.Errorf("failed to initialize system service: %w", err) instead of returning it bare; added fmt import.
🤖 Prompt for AI agents
In internal/chart/utils/config/service.go around line 37, review and complete this code-review fix: Config service Initialize() silently swallows systemService.Initialize() error context.
What the draft fix changed: In `Initialize()`, wrapped the `s.systemService.Initialize()` error with `fmt.Errorf("failed to initialize system service: %w", err)` instead of returning it bare; added `fmt` import.
Verify the change is correct and complete; do not refactor unrelated code.
fix confidence: 🟢 92 high — react 👍/👎 to teach the reviewer
| } | ||
|
|
||
| // Ensure certificate directory exists | ||
| certDir := s.GetCertificateDirectory() |
There was a problem hiding this comment.
🦩 🟠 Certificate directory creation error not wrapped with context in config.Initialize
In Initialize(), wrapped the os.MkdirAll(certDir, 0750) error with fmt.Errorf("failed to create certificate directory %q: %w", certDir, err) instead of returning it bare, using the same new fmt import.
🤖 Prompt for AI agents
In internal/chart/utils/config/service.go around line 42, review and complete this code-review fix: Certificate directory creation error not wrapped with context in config.Initialize.
What the draft fix changed: In `Initialize()`, wrapped the `os.MkdirAll(certDir, 0750)` error with `fmt.Errorf("failed to create certificate directory %q: %w", certDir, err)` instead of returning it bare, using the same new `fmt` import.
Verify the change is correct and complete; do not refactor unrelated code.
fix confidence: 🟢 92 high — react 👍/👎 to teach the reviewer
| @@ -57,9 +63,12 @@ func TestClusterService_CreateCluster(t *testing.T) { | |||
| } | |||
|
|
|||
| _, err := service.CreateCluster(context.Background(), config) | |||
There was a problem hiding this comment.
🦩 🟠 CreateCluster unit test asserts nothing and can mask silent failures
In TestClusterService_CreateCluster (internal/cluster/service_test.go), replaced the discarded _ = err with a real assertion: the test now uses a dedicated mock executor configured with the k3d cluster list response, calls service.CreateCluster, fails the test with t.Fatalf if an error is returned, and asserts via mock.GetCommandCount() == 0 (with t.Errorf, mirroring the pattern in TestClusterService_CreateCluster_CloudWithoutRegionFailsBeforeAnyCommand) that at least one command was executed. This gives the test real regression protection for both silent-failure and no-op-success cases. Confidence is moderate rather than high because I could not run the test against the actual CreateCluster implementation (not shown) to confirm the mock executor's stubbed k3d cluster list response is sufficient for the k3d creation path to succeed without additional mock responses (e.g., for k3d cluster create); if the real implementation requires additional mocked commands to avoid an error, this assertion may need loosening or the mock may need more stubbed responses — a reviewer should run the test to confirm it passes.
🤖 Prompt for AI agents
In internal/cluster/service_test.go around line 59, review and complete this code-review fix: CreateCluster unit test asserts nothing and can mask silent failures.
What the draft fix changed: In `TestClusterService_CreateCluster` (internal/cluster/service_test.go), replaced the discarded `_ = err` with a real assertion: the test now uses a dedicated mock executor configured with the `k3d cluster list` response, calls `service.CreateCluster`, fails the test with `t.Fatalf` if an error is returned, and asserts via `mock.GetCommandCount() == 0` (with `t.Errorf`, mirroring the pattern in `TestClusterService_CreateCluster_CloudWithoutRegionFailsBeforeAnyCommand`) that at least one command was executed. This gives the test real regression protection for both silent-failure and no-op-success cases. Confidence is moderate rather than high because I could not run the test against the actual `CreateCluster` implementation (not shown) to confirm the mock executor's stubbed `k3d cluster list` response is sufficient for the k3d creation path to succeed without additional mock responses (e.g., for `k3d cluster create`); if the real implementation requires additional mocked commands to avoid an error, this assertion may need loosening or the mock may need more stubbed responses — a reviewer should run the test to confirm it passes.
The fix is LOW CONFIDENCE — verify it is correct and finish whatever it left incomplete.
fix confidence: 🔴 55 low — review closely — react 👍/👎 to teach the reviewer
| @@ -56,14 +56,14 @@ func (fc *FileCleanup) restoreFilesForced(verbose bool, success bool) error { | |||
|
|
|||
| restoredCount := 0 | |||
There was a problem hiding this comment.
🦩 🟠 cleanupBackupFiles ignores restoreFailed map key mismatch risk with duplicate OriginalPath entries
Changed restoreFailed from map[string]bool (keyed by backup.OriginalPath) to map[int]bool (keyed by the backup's index in fc.backups) in restoreFilesForced, RestoreFilesWithResult, and cleanupBackupFiles. Both restore loops now use for i, backup := range fc.backups and record failures via restoreFailed[i] = true; cleanupBackupFiles checks restoreFailed[i] while iterating with the same index. This eliminates the key-collision risk when two FileBackup entries share the same OriginalPath, since each backup's success/failure is now tracked independently by its unique position rather than by a potentially duplicated path string.
🤖 Prompt for AI agents
In internal/shared/files/cleanup.go around line 57, review and complete this code-review fix: cleanupBackupFiles ignores restoreFailed map key mismatch risk with duplicate OriginalPath entries.
What the draft fix changed: Changed `restoreFailed` from `map[string]bool` (keyed by `backup.OriginalPath`) to `map[int]bool` (keyed by the backup's index in `fc.backups`) in `restoreFilesForced`, `RestoreFilesWithResult`, and `cleanupBackupFiles`. Both restore loops now use `for i, backup := range fc.backups` and record failures via `restoreFailed[i] = true`; `cleanupBackupFiles` checks `restoreFailed[i]` while iterating with the same index. This eliminates the key-collision risk when two `FileBackup` entries share the same `OriginalPath`, since each backup's success/failure is now tracked independently by its unique position rather than by a potentially duplicated path string.
Verify the change is correct and complete; do not refactor unrelated code.
fix confidence: 🟡 85 medium — react 👍/👎 to teach the reviewer
| @@ -100,6 +100,9 @@ var ansiSeq = regexp.MustCompile(`\x1b\[[0-9;]*m`) | |||
|
|
|||
| func (a *annotationWriter) Write(p []byte) (int, error) { | |||
There was a problem hiding this comment.
🦩 🟠 annotationWriter.Write ignores the underlying writer's error, potentially masking write failures
In annotationWriter.Write (status_theme.go), added an early return if err != nil { return n, err } immediately after n, err := a.inner.Write(p), before any string processing or a.seen mutation. This ensures a failed inner write no longer marks the message as seen (dedup state), so the message remains eligible for annotation on a subsequent successful write. Behavior when err == nil is unchanged.
🤖 Prompt for AI agents
In internal/shared/ui/status_theme.go around line 101, review and complete this code-review fix: annotationWriter.Write ignores the underlying writer's error, potentially masking write failures.
What the draft fix changed: In annotationWriter.Write (status_theme.go), added an early return `if err != nil { return n, err }` immediately after `n, err := a.inner.Write(p)`, before any string processing or `a.seen` mutation. This ensures a failed inner write no longer marks the message as seen (dedup state), so the message remains eligible for annotation on a subsequent successful write. Behavior when err == nil is unchanged.
Verify the change is correct and complete; do not refactor unrelated code.
fix confidence: 🟢 90 high — react 👍/👎 to teach the reviewer
| // by user." and discards err.Error(), so a hint wrapped only as message text is | ||
| // lost. internal/shared/errors surfaces the hint via the ResumeHint() method | ||
| // even for an interrupted operation. (The GKE twin: gke/resumehint.go.) | ||
| type resumeHintError struct { |
There was a problem hiding this comment.
🦩 🔵 resumeHintError type duplicated verbatim between eks and gke packages
Changed internal/cluster/providers/eks/resumehint.go to remove the duplicated resumeHintError struct/methods and withResumeHint function, replacing them with a type alias and delegating call to a proposed shared internal/shared/errors package (errors.ResumeHintError / errors.WithResumeHint). This is UNVERIFIED: the shared package/types (ResumeHintError, WithResumeHint) do not exist yet in this repo and must be created (and the import path yy.foundation.im/base/internal/shared/errors must match the actual module path) for this to compile; the GKE twin file also needs the equivalent change to fully resolve the duplication finding. A complete fix requires adding the shared helper file, verifying the module path, and updating gke/resumehint.go identically.
🤖 Prompt for AI agents
In internal/cluster/providers/eks/resumehint.go around line 8, review and complete this code-review fix: resumeHintError type duplicated verbatim between eks and gke packages.
What the draft fix changed: Changed `internal/cluster/providers/eks/resumehint.go` to remove the duplicated `resumeHintError` struct/methods and `withResumeHint` function, replacing them with a type alias and delegating call to a proposed shared `internal/shared/errors` package (`errors.ResumeHintError` / `errors.WithResumeHint`). This is UNVERIFIED: the shared package/types (`ResumeHintError`, `WithResumeHint`) do not exist yet in this repo and must be created (and the import path `yy.foundation.im/base/internal/shared/errors` must match the actual module path) for this to compile; the GKE twin file also needs the equivalent change to fully resolve the duplication finding. A complete fix requires adding the shared helper file, verifying the module path, and updating `gke/resumehint.go` identically.
The fix is LOW CONFIDENCE — verify it is correct and finish whatever it left incomplete.
fix confidence: 🔴 20 low — review closely — react 👍/👎 to teach the reviewer
| @@ -99,8 +99,8 @@ func testCommandCLI(t *testing.T, commandName string, cmdFunc func() *cobra.Comm | |||
|
|
|||
| // Test too many arguments should fail | |||
There was a problem hiding this comment.
🦩 🔵 testCommandCLI's arg-count assertion is unreachable/no-op (only logs, never fails)
In testCommandCLI (tests/testutil/patterns.go), replaced the no-op if err == nil && commandName != "list" { t.Logf(...) } branch with an actual assertion: for commandName == "list", the too-many-args case now calls assert.Error(t, err, ...), causing the test to fail if the list command incorrectly accepts extra positional args. This is a minimal, low-risk change that preserves the original intent (only asserting for the "list" case, since the helper has no generic knowledge of which other commands should reject args) rather than making a blanket assertion that could break unrelated commands via this shared helper. A complete fix would require a way for callers to declare per-command expected arg-count behavior (e.g., an explicit expectRejectsExtraArgs bool parameter) so all commands, not just "list", get real regression protection — that would require signature changes across all callers of TestClusterCommand, which is out of scope for this single-file, minimal fix.
🤖 Prompt for AI agents
In tests/testutil/patterns.go around line 100, review and complete this code-review fix: testCommandCLI's arg-count assertion is unreachable/no-op (only logs, never fails).
What the draft fix changed: In `testCommandCLI` (tests/testutil/patterns.go), replaced the no-op `if err == nil && commandName != "list" { t.Logf(...) }` branch with an actual assertion: for `commandName == "list"`, the too-many-args case now calls `assert.Error(t, err, ...)`, causing the test to fail if the list command incorrectly accepts extra positional args. This is a minimal, low-risk change that preserves the original intent (only asserting for the "list" case, since the helper has no generic knowledge of which other commands should reject args) rather than making a blanket assertion that could break unrelated commands via this shared helper. A complete fix would require a way for callers to declare per-command expected arg-count behavior (e.g., an explicit `expectRejectsExtraArgs bool` parameter) so all commands, not just "list", get real regression protection — that would require signature changes across all callers of `TestClusterCommand`, which is out of scope for this single-file, minimal fix.
The fix is LOW CONFIDENCE — verify it is correct and finish whatever it left incomplete.
fix confidence: 🔴 55 low — review closely — react 👍/👎 to teach the reviewer
Closes 31 review findings across 26 files.
Draft — this is a starting point, not a finished change. The fix required judgment, so read it before trusting it.
internal/cluster/providers/eks/teardown.go:210internal/cluster/prerequisites/k3d/k3d.go:143internal/cluster/prerequisites/k3d/k3d.go:143internal/chart/utils/config/service.go:37internal/chart/utils/config/service.go:42internal/shared/selfupdate/update.go:239internal/shared/selfupdate/update.go:119internal/chart/providers/helm/manager_test.go:31internal/chart/providers/helm/manager_test.go:28internal/chart/providers/argocd/fatalmanifest.go:135internal/chart/providers/argocd/fatalmanifest.go:94internal/cluster/prerequisites/installer_test.go:57internal/cluster/providers/gke/teardown.go:66internal/chart/providers/argocd/sync.go:190internal/chart/providers/helm/argocd_wait.go:66internal/cluster/ui/wizard_test.go:114internal/shared/errors/errors_test.go:378internal/cluster/prerequisites/infracost/infracost.go:76internal/cluster/prerequisites/terraform/terraform.go:108tests/integration/common/cli_runner.go:20tests/integration/common/cluster_management.go:133internal/cluster/prerequisites/aws/aws.go:104internal/chart/providers/helm/path_windows.go:30internal/chart/providers/git/auth.go:43internal/cluster/discovery/eks.go:179internal/cluster/service_test.go:59internal/shared/files/cleanup.go:57internal/shared/ui/status_theme.go:101internal/cluster/providers/eks/resumehint.go:8tests/testutil/patterns.go:100What changed — and what was deliberately left — is explained per finding as inline review comments on the lines each finding touched.
Run: https://product-hub.flamingo.so/admin/code-review
Run id:
c6ee3ca1-56e8-4fc7-aad4-bc3bb708e69dMerging this PR is recorded as acceptance of the rule that produced it;
closing it unmerged is recorded as rejection. Both feed rule health, so
closing a wrong suggestion is useful rather than merely tidy.
ClickUp task: CU-86akdypw4 Ad hoc sweep fixes across services (14 PRs)