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

Switch ints to time.Duration #427

Merged
merged 7 commits into from
Aug 28, 2018

Conversation

theishshah
Copy link
Member

Issue #345

@CSdread
Copy link
Contributor

CSdread commented Aug 27, 2018

not sure if we are allowed to do reviews when not core team, we would need to update the documentation on this in the user guide i believe. I am excited for this one. ;)

@@ -40,7 +41,7 @@ var (
// Consult the API reference for the Group, Version and Kind of a resource: https://kubernetes.io/docs/reference/
// namespace is the Namespace to watch for the resource
// TODO: support opts for specifying label selector
func Watch(apiVersion, kind, namespace string, resyncPeriod int, opts ...watchOption) {
func Watch(apiVersion, kind, namespace string, resyncPeriod time.Duration, opts ...watchOption) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we update the godoc for this change as well?

@fanminshi
Copy link
Contributor

@CSdread feel free to code review any existing PRs.

@@ -159,7 +160,7 @@ func main() {
if err != nil {
logrus.Fatalf("failed to get watch namespace: %v", err)
}
resyncPeriod := 5
resyncPeriod := time.Duration(5)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't' this be a default of 5 seconds:

resyncPeriod := time.Duration(5) * time.Second

Otherwise simply casting it to time.Duration means this is 5ns.
Duration is just an int64 nanosecond count.
https://golang.org/pkg/time/#Duration

@@ -56,7 +56,7 @@ func NewInformer(resourcePluralName, namespace string, resourceClient dynamic.Re
numWorkers: n,
}

resyncDuration := time.Duration(resyncPeriod) * time.Second
resyncDuration := resyncPeriod * time.Second
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to multiply by time.Second here.
The user is allowed to pass in any Duration to sdk.Watch().

pkg/sdk/api.go Outdated
@@ -35,12 +36,12 @@ var (
// - Pods have Group "Core" and Version "v1" giving the APIVersion "v1"
// - The custom resource Memcached might have Group "cache.example.com" and Version "v1alpha1" giving the APIVersion "cache.example.com/v1alpha1"
// kind is the Kind of the resource, e.g "Pod" for pods
// resyncPeriod is the time period in seconds for how often an event with the latest resource version will be sent to the handler, even if there is no change.
// resyncPeriod is the time period in ms for how often an event with the latest resource version will be sent to the handler, even if there is no change.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

resyncPeriod is the time period in time.Duration (int64 nanoseconds count)...

@hasbro17
Copy link
Contributor

LGTM
defer to @shawn-hurley

@fanminshi
Copy link
Contributor

lgtm

@theishshah theishshah merged commit 7152fb7 into operator-framework:master Aug 28, 2018
@hasbro17
Copy link
Contributor

@theishshah We forgot to update the user-guide for this. In the watch the CR section we need to change the argument type to duration for the resync period.
From:

sdk.Watch("cache.example.com/v1alpha1", "Memcached", "default", 5)

to:

sdk.Watch("cache.example.com/v1alpha1", "Memcached", "default", time.Duration(5)*time.Second)

Can you put up a PR for that.

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.

None yet

5 participants