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 63
/
application_config_provider.go
152 lines (136 loc) · 4.87 KB
/
application_config_provider.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
package runtime
import (
"context"
"io/ioutil"
"os"
"strings"
"time"
"github.com/flyteorg/flyteadmin/pkg/common"
"github.com/flyteorg/flyteadmin/pkg/runtime/interfaces"
"github.com/flyteorg/flytestdlib/config"
"github.com/flyteorg/flytestdlib/logger"
"k8s.io/apimachinery/pkg/util/wait"
)
const database = "database"
const flyteAdmin = "flyteadmin"
const scheduler = "scheduler"
const remoteData = "remoteData"
const notifications = "notifications"
const domains = "domains"
const externalEvents = "externalEvents"
const metricPort = 10254
const postgres = "postgres"
const KB = 1024
const MB = KB * KB
var databaseConfig = config.MustRegisterSection(database, &interfaces.DbConfigSection{
Port: 5432,
User: postgres,
Host: postgres,
DbName: postgres,
ExtraOptions: "sslmode=disable",
})
var flyteAdminConfig = config.MustRegisterSection(flyteAdmin, &interfaces.ApplicationConfig{
ProfilerPort: metricPort,
MetricsScope: "flyte:",
MetadataStoragePrefix: []string{"metadata", "admin"},
EventVersion: 2,
AsyncEventsBufferSize: 100,
MaxParallelism: 25,
})
var schedulerConfig = config.MustRegisterSection(scheduler, &interfaces.SchedulerConfig{
ProfilerPort: config.Port{Port: metricPort},
EventSchedulerConfig: interfaces.EventSchedulerConfig{
Scheme: common.Local,
FlyteSchedulerConfig: &interfaces.FlyteSchedulerConfig{},
},
WorkflowExecutorConfig: interfaces.WorkflowExecutorConfig{
Scheme: common.Local,
FlyteWorkflowExecutorConfig: &interfaces.FlyteWorkflowExecutorConfig{
AdminRateLimit: &interfaces.AdminRateLimit{
Tps: 100,
Burst: 10,
},
},
},
PrecheckBackoff: wait.Backoff{
Duration: time.Second, Factor: 2.0, Steps: 30, Jitter: 0.1,
},
})
var remoteDataConfig = config.MustRegisterSection(remoteData, &interfaces.RemoteDataConfig{
Scheme: common.None,
MaxSizeInBytes: 2 * MB,
InlineEventDataPolicy: interfaces.InlineEventDataPolicyOffload,
SignedURL: interfaces.SignedURL{
Enabled: false,
},
})
var notificationsConfig = config.MustRegisterSection(notifications, &interfaces.NotificationsConfig{
Type: common.Local,
})
var domainsConfig = config.MustRegisterSection(domains, &interfaces.DomainsConfig{
{
ID: "development",
Name: "development",
},
{
ID: "staging",
Name: "staging",
},
{
ID: "production",
Name: "production",
},
})
var externalEventsConfig = config.MustRegisterSection(externalEvents, &interfaces.ExternalEventsConfig{
Type: common.Local,
})
// Implementation of an interfaces.ApplicationConfiguration
type ApplicationConfigurationProvider struct{}
func (p *ApplicationConfigurationProvider) GetDbConfig() interfaces.DbConfig {
dbConfigSection := databaseConfig.GetConfig().(*interfaces.DbConfigSection)
password := dbConfigSection.Password
if len(dbConfigSection.PasswordPath) > 0 {
if _, err := os.Stat(dbConfigSection.PasswordPath); os.IsNotExist(err) {
logger.Fatalf(context.Background(),
"missing database password at specified path [%s]", dbConfigSection.PasswordPath)
}
passwordVal, err := ioutil.ReadFile(dbConfigSection.PasswordPath)
if err != nil {
logger.Fatalf(context.Background(), "failed to read database password from path [%s] with err: %v",
dbConfigSection.PasswordPath, err)
}
// Passwords can contain special characters as long as they are percent encoded
// https://www.postgresql.org/docs/current/libpq-connect.html
password = strings.TrimSpace(string(passwordVal))
}
return interfaces.DbConfig{
Host: dbConfigSection.Host,
Port: dbConfigSection.Port,
DbName: dbConfigSection.DbName,
User: dbConfigSection.User,
Password: password,
ExtraOptions: dbConfigSection.ExtraOptions,
Debug: dbConfigSection.Debug,
}
}
func (p *ApplicationConfigurationProvider) GetTopLevelConfig() *interfaces.ApplicationConfig {
return flyteAdminConfig.GetConfig().(*interfaces.ApplicationConfig)
}
func (p *ApplicationConfigurationProvider) GetSchedulerConfig() *interfaces.SchedulerConfig {
return schedulerConfig.GetConfig().(*interfaces.SchedulerConfig)
}
func (p *ApplicationConfigurationProvider) GetRemoteDataConfig() *interfaces.RemoteDataConfig {
return remoteDataConfig.GetConfig().(*interfaces.RemoteDataConfig)
}
func (p *ApplicationConfigurationProvider) GetNotificationsConfig() *interfaces.NotificationsConfig {
return notificationsConfig.GetConfig().(*interfaces.NotificationsConfig)
}
func (p *ApplicationConfigurationProvider) GetDomainsConfig() *interfaces.DomainsConfig {
return domainsConfig.GetConfig().(*interfaces.DomainsConfig)
}
func (p *ApplicationConfigurationProvider) GetExternalEventsConfig() *interfaces.ExternalEventsConfig {
return externalEventsConfig.GetConfig().(*interfaces.ExternalEventsConfig)
}
func NewApplicationConfigurationProvider() interfaces.ApplicationConfiguration {
return &ApplicationConfigurationProvider{}
}