This repository has been archived by the owner on Oct 9, 2023. It is now read-only.
/
config.go
64 lines (50 loc) · 2.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
55
56
57
58
59
60
61
62
63
64
package catalog
import (
"context"
"fmt"
"github.com/flyteorg/flyteplugins/go/tasks/pluginmachinery/catalog"
"github.com/flyteorg/flytestdlib/config"
"google.golang.org/grpc"
"github.com/flyteorg/flytepropeller/pkg/controller/nodes/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"`
UseAdminAuth bool `json:"use-admin-auth" pflag:"false, Use the same gRPC credentials option as the flyteadmin client"`
// Set the gRPC service config formatted as a json string https://github.com/grpc/grpc/blob/master/doc/service_config.md
// eg. {"loadBalancingConfig": [{"round_robin":{}}], "methodConfig": [{"name":[{"service": "foo", "method": "bar"}, {"service": "baz"}], "timeout": "1.000000001s"}]}
// find the full schema here https://github.com/grpc/grpc-proto/blob/master/grpc/service_config/service_config.proto#L625
// Note that required packages may need to be preloaded to support certain service config. For example "google.golang.org/grpc/balancer/roundrobin" should be preloaded to have round-robin policy supported.
DefaultServiceConfig string `json:"default-service-config" pflag:"\"\", Set the default service config for the catalog gRPC client"`
}
// GetConfig gets loaded config for Discovery
func GetConfig() *Config {
return configSection.GetConfig().(*Config)
}
func NewCatalogClient(ctx context.Context, authOpt ...grpc.DialOption) (catalog.Client, error) {
catalogConfig := GetConfig()
switch catalogConfig.Type {
case DataCatalogType:
return datacatalog.NewDataCatalog(ctx, catalogConfig.Endpoint, catalogConfig.Insecure,
catalogConfig.MaxCacheAge.Duration, catalogConfig.UseAdminAuth, catalogConfig.DefaultServiceConfig,
authOpt...)
case NoOpDiscoveryType, "":
return NOOPCatalog{}, nil
}
return nil, fmt.Errorf("no such catalog type available: %s", catalogConfig.Type)
}