Skip to content

Commit e2b47c9

Browse files
authored
Merge pull request #280 from shawn-hurley/issue-272
pkg/k8sclient: add cache reset on 1 minute interval
2 parents ef94d73 + 91e8df3 commit e2b47c9

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212

1313
### Fixed
1414

15+
- 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)
16+
1517
### Deprecated
1618

1719
### Security

pkg/k8sclient/client.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818
"fmt"
1919
"net"
2020
"os"
21+
"time"
2122

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

@@ -45,6 +46,7 @@ func init() {
4546
restMapper.Reset()
4647
kubeConfig.ContentConfig = dynamic.ContentConfig()
4748
clientPool = dynamic.NewClientPool(kubeConfig, restMapper, dynamic.LegacyAPIPathResolverFunc)
49+
runBackgroundCacheReset(1 * time.Minute)
4850
}
4951

5052
// GetResourceClient returns the dynamic client and pluralName for the resource specified by the apiVersion and kind
@@ -124,3 +126,14 @@ func outOfClusterConfig() (*rest.Config, error) {
124126
config, err := clientcmd.BuildConfigFromFlags("", kubeconfig)
125127
return config, err
126128
}
129+
130+
// runBackgroundCacheReset - Starts the rest mapper cache reseting
131+
// at a duration given.
132+
func runBackgroundCacheReset(duration time.Duration) {
133+
ticker := time.NewTicker(duration)
134+
go func() {
135+
for range ticker.C {
136+
restMapper.Reset()
137+
}
138+
}()
139+
}

0 commit comments

Comments
 (0)