Skip to content

add apiClient make requests to the api server and not the cache #609

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

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions pkg/manager/internal.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ type controllerManager struct {
// apiReader is the reader that will make requests to the api server and not the cache.
apiReader client.Reader

// apiClient is the client that will make requests to the api server and not the cache.
apiClient client.Client

// fieldIndexes knows how to add field indexes over the Cache used by this controller,
// which can later be consumed via field selectors from the injected client.
fieldIndexes client.FieldIndexer
Expand Down Expand Up @@ -220,6 +223,10 @@ func (cm *controllerManager) GetAPIReader() client.Reader {
return cm.apiReader
}

func (cm *controllerManager) GetAPIClient() client.Client {
return cm.apiClient
}

func (cm *controllerManager) GetWebhookServer() *webhook.Server {
if cm.webhookServer == nil {
cm.webhookServer = &webhook.Server{
Expand Down
10 changes: 8 additions & 2 deletions pkg/manager/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,11 @@ type Manager interface {
// use case.
GetAPIReader() client.Reader

// GetAPIClient returns a client that will be configured to use the API server.
// This should be used sparingly and only when the cached client does not fit your
// use case.
GetAPIClient() client.Client

// GetWebhookServer returns a webhook.Server
GetWebhookServer() *webhook.Server
}
Expand Down Expand Up @@ -227,7 +232,7 @@ func New(config *rest.Config, options Options) (Manager, error) {
return nil, err
}

apiReader, err := client.New(config, client.Options{Scheme: options.Scheme, Mapper: mapper})
apiClient, err := client.New(config, client.Options{Scheme: options.Scheme, Mapper: mapper})
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -270,7 +275,8 @@ func New(config *rest.Config, options Options) (Manager, error) {
cache: cache,
fieldIndexes: cache,
client: writeObj,
apiReader: apiReader,
apiReader: apiClient,
apiClient: apiClient,
recorderProvider: recorderProvider,
resourceLock: resourceLock,
mapper: mapper,
Expand Down