Skip to content

Commit

Permalink
vai provider service specific config
Browse files Browse the repository at this point in the history
  • Loading branch information
chr12c committed Dec 20, 2024
1 parent be3f85f commit 001cfa9
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 58 deletions.
58 changes: 0 additions & 58 deletions provider-service/vai/internal/config.go

This file was deleted.

71 changes: 71 additions & 0 deletions provider-service/vai/internal/config/config.go
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
}

0 comments on commit 001cfa9

Please sign in to comment.