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