-
Notifications
You must be signed in to change notification settings - Fork 1
update-provider-table #128
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
WalkthroughRefactors provider inventory listing from provider-specific column construction to a unified, resource-type-agnostic approach. Introduces field normalization that maps inventory fields to resource types and dynamically counts missing resources. The core logic now consistently populates provider item fields through integrated normalization throughout the listing flow. Changes
Sequence DiagramsequenceDiagram
participant List as List Flow
participant Norm as normalizeProviderInventory
participant GetProv as getSpecificProvider
participant Count as countProviderResources
participant Client as Provider Client
List->>List: Iterate provider items
List->>Norm: Normalize inventory data
Norm->>GetProv: Get provider by name
GetProv-->>Norm: Provider details
Norm->>Norm: Determine relevant fields (vmCount, networkCount)
alt Missing field & baseURL available
Norm->>Count: Count resources
Count->>Client: Fetch inventory items
Client-->>Count: Items list
Count->>Count: Count items (or -1 on error)
Count-->>Norm: Count result
Norm->>Norm: Store count in item
else Missing field & no baseURL
Norm->>Norm: Default count to 0 with logging
end
Norm-->>List: Normalized item
List->>List: Add to output
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~30 minutes
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 inconclusive)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (3)
pkg/cmd/get/provider/list.go (3)
19-27: UnusedproviderTypeparameter.The
providerTypeparameter is never used in this function. If this is intentional for future extensibility, consider adding a comment or using_ stringto make the intent explicit. Otherwise, remove it.-func getProviderRelevantFields(providerType string) map[string]string { +func getProviderRelevantFields(_ string) map[string]string {Or remove the parameter entirely if
getDynamicInventoryColumnsalso doesn't need provider-type-specific behavior.
66-74: UnusedproviderTypesparameter.Similar to
getProviderRelevantFields, theproviderTypesparameter is unused. For consistency, either document the intent for future extensibility or remove both unused parameters.-func getDynamicInventoryColumns(providerTypes map[string]bool) []output.Header { +func getDynamicInventoryColumns(_ map[string]bool) []output.Header {
247-295: Consider reducing repetition in field extraction.The 16+ sequential
if okblocks follow the same pattern. This could be simplified with a helper or loop:// Define fields to extract countFields := []string{ "vmCount", "hostCount", "datacenterCount", "clusterCount", "networkCount", "datastoreCount", "storageClassCount", "product", "regionCount", "projectCount", "imageCount", "volumeCount", "volumeTypeCount", "diskCount", "storageCount", "storageDomainCount", } for _, field := range countFields { if val, ok := bulkProvider[field]; ok { item[field] = val } }This reduces code duplication and makes it easier to add new fields in the future.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
pkg/cmd/get/provider/list.go(2 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
pkg/cmd/get/provider/list.go (2)
pkg/util/output/table.go (1)
Header(65-68)pkg/util/client/inventory.go (1)
FetchProviderInventoryWithInsecure(45-88)
🔇 Additional comments (3)
pkg/cmd/get/provider/list.go (3)
29-64: LGTM!The normalization logic is well-structured: it gracefully handles missing fields by attempting to count resources from the inventory API and falling back to 0 on failure. The debug logging is helpful for troubleshooting.
76-93: LGTM!The resource counting logic is straightforward and handles errors appropriately. Returning -1 on failure allows the caller to distinguish between "0 resources" and "failed to count."
309-312: LGTM with a note on performance.The normalization step is correctly placed after bulk data extraction. Since
normalizeProviderInventoryskips fields that already exist, it only makes additional HTTP requests when bulk data is unavailable or incomplete.For large provider counts, if bulk fetch fails, this could result in 2 requests per provider. Verify this fallback behavior is acceptable for your deployment scenarios, or consider adding a flag to disable fallback counting.
Signed-off-by: yaacov <[email protected]>
Summary by CodeRabbit
Bug Fixes
Refactor
✏️ Tip: You can customize this high-level summary in your review settings.