From c4ed30f255a25b8251500393e20b852d84937542 Mon Sep 17 00:00:00 2001 From: Ish Shah Date: Fri, 24 Aug 2018 12:25:09 -0700 Subject: [PATCH 1/7] Switch ints to time.duration --- pkg/sdk/api.go | 3 ++- pkg/sdk/informer.go | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/pkg/sdk/api.go b/pkg/sdk/api.go index 54970515039..c176af148c1 100644 --- a/pkg/sdk/api.go +++ b/pkg/sdk/api.go @@ -16,6 +16,7 @@ package sdk import ( "context" + "time" "github.com/operator-framework/operator-sdk/pkg/k8sclient" "github.com/operator-framework/operator-sdk/pkg/sdk/internal/metrics" @@ -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) { resourceClient, resourcePluralName, err := k8sclient.GetResourceClient(apiVersion, kind, namespace) // TODO: Better error handling, e.g retry if err != nil { diff --git a/pkg/sdk/informer.go b/pkg/sdk/informer.go index 9f199b0d2be..580cd0a8d28 100644 --- a/pkg/sdk/informer.go +++ b/pkg/sdk/informer.go @@ -46,7 +46,7 @@ type informer struct { numWorkers int } -func NewInformer(resourcePluralName, namespace string, resourceClient dynamic.ResourceInterface, resyncPeriod int, c *metrics.Collector, n int) Informer { +func NewInformer(resourcePluralName, namespace string, resourceClient dynamic.ResourceInterface, resyncPeriod time.Duration, c *metrics.Collector, n int) Informer { i := &informer{ resourcePluralName: resourcePluralName, queue: workqueue.NewNamedRateLimitingQueue(workqueue.DefaultControllerRateLimiter(), resourcePluralName), @@ -56,7 +56,7 @@ func NewInformer(resourcePluralName, namespace string, resourceClient dynamic.Re numWorkers: n, } - resyncDuration := time.Duration(resyncPeriod) * time.Second + resyncDuration := resyncPeriod * time.Second i.sharedIndexInformer = cache.NewSharedIndexInformer( newListWatcherFromResourceClient(resourceClient), &unstructured.Unstructured{}, resyncDuration, cache.Indexers{}, ) From 3ec5596b2508cae3c33671c6a02273726d635f16 Mon Sep 17 00:00:00 2001 From: Ish Shah Date: Fri, 24 Aug 2018 12:46:45 -0700 Subject: [PATCH 2/7] update templates --- pkg/generator/generator_test.go | 3 ++- pkg/generator/templates.go | 5 +++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/pkg/generator/generator_test.go b/pkg/generator/generator_test.go index d93152d704a..b3e16bd7bfd 100644 --- a/pkg/generator/generator_test.go +++ b/pkg/generator/generator_test.go @@ -417,6 +417,7 @@ const mainExp = `package main import ( "context" + "time" "runtime" stub "github.com/example-inc/app-operator/pkg/stub" @@ -445,7 +446,7 @@ func main() { if err != nil { logrus.Fatalf("failed to get watch namespace: %v", err) } - resyncPeriod := 5 + resyncPeriod := time.Duration(5) logrus.Infof("Watching %s, %s, %s, %d", resource, kind, namespace, resyncPeriod) sdk.Watch(resource, kind, namespace, resyncPeriod) sdk.Handle(stub.NewHandler()) diff --git a/pkg/generator/templates.go b/pkg/generator/templates.go index 5d5b7cd5c5c..86cbd75ef18 100644 --- a/pkg/generator/templates.go +++ b/pkg/generator/templates.go @@ -131,7 +131,8 @@ const mainTmpl = `package main import ( "context" - "runtime" + "runtime" + "time" stub "{{.StubImport}}" sdk "{{.OperatorSDKImport}}" @@ -159,7 +160,7 @@ func main() { if err != nil { logrus.Fatalf("failed to get watch namespace: %v", err) } - resyncPeriod := 5 + resyncPeriod := time.Duration(5) logrus.Infof("Watching %s, %s, %s, %d", resource, kind, namespace, resyncPeriod) sdk.Watch(resource, kind, namespace, resyncPeriod) sdk.Handle(stub.NewHandler()) From 616e702f32bf8febbf3c9d5362b7eb481b9e6ab1 Mon Sep 17 00:00:00 2001 From: Ish Shah Date: Fri, 24 Aug 2018 13:00:20 -0700 Subject: [PATCH 3/7] line spacing --- pkg/generator/templates.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/generator/templates.go b/pkg/generator/templates.go index 86cbd75ef18..17d56c83e54 100644 --- a/pkg/generator/templates.go +++ b/pkg/generator/templates.go @@ -131,8 +131,8 @@ const mainTmpl = `package main import ( "context" - "runtime" - "time" + "runtime" + "time" stub "{{.StubImport}}" sdk "{{.OperatorSDKImport}}" From 25871915b2420761b6ca5d5fc65ed4d5e643405f Mon Sep 17 00:00:00 2001 From: Ish Shah Date: Fri, 24 Aug 2018 13:16:55 -0700 Subject: [PATCH 4/7] fix import order --- pkg/generator/generator_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/generator/generator_test.go b/pkg/generator/generator_test.go index b3e16bd7bfd..6ab8ee2830e 100644 --- a/pkg/generator/generator_test.go +++ b/pkg/generator/generator_test.go @@ -417,8 +417,8 @@ const mainExp = `package main import ( "context" - "time" "runtime" + "time" stub "github.com/example-inc/app-operator/pkg/stub" sdk "github.com/operator-framework/operator-sdk/pkg/sdk" From 4cbc0062a63463e2c39a155f9acbc887a677b4c3 Mon Sep 17 00:00:00 2001 From: Ish Shah Date: Mon, 27 Aug 2018 14:28:09 -0700 Subject: [PATCH 5/7] updated godoc and removed multiplier --- pkg/sdk/api.go | 2 +- pkg/sdk/informer.go | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/pkg/sdk/api.go b/pkg/sdk/api.go index c176af148c1..81c9505a42a 100644 --- a/pkg/sdk/api.go +++ b/pkg/sdk/api.go @@ -36,7 +36,7 @@ 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. // - 0 means no periodic events will be sent // 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 diff --git a/pkg/sdk/informer.go b/pkg/sdk/informer.go index 580cd0a8d28..3cd466bd343 100644 --- a/pkg/sdk/informer.go +++ b/pkg/sdk/informer.go @@ -56,9 +56,8 @@ func NewInformer(resourcePluralName, namespace string, resourceClient dynamic.Re numWorkers: n, } - resyncDuration := resyncPeriod * time.Second i.sharedIndexInformer = cache.NewSharedIndexInformer( - newListWatcherFromResourceClient(resourceClient), &unstructured.Unstructured{}, resyncDuration, cache.Indexers{}, + newListWatcherFromResourceClient(resourceClient), &unstructured.Unstructured{}, resyncPeriod, cache.Indexers{}, ) i.sharedIndexInformer.AddEventHandler(cache.ResourceEventHandlerFuncs{ AddFunc: i.handleAddResourceEvent, From b994d20171d826aed22e4dd1c432e269440762c8 Mon Sep 17 00:00:00 2001 From: Ish Shah Date: Mon, 27 Aug 2018 14:41:05 -0700 Subject: [PATCH 6/7] move from ns to seconds --- pkg/generator/generator_test.go | 2 +- pkg/generator/templates.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/generator/generator_test.go b/pkg/generator/generator_test.go index 6ab8ee2830e..92130ff094c 100644 --- a/pkg/generator/generator_test.go +++ b/pkg/generator/generator_test.go @@ -446,7 +446,7 @@ func main() { if err != nil { logrus.Fatalf("failed to get watch namespace: %v", err) } - resyncPeriod := time.Duration(5) + resyncPeriod := time.Duration(5) * time.Second logrus.Infof("Watching %s, %s, %s, %d", resource, kind, namespace, resyncPeriod) sdk.Watch(resource, kind, namespace, resyncPeriod) sdk.Handle(stub.NewHandler()) diff --git a/pkg/generator/templates.go b/pkg/generator/templates.go index 17d56c83e54..d85ad0dff3a 100644 --- a/pkg/generator/templates.go +++ b/pkg/generator/templates.go @@ -160,7 +160,7 @@ func main() { if err != nil { logrus.Fatalf("failed to get watch namespace: %v", err) } - resyncPeriod := time.Duration(5) + resyncPeriod := time.Duration(5) * time.Second logrus.Infof("Watching %s, %s, %s, %d", resource, kind, namespace, resyncPeriod) sdk.Watch(resource, kind, namespace, resyncPeriod) sdk.Handle(stub.NewHandler()) From 6875f80d395a0d7a2340f14511bc43f5fd92661d Mon Sep 17 00:00:00 2001 From: Ish Shah Date: Tue, 28 Aug 2018 09:36:12 -0700 Subject: [PATCH 7/7] update godoc --- pkg/sdk/api.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/sdk/api.go b/pkg/sdk/api.go index 81c9505a42a..954e8f47266 100644 --- a/pkg/sdk/api.go +++ b/pkg/sdk/api.go @@ -36,7 +36,7 @@ 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 ms 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 for how often an event with the latest resource version will be sent to the handler, even if there is no change. // - 0 means no periodic events will be sent // 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