Skip to content

Commit

Permalink
pkg/k8sclient: add cache reset on 1 minute interval
Browse files Browse the repository at this point in the history
This sets up a go routine to reset the restMapper at a 1 minute
interval so that new resources can be found in the cluster.

fixes #272
  • Loading branch information
Shawn Hurley committed May 23, 2018
1 parent 02cf852 commit 364f8c1
Showing 1 changed file with 13 additions and 0 deletions.
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()
}
}()
}

0 comments on commit 364f8c1

Please sign in to comment.