-
Notifications
You must be signed in to change notification settings - Fork 111
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add configuration options to Kube Cache service (#1304)
- Loading branch information
Showing
5 changed files
with
126 additions
and
27 deletions.
There are no files selected for viewing
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 |
---|---|---|
|
@@ -19,7 +19,6 @@ linters: | |
- errorlint | ||
- cyclop | ||
- errname | ||
- exportloopref | ||
- gocritic | ||
- goimports | ||
- gosimple | ||
|
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
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,53 @@ | ||
package kubecache | ||
|
||
import ( | ||
"fmt" | ||
"io" | ||
"time" | ||
|
||
"github.com/caarlos0/env/v9" | ||
"gopkg.in/yaml.v3" | ||
) | ||
|
||
// Config options of the Kubernetes Cache service. Check the "DefaultConfig" variable for a view of the default values. | ||
type Config struct { | ||
// LogLevel can be one of: debug, info, warn, error | ||
LogLevel string `yaml:"log_level" env:"BEYLA_K8S_CACHE_LOG_LEVEL"` | ||
// Port where the service is going to listen to | ||
Port int `yaml:"port" env:"BEYLA_K8S_CACHE_PORT"` | ||
// MaxConnection is the maximum number of concurrent clients that the service can handle at the same time | ||
MaxConnections int `yaml:"max_connections" env:"BEYLA_K8S_CACHE_MAX_CONNECTIONS"` | ||
// ProfilePort is the port where the pprof server is going to listen to. 0 (default) means disabled | ||
ProfilePort int `yaml:"profile_port" env:"BEYLA_K8S_CACHE_PROFILE_PORT"` | ||
// InformerResyncPeriod is the time interval between complete resyncs of the informers | ||
InformerResyncPeriod time.Duration `yaml:"informer_resync_period" env:"BEYLA_K8S_CACHE_INFORMER_RESYNC_PERIOD"` | ||
} | ||
|
||
var DefaultConfig = Config{ | ||
LogLevel: "info", | ||
Port: 50055, | ||
MaxConnections: 100, | ||
InformerResyncPeriod: 30 * time.Minute, | ||
ProfilePort: 0, | ||
} | ||
|
||
// LoadConfig overrides configuration in the following order (from less to most priority) | ||
// 1 - Default configuration (DefaultConfig variable) | ||
// 2 - Contents of the provided file reader (nillable) | ||
// 3 - Environment variables | ||
func LoadConfig(file io.Reader) (*Config, error) { | ||
cfg := DefaultConfig | ||
if file != nil { | ||
cfgBuf, err := io.ReadAll(file) | ||
if err != nil { | ||
return nil, fmt.Errorf("reading YAML configuration: %w", err) | ||
} | ||
if err := yaml.Unmarshal(cfgBuf, &cfg); err != nil { | ||
return nil, fmt.Errorf("parsing YAML configuration: %w", err) | ||
} | ||
} | ||
if err := env.Parse(&cfg); err != nil { | ||
return nil, fmt.Errorf("reading env vars: %w", err) | ||
} | ||
return &cfg, nil | ||
} |
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
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