Skip to content
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

pkg/k8sclient: add cache reset on 1 minute interval #280

Merged
merged 1 commit into from
May 25, 2018
Merged
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

### Fixed

- The cache of available clients is being reset every minute for discovery of newely added resources to a cluster. [#280](https://github.com/operator-framework/operator-sdk/pull/280)

### Deprecated

### Security
13 changes: 13 additions & 0 deletions pkg/k8sclient/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"fmt"
"net"
"os"
"time"

"github.com/operator-framework/operator-sdk/pkg/util/k8sutil"

Expand Down Expand Up @@ -45,6 +46,7 @@ func init() {
restMapper.Reset()
kubeConfig.ContentConfig = dynamic.ContentConfig()
clientPool = dynamic.NewClientPool(kubeConfig, restMapper, dynamic.LegacyAPIPathResolverFunc)
runBackgroundCacheReset(1 * time.Minute)
}

// GetResourceClient returns the dynamic client and pluralName for the resource specified by the apiVersion and kind
Expand Down Expand Up @@ -124,3 +126,14 @@ func outOfClusterConfig() (*rest.Config, error) {
config, err := clientcmd.BuildConfigFromFlags("", kubeconfig)
return config, err
}

// runBackgroundCacheReset - Starts the rest mapper cache reseting
// at a duration given.
func runBackgroundCacheReset(duration time.Duration) {
ticker := time.NewTicker(duration)
go func() {
for range ticker.C {
restMapper.Reset()
}
}()
}