Skip to content

Commit

Permalink
fix(controller): Revert cb9676e. Fixes #5852 (#5933)
Browse files Browse the repository at this point in the history
Signed-off-by: Alex Collins <alex_collins@intuit.com>
  • Loading branch information
alexec committed May 18, 2021
1 parent 8cb0e5c commit 56b71d0
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
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
26 changes: 22 additions & 4 deletions workflow/cron/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ import (
"reflect"
"time"

"k8s.io/apimachinery/pkg/selection"

"github.com/argoproj/argo-workflows/v3/workflow/common"

"github.com/argoproj/argo-workflows/v3/util/env"

"github.com/argoproj/pkg/sync"
Expand Down Expand Up @@ -42,7 +46,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 +71,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 +99,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 +294,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()
}

0 comments on commit 56b71d0

Please sign in to comment.