diff --git a/pkg/controller/common/context.go b/pkg/controller/common/context.go new file mode 100644 index 000000000..657f4c785 --- /dev/null +++ b/pkg/controller/common/context.go @@ -0,0 +1,31 @@ +/* +Copyright 2021 The KubeVela Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package common + +import ( + "context" + "time" +) + +const ( + reconcileTimeout = time.Minute +) + +// NewReconcileContext create context with default timeout (60s) +func NewReconcileContext() (context.Context, context.CancelFunc) { + return context.WithTimeout(context.Background(), reconcileTimeout) +} diff --git a/pkg/controller/core.oam.dev/v1alpha2/appdeployment/appdeployment_controller.go b/pkg/controller/core.oam.dev/v1alpha2/appdeployment/appdeployment_controller.go index 857e36804..2cc3e3029 100644 --- a/pkg/controller/core.oam.dev/v1alpha2/appdeployment/appdeployment_controller.go +++ b/pkg/controller/core.oam.dev/v1alpha2/appdeployment/appdeployment_controller.go @@ -39,6 +39,7 @@ import ( oamcorealpha "github.com/oam-dev/kubevela/apis/core.oam.dev/v1alpha2" oamcore "github.com/oam-dev/kubevela/apis/core.oam.dev/v1beta1" "github.com/oam-dev/kubevela/pkg/clustermanager" + common2 "github.com/oam-dev/kubevela/pkg/controller/common" oamctrl "github.com/oam-dev/kubevela/pkg/controller/core.oam.dev" "github.com/oam-dev/kubevela/pkg/controller/utils" "github.com/oam-dev/kubevela/pkg/oam/discoverymapper" @@ -47,7 +48,6 @@ import ( const ( appDeploymentFinalizer = "finalizers.appdeployment.oam.dev" - reconcileTimeOut = 60 * time.Second secretKeyConfig = "config" ) @@ -71,9 +71,9 @@ type Reconciler struct { // Reconcile is the main logic of appDeployment controller func (r *Reconciler) Reconcile(req ctrl.Request) (res reconcile.Result, retErr error) { - appDeployment := &oamcore.AppDeployment{} - ctx, cancel := context.WithTimeout(context.TODO(), reconcileTimeOut) + ctx, cancel := common2.NewReconcileContext() defer cancel() + appDeployment := &oamcore.AppDeployment{} startTime := time.Now() defer func() { diff --git a/pkg/controller/core.oam.dev/v1alpha2/application/application_controller.go b/pkg/controller/core.oam.dev/v1alpha2/application/application_controller.go index 20e0fd0a4..88610a152 100644 --- a/pkg/controller/core.oam.dev/v1alpha2/application/application_controller.go +++ b/pkg/controller/core.oam.dev/v1alpha2/application/application_controller.go @@ -21,8 +21,6 @@ import ( "fmt" "time" - "github.com/oam-dev/kubevela/apis/core.oam.dev/condition" - "github.com/crossplane/crossplane-runtime/pkg/event" "github.com/crossplane/crossplane-runtime/pkg/meta" "github.com/pkg/errors" @@ -35,9 +33,11 @@ import ( "sigs.k8s.io/controller-runtime/pkg/reconcile" "github.com/oam-dev/kubevela/apis/core.oam.dev/common" + "github.com/oam-dev/kubevela/apis/core.oam.dev/condition" "github.com/oam-dev/kubevela/apis/core.oam.dev/v1beta1" velatypes "github.com/oam-dev/kubevela/apis/types" "github.com/oam-dev/kubevela/pkg/appfile" + common2 "github.com/oam-dev/kubevela/pkg/controller/common" core "github.com/oam-dev/kubevela/pkg/controller/core.oam.dev" "github.com/oam-dev/kubevela/pkg/cue/packages" "github.com/oam-dev/kubevela/pkg/oam" @@ -80,7 +80,8 @@ type Reconciler struct { // Reconcile process app event func (r *Reconciler) Reconcile(req ctrl.Request) (ctrl.Result, error) { - ctx := context.Background() + ctx, cancel := common2.NewReconcileContext() + defer cancel() klog.InfoS("Reconcile application", "application", klog.KRef(req.Namespace, req.Name)) app := new(v1beta1.Application) diff --git a/pkg/controller/core.oam.dev/v1alpha2/applicationconfiguration/applicationconfiguration.go b/pkg/controller/core.oam.dev/v1alpha2/applicationconfiguration/applicationconfiguration.go index caf1fad68..ea94c2b30 100644 --- a/pkg/controller/core.oam.dev/v1alpha2/applicationconfiguration/applicationconfiguration.go +++ b/pkg/controller/core.oam.dev/v1alpha2/applicationconfiguration/applicationconfiguration.go @@ -53,8 +53,6 @@ import ( "github.com/oam-dev/kubevela/pkg/utils/apply" ) -const reconcileTimeout = 1 * time.Minute - // Reconcile error strings. const ( errGetAppConfig = "cannot get application configuration" @@ -222,10 +220,9 @@ func NewReconciler(m ctrl.Manager, dm discoverymapper.DiscoveryMapper, o ...Reco // Reconcile an OAM ApplicationConfigurations by rendering and instantiating its // Components and Traits. func (r *OAMApplicationReconciler) Reconcile(req reconcile.Request) (reconcile.Result, error) { - klog.InfoS("Reconcile applicationConfiguration", "applicationConfiguration", klog.KRef(req.Namespace, req.Name)) - - ctx, cancel := context.WithTimeout(context.Background(), reconcileTimeout) + ctx, cancel := common.NewReconcileContext() defer cancel() + klog.InfoS("Reconcile applicationConfiguration", "applicationConfiguration", klog.KRef(req.Namespace, req.Name)) ac := &v1alpha2.ApplicationConfiguration{} if err := r.client.Get(ctx, req.NamespacedName, ac); err != nil { diff --git a/pkg/controller/core.oam.dev/v1alpha2/applicationcontext/applicationcontext_controller.go b/pkg/controller/core.oam.dev/v1alpha2/applicationcontext/applicationcontext_controller.go index fb612aff3..552559c9f 100644 --- a/pkg/controller/core.oam.dev/v1alpha2/applicationcontext/applicationcontext_controller.go +++ b/pkg/controller/core.oam.dev/v1alpha2/applicationcontext/applicationcontext_controller.go @@ -17,7 +17,6 @@ limitations under the License. package applicationcontext import ( - "context" "fmt" "strings" "time" @@ -35,6 +34,7 @@ import ( "github.com/oam-dev/kubevela/apis/core.oam.dev/v1alpha2" "github.com/oam-dev/kubevela/apis/types" + common2 "github.com/oam-dev/kubevela/pkg/controller/common" core "github.com/oam-dev/kubevela/pkg/controller/core.oam.dev" ac "github.com/oam-dev/kubevela/pkg/controller/core.oam.dev/v1alpha2/applicationconfiguration" "github.com/oam-dev/kubevela/pkg/oam/discoverymapper" @@ -48,8 +48,6 @@ const ( errUpdateAppContextStatus = "cannot update application context status" ) -const reconcileTimeout = 1 * time.Minute - // Reconciler reconciles an Application Context by constructing an in-memory // application configuration and reuse its reconcile logic type Reconciler struct { @@ -62,9 +60,9 @@ type Reconciler struct { // Reconcile reconcile an application context func (r *Reconciler) Reconcile(request reconcile.Request) (reconcile.Result, error) { - klog.InfoS("Reconcile", "applicationContext", klog.KRef(request.Namespace, request.Name)) - ctx, cancel := context.WithTimeout(context.Background(), reconcileTimeout) + ctx, cancel := common2.NewReconcileContext() defer cancel() + klog.InfoS("Reconcile", "applicationContext", klog.KRef(request.Namespace, request.Name)) // fetch the app context appContext := &v1alpha2.ApplicationContext{} if err := r.client.Get(ctx, request.NamespacedName, appContext); err != nil { diff --git a/pkg/controller/core.oam.dev/v1alpha2/applicationrollout/applicationrollout_controller.go b/pkg/controller/core.oam.dev/v1alpha2/applicationrollout/applicationrollout_controller.go index afda85597..2bd4a8db8 100644 --- a/pkg/controller/core.oam.dev/v1alpha2/applicationrollout/applicationrollout_controller.go +++ b/pkg/controller/core.oam.dev/v1alpha2/applicationrollout/applicationrollout_controller.go @@ -21,8 +21,6 @@ import ( "fmt" "time" - "github.com/oam-dev/kubevela/apis/core.oam.dev/condition" - "github.com/crossplane/crossplane-runtime/pkg/event" "github.com/crossplane/crossplane-runtime/pkg/meta" "github.com/pkg/errors" @@ -36,8 +34,10 @@ import ( "sigs.k8s.io/controller-runtime/pkg/controller" "sigs.k8s.io/controller-runtime/pkg/reconcile" + "github.com/oam-dev/kubevela/apis/core.oam.dev/condition" "github.com/oam-dev/kubevela/apis/core.oam.dev/v1beta1" "github.com/oam-dev/kubevela/apis/standard.oam.dev/v1alpha1" + common2 "github.com/oam-dev/kubevela/pkg/controller/common" "github.com/oam-dev/kubevela/pkg/controller/common/rollout" oamctrl "github.com/oam-dev/kubevela/pkg/controller/core.oam.dev" "github.com/oam-dev/kubevela/pkg/oam/discoverymapper" @@ -48,8 +48,6 @@ const ( errUpdateAppRollout = "failed to update the app rollout" appRolloutFinalizer = "finalizers.approllout.oam.dev" - - reconcileTimeOut = 60 * time.Second ) // Reconciler reconciles an AppRollout object @@ -69,10 +67,10 @@ type Reconciler struct { // Reconcile is the main logic of appRollout controller // nolint:gocyclo func (r *Reconciler) Reconcile(req ctrl.Request) (res reconcile.Result, retErr error) { - var appRollout v1beta1.AppRollout - ctx, cancel := context.WithTimeout(context.TODO(), reconcileTimeOut) + ctx, cancel := common2.NewReconcileContext() defer cancel() ctx = oamutil.SetNamespaceInCtx(ctx, req.Namespace) + var appRollout v1beta1.AppRollout startTime := time.Now() defer func() { diff --git a/pkg/controller/core.oam.dev/v1alpha2/core/components/componentdefinition/componentdefinition_controller.go b/pkg/controller/core.oam.dev/v1alpha2/core/components/componentdefinition/componentdefinition_controller.go index 74cfa7632..f9a5b8a35 100644 --- a/pkg/controller/core.oam.dev/v1alpha2/core/components/componentdefinition/componentdefinition_controller.go +++ b/pkg/controller/core.oam.dev/v1alpha2/core/components/componentdefinition/componentdefinition_controller.go @@ -37,6 +37,7 @@ import ( "github.com/oam-dev/kubevela/apis/core.oam.dev/condition" "github.com/oam-dev/kubevela/apis/core.oam.dev/v1beta1" "github.com/oam-dev/kubevela/apis/types" + common2 "github.com/oam-dev/kubevela/pkg/controller/common" oamctrl "github.com/oam-dev/kubevela/pkg/controller/core.oam.dev" coredef "github.com/oam-dev/kubevela/pkg/controller/core.oam.dev/v1alpha2/core" "github.com/oam-dev/kubevela/pkg/controller/utils" @@ -59,8 +60,9 @@ type Reconciler struct { // Reconcile is the main logic for ComponentDefinition controller func (r *Reconciler) Reconcile(req ctrl.Request) (ctrl.Result, error) { + ctx, cancel := common2.NewReconcileContext() + defer cancel() klog.InfoS("Reconcile componentDefinition", "componentDefinition", klog.KRef(req.Namespace, req.Name)) - ctx := context.Background() var componentDefinition v1beta1.ComponentDefinition if err := r.Get(ctx, req.NamespacedName, &componentDefinition); err != nil { diff --git a/pkg/controller/core.oam.dev/v1alpha2/core/policies/policydefinition/policydefinition_controller.go b/pkg/controller/core.oam.dev/v1alpha2/core/policies/policydefinition/policydefinition_controller.go index f4395b9c0..11ead9549 100644 --- a/pkg/controller/core.oam.dev/v1alpha2/core/policies/policydefinition/policydefinition_controller.go +++ b/pkg/controller/core.oam.dev/v1alpha2/core/policies/policydefinition/policydefinition_controller.go @@ -36,6 +36,7 @@ import ( "github.com/oam-dev/kubevela/apis/core.oam.dev/common" "github.com/oam-dev/kubevela/apis/core.oam.dev/condition" "github.com/oam-dev/kubevela/apis/core.oam.dev/v1beta1" + common2 "github.com/oam-dev/kubevela/pkg/controller/common" oamctrl "github.com/oam-dev/kubevela/pkg/controller/core.oam.dev" coredef "github.com/oam-dev/kubevela/pkg/controller/core.oam.dev/v1alpha2/core" "github.com/oam-dev/kubevela/pkg/controller/utils" @@ -58,9 +59,10 @@ type Reconciler struct { // Reconcile is the main logic for PolicyDefinition controller func (r *Reconciler) Reconcile(req ctrl.Request) (ctrl.Result, error) { + ctx, cancel := common2.NewReconcileContext() + defer cancel() definitionName := req.NamespacedName.Name klog.InfoS("Reconciling PolicyDefinition...", "Name", definitionName, "Namespace", req.Namespace) - ctx := context.Background() var policydefinition v1beta1.PolicyDefinition if err := r.Get(ctx, req.NamespacedName, &policydefinition); err != nil { diff --git a/pkg/controller/core.oam.dev/v1alpha2/core/scopes/healthscope/healthscope_controller.go b/pkg/controller/core.oam.dev/v1alpha2/core/scopes/healthscope/healthscope_controller.go index 39f8caba1..5b2576db3 100644 --- a/pkg/controller/core.oam.dev/v1alpha2/core/scopes/healthscope/healthscope_controller.go +++ b/pkg/controller/core.oam.dev/v1alpha2/core/scopes/healthscope/healthscope_controller.go @@ -39,8 +39,7 @@ import ( ) const ( - reconcileTimeout = 1 * time.Minute - longWait = 10 * time.Second + longWait = 10 * time.Second ) // Reconcile error strings. @@ -130,10 +129,9 @@ func NewReconciler(m ctrl.Manager, o ...ReconcilerOption) *Reconciler { // Reconcile an OAM HealthScope by keeping track of its health status. func (r *Reconciler) Reconcile(req reconcile.Request) (reconcile.Result, error) { - klog.InfoS("Reconcile healthScope", "healthScope", klog.KRef(req.Namespace, req.Name)) - - ctx, cancel := context.WithTimeout(context.Background(), reconcileTimeout) + ctx, cancel := common.NewReconcileContext() defer cancel() + klog.InfoS("Reconcile healthScope", "healthScope", klog.KRef(req.Namespace, req.Name)) hs := &v1alpha2.HealthScope{} if err := r.client.Get(ctx, req.NamespacedName, hs); err != nil { diff --git a/pkg/controller/core.oam.dev/v1alpha2/core/traits/manualscalertrait/manualscalertrait_controller.go b/pkg/controller/core.oam.dev/v1alpha2/core/traits/manualscalertrait/manualscalertrait_controller.go index 85c77d442..93079718f 100644 --- a/pkg/controller/core.oam.dev/v1alpha2/core/traits/manualscalertrait/manualscalertrait_controller.go +++ b/pkg/controller/core.oam.dev/v1alpha2/core/traits/manualscalertrait/manualscalertrait_controller.go @@ -38,6 +38,7 @@ import ( "github.com/oam-dev/kubevela/apis/core.oam.dev/condition" oamv1alpha2 "github.com/oam-dev/kubevela/apis/core.oam.dev/v1alpha2" + "github.com/oam-dev/kubevela/pkg/controller/common" controller "github.com/oam-dev/kubevela/pkg/controller/core.oam.dev" "github.com/oam-dev/kubevela/pkg/oam/discoverymapper" "github.com/oam-dev/kubevela/pkg/oam/util" @@ -79,7 +80,8 @@ type Reconciler struct { // +kubebuilder:rbac:groups=core.oam.dev,resources=workloaddefinition,verbs=get;list; // +kubebuilder:rbac:groups=apps,resources=deployments,verbs=get;list;watch;update;patch;delete func (r *Reconciler) Reconcile(req ctrl.Request) (ctrl.Result, error) { - ctx := context.Background() + ctx, cancel := common.NewReconcileContext() + defer cancel() klog.InfoS("Reconcile manualscalar trait", "trait", klog.KRef(req.Namespace, req.Name)) var manualScalar oamv1alpha2.ManualScalerTrait diff --git a/pkg/controller/core.oam.dev/v1alpha2/core/traits/traitdefinition/traitdefinition_controller.go b/pkg/controller/core.oam.dev/v1alpha2/core/traits/traitdefinition/traitdefinition_controller.go index c1419d0c9..1c031780f 100644 --- a/pkg/controller/core.oam.dev/v1alpha2/core/traits/traitdefinition/traitdefinition_controller.go +++ b/pkg/controller/core.oam.dev/v1alpha2/core/traits/traitdefinition/traitdefinition_controller.go @@ -36,6 +36,7 @@ import ( "github.com/oam-dev/kubevela/apis/core.oam.dev/common" "github.com/oam-dev/kubevela/apis/core.oam.dev/condition" "github.com/oam-dev/kubevela/apis/core.oam.dev/v1beta1" + common2 "github.com/oam-dev/kubevela/pkg/controller/common" oamctrl "github.com/oam-dev/kubevela/pkg/controller/core.oam.dev" coredef "github.com/oam-dev/kubevela/pkg/controller/core.oam.dev/v1alpha2/core" "github.com/oam-dev/kubevela/pkg/controller/utils" @@ -58,8 +59,9 @@ type Reconciler struct { // Reconcile is the main logic for TraitDefinition controller func (r *Reconciler) Reconcile(req ctrl.Request) (ctrl.Result, error) { + ctx, cancel := common2.NewReconcileContext() + defer cancel() klog.InfoS("Reconcile traitDefinition", "traitDefinition", klog.KRef(req.Namespace, req.Name)) - ctx := context.Background() var traitdefinition v1beta1.TraitDefinition if err := r.Get(ctx, req.NamespacedName, &traitdefinition); err != nil { diff --git a/pkg/controller/core.oam.dev/v1alpha2/core/workflow/workflowstepdefinition/workflowstepdefinition_controller.go b/pkg/controller/core.oam.dev/v1alpha2/core/workflow/workflowstepdefinition/workflowstepdefinition_controller.go index dc2babb25..a70367560 100644 --- a/pkg/controller/core.oam.dev/v1alpha2/core/workflow/workflowstepdefinition/workflowstepdefinition_controller.go +++ b/pkg/controller/core.oam.dev/v1alpha2/core/workflow/workflowstepdefinition/workflowstepdefinition_controller.go @@ -36,6 +36,7 @@ import ( "github.com/oam-dev/kubevela/apis/core.oam.dev/common" "github.com/oam-dev/kubevela/apis/core.oam.dev/condition" "github.com/oam-dev/kubevela/apis/core.oam.dev/v1beta1" + common2 "github.com/oam-dev/kubevela/pkg/controller/common" oamctrl "github.com/oam-dev/kubevela/pkg/controller/core.oam.dev" coredef "github.com/oam-dev/kubevela/pkg/controller/core.oam.dev/v1alpha2/core" "github.com/oam-dev/kubevela/pkg/controller/utils" @@ -58,9 +59,10 @@ type Reconciler struct { // Reconcile is the main logic for WorkflowStepDefinition controller func (r *Reconciler) Reconcile(req ctrl.Request) (ctrl.Result, error) { + ctx, cancel := common2.NewReconcileContext() + defer cancel() definitionName := req.NamespacedName.Name klog.InfoS("Reconciling WorkflowStepDefinition...", "Name", definitionName, "Namespace", req.Namespace) - ctx := context.Background() var wfstepdefinition v1beta1.WorkflowStepDefinition if err := r.Get(ctx, req.NamespacedName, &wfstepdefinition); err != nil { diff --git a/pkg/controller/core.oam.dev/v1alpha2/core/workloads/containerizedworkload/containerizedworkload_controller.go b/pkg/controller/core.oam.dev/v1alpha2/core/workloads/containerizedworkload/containerizedworkload_controller.go index de309fc3e..36b646038 100644 --- a/pkg/controller/core.oam.dev/v1alpha2/core/workloads/containerizedworkload/containerizedworkload_controller.go +++ b/pkg/controller/core.oam.dev/v1alpha2/core/workloads/containerizedworkload/containerizedworkload_controller.go @@ -37,6 +37,7 @@ import ( "github.com/oam-dev/kubevela/apis/core.oam.dev/condition" "github.com/oam-dev/kubevela/apis/core.oam.dev/v1alpha2" + common2 "github.com/oam-dev/kubevela/pkg/controller/common" controller "github.com/oam-dev/kubevela/pkg/controller/core.oam.dev" "github.com/oam-dev/kubevela/pkg/oam/util" ) @@ -74,7 +75,8 @@ type Reconciler struct { // +kubebuilder:rbac:groups=core,resources=services,verbs=get;list;watch;create;update;patch;delete // +kubebuilder:rbac:groups=core,resources=configmaps,verbs=get;list;watch;create;update;patch;delete func (r *Reconciler) Reconcile(req ctrl.Request) (ctrl.Result, error) { - ctx := context.Background() + ctx, cancel := common2.NewReconcileContext() + defer cancel() klog.InfoS("Reconcile containerizedworkload", klog.KRef(req.Namespace, req.Name)) var workload v1alpha2.ContainerizedWorkload diff --git a/pkg/controller/core.oam.dev/v1alpha2/envbinding/envbinding_controller.go b/pkg/controller/core.oam.dev/v1alpha2/envbinding/envbinding_controller.go index 62e70578e..a7d14a015 100644 --- a/pkg/controller/core.oam.dev/v1alpha2/envbinding/envbinding_controller.go +++ b/pkg/controller/core.oam.dev/v1alpha2/envbinding/envbinding_controller.go @@ -30,6 +30,7 @@ import ( "github.com/oam-dev/kubevela/apis/core.oam.dev/condition" "github.com/oam-dev/kubevela/apis/core.oam.dev/v1alpha1" "github.com/oam-dev/kubevela/pkg/appfile" + common2 "github.com/oam-dev/kubevela/pkg/controller/common" oamctrl "github.com/oam-dev/kubevela/pkg/controller/core.oam.dev" "github.com/oam-dev/kubevela/pkg/cue/packages" "github.com/oam-dev/kubevela/pkg/oam/discoverymapper" @@ -48,9 +49,10 @@ type Reconciler struct { // Reconcile is the main logic for EnvBinding controller func (r *Reconciler) Reconcile(req ctrl.Request) (ctrl.Result, error) { + ctx, cancel := common2.NewReconcileContext() + defer cancel() klog.InfoS("Reconcile EnvBinding", "envbinding", klog.KRef(req.Namespace, req.Name)) - ctx := context.Background() envBinding := new(v1alpha1.EnvBinding) if err := r.Client.Get(ctx, client.ObjectKey{Namespace: req.Namespace, Name: req.Name}, envBinding); err != nil { return ctrl.Result{}, client.IgnoreNotFound(err) diff --git a/pkg/controller/core.oam.dev/v1alpha2/initializer/initializer_controller.go b/pkg/controller/core.oam.dev/v1alpha2/initializer/initializer_controller.go index 6ea0dcfc0..bf6131b45 100644 --- a/pkg/controller/core.oam.dev/v1alpha2/initializer/initializer_controller.go +++ b/pkg/controller/core.oam.dev/v1alpha2/initializer/initializer_controller.go @@ -37,6 +37,7 @@ import ( "github.com/oam-dev/kubevela/apis/core.oam.dev/condition" "github.com/oam-dev/kubevela/apis/core.oam.dev/v1beta1" velatypes "github.com/oam-dev/kubevela/apis/types" + common2 "github.com/oam-dev/kubevela/pkg/controller/common" oamctrl "github.com/oam-dev/kubevela/pkg/controller/core.oam.dev" "github.com/oam-dev/kubevela/pkg/controller/utils" "github.com/oam-dev/kubevela/pkg/oam/discoverymapper" @@ -57,8 +58,9 @@ type Reconciler struct { // Reconcile is the main logic for Initializer controller func (r *Reconciler) Reconcile(req ctrl.Request) (ctrl.Result, error) { + ctx, cancel := common2.NewReconcileContext() + defer cancel() klog.InfoS("Reconcile initializer", "initializer", klog.KRef(req.Namespace, req.Name)) - ctx := context.Background() init := new(v1beta1.Initializer) if err := r.Client.Get(ctx, req.NamespacedName, init); err != nil { diff --git a/pkg/controller/standard.oam.dev/v1alpha1/podspecworkload/podspecworkload_controller.go b/pkg/controller/standard.oam.dev/v1alpha1/podspecworkload/podspecworkload_controller.go index 4a5e4d34f..ab9d5ab9c 100644 --- a/pkg/controller/standard.oam.dev/v1alpha1/podspecworkload/podspecworkload_controller.go +++ b/pkg/controller/standard.oam.dev/v1alpha1/podspecworkload/podspecworkload_controller.go @@ -22,6 +22,7 @@ import ( "reflect" "github.com/oam-dev/kubevela/apis/core.oam.dev/condition" + common2 "github.com/oam-dev/kubevela/pkg/controller/common" controller "github.com/oam-dev/kubevela/pkg/controller/core.oam.dev" @@ -77,7 +78,8 @@ type Reconciler struct { // +kubebuilder:rbac:groups=apps,resources=deployments,verbs=get;list;watch;create;update;patch;delete // +kubebuilder:rbac:groups=,resources=services,verbs=get;list;watch;create;update;patch;delete func (r *Reconciler) Reconcile(req ctrl.Request) (ctrl.Result, error) { - ctx := context.Background() + ctx, cancel := common2.NewReconcileContext() + defer cancel() log := r.log.WithValues("podspecworkload", req.NamespacedName) log.Info("Reconcile podspecworkload workload") diff --git a/pkg/controller/standard.oam.dev/v1alpha1/rollout/rollout_controller.go b/pkg/controller/standard.oam.dev/v1alpha1/rollout/rollout_controller.go index f2ce122af..6b1ac95d1 100644 --- a/pkg/controller/standard.oam.dev/v1alpha1/rollout/rollout_controller.go +++ b/pkg/controller/standard.oam.dev/v1alpha1/rollout/rollout_controller.go @@ -18,15 +18,9 @@ package rollout import ( "context" - "time" - - "github.com/oam-dev/kubevela/pkg/utils/apply" "github.com/pkg/errors" - "github.com/oam-dev/kubevela/apis/standard.oam.dev/v1alpha1" - rolloutplan "github.com/oam-dev/kubevela/pkg/controller/common/rollout" - "github.com/crossplane/crossplane-runtime/pkg/event" "github.com/crossplane/crossplane-runtime/pkg/meta" "k8s.io/apimachinery/pkg/runtime" @@ -36,15 +30,17 @@ import ( "sigs.k8s.io/controller-runtime/pkg/controller" "sigs.k8s.io/controller-runtime/pkg/reconcile" + "github.com/oam-dev/kubevela/apis/standard.oam.dev/v1alpha1" + common2 "github.com/oam-dev/kubevela/pkg/controller/common" + rolloutplan "github.com/oam-dev/kubevela/pkg/controller/common/rollout" oamctrl "github.com/oam-dev/kubevela/pkg/controller/core.oam.dev" "github.com/oam-dev/kubevela/pkg/cue/packages" "github.com/oam-dev/kubevela/pkg/oam/discoverymapper" oamutil "github.com/oam-dev/kubevela/pkg/oam/util" + "github.com/oam-dev/kubevela/pkg/utils/apply" ) const ( - reconcileTimeOut = 60 * time.Second - rolloutFinalizer = "finalizers.rollout.standard.oam.dev" errUpdateRollout = "failed to update the rollout" @@ -61,9 +57,9 @@ type reconciler struct { } func (r *reconciler) Reconcile(req ctrl.Request) (ctrl.Result, error) { - rollout := new(v1alpha1.Rollout) - ctx, cancel := context.WithTimeout(context.TODO(), reconcileTimeOut) + ctx, cancel := common2.NewReconcileContext() defer cancel() + rollout := new(v1alpha1.Rollout) ctx = oamutil.SetNamespaceInCtx(ctx, req.Namespace) if err := r.Get(ctx, req.NamespacedName, rollout); err != nil {