Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(controller): Revert cb9676e88. Fixes #5852 #5933

Merged
merged 2 commits into from
May 18, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion workflow/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ func (wfc *WorkflowController) runTTLController(ctx context.Context, workflowTTL
func (wfc *WorkflowController) runCronController(ctx context.Context) {
defer runtimeutil.HandleCrash(runtimeutil.PanicHandlers...)

cronController := cron.NewCronController(wfc.wfclientset, wfc.dynamicInterface, wfc.wfInformer, wfc.namespace, wfc.GetManagedNamespace(), wfc.Config.InstanceID, wfc.metrics, wfc.eventRecorderManager)
cronController := cron.NewCronController(wfc.wfclientset, wfc.dynamicInterface, wfc.namespace, wfc.GetManagedNamespace(), wfc.Config.InstanceID, wfc.metrics, wfc.eventRecorderManager)
cronController.Run(ctx)
}

Expand Down
24 changes: 20 additions & 4 deletions workflow/cron/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package cron
import (
"context"
"fmt"
"github.com/argoproj/argo-workflows/v3/workflow/common"
"k8s.io/apimachinery/pkg/selection"
"reflect"
"time"

Expand Down Expand Up @@ -42,7 +44,6 @@ type Controller struct {
keyLock sync.KeyLock
wfClientset versioned.Interface
wfLister util.WorkflowLister
wfInformer cache.SharedIndexInformer
cronWfInformer informers.GenericInformer
cronWfQueue workqueue.RateLimitingInterface
dynamicInterface dynamic.Interface
Expand All @@ -68,10 +69,9 @@ func init() {
log.WithField("cronSyncPeriod", cronSyncPeriod).Info("cron config")
}

func NewCronController(wfclientset versioned.Interface, dynamicInterface dynamic.Interface, wfInformer cache.SharedIndexInformer, namespace string, managedNamespace string, instanceId string, metrics *metrics.Metrics, eventRecorderManager events.EventRecorderManager) *Controller {
func NewCronController(wfclientset versioned.Interface, dynamicInterface dynamic.Interface, namespace string, managedNamespace string, instanceId string, metrics *metrics.Metrics, eventRecorderManager events.EventRecorderManager) *Controller {
return &Controller{
wfClientset: wfclientset,
wfInformer: wfInformer,
namespace: namespace,
managedNamespace: managedNamespace,
instanceId: instanceId,
Expand All @@ -97,7 +97,12 @@ func (cc *Controller) Run(ctx context.Context) {
}).ForResource(schema.GroupVersionResource{Group: workflow.Group, Version: workflow.Version, Resource: workflow.CronWorkflowPlural})
cc.addCronWorkflowInformerHandler()

cc.wfLister = util.NewWorkflowLister(cc.wfInformer)
wfInformer := util.NewWorkflowInformer(cc.dynamicInterface, cc.managedNamespace, cronWorkflowResyncPeriod, func(options *v1.ListOptions) {
wfInformerListOptionsFunc(options, cc.instanceId)
}, cache.Indexers{})
go wfInformer.Run(ctx.Done())

cc.wfLister = util.NewWorkflowLister(wfInformer)

cc.cron.Start()
defer cc.cron.Stop()
Expand Down Expand Up @@ -287,3 +292,14 @@ func cronWfInformerListOptionsFunc(options *v1.ListOptions, instanceId string) {
labelSelector := labels.NewSelector().Add(util.InstanceIDRequirement(instanceId))
options.LabelSelector = labelSelector.String()
}

func wfInformerListOptionsFunc(options *v1.ListOptions, instanceId string) {
options.FieldSelector = fields.Everything().String()
isCronWorkflowChildReq, err := labels.NewRequirement(common.LabelKeyCronWorkflow, selection.Exists, []string{})
if err != nil {
panic(err)
}
labelSelector := labels.NewSelector().Add(*isCronWorkflowChildReq)
labelSelector = labelSelector.Add(util.InstanceIDRequirement(instanceId))
options.LabelSelector = labelSelector.String()
}