From 8a96b16a08d620cc64e5b457c4a2c8adc63ab565 Mon Sep 17 00:00:00 2001 From: xushiwei 00425595 Date: Mon, 27 May 2019 20:32:56 +0800 Subject: [PATCH] make resyncPeriod Configurable --- cmd/tf-operator.v1/app/options/options.go | 6 ++++++ cmd/tf-operator.v1/app/server.go | 5 ++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/cmd/tf-operator.v1/app/options/options.go b/cmd/tf-operator.v1/app/options/options.go index 9610791481..8a992eb1d2 100644 --- a/cmd/tf-operator.v1/app/options/options.go +++ b/cmd/tf-operator.v1/app/options/options.go @@ -16,10 +16,13 @@ package options import ( "flag" + "time" "k8s.io/api/core/v1" ) +const DefaultResyncPeriod = 12 * time.Hour + // ServerOption is the main context object for the controller manager. type ServerOption struct { Kubeconfig string @@ -29,6 +32,7 @@ type ServerOption struct { JSONLogFormat bool EnableGangScheduling bool Namespace string + ResyncPeriod time.Duration } // NewServerOption creates a new CMServer with a default config. @@ -55,4 +59,6 @@ func (s *ServerOption) AddFlags(fs *flag.FlagSet) { fs.BoolVar(&s.JSONLogFormat, "json-log-format", true, "Set true to use json style log format. Set false to use plaintext style log format") fs.BoolVar(&s.EnableGangScheduling, "enable-gang-scheduling", false, "Set true to enable gang scheduling by kube-batch.") + + fs.DurationVar(&s.ResyncPeriod, "resyc-period", DefaultResyncPeriod, "Resync interval of the tf-operator") } diff --git a/cmd/tf-operator.v1/app/server.go b/cmd/tf-operator.v1/app/server.go index ff0e7ce03a..e6aa8b1452 100644 --- a/cmd/tf-operator.v1/app/server.go +++ b/cmd/tf-operator.v1/app/server.go @@ -50,7 +50,6 @@ var ( leaseDuration = 15 * time.Second renewDuration = 5 * time.Second retryPeriod = 3 * time.Second - resyncPeriod = 30 * time.Second ) const RecommendedKubeConfigPathEnv = "KUBECONFIG" @@ -101,8 +100,8 @@ func Run(opt *options.ServerOption) error { os.Exit(1) } // Create informer factory. - kubeInformerFactory := kubeinformers.NewFilteredSharedInformerFactory(kubeClientSet, resyncPeriod, opt.Namespace, nil) - tfJobInformerFactory := tfjobinformers.NewSharedInformerFactory(tfJobClientSet, resyncPeriod) + kubeInformerFactory := kubeinformers.NewFilteredSharedInformerFactory(kubeClientSet, opt.ResyncPeriod, opt.Namespace, nil) + tfJobInformerFactory := tfjobinformers.NewSharedInformerFactory(tfJobClientSet, opt.ResyncPeriod) unstructuredInformer := controller.NewUnstructuredTFJobInformer(kcfg, opt.Namespace)