Skip to content

Switch ints to time.Duration#427

Merged
theishshah merged 7 commits intooperator-framework:masterfrom
theishshah:time-not-int
Aug 28, 2018
Merged

Switch ints to time.Duration#427
theishshah merged 7 commits intooperator-framework:masterfrom
theishshah:time-not-int

Conversation

@theishshah
Copy link
Contributor

Issue #345

@theishshah theishshah requested a review from hasbro17 August 24, 2018 19:25
@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. ;)

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

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

}

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

5 participants