-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Conversation
pkg/k8sclient/client.go
Outdated
@@ -124,3 +128,30 @@ func outOfClusterConfig() (*rest.Config, error) { | |||
config, err := clientcmd.BuildConfigFromFlags("", kubeconfig) | |||
return config, err | |||
} | |||
|
|||
// stopCacheReset - Stops the rest mapper cache from reseting. | |||
func stopCacheReset() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we ever need to call stopCacheReset()
? I don't see it being used anywhere.
Also it's not something exposed to the user in the handler since it's not expected that an operator would ever want to turn this off and on again as part of normal operations.
So I would suggest to remove stopCacheReset()
for now until we have a use case for it.
With that we can also get rid of quit
and started
and simplify the cache reset to:
func init() {
...
go periodicResetRestMapper(1 * time.Minute)
}
func periodicResetRestMapper(duration time.Duration) {
ticker := time.NewTicker(duration)
for {
select {
case <-ticker.C:
restMapper.Reset()
}
}
}
Ideally we'd pass a context to the go routine but we can't do that while all of this is being done in the init() function. That will have to wait until we refactor all of the global state into objects.
@shawn-hurley have you try this pr to see if it fixes the issue in #272. |
@shawn-hurley You can do a manual test with the example in #272 to see if the RestMapper is able to pick a newly registered resource. |
For testing I am using the starter-pack-operator. I am overriding the GoPkg.toml to use my branch of the operator-sdk and then running the While the operator is running you should see that we can't find the cluster service broker resource. To test the PR you can install the svc-catalog through helm and it should go away. |
@shawn-hurley It will be nice if you can test the pr using the same mechanism as described in #272 and post your test output in the comment section. I expect that after one minute, a retrieval of a |
INFO[0000] Go Version: go1.10.1
INFO[0000] Go OS/Arch: darwin/amd64
INFO[0000] operator-sdk Version: 0.0.5+git
ERRO[0000] failed to get resource client for (apiVersion:example.com/v1alpha1, kind:AppService, ns:default): failed to get resource type: failed to get the resource REST mapping for GroupVersionKind(example.com/v1alpha1, Kind=AppService): no matches for example.com/, Kind=AppService
ERRO[0005] failed to get resource client for (apiVersion:example.com/v1alpha1, kind:AppService, ns:default): failed to get resource type: failed to get the resource REST mapping for GroupVersionKind(example.com/v1alpha1, Kind=AppService): no matches for example.com/, Kind=AppService
ERRO[0010] failed to get resource client for (apiVersion:example.com/v1alpha1, kind:AppService, ns:default): failed to get resource type: failed to get the resource REST mapping for GroupVersionKind(example.com/v1alpha1, Kind=AppService): no matches for example.com/, Kind=AppService
ERRO[0015] failed to get resource client for (apiVersion:example.com/v1alpha1, kind:AppService, ns:default): failed to get resource type: failed to get the resource REST mapping for GroupVersionKind(example.com/v1alpha1, Kind=AppService): no matches for example.com/, Kind=AppService
ERRO[0020] failed to get resource client for (apiVersion:example.com/v1alpha1, kind:AppService, ns:default): failed to get resource type: failed to get the resource REST mapping for GroupVersionKind(example.com/v1alpha1, Kind=AppService): no matches for example.com/, Kind=AppService
ERRO[0025] failed to get resource client for (apiVersion:example.com/v1alpha1, kind:AppService, ns:default): failed to get resource type: failed to get the resource REST mapping for GroupVersionKind(example.com/v1alpha1, Kind=AppService): no matches for example.com/, Kind=AppService
ERRO[0030] failed to get resource client for (apiVersion:example.com/v1alpha1, kind:AppService, ns:default): failed to get resource type: failed to get the resource REST mapping for GroupVersionKind(example.com/v1alpha1, Kind=AppService): no matches for example.com/, Kind=AppService
ERRO[0035] failed to get resource client for (apiVersion:example.com/v1alpha1, kind:AppService, ns:default): failed to get resource type: failed to get the resource REST mapping for GroupVersionKind(example.com/v1alpha1, Kind=AppService): no matches for example.com/, Kind=AppService
ERRO[0040] failed to get resource client for (apiVersion:example.com/v1alpha1, kind:AppService, ns:default): failed to get resource type: failed to get the resource REST mapping for GroupVersionKind(example.com/v1alpha1, Kind=AppService): no matches for example.com/, Kind=AppService
ERRO[0045] failed to get resource client for (apiVersion:example.com/v1alpha1, kind:AppService, ns:default): failed to get resource type: failed to get the resource REST mapping for GroupVersionKind(example.com/v1alpha1, Kind=AppService): no matches for example.com/, Kind=AppService
ERRO[0050] failed to get resource client for (apiVersion:example.com/v1alpha1, kind:AppService, ns:default): failed to get resource type: failed to get the resource REST mapping for GroupVersionKind(example.com/v1alpha1, Kind=AppService): no matches for example.com/, Kind=AppService
ERRO[0055] failed to get resource client for (apiVersion:example.com/v1alpha1, kind:AppService, ns:default): failed to get resource type: failed to get the resource REST mapping for GroupVersionKind(example.com/v1alpha1, Kind=AppService): no matches for example.com/, Kind=AppService
ERRO[0060] appservices.example.com "bla" not found
ERRO[0065] appservices.example.com "bla" not found
ERRO[0070] appservices.example.com "bla" not found
ERRO[0075] appservices.example.com "bla" not found
ERRO[0080] appservices.example.com "bla" not found
ERRO[0085] appservices.example.com "bla" not found
ERRO[0090] appservices.example.com "bla" not found Output from running the operator with the my change. |
lgtm |
@shawn-hurley One more thing. Could you also update changelog with this fix. Thanks! |
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. adds fix to CHANGELOG.md fixes operator-framework#272
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