forked from argoproj/argo-workflows
-
Notifications
You must be signed in to change notification settings - Fork 0
/
persistence.go
63 lines (57 loc) · 1.73 KB
/
persistence.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
package fixtures
import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes"
"sigs.k8s.io/yaml"
"upper.io/db.v3/lib/sqlbuilder"
"github.com/argoproj/argo/persist/sqldb"
"github.com/argoproj/argo/workflow/config"
)
type Persistence struct {
session sqlbuilder.Database
offloadNodeStatusRepo sqldb.OffloadNodeStatusRepo
workflowArchive sqldb.WorkflowArchive
}
func newPersistence(kubeClient kubernetes.Interface) *Persistence {
cm, err := kubeClient.CoreV1().ConfigMaps(Namespace).Get("workflow-controller-configmap", metav1.GetOptions{})
if err != nil {
panic(err)
}
wcConfig := &config.WorkflowControllerConfig{}
err = yaml.Unmarshal([]byte(cm.Data["config"]), wcConfig)
if err != nil {
panic(err)
}
persistence := wcConfig.Persistence
if persistence != nil {
if persistence.PostgreSQL != nil {
persistence.PostgreSQL.Host = "localhost"
}
if persistence.MySQL != nil {
persistence.MySQL.Host = "localhost"
}
session, tableName, err := sqldb.CreateDBSession(kubeClient, Namespace, persistence)
if err != nil {
panic(err)
}
offloadNodeStatusRepo, err := sqldb.NewOffloadNodeStatusRepo(session, persistence.GetClusterName(), tableName)
if err != nil {
panic(err)
}
workflowArchive := sqldb.NewWorkflowArchive(session, persistence.GetClusterName())
return &Persistence{session, offloadNodeStatusRepo, workflowArchive}
} else {
return &Persistence{offloadNodeStatusRepo: sqldb.ExplosiveOffloadNodeStatusRepo, workflowArchive: sqldb.NullWorkflowArchive}
}
}
func (s *Persistence) IsEnabled() bool {
return s.offloadNodeStatusRepo.IsEnabled()
}
func (s *Persistence) Close() {
if s.IsEnabled() {
err := s.session.Close()
if err != nil {
panic(err)
}
}
}