mirror of
https://github.com/kubevela/kubevela.git
synced 2026-08-27 16:17:34 +00:00
add more options for vela-controller (#1769)
* add more option for controller 1. add ConcurrentReconciles for setting the concurrent reconcile number of the controller 2. add DependCheckWait for setting the time to wait for ApplicationConfiguration's dependent-resource ready * fix test * add controller reference
This commit is contained in:
@@ -52,4 +52,10 @@ type Args struct {
|
||||
|
||||
// LongWait is controller next reconcile interval time
|
||||
LongWait time.Duration
|
||||
|
||||
// ConcurrentReconciles is the concurrent reconcile number of the controller
|
||||
ConcurrentReconciles int
|
||||
|
||||
// DependCheckWait is the time to wait for ApplicationConfiguration's dependent-resource ready
|
||||
DependCheckWait time.Duration
|
||||
}
|
||||
|
||||
+18
-4
@@ -31,6 +31,7 @@ import (
|
||||
"k8s.io/client-go/util/retry"
|
||||
ctrl "sigs.k8s.io/controller-runtime"
|
||||
"sigs.k8s.io/controller-runtime/pkg/client"
|
||||
"sigs.k8s.io/controller-runtime/pkg/controller"
|
||||
"sigs.k8s.io/controller-runtime/pkg/reconcile"
|
||||
"sigs.k8s.io/controller-runtime/pkg/source"
|
||||
|
||||
@@ -51,7 +52,6 @@ import (
|
||||
|
||||
const (
|
||||
reconcileTimeout = 1 * time.Minute
|
||||
dependCheckWait = 10 * time.Second
|
||||
shortWait = 30 * time.Second
|
||||
)
|
||||
|
||||
@@ -92,7 +92,12 @@ func Setup(mgr ctrl.Manager, args core.Args, l logging.Logger) error {
|
||||
}
|
||||
name := "oam/" + strings.ToLower(v1alpha2.ApplicationConfigurationGroupKind)
|
||||
|
||||
return ctrl.NewControllerManagedBy(mgr).
|
||||
builder := ctrl.NewControllerManagedBy(mgr)
|
||||
builder.WithOptions(controller.Options{
|
||||
MaxConcurrentReconciles: args.ConcurrentReconciles,
|
||||
})
|
||||
|
||||
return builder.
|
||||
Named(name).
|
||||
For(&v1alpha2.ApplicationConfiguration{}).
|
||||
Watches(&source.Kind{Type: &v1alpha2.Component{}}, &ComponentHandler{
|
||||
@@ -105,7 +110,8 @@ func Setup(mgr ctrl.Manager, args core.Args, l logging.Logger) error {
|
||||
l.WithValues("controller", name),
|
||||
WithRecorder(event.NewAPIRecorder(mgr.GetEventRecorderFor(name))),
|
||||
WithApplyOnceOnlyMode(args.ApplyMode),
|
||||
WithLongWaitTime(args.LongWait)))
|
||||
WithLongWaitTime(args.LongWait),
|
||||
WithDependCheckWait(args.DependCheckWait)))
|
||||
}
|
||||
|
||||
// An OAMApplicationReconciler reconciles OAM ApplicationConfigurations by rendering and
|
||||
@@ -122,6 +128,7 @@ type OAMApplicationReconciler struct {
|
||||
postHooks map[string]ControllerHooks
|
||||
applyOnceOnlyMode core.ApplyOnceOnlyMode
|
||||
longWait time.Duration
|
||||
dependCheckWait time.Duration
|
||||
}
|
||||
|
||||
// A ReconcilerOption configures a Reconciler.
|
||||
@@ -186,6 +193,13 @@ func WithLongWaitTime(longWait time.Duration) ReconcilerOption {
|
||||
}
|
||||
}
|
||||
|
||||
// WithDependCheckWait set depend check wait
|
||||
func WithDependCheckWait(dependCheckWait time.Duration) ReconcilerOption {
|
||||
return func(r *OAMApplicationReconciler) {
|
||||
r.dependCheckWait = dependCheckWait
|
||||
}
|
||||
}
|
||||
|
||||
// NewReconciler returns an OAMApplicationReconciler that reconciles ApplicationConfigurations
|
||||
// by rendering and instantiating their Components and Traits.
|
||||
func NewReconciler(m ctrl.Manager, dm discoverymapper.DiscoveryMapper, log logging.Logger, o ...ReconcilerOption) *OAMApplicationReconciler {
|
||||
@@ -349,7 +363,7 @@ func (r *OAMApplicationReconciler) Reconcile(req reconcile.Request) (result reco
|
||||
ac.Status.Dependency = v1alpha2.DependencyStatus{}
|
||||
waitTime := r.longWait
|
||||
if len(depStatus.Unsatisfied) != 0 {
|
||||
waitTime = dependCheckWait
|
||||
waitTime = r.dependCheckWait
|
||||
ac.Status.Dependency = *depStatus
|
||||
}
|
||||
|
||||
|
||||
+16
-1
@@ -183,6 +183,7 @@ func TestReconciler(t *testing.T) {
|
||||
WithRenderer(ComponentRenderFn(func(_ context.Context, _ *v1alpha2.ApplicationConfiguration) ([]Workload, *v1alpha2.DependencyStatus, error) {
|
||||
return nil, &v1alpha2.DependencyStatus{}, errBoom
|
||||
})),
|
||||
WithDependCheckWait(10 * time.Second),
|
||||
},
|
||||
},
|
||||
want: want{
|
||||
@@ -212,6 +213,7 @@ func TestReconciler(t *testing.T) {
|
||||
WithApplicator(WorkloadApplyFns{ApplyFn: func(_ context.Context, _ []v1alpha2.WorkloadStatus, _ []Workload, _ ...apply.ApplyOption) error {
|
||||
return errBoom
|
||||
}}),
|
||||
WithDependCheckWait(10 * time.Second),
|
||||
},
|
||||
},
|
||||
want: want{
|
||||
@@ -245,6 +247,7 @@ func TestReconciler(t *testing.T) {
|
||||
WithGarbageCollector(GarbageCollectorFn(func(_ string, _ []v1alpha2.WorkloadStatus, _ []Workload) []unstructured.Unstructured {
|
||||
return []unstructured.Unstructured{*workload}
|
||||
})),
|
||||
WithDependCheckWait(10 * time.Second),
|
||||
},
|
||||
},
|
||||
want: want{
|
||||
@@ -308,10 +311,11 @@ func TestReconciler(t *testing.T) {
|
||||
WithGarbageCollector(GarbageCollectorFn(func(_ string, _ []v1alpha2.WorkloadStatus, _ []Workload) []unstructured.Unstructured {
|
||||
return []unstructured.Unstructured{*trait}
|
||||
})),
|
||||
WithDependCheckWait(10 * time.Second),
|
||||
},
|
||||
},
|
||||
want: want{
|
||||
result: reconcile.Result{RequeueAfter: dependCheckWait},
|
||||
result: reconcile.Result{RequeueAfter: 10 * time.Second},
|
||||
},
|
||||
},
|
||||
"FailedPreHook": {
|
||||
@@ -352,6 +356,7 @@ 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
|
||||
})),
|
||||
WithDependCheckWait(10 * time.Second),
|
||||
},
|
||||
},
|
||||
want: want{
|
||||
@@ -422,6 +427,7 @@ func TestReconciler(t *testing.T) {
|
||||
WithPosthook("preHookFailed", ControllerHooksFn(func(ctx context.Context, ac *v1alpha2.ApplicationConfiguration, logger logging.Logger) (reconcile.Result, error) {
|
||||
return reconcile.Result{RequeueAfter: 15 * time.Second}, errBoom
|
||||
})),
|
||||
WithDependCheckWait(10 * time.Second),
|
||||
},
|
||||
},
|
||||
want: want{
|
||||
@@ -472,6 +478,7 @@ func TestReconciler(t *testing.T) {
|
||||
WithPosthook("preHookFailed", ControllerHooksFn(func(ctx context.Context, ac *v1alpha2.ApplicationConfiguration, logger logging.Logger) (reconcile.Result, error) {
|
||||
return reconcile.Result{RequeueAfter: 15 * time.Second}, errBoom
|
||||
})),
|
||||
WithDependCheckWait(10 * time.Second),
|
||||
},
|
||||
},
|
||||
want: want{
|
||||
@@ -540,6 +547,7 @@ func TestReconciler(t *testing.T) {
|
||||
return reconcile.Result{RequeueAfter: shortWait}, nil
|
||||
})),
|
||||
WithLongWaitTime(1 * time.Minute),
|
||||
WithDependCheckWait(10 * time.Second),
|
||||
},
|
||||
},
|
||||
want: want{
|
||||
@@ -584,6 +592,9 @@ func TestReconciler(t *testing.T) {
|
||||
MockStatusUpdate: test.NewMockStatusUpdateFn(nil),
|
||||
},
|
||||
},
|
||||
o: []ReconcilerOption{
|
||||
WithDependCheckWait(10 * time.Second),
|
||||
},
|
||||
},
|
||||
want: want{
|
||||
result: reconcile.Result{},
|
||||
@@ -616,6 +627,9 @@ func TestReconciler(t *testing.T) {
|
||||
MockStatusUpdate: test.NewMockStatusUpdateFn(nil),
|
||||
},
|
||||
},
|
||||
o: []ReconcilerOption{
|
||||
WithDependCheckWait(10 * time.Second),
|
||||
},
|
||||
},
|
||||
want: want{
|
||||
result: reconcile.Result{},
|
||||
@@ -652,6 +666,7 @@ func TestReconciler(t *testing.T) {
|
||||
WithApplicator(WorkloadApplyFns{FinalizeFn: func(ctx context.Context, ac *v1alpha2.ApplicationConfiguration) error {
|
||||
return errBoom
|
||||
}}),
|
||||
WithDependCheckWait(10 * time.Second),
|
||||
},
|
||||
},
|
||||
want: want{
|
||||
|
||||
Reference in New Issue
Block a user