osbuild-service-maintenance: Move type conversion to config
This commit is contained in:
parent
8219dcdee8
commit
d1911f6484
2 changed files with 17 additions and 17 deletions
|
|
@ -9,8 +9,8 @@ import (
|
|||
|
||||
// Do not write this config to logs or stdout, it contains secrets!
|
||||
type Config struct {
|
||||
DryRun string `env:"DRY_RUN"`
|
||||
MaxConcurrentRequests string `env:"MAX_CONCURRENT_REQUESTS"`
|
||||
DryRun bool `env:"DRY_RUN"`
|
||||
MaxConcurrentRequests int `env:"MAX_CONCURRENT_REQUESTS"`
|
||||
EnableDBMaintenance bool `env:"ENABLE_DB_MAINTENANCE"`
|
||||
EnableGCPMaintenance bool `env:"ENABLE_GCP_MAINTENANCE"`
|
||||
EnableAWSMaintenance bool `env:"ENABLE_AWS_MAINTENANCE"`
|
||||
|
|
@ -57,6 +57,12 @@ func LoadConfigFromEnv(intf interface{}) error {
|
|||
switch kind {
|
||||
case reflect.String:
|
||||
fieldV.SetString(confV)
|
||||
case reflect.Int:
|
||||
value, err := strconv.ParseInt(confV, 10, 64)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
fieldV.SetInt(value)
|
||||
case reflect.Bool:
|
||||
value, err := strconv.ParseBool(confV)
|
||||
if err != nil {
|
||||
|
|
|
|||
|
|
@ -3,7 +3,6 @@ package main
|
|||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"strconv"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
|
|
@ -24,22 +23,17 @@ func main() {
|
|||
var conf Config
|
||||
err := LoadConfigFromEnv(&conf)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
logrus.Fatal(err)
|
||||
}
|
||||
|
||||
maxCReqs, err := strconv.Atoi(conf.MaxConcurrentRequests)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
dryRun, err := strconv.ParseBool(conf.DryRun)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
if dryRun {
|
||||
if conf.DryRun {
|
||||
logrus.Info("Dry run, no state will be changed")
|
||||
}
|
||||
|
||||
if conf.MaxConcurrentRequests == 0 {
|
||||
logrus.Fatal("Max concurrent requests is 0")
|
||||
}
|
||||
|
||||
var wg sync.WaitGroup
|
||||
wg.Add(1)
|
||||
go func() {
|
||||
|
|
@ -50,7 +44,7 @@ func main() {
|
|||
}
|
||||
|
||||
logrus.Info("Cleaning up AWS")
|
||||
err := AWSCleanup(maxCReqs, dryRun, conf.AWSAccessKeyID, conf.AWSSecretAccessKey, "us-east-1", cutoff)
|
||||
err := AWSCleanup(conf.MaxConcurrentRequests, conf.DryRun, conf.AWSAccessKeyID, conf.AWSSecretAccessKey, "us-east-1", cutoff)
|
||||
if err != nil {
|
||||
logrus.Errorf("AWS cleanup failed: %v", err)
|
||||
}
|
||||
|
|
@ -83,7 +77,7 @@ func main() {
|
|||
return
|
||||
}
|
||||
|
||||
err = GCPCleanup(creds, maxCReqs, dryRun, cutoff)
|
||||
err = GCPCleanup(creds, conf.MaxConcurrentRequests, conf.DryRun, cutoff)
|
||||
if err != nil {
|
||||
logrus.Errorf("GCP Cleanup failed: %v", err)
|
||||
}
|
||||
|
|
@ -123,7 +117,7 @@ func main() {
|
|||
|
||||
for k, v := range jobsByType {
|
||||
logrus.Infof("Deleting jobs and their dependencies of type %v", k)
|
||||
if dryRun {
|
||||
if conf.DryRun {
|
||||
logrus.Infof("Dry run, skipping deletion of jobs: %v", v)
|
||||
continue
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue