Skip to content

improvements to MIG (Managed Instance Group) handling, TUI enhancements, and cache management.#26

Merged
sysblade merged 4 commits intomainfrom
keybindings-fixes
Jan 22, 2026
Merged

improvements to MIG (Managed Instance Group) handling, TUI enhancements, and cache management.#26
sysblade merged 4 commits intomainfrom
keybindings-fixes

Conversation

@sysblade
Copy link
Copy Markdown
Owner

@sysblade sysblade commented Jan 22, 2026

Summary

This PR introduces several improvements to MIG (Managed Instance Group) handling, TUI enhancements, cache management, and fixes instance name uniqueness across projects.

Instance/MIG Names Unique Per Project

  • Composite Primary Key: Changed the cache schema to use PRIMARY KEY (name, project) instead of just name. This allows the same instance name (e.g., "netmgt") to exist in multiple projects without conflicts.

  • New Cache API Methods:

    • GetWithProject(name, project): Precise lookup by name+project combination
    • GetAllByName(name): Returns all instances with a given name across all projects
    • Updated Delete(name, project) and MarkInstanceUsed(name, project) to require project parameter
  • CLI Multi-Project Selection: When running compass gcp ssh <instance> without --project and the instance name exists in multiple projects, an interactive selection prompt is displayed to choose which project's instance to connect to.

  • Database Migration v6: Added migration that recreates the instances table with composite primary key while preserving existing data.

MIG Improvements

  • MIG Instance Selection Modal: When connecting to a MIG via TUI SSH that has multiple instances, a selection modal is now displayed allowing the user to choose which instance to connect to. If the MIG has only one instance, it connects directly.

  • Hide MIG Member Instances: Instances that belong to a MIG are now filtered out from the main instance list in the TUI. They can still be accessed via their parent MIG entry. This reduces clutter and avoids confusion when the same workload appears multiple times.

  • Fix MIG Details View: Fixed the "d" (details) shortcut for MIGs which was returning 404 errors. Added GetManagedInstanceGroup API call and FormatMIGDetailsLive formatter to properly fetch and display MIG details.

  • MIG Name Extraction: Added extraction of MIG membership from instance created-by metadata. New mig_name column added to cache via migration v5.

TUI Enhancements

  • Type Column: Added a "Type" column to the instance table to distinguish between "Instance" and "MIG" entries.

  • Keybindings Refactor: Refactored keyboard handling into a dedicated KeyBindings manager with proper modal/filter mode support. This fixes inconsistencies where keybindings would trigger inappropriately in different modes.

  • Progress Bar Text Clearing: Fixed issue where progress bar titles weren't being fully cleared when updated with shorter text.

CLI Improvements

  • Refresh All Projects: compass gcp projects refresh can now be run without a project name to refresh all currently imported projects. When run without arguments, it prompts to select which projects to refresh.

  • Log File Support: Added --log-file parameter to write logs to a file. This is particularly useful for debugging TUI issues since stderr is redirected during TUI mode. File logging continues even when console output is disabled for TUI.

Cache Management

  • Stale Resource Cleanup: When refreshing a project, stale/deleted resources are now properly removed from the cache. Previously, deleted instances, MIGs, subnets, and zones would remain in the cache until TTL expiration. Now they are cleared before rescanning:
    • ClearProjectInstances - removes instances and MIGs
    • ClearProjectSubnets - removes subnets
    • ClearProjectZones - removes zones

Files Changed

File Changes
cmd/root.go Added --log-file flag
cmd/gcp.go Added multi-project selection prompt, updated MarkInstanceUsed call
cmd/gcp_projects.go Added refresh-all-projects functionality, improved progress bar
internal/cache/cache.go Added InstanceMatch type, GetWithProject, GetAllByName methods, updated Delete/MarkInstanceUsed signatures, composite key support
internal/cache/schema.go Updated base schema with composite primary key (name, project)
internal/cache/migrations/v5_mig_name.go Migration for mig_name column
internal/cache/migrations/v6_composite_key.go New - Migration to change primary key to (name, project)
internal/cache/cache_test.go Added tests for composite key functionality
internal/gcp/cache_ops.go Use GetWithProject() for IAP preference preservation
internal/gcp/extract.go Added extractMIGNameFromCreatedBy function
internal/gcp/instances.go Use GetWithProject() for cache lookup
internal/gcp/mig.go Use GetWithProject() for MIG cache lookup
internal/gcp/scan.go Clear stale resources before rescanning
internal/gcp/types.go Added MIGName field to Instance struct
internal/logger/logger.go Added file logging support, separate console disable
internal/tui/actions.go Added MIG instance selection modal, updated MarkInstanceUsed calls
internal/tui/direct.go Filter MIG members, handle MIG details, refactored keybindings
internal/tui/keybindings.go New keybinding manager with modal support

Test Plan

Composite Key / Multi-Project Instance Names

  • Import two projects that have instances with the same name
  • Run compass gcp ssh <shared-name> without --project - verify selection prompt appears
  • Select a project from the prompt - verify connection to correct instance
  • Run compass gcp ssh <shared-name> --project <project> - verify direct connection without prompt
  • Open TUI and verify both instances appear in the list with correct projects
  • SSH to each instance from TUI - verify correct instance is connected
  • Run cache tests: go test ./internal/cache/... -v -run "TestSameNameDifferentProjects|TestDeleteWithProject|TestGetAllByName"

MIG Functionality

  • Open TUI and verify MIG member instances are not shown in the list
  • Select a MIG with multiple instances and press s - verify selection modal appears
  • Select a MIG with one instance and press s - verify it connects directly
  • Press d on a MIG entry and verify details are displayed correctly
  • Verify the "Type" column shows "Instance" or "MIG" appropriately

Project Management

  • Run compass gcp projects refresh without arguments and verify all projects can be refreshed
  • Run compass gcp projects refresh <project> and verify single project refresh works
  • Delete an instance in GCP, run refresh, and verify it's removed from the cache

Logging

  • Run with --log-file /tmp/test.log --log-level debug and verify logs are written to file

Full Check

  • Run task check and verify all tests pass with no lint issues

@sysblade sysblade merged commit 335c50b into main Jan 22, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant