Skip to content

Commit

Permalink
feat: adding check interval + required args
Browse files Browse the repository at this point in the history
  • Loading branch information
deimosfr committed Nov 13, 2020
1 parent 54d4ed5 commit eb6d934
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 16 deletions.
4 changes: 2 additions & 2 deletions charts/pleco/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ name: pleco
description: Automatically removes Cloud managed services and Kubernetes resources based on tags with TTL
type: application
home: https://github.com/Qovery/pleco
version: 0.1.5
appVersion: 0.1.5
version: 0.1.6
appVersion: 0.1.6
icon: https://github.com/Qovery/pleco/raw/main/assets/pleco_logo.png
2 changes: 1 addition & 1 deletion charts/pleco/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ replicaCount: 1
image:
repository: qoveryrd/pleco
pullPolicy: IfNotPresent
plecoImageTag: "v0.1.5"
plecoImageTag: "v0.1.6"

environmentVariables:
LOGLEVEL: info
Expand Down
6 changes: 4 additions & 2 deletions cmd/start.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package cmd

import (
"github.com/Qovery/pleco/pleco"
"github.com/Qovery/pleco/core"
"github.com/spf13/cobra"
)

Expand All @@ -13,12 +13,14 @@ var startCmd = &cobra.Command{
_ = setLogLevel()

dryRun, _ := cmd.Flags().GetBool("dry-run")
pleco.StartDaemon(dryRun)
interval, _ := cmd.Flags().GetInt64("check-interval")
core.StartDaemon(dryRun, interval)
},
}

func init() {
rootCmd.AddCommand(startCmd)

startCmd.Flags().BoolP("dry-run", "t", false, "Dry run mode")
startCmd.Flags().Int64P("check-interval", "i", 120, "Check interval in seconds")
}
2 changes: 1 addition & 1 deletion cmd/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@ func init() {
}

func GetCurrentVersion() string {
return "0.1.5" // ci-version-check
return "0.1.6" // ci-version-check
}
20 changes: 10 additions & 10 deletions pleco/daemon.go → core/daemon.go
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
package pleco
package core

import (
"fmt"
"github.com/Qovery/pleco/providers/aws"
log "github.com/sirupsen/logrus"
"os"
"time"
)

func StartDaemon(dryRun bool) {
fmt.Println("\n ____ _ _____ ____ ___ \n| _ \\| | | ____/ ___/ _ \\ \n| |_) | | | _|| | | | | |\n| __/| |___| |__| |__| |_| |\n|_| |_____|_____\\____\\___/\nBy Qovery\n")
func StartDaemon(dryRun bool, interval int64) {
log.Info("\n\n ____ _ _____ ____ ___ \n| _ \\| | | ____/ ___/ _ \\ \n| |_) | | | _|| | | | | |\n| __/| |___| |__| |__| |_| |\n|_| |_____|_____\\____\\___/\nBy Qovery\n\n")
log.Info("Starting Pleco")

if dryRun {
log.Info("Dry run mode enabled")
}

region := "us-east-2"
checkEnvVars()

// AWS session
currentSession, err := aws.CreateSession(region)
currentSession, err := aws.CreateSession(os.Getenv("AWS_DEFAULT_REGION"))
if err != nil {
log.Errorf("AWS session error: %s", err)
}

// check RDS
currentRdsSession := aws.RdsSession(*currentSession, region)
currentRdsSession := aws.RdsSession(*currentSession, os.Getenv("AWS_DEFAULT_REGION"))

for {
// check RDS
err = aws.DeleteExpiredDatabases(*currentRdsSession, "ttl", dryRun)
if err != nil {
log.Error(err)
Expand All @@ -36,6 +36,6 @@ func StartDaemon(dryRun bool) {
log.Error(err)
}

time.Sleep(10 * time.Second)
time.Sleep(time.Duration(interval) * time.Second)
}
}
20 changes: 20 additions & 0 deletions core/validate.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package core

import (
"log"
"os"
)

func checkEnvVars() {
requiredEnvVars := []string{
"AWS_ACCESS_KEY_ID",
"AWS_SECRET_ACCESS_KEY",
"AWS_DEFAULT_REGION",
}

for _, envVar := range requiredEnvVars {
if os.Getenv(envVar) == "" {
log.Fatalf("%s environment variable is required and not found", envVar)
}
}
}

0 comments on commit eb6d934

Please sign in to comment.