-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
vai provider service specific config
- Loading branch information
Showing
2 changed files
with
71 additions
and
58 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package config | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"github.com/sky-uk/kfp-operator/argo/common" | ||
"strings" | ||
|
||
"github.com/spf13/viper" | ||
) | ||
|
||
// temporarily copied over here for vai specific provider config | ||
type Config struct { | ||
ProviderName string `mapstructure:"providerName"` | ||
OperatorWebhook string `mapstructure:"operatorWebhook"` | ||
Pod Pod `mapstructure:"pod"` | ||
Server Server `mapstructure:"server"` | ||
Parameters Parameters `mapstructure:"parameters"` | ||
} | ||
|
||
type Pod struct { | ||
Namespace string `mapstructure:"namespace"` | ||
} | ||
|
||
type Server struct { | ||
Host string `mapstructure:"host"` | ||
Port int `mapstructure:"port"` | ||
} | ||
|
||
type Parameters struct { | ||
VaiProject string `mapstructure:"vaiProject"` | ||
VaiLocation string `mapstructure:"vaiLocation"` | ||
VaiJobServiceAccount string `mapstructure:"vaiJobServiceAccount"` | ||
GcsEndpoint string `mapstructure:"gcsEndpoint"` | ||
PipelineBucket string `mapstructure:"pipelineBucket"` | ||
EventsourcePipelineEventsSubscription string `mapstructure:"eventsourcePipelineEventsSubscription"` | ||
MaxConcurrentRunCount int64 `mapstructure:"maxConcurrentRunCount"` | ||
} | ||
|
||
func LoadConfig(ctx context.Context) (*Config, error) { | ||
logger := common.LoggerFromContext(ctx) | ||
config, err := load() | ||
|
||
if err != nil { | ||
logger.Error(err, "failed to load config file") | ||
return nil, err | ||
} | ||
|
||
logger.Info(fmt.Sprintf("loaded config: %+v", config)) | ||
return config, nil | ||
} | ||
|
||
func load() (*Config, error) { | ||
viper.SetConfigName("config") | ||
viper.AddConfigPath("/etc/provider-service") | ||
viper.AddConfigPath(".") | ||
|
||
if err := viper.ReadInConfig(); err != nil { | ||
return nil, fmt.Errorf("fatal error loading config %w", err) | ||
} | ||
|
||
viper.AutomaticEnv() | ||
viper.SetEnvKeyReplacer(strings.NewReplacer(`.`, `_`)) | ||
|
||
var config Config | ||
if err := viper.Unmarshal(&config); err != nil { | ||
return nil, fmt.Errorf("fatal error unmarshalling config %w", err) | ||
} | ||
|
||
return &config, nil | ||
} |