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
/
config.go
54 lines (41 loc) · 1.55 KB
/
config.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
package catalog
import (
"context"
"fmt"
"github.com/flyteorg/flyteplugins/go/tasks/pluginmachinery/catalog"
"github.com/flyteorg/flytestdlib/config"
"github.com/flyteorg/flytepropeller/pkg/controller/nodes/task/catalog/datacatalog"
)
//go:generate pflags Config --default-var defaultConfig
const ConfigSectionKey = "catalog-cache"
var (
defaultConfig = &Config{
Type: NoOpDiscoveryType,
}
configSection = config.MustRegisterSection(ConfigSectionKey, defaultConfig)
)
type DiscoveryType = string
const (
NoOpDiscoveryType DiscoveryType = "noop"
DataCatalogType DiscoveryType = "datacatalog"
)
type Config struct {
Type DiscoveryType `json:"type" pflag:"\"noop\", Catalog Implementation to use"`
Endpoint string `json:"endpoint" pflag:"\"\", Endpoint for catalog service"`
Insecure bool `json:"insecure" pflag:"false, Use insecure grpc connection"`
MaxCacheAge config.Duration `json:"max-cache-age" pflag:", Cache entries past this age will incur cache miss. 0 means cache never expires"`
}
// Gets loaded config for Discovery
func GetConfig() *Config {
return configSection.GetConfig().(*Config)
}
func NewCatalogClient(ctx context.Context) (catalog.Client, error) {
catalogConfig := GetConfig()
switch catalogConfig.Type {
case DataCatalogType:
return datacatalog.NewDataCatalog(ctx, catalogConfig.Endpoint, catalogConfig.Insecure, catalogConfig.MaxCacheAge.Duration)
case NoOpDiscoveryType, "":
return NOOPCatalog{}, nil
}
return nil, fmt.Errorf("no such catalog type available: %s", catalogConfig.Type)
}