This repository has been archived by the owner on Oct 9, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 59
/
inmemory.go
70 lines (61 loc) · 1.87 KB
/
inmemory.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
package workflowstore
import (
"context"
"fmt"
"github.com/lyft/flytepropeller/pkg/apis/flyteworkflow/v1alpha1"
kubeerrors "k8s.io/apimachinery/pkg/api/errors"
)
type InmemoryWorkflowStore struct {
store map[string]map[string]*v1alpha1.FlyteWorkflow
}
func (i *InmemoryWorkflowStore) Create(ctx context.Context, w *v1alpha1.FlyteWorkflow) error {
if w != nil {
if w.Name != "" && w.Namespace != "" {
if _, ok := i.store[w.Namespace]; !ok {
i.store[w.Namespace] = map[string]*v1alpha1.FlyteWorkflow{}
}
i.store[w.Namespace][w.Name] = w
return nil
}
}
return kubeerrors.NewBadRequest(fmt.Sprintf("Workflow object with Namespace [%v] & Name [%v] is required", w.Namespace, w.Name))
}
func (i *InmemoryWorkflowStore) Delete(ctx context.Context, namespace, name string) error {
if m, ok := i.store[namespace]; ok {
if _, ok := m[name]; ok {
delete(m, name)
return nil
}
}
return nil
}
func (i *InmemoryWorkflowStore) Get(ctx context.Context, namespace, name string) (*v1alpha1.FlyteWorkflow, error) {
if m, ok := i.store[namespace]; ok {
if v, ok := m[name]; ok {
return v, nil
}
}
return nil, errWorkflowNotFound
}
func (i *InmemoryWorkflowStore) UpdateStatus(ctx context.Context, w *v1alpha1.FlyteWorkflow, priorityClass PriorityClass) error {
if w != nil {
if w.Name != "" && w.Namespace != "" {
if m, ok := i.store[w.Namespace]; ok {
if _, ok := m[w.Name]; ok {
m[w.Name] = w
return nil
}
}
return nil
}
}
return kubeerrors.NewBadRequest("Workflow object with Namespace & Name is required")
}
func (i *InmemoryWorkflowStore) Update(ctx context.Context, w *v1alpha1.FlyteWorkflow, priorityClass PriorityClass) error {
return i.UpdateStatus(ctx, w, priorityClass)
}
func NewInMemoryWorkflowStore() *InmemoryWorkflowStore {
return &InmemoryWorkflowStore{
store: map[string]map[string]*v1alpha1.FlyteWorkflow{},
}
}