osbuild-service-maintenance: Explicitly enable maintenance parts

Stage and production share the GCP account. To avoid trying to delete
each GCP image twice, the maintenance script needs the ability to
selectively disable certain parts based on the config.
This commit is contained in:
Sanne Raymaekers 2022-05-13 13:35:43 +02:00 committed by Achilleas Koutsou
parent e2fe4b8de2
commit 8219dcdee8
2 changed files with 23 additions and 7 deletions

View file

@ -4,12 +4,16 @@ import (
"fmt"
"os"
"reflect"
"strconv"
)
// 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"`
EnableDBMaintenance bool `env:"ENABLE_DB_MAINTENANCE"`
EnableGCPMaintenance bool `env:"ENABLE_GCP_MAINTENANCE"`
EnableAWSMaintenance bool `env:"ENABLE_AWS_MAINTENANCE"`
PGHost string `env:"PGHOST"`
PGPort string `env:"PGPORT"`
PGDatabase string `env:"PGDATABASE"`
@ -51,13 +55,14 @@ func LoadConfigFromEnv(intf interface{}) error {
kind := fieldV.Kind()
if ok {
switch kind {
case reflect.Ptr:
if fieldT.Type.Elem().Kind() != reflect.String {
return fmt.Errorf("Unsupported type")
}
fieldV.Set(reflect.ValueOf(&confV))
case reflect.String:
fieldV.SetString(confV)
case reflect.Bool:
value, err := strconv.ParseBool(confV)
if err != nil {
return err
}
fieldV.SetBool(value)
default:
return fmt.Errorf("Unsupported type")
}

View file

@ -26,6 +26,7 @@ func main() {
if err != nil {
panic(err)
}
maxCReqs, err := strconv.Atoi(conf.MaxConcurrentRequests)
if err != nil {
panic(err)
@ -43,6 +44,11 @@ func main() {
wg.Add(1)
go func() {
defer wg.Done()
if !conf.EnableAWSMaintenance {
logrus.Info("AWS maintenance not enabled, skipping")
return
}
logrus.Info("Cleaning up AWS")
err := AWSCleanup(maxCReqs, dryRun, conf.AWSAccessKeyID, conf.AWSSecretAccessKey, "us-east-1", cutoff)
if err != nil {
@ -53,6 +59,11 @@ func main() {
wg.Add(1)
go func() {
defer wg.Done()
if !conf.EnableGCPMaintenance {
logrus.Info("GCP maintenance not enabled, skipping")
return
}
logrus.Info("Cleaning up GCP")
var gcpConf GCPCredentialsConfig
err := LoadConfigFromEnv(&gcpConf)
@ -81,8 +92,8 @@ func main() {
wg.Wait()
logrus.Info("🦀🦀🦀 cloud cleanup done 🦀🦀🦀")
if conf.PGHost == "" {
logrus.Info("🦀🦀🦀 db host not defined, skipping db cleanup 🦀🦀🦀")
if !conf.EnableDBMaintenance {
logrus.Info("🦀🦀🦀 DB maintenance not enabled, skipping 🦀🦀🦀")
return
}