fix missing prefix while listing cloud run resources#748
Conversation
Neo - PR Security ReviewNo security issues found Hardening Notes
Comment |
WalkthroughThe Cloud Run service enumeration now constructs the fully qualified parent path ( Changes
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~5 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Review rate limit: 4/5 reviews remaining, refill in 12 minutes. Comment |
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
pkg/providers/gcp/cloud-run.go (1)
53-74:⚠️ Potential issue | 🟠 MajorPropagate
context.Contextthrough Cloud Run discovery loop.
getServices()ignores cancellation while iterating projects/locations, so discovery can continue afterResources(ctx)is canceled.Proposed patch
func (d *cloudRunProvider) GetResource(ctx context.Context) (*schema.Resources, error) { list := schema.NewResources() - services, err := d.getServices() + services, err := d.getServices(ctx) if err != nil { return nil, fmt.Errorf("could not get services: %s", err) } @@ -func (d *cloudRunProvider) getServices() ([]*run.Service, error) { +func (d *cloudRunProvider) getServices(ctx context.Context) ([]*run.Service, error) { var services []*run.Service for _, project := range d.projects { + if err := ctx.Err(); err != nil { + return services, err + } locationsService := d.run.Projects.Locations.List(fmt.Sprintf("projects/%s", project)) locationsResponse, err := locationsService.Do() if err != nil { gologger.Warning().Msgf("could not list cloud run locations for project %s: %s", project, err) continue } for _, location := range locationsResponse.Locations { + if err := ctx.Err(); err != nil { + return services, err + } // build the parent explicitly because the location.Name is not returned with the projects/ prefix in Knative API parent := fmt.Sprintf("projects/%s/locations/%s", project, location.LocationId) servicesResponse, err := d.run.Projects.Locations.Services.List(parent).Do()As per coding guidelines, "Always pass and honor context.Context in Resources() and long-running API calls to support cancellation".
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@pkg/providers/gcp/cloud-run.go` around lines 53 - 74, getServices() ignores cancellation; change its signature to accept context.Context (e.g., getServices(ctx context.Context)) and propagate the context from Resources(ctx) into it, then apply the context to the long-running GCP calls by calling Context(ctx) on the returned call objects before Do() (for example, use d.run.Projects.Locations.List(...).Context(ctx).Do() and d.run.Projects.Locations.Services.List(parent).Context(ctx).Do()); update any callers (Resources or others) to pass the ctx through so discovery honors cancellation.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Outside diff comments:
In `@pkg/providers/gcp/cloud-run.go`:
- Around line 53-74: getServices() ignores cancellation; change its signature to
accept context.Context (e.g., getServices(ctx context.Context)) and propagate
the context from Resources(ctx) into it, then apply the context to the
long-running GCP calls by calling Context(ctx) on the returned call objects
before Do() (for example, use
d.run.Projects.Locations.List(...).Context(ctx).Do() and
d.run.Projects.Locations.Services.List(parent).Context(ctx).Do()); update any
callers (Resources or others) to pass the ctx through so discovery honors
cancellation.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: e033d764-e877-482f-8826-a420b2cc7735
📒 Files selected for processing (1)
pkg/providers/gcp/cloud-run.go
closes #747
Summary by CodeRabbit