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

Conversation

shawn-hurley
Copy link
Member

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

@@ -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() {
Copy link
Contributor

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.

@fanminshi
Copy link
Contributor

@shawn-hurley have you try this pr to see if it fixes the issue in #272.

@hasbro17
Copy link
Contributor

@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.

@shawn-hurley
Copy link
Member Author

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 kubectl create -f deploy/crd.yaml then running operator-sdk up local --operator-flags="--namespace test" then you will have to create the cr using kubectl create -f deploy/cr.yaml

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.

@fanminshi
Copy link
Contributor

fanminshi commented May 23, 2018

@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 AppService custom resource succeeds.

@shawn-hurley
Copy link
Member Author

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.

@fanminshi
Copy link
Contributor

lgtm

@fanminshi
Copy link
Contributor

@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
@fanminshi fanminshi merged commit e2b47c9 into operator-framework:master May 25, 2018
@shawn-hurley shawn-hurley deleted the issue-272 branch October 17, 2018 15:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Dynamic Client doesn't discover newly created resources after operator has run
3 participants