Skip to content

Commit

Permalink
Add reconcile resync period to cmd arg to avoid stale resource caching (
Browse files Browse the repository at this point in the history
#1148)

Co-Authored-By: Jan Schlicht <jan.schlicht+gh@gmail.com>
  • Loading branch information
2 people authored and Jan Schlicht committed Dec 9, 2019
1 parent 45d6cf5 commit 62810dc
Showing 1 changed file with 28 additions and 2 deletions.
30 changes: 28 additions & 2 deletions cmd/manager/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"net/url"
"os"
"strings"
"time"

"github.com/go-logr/logr"
apiextenstionsv1beta1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1"
Expand All @@ -42,6 +43,19 @@ import (
"github.com/kudobuilder/kudo/pkg/version"
)

// parseSyncPeriod determines the minimum frequency at which watched resources are reconciled.
// If the variable is present in the environment the duration is returned.
func parseSyncPeriod() (*time.Duration, error) {
if val, ok := os.LookupEnv("KUDO_SYNCPERIOD"); ok {
sync, err := time.ParseDuration(val)
if err != nil {
return nil, err
}
return &sync, nil
}
return nil, nil
}

func main() {
logf.SetLogger(zap.New(zap.UseDevMode(false)))
log := logf.Log.WithName("entrypoint")
Expand All @@ -50,9 +64,21 @@ func main() {
log.Info(fmt.Sprintf("KUDO Version: %s", fmt.Sprintf("%#v", version.Get())))

// create new controller-runtime manager
log.Info("setting up manager")
syncPeriod, err := parseSyncPeriod()
if err != nil {
log.Error(err, "unable to parse manager sync period variable")
os.Exit(1)
}

if syncPeriod != nil {
log.Info(fmt.Sprintf("setting up manager, sync-period is %v", syncPeriod))
} else {
log.Info("setting up manager")
}

mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{
CertDir: "/tmp/cert",
CertDir: "/tmp/cert",
SyncPeriod: syncPeriod,
})
if err != nil {
log.Error(err, "unable to start manager")
Expand Down

0 comments on commit 62810dc

Please sign in to comment.