-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
perf: Add workflow template informer to server (#13672)
Signed-off-by: Jakub Buczak <[email protected]>
- Loading branch information
Showing
22 changed files
with
622 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package clusterworkflowtemplate | ||
|
||
import ( | ||
"context" | ||
"time" | ||
|
||
log "github.com/sirupsen/logrus" | ||
|
||
"k8s.io/client-go/dynamic" | ||
"k8s.io/client-go/rest" | ||
"k8s.io/client-go/tools/cache" | ||
|
||
wfextvv1alpha1 "github.com/argoproj/argo-workflows/v3/pkg/client/informers/externalversions/workflow/v1alpha1" | ||
"github.com/argoproj/argo-workflows/v3/server/types" | ||
"github.com/argoproj/argo-workflows/v3/workflow/controller/informer" | ||
"github.com/argoproj/argo-workflows/v3/workflow/templateresolution" | ||
) | ||
|
||
const ( | ||
workflowTemplateResyncPeriod = 20 * time.Minute | ||
) | ||
|
||
var _ types.ClusterWorkflowTemplateStore = &Informer{} | ||
|
||
type Informer struct { | ||
informer wfextvv1alpha1.ClusterWorkflowTemplateInformer | ||
} | ||
|
||
func NewInformer(restConfig *rest.Config) (*Informer, error) { | ||
dynamicInterface, err := dynamic.NewForConfig(restConfig) | ||
if err != nil { | ||
return nil, err | ||
} | ||
informer := informer.NewTolerantClusterWorkflowTemplateInformer( | ||
dynamicInterface, | ||
workflowTemplateResyncPeriod, | ||
) | ||
return &Informer{ | ||
informer: informer, | ||
}, nil | ||
} | ||
|
||
// Start informer in separate go-routine and block until cache sync | ||
func (cwti *Informer) Run(stopCh <-chan struct{}) { | ||
|
||
go cwti.informer.Informer().Run(stopCh) | ||
|
||
if !cache.WaitForCacheSync( | ||
stopCh, | ||
cwti.informer.Informer().HasSynced, | ||
) { | ||
log.Fatal("Timed out waiting for caches to sync") | ||
} | ||
} | ||
|
||
// if namespace contains empty string Lister will use the namespace provided during initialization | ||
func (cwti *Informer) Getter(_ context.Context) templateresolution.ClusterWorkflowTemplateGetter { | ||
if cwti.informer == nil { | ||
log.Fatal("Template informer not started") | ||
} | ||
return cwti.informer.Lister() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package clusterworkflowtemplate | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/argoproj/argo-workflows/v3/server/auth" | ||
"github.com/argoproj/argo-workflows/v3/workflow/templateresolution" | ||
) | ||
|
||
// Store is a wrapper around informer | ||
type ClusterWorkflowTemplateClientStore struct { | ||
} | ||
|
||
func NewClusterWorkflowTemplateClientStore() *ClusterWorkflowTemplateClientStore { | ||
return &ClusterWorkflowTemplateClientStore{} | ||
} | ||
|
||
func (wcs *ClusterWorkflowTemplateClientStore) Getter(ctx context.Context) templateresolution.ClusterWorkflowTemplateGetter { | ||
wfClient := auth.GetWfClient(ctx) | ||
return templateresolution.WrapClusterWorkflowTemplateInterface(wfClient.ArgoprojV1alpha1().ClusterWorkflowTemplates()) | ||
} |
Oops, something went wrong.