From 429ce4b4333b347186e25f542264ce5e7a91cfe0 Mon Sep 17 00:00:00 2001 From: Yuping Fan Date: Wed, 14 Aug 2024 17:03:15 +0800 Subject: [PATCH] fix(controller): Correct limit in controller List API when `Relist` called Signed-off-by: Yuping Fan --- workflow/common/common.go | 3 +++ workflow/controller/controller.go | 3 +++ .../informer/tolerant_cluster_workflow_template_informer.go | 5 +++++ .../informer/tolerant_workflow_template_informer.go | 5 +++++ workflow/controller/taskresult.go | 3 +++ 5 files changed, 19 insertions(+) diff --git a/workflow/common/common.go b/workflow/common/common.go index b4f174263eaa..24480179282a 100644 --- a/workflow/common/common.go +++ b/workflow/common/common.go @@ -260,6 +260,9 @@ const ( ArgoProgressPath = VarRunArgoPath + "/progress" ConfigMapName = "workflow-controller-configmap" + + // DefaultPageSize is the limit value of the request k8s apiserver + DefaultPageSize = 500 ) // AnnotationKeyKillCmd specifies the command to use to kill to container, useful for injected sidecars diff --git a/workflow/controller/controller.go b/workflow/controller/controller.go index 7dfce1a960b4..4238016502b5 100644 --- a/workflow/controller/controller.go +++ b/workflow/controller/controller.go @@ -916,6 +916,9 @@ func (wfc *WorkflowController) tweakListRequestListOptions(options *metav1.ListO // `ResourceVersion=0` does not honor the `limit` in API calls, which results in making significant List calls // without `limit`. For details, see https://github.com/argoproj/argo-workflows/pull/11343 options.ResourceVersion = "" + if options.Limit == 0 { + options.Limit = common.DefaultPageSize + } } func (wfc *WorkflowController) tweakWatchRequestListOptions(options *metav1.ListOptions) { diff --git a/workflow/controller/informer/tolerant_cluster_workflow_template_informer.go b/workflow/controller/informer/tolerant_cluster_workflow_template_informer.go index b603f0cfeec9..ce4fcc335513 100644 --- a/workflow/controller/informer/tolerant_cluster_workflow_template_informer.go +++ b/workflow/controller/informer/tolerant_cluster_workflow_template_informer.go @@ -3,6 +3,8 @@ package informer import ( "time" + "github.com/argoproj/argo-workflows/v3/workflow/common" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime/schema" "k8s.io/client-go/dynamic" @@ -25,6 +27,9 @@ func NewTolerantClusterWorkflowTemplateInformer(dynamicInterface dynamic.Interfa // `ResourceVersion=0` does not honor the `limit` in API calls, which results in making significant List calls // without `limit`. For details, see https://github.com/argoproj/argo-workflows/pull/11343 options.ResourceVersion = "" + if options.Limit == 0 { + options.Limit = common.DefaultPageSize + } }).ForResource(schema.GroupVersionResource{Group: workflow.Group, Version: workflow.Version, Resource: workflow.ClusterWorkflowTemplatePlural})} } diff --git a/workflow/controller/informer/tolerant_workflow_template_informer.go b/workflow/controller/informer/tolerant_workflow_template_informer.go index 21c89636dfe5..c9e71e0ffd1f 100644 --- a/workflow/controller/informer/tolerant_workflow_template_informer.go +++ b/workflow/controller/informer/tolerant_workflow_template_informer.go @@ -3,6 +3,8 @@ package informer import ( "time" + "github.com/argoproj/argo-workflows/v3/workflow/common" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime/schema" "k8s.io/client-go/dynamic" @@ -25,6 +27,9 @@ func NewTolerantWorkflowTemplateInformer(dynamicInterface dynamic.Interface, def // `ResourceVersion=0` does not honor the `limit` in API calls, which results in making significant List calls // without `limit`. For details, see https://github.com/argoproj/argo-workflows/pull/11343 options.ResourceVersion = "" + if options.Limit == 0 { + options.Limit = common.DefaultPageSize + } }).ForResource(schema.GroupVersionResource{Group: workflow.Group, Version: workflow.Version, Resource: workflow.WorkflowTemplatePlural})} } diff --git a/workflow/controller/taskresult.go b/workflow/controller/taskresult.go index be4bed0db701..1f04147b516c 100644 --- a/workflow/controller/taskresult.go +++ b/workflow/controller/taskresult.go @@ -34,6 +34,9 @@ func (wfc *WorkflowController) newWorkflowTaskResultInformer() cache.SharedIndex // `ResourceVersion=0` does not honor the `limit` in API calls, which results in making significant List calls // without `limit`. For details, see https://github.com/argoproj/argo-workflows/pull/11343 options.ResourceVersion = "" + if options.Limit == 0 { + options.Limit = common.DefaultPageSize + } }, ) //nolint:errcheck // the error only happens if the informer was stopped, and it hasn't even started (https://github.com/kubernetes/client-go/blob/46588f2726fa3e25b1704d6418190f424f95a990/tools/cache/shared_informer.go#L580)