Skip to content

Use API reader for CR status refresh#1829

Open
vivekr-splunk wants to merge 1 commit intodevelopfrom
fix/standalone-status-live-reader
Open

Use API reader for CR status refresh#1829
vivekr-splunk wants to merge 1 commit intodevelopfrom
fix/standalone-status-live-reader

Conversation

@vivekr-splunk
Copy link
Copy Markdown
Collaborator

Summary

  • wrap the enterprise controller client with an API reader
  • use live reads when re-fetching CRs before status updates
  • keep the existing cached read loop for post-update cache convergence

Testing

  • env GOCACHE=/tmp/go-build GOMODCACHE=/tmp/go-mod GOTMPDIR=/tmp go test ./cmd/... ./pkg/splunk/enterprise -run 'TestUpdateCRStatus|TestFetchCurrentCRWithStatusUpdate'

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR introduces a way to perform live (non-cached) reads of Splunk Enterprise CRs right before status updates, reducing the chance of updating status based on stale cached objects while still retaining the existing cache-convergence loop after status writes.

Changes:

  • Added a client.Client wrapper that exposes the controller-runtime APIReader, plus a helper to resolve it when available.
  • Updated CR status refresh logic to use the resolved live reader for the pre-status-update re-fetch.
  • Wired the new wrapped client into the manager setup so enterprise reconcilers receive an API-reader-aware client.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
pkg/splunk/enterprise/util.go Uses a resolved live client.Reader for the “fresh read” before status updates while keeping cached reads for convergence checks.
pkg/splunk/common/client.go Adds APIAwareClient wrapper + ResolveAPIReader helper to expose/resolve a live API reader.
cmd/main.go Wraps the manager client with the API reader and passes it into enterprise reconcilers.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +20 to +63
// APIReaderProvider exposes a direct API reader alongside a controller client.
type APIReaderProvider interface {
GetAPIReader() client.Reader
}

// APIAwareClient keeps the standard controller client behavior while exposing a
// direct API reader for code paths that need a live read before a write.
type APIAwareClient struct {
client.Client
apiReader client.Reader
}

// NewAPIAwareClient returns a client wrapper that exposes the provided API reader.
func NewAPIAwareClient(baseClient client.Client, apiReader client.Reader) client.Client {
if baseClient == nil || apiReader == nil {
return baseClient
}

return &APIAwareClient{
Client: baseClient,
apiReader: apiReader,
}
}

// GetAPIReader returns the live API reader associated with the wrapped client.
func (c *APIAwareClient) GetAPIReader() client.Reader {
if c.apiReader != nil {
return c.apiReader
}

return c.Client
}

// ResolveAPIReader returns a live API reader when one is available, otherwise
// it falls back to the provided client.
func ResolveAPIReader(baseClient client.Client) client.Reader {
if provider, ok := baseClient.(APIReaderProvider); ok {
if apiReader := provider.GetAPIReader(); apiReader != nil {
return apiReader
}
}

return baseClient
}
Copy link

Copilot AI Apr 8, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New exported API-reader wrapper helpers are introduced here, but there are no unit tests validating the key behaviors (e.g., ResolveAPIReader returns the provided API reader when the client implements APIReaderProvider, and falls back to the base client when it does not / when nils are provided). Adding a small client_test.go would help prevent regressions since this code changes read consistency around status updates.

Copilot uses AI. Check for mistakes.
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.

3 participants