Skip to content

Commit cf605b5

Browse files
Joibeleduardodbrmraerino
authored
fix: cluster workflow template store is not initialized in namespace mode. Fixes #14763 (cherry-pick release-3.7) (#14826)
Signed-off-by: Eduardo Rodrigues <[email protected]> Signed-off-by: Marcus Weiner <[email protected]> Signed-off-by: Alan Clucas <[email protected]> Co-authored-by: Eduardo Rodrigues <[email protected]> Co-authored-by: Marcus Weiner <[email protected]>
1 parent ea66014 commit cf605b5

File tree

5 files changed

+49
-5
lines changed

5 files changed

+49
-5
lines changed

pkg/apiclient/argo-kube-client.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,8 @@ func (a *argoKubeClient) startStores(ctx context.Context, restConfig *restclient
168168
} else {
169169
a.cwfTmplStore = clusterworkflowtmplserver.NewClusterWorkflowTemplateClientStore()
170170
}
171+
} else {
172+
a.cwfTmplStore = clusterworkflowtmplserver.NewNullClusterWorkflowTemplate()
171173
}
172174

173175
return nil

server/apiserver/argoserver.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,12 +238,14 @@ func (as *argoServer) Run(ctx context.Context, port int, browserOpenFunc func(st
238238
log.Fatal(err)
239239
}
240240
kubeclientset := kubernetes.NewForConfigOrDie(as.restConfig)
241-
var cwftmplInformer *clusterworkflowtemplate.Informer
241+
var cwftmplInformer clusterworkflowtemplate.ClusterWorkflowTemplateInformer
242242
if rbacutil.HasAccessToClusterWorkflowTemplates(ctx, kubeclientset, resourceCacheNamespace) {
243243
cwftmplInformer, err = clusterworkflowtemplate.NewInformer(as.restConfig)
244244
if err != nil {
245245
log.Fatal(err)
246246
}
247+
} else {
248+
cwftmplInformer = clusterworkflowtemplate.NewNullClusterWorkflowTemplate()
247249
}
248250
eventRecorderManager := events.NewEventRecorderManager(as.clients.Kubernetes)
249251
artifactRepositories := artifactrepositories.New(as.clients.Kubernetes, as.managedNamespace, &config.ArtifactRepository)

server/clusterworkflowtemplate/informer.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ const (
2020
workflowTemplateResyncPeriod = 20 * time.Minute
2121
)
2222

23+
type ClusterWorkflowTemplateInformer interface {
24+
Run(stopCh <-chan struct{})
25+
Getter(ctx context.Context) templateresolution.ClusterWorkflowTemplateGetter
26+
}
27+
2328
var _ types.ClusterWorkflowTemplateStore = &Informer{}
2429

2530
type Informer struct {
@@ -54,9 +59,10 @@ func (cwti *Informer) Run(stopCh <-chan struct{}) {
5459
}
5560

5661
// if namespace contains empty string Lister will use the namespace provided during initialization
57-
func (cwti *Informer) Getter(_ context.Context) templateresolution.ClusterWorkflowTemplateGetter {
58-
if cwti.informer == nil {
59-
log.Fatal("Template informer not started")
62+
func (cwti *Informer) Getter(ctx context.Context) templateresolution.ClusterWorkflowTemplateGetter {
63+
if cwti == nil || cwti.informer == nil {
64+
log.Error("Template informer not started")
65+
return nil
6066
}
61-
return cwti.informer.Lister()
67+
return templateresolution.WrapClusterWorkflowTemplateLister(cwti.informer.Lister())
6268
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package clusterworkflowtemplate
2+
3+
import (
4+
"context"
5+
6+
"github.com/argoproj/argo-workflows/v3/workflow/templateresolution"
7+
)
8+
9+
// NullClusterWorkflowTemplateStore is a no-op implementation of ClusterWorkflowTemplateStore
10+
// implements both informer and store interfaces
11+
type NullClusterWorkflowTemplateStore struct{}
12+
13+
func NewNullClusterWorkflowTemplate() *NullClusterWorkflowTemplateStore {
14+
return &NullClusterWorkflowTemplateStore{}
15+
}
16+
17+
func (NullClusterWorkflowTemplateStore) Getter(context.Context) templateresolution.ClusterWorkflowTemplateGetter {
18+
return &templateresolution.NullClusterWorkflowTemplateGetter{}
19+
}
20+
21+
func (NullClusterWorkflowTemplateStore) Run(stopCh <-chan struct{}) {}

workflow/templateresolution/context.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"github.com/argoproj/argo-workflows/v3/errors"
1212
wfv1 "github.com/argoproj/argo-workflows/v3/pkg/apis/workflow/v1alpha1"
1313
typed "github.com/argoproj/argo-workflows/v3/pkg/client/clientset/versioned/typed/workflow/v1alpha1"
14+
listers "github.com/argoproj/argo-workflows/v3/pkg/client/listers/workflow/v1alpha1"
1415
"github.com/argoproj/argo-workflows/v3/workflow/common"
1516
)
1617

@@ -57,6 +58,18 @@ func (n *NullClusterWorkflowTemplateGetter) Get(name string) (*wfv1.ClusterWorkf
5758
"forbidden: User cannot get resource 'clusterworkflowtemplates' in API group argoproj.io at the cluster scope", name)
5859
}
5960

61+
type clusterWorkflowTemplateListerWrapper struct {
62+
lister listers.ClusterWorkflowTemplateLister
63+
}
64+
65+
func WrapClusterWorkflowTemplateLister(lister listers.ClusterWorkflowTemplateLister) ClusterWorkflowTemplateGetter {
66+
return &clusterWorkflowTemplateListerWrapper{lister: lister}
67+
}
68+
69+
func (w *clusterWorkflowTemplateListerWrapper) Get(name string) (*wfv1.ClusterWorkflowTemplate, error) {
70+
return w.lister.Get(name)
71+
}
72+
6073
// Get retrieves the WorkflowTemplate of a given name.
6174
func (wrapper *clusterWorkflowTemplateInterfaceWrapper) Get(name string) (*wfv1.ClusterWorkflowTemplate, error) {
6275
ctx := context.TODO()

0 commit comments

Comments
 (0)