forked from argoproj/argo-workflows
-
Notifications
You must be signed in to change notification settings - Fork 0
/
lazyworkflowtemplate.go
72 lines (61 loc) · 2.1 KB
/
lazyworkflowtemplate.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package templateresolution
import (
"k8s.io/apimachinery/pkg/runtime/schema"
"github.com/argoproj/argo/pkg/apis/workflow"
v1alpha1 "github.com/argoproj/argo/pkg/apis/workflow/v1alpha1"
wfv1 "github.com/argoproj/argo/pkg/apis/workflow/v1alpha1"
)
// lazyWorkflowTemplate retrieves WorkflowTemplate lazily.
type lazyWorkflowTemplate struct {
// wftmplGetter is a proxied WorkflowTemplate getter.
wftmplGetter WorkflowTemplateNamespacedGetter
// wftmpl is a cache of retrieved WorkflowTemplate.
wftmpl *wfv1.WorkflowTemplate
// namespace is the namespace of the WorkflowTemplate.
namespace string
// name is the name of the WorkflowTemplate.
name string
}
var _ wfv1.TemplateGetter = &lazyWorkflowTemplate{}
// NewLazyWorkflowTemplate is a public constructor of lazyWorkflowTemplate.
func NewLazyWorkflowTemplate(wftmplGetter WorkflowTemplateNamespacedGetter, namespace, name string) *lazyWorkflowTemplate {
return &lazyWorkflowTemplate{
wftmplGetter: wftmplGetter,
namespace: namespace,
name: name,
}
}
// GetNamespace returns the namespace of the WorkflowTemplate.
func (lwt *lazyWorkflowTemplate) GetNamespace() string {
return lwt.namespace
}
// GetName returns the name of the WorkflowTemplate.
func (lwt *lazyWorkflowTemplate) GetName() string {
return lwt.name
}
// GroupVersionKind returns a GroupVersionKind of WorkflowTemplate.
func (lwt *lazyWorkflowTemplate) GroupVersionKind() schema.GroupVersionKind {
return v1alpha1.SchemeGroupVersion.WithKind(workflow.WorkflowTemplateKind)
}
// GetTemplateByName retrieves a defined template by its name
func (lwt *lazyWorkflowTemplate) GetTemplateByName(name string) *wfv1.Template {
err := lwt.ensureWorkflowTemplate()
if err != nil {
return nil
}
return lwt.wftmpl.GetTemplateByName(name)
}
// GetTemplateScope returns the template scope of workflow template.
func (lwt *lazyWorkflowTemplate) GetTemplateScope() string {
return lwt.name
}
func (lwt *lazyWorkflowTemplate) ensureWorkflowTemplate() error {
if lwt.wftmpl == nil {
wftmpl, err := lwt.wftmplGetter.Get(lwt.name)
if err != nil {
return err
}
lwt.wftmpl = wftmpl
}
return nil
}