Skip to content
This repository has been archived by the owner on Jun 8, 2022. It is now read-only.

Commit

Permalink
set LongWait as a configurable global var (#334)
Browse files Browse the repository at this point in the history
Signed-off-by: wangyike <wangyike.wyk@alibaba-inc.com>
  • Loading branch information
wangyikewxgm authored May 31, 2021
1 parent 2a9537d commit 64a2994
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 4 deletions.
3 changes: 3 additions & 0 deletions cmd/oam-kubernetes-runtime/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"io"
"os"
"strconv"
"time"

"github.com/crossplane/crossplane-runtime/pkg/logging"
"go.uber.org/zap/zapcore"
Expand Down Expand Up @@ -56,6 +57,8 @@ func main() {
"RevisionLimit is the maximum number of revisions that will be maintained. The default value is 50.")
flag.BoolVar(&controllerArgs.ApplyOnceOnly, "apply-once-only", false,
"For the purpose of some production environment that workload or trait should not be affected if no spec change")
flag.DurationVar(&controllerArgs.LongWait, "long-wait", 1*time.Minute, "long-wait is controller next reconcile interval time like 30s, 2m etc. The default value is 1m, "+
"you can set it to 0 for no reconcile routine after success ")
flag.Parse()

// setup logging
Expand Down
5 changes: 5 additions & 0 deletions pkg/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ limitations under the License.

package controller

import "time"

// Args args used by controller
type Args struct {
// RevisionLimit is the maximum number of revisions that will be maintained.
Expand All @@ -22,4 +24,7 @@ type Args struct {
// ApplyOnceOnly indicates whether workloads and traits should be
// affected if no spec change is made in the ApplicationConfiguration.
ApplyOnceOnly bool

// LongWait is controller next reconcile interval time
LongWait time.Duration
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ const (
reconcileTimeout = 1 * time.Minute
dependCheckWait = 10 * time.Second
shortWait = 30 * time.Second
longWait = 1 * time.Minute
)

// Reconcile error strings.
Expand Down Expand Up @@ -99,7 +98,8 @@ func Setup(mgr ctrl.Manager, args controller.Args, l logging.Logger) error {
Complete(NewReconciler(mgr, dm,
WithLogger(l.WithValues("controller", name)),
WithRecorder(event.NewAPIRecorder(mgr.GetEventRecorderFor(name))),
WithApplyOnceOnly(args.ApplyOnceOnly)))
WithApplyOnceOnly(args.ApplyOnceOnly),
WithLogWaitTime(args.LongWait)))
}

// An OAMApplicationReconciler reconciles OAM ApplicationConfigurations by rendering and
Expand All @@ -115,6 +115,7 @@ type OAMApplicationReconciler struct {
preHooks map[string]ControllerHooks
postHooks map[string]ControllerHooks
applyOnceOnly bool
longWait time.Duration
}

// A ReconcilerOption configures a Reconciler.
Expand Down Expand Up @@ -179,6 +180,13 @@ func WithApplyOnceOnly(applyOnceOnly bool) ReconcilerOption {
}
}

// WithLogWaitTime set next reconcile time interval
func WithLogWaitTime(longWait time.Duration) ReconcilerOption {
return func(r *OAMApplicationReconciler) {
r.longWait = longWait
}
}

// NewReconciler returns an OAMApplicationReconciler that reconciles ApplicationConfigurations
// by rendering and instantiating their Components and Traits.
func NewReconciler(m ctrl.Manager, dm discoverymapper.DiscoveryMapper, o ...ReconcilerOption) *OAMApplicationReconciler {
Expand Down Expand Up @@ -288,7 +296,7 @@ func (r *OAMApplicationReconciler) Reconcile(req reconcile.Request) (result reco
ac.SetConditions(v1alpha1.ReconcileError(errors.Wrap(err, errRenderComponents)))
return reconcile.Result{RequeueAfter: shortWait}, errors.Wrap(r.client.Status().Update(ctx, ac), errUpdateAppConfigStatus)
}
waitTime := longWait
waitTime := r.longWait
if len(depStatus.Unsatisfied) != 0 {
waitTime = dependCheckWait
ac.Status.Dependency = *depStatus
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -538,10 +538,11 @@ func TestReconciler(t *testing.T) {
WithPosthook("postHook", ControllerHooksFn(func(ctx context.Context, ac *v1alpha2.ApplicationConfiguration, logger logging.Logger) (reconcile.Result, error) {
return reconcile.Result{RequeueAfter: shortWait}, nil
})),
WithLogWaitTime(1 * time.Minute),
},
},
want: want{
result: reconcile.Result{RequeueAfter: longWait},
result: reconcile.Result{RequeueAfter: 1 * time.Minute},
},
},
"RegisterFinalizer": {
Expand Down

0 comments on commit 64a2994

Please sign in to comment.