diff --git a/Dockerfile b/Dockerfile index 2489a9b..20d8f6f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,11 +1,11 @@ -FROM debian:buster-slim as build - -RUN apt-get update && apt-get install -y curl && \ - curl -sLo pleco.tgz https://github.com/Qovery/pleco/releases/download/v0.1/pleco_0.1_linux_amd64.tar.gz &&\ - tar -xzf pleco.tgz +FROM golang:1.15.5-buster as build +ADD . /pleco +WORKDIR /pleco +RUN go get && go build -o /pleco.bin main.go FROM debian:buster-slim as run -COPY --from=build /pleco /usr/bin/pleco -CMD ["pleco", "start"] \ No newline at end of file +RUN apt-get update && apt-get install -y ca-certificates && apt-get clean +COPY --from=build /pleco.bin /usr/bin/pleco +CMD ["pleco", "start"] diff --git a/charts/pleco/Chart.yaml b/charts/pleco/Chart.yaml index 0ee9604..9d28a16 100644 --- a/charts/pleco/Chart.yaml +++ b/charts/pleco/Chart.yaml @@ -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.4 -appVersion: 0.1.4 +version: 0.1.5 +appVersion: 0.1.5 icon: https://github.com/Qovery/pleco/raw/main/assets/pleco_logo.png diff --git a/charts/pleco/templates/deployment.yaml b/charts/pleco/templates/deployment.yaml index c19df4c..3a11850 100644 --- a/charts/pleco/templates/deployment.yaml +++ b/charts/pleco/templates/deployment.yaml @@ -1,47 +1,60 @@ +{{- $kubefullname := include "kubernetes.fullname" . }} apiVersion: apps/v1 kind: Deployment metadata: name: {{ include "kubernetes.fullname" . }} labels: - {{- include "kubernetes.labels" . | nindent 4 }} + {{- include "kubernetes.labels" . | nindent 4 }} spec: replicas: {{ .Values.replicaCount }} selector: matchLabels: - {{- include "kubernetes.selectorLabels" . | nindent 6 }} + {{- include "kubernetes.selectorLabels" . | nindent 6 }} template: metadata: {{- with .Values.podAnnotations }} annotations: - {{- toYaml . | nindent 8 }} + {{- toYaml . | nindent 8 }} {{- end }} labels: - {{- include "kubernetes.selectorLabels" . | nindent 8 }} + {{- include "kubernetes.selectorLabels" . | nindent 8 }} spec: {{- with .Values.imagePullSecrets }} imagePullSecrets: - {{- toYaml . | nindent 8 }} + {{- toYaml . | nindent 8 }} {{- end }} serviceAccountName: {{ include "kubernetes.serviceAccountName" . }} securityContext: - {{- toYaml .Values.podSecurityContext | nindent 8 }} + {{- toYaml .Values.podSecurityContext | nindent 8 }} containers: - name: {{ .Chart.Name }} securityContext: - {{- toYaml .Values.securityContext | nindent 12 }} + {{- toYaml .Values.securityContext | nindent 12 }} image: "{{ .Values.image.repository }}:{{ .Values.image.plecoImageTag | default .Chart.AppVersion }}" imagePullPolicy: {{ .Values.image.pullPolicy }} + command: [ "pleco", "start" ] + args: + - --level + - "$(LOGLEVEL)" + env: + {{ range $key, $value := .Values.environmentVariables -}} + - name: "{{ $key }}" + valueFrom: + secretKeyRef: + name: {{ $kubefullname }} + key: {{ $key }} + {{ end }} resources: - {{- toYaml .Values.resources | nindent 12 }} + {{- toYaml .Values.resources | nindent 12 }} {{- with .Values.nodeSelector }} nodeSelector: - {{- toYaml . | nindent 8 }} + {{- toYaml . | nindent 8 }} {{- end }} {{- with .Values.affinity }} affinity: - {{- toYaml . | nindent 8 }} + {{- toYaml . | nindent 8 }} {{- end }} {{- with .Values.tolerations }} tolerations: - {{- toYaml . | nindent 8 }} - {{- end }} + {{- toYaml . | nindent 8 }} + {{- end }} diff --git a/charts/pleco/templates/secrets.yaml b/charts/pleco/templates/secrets.yaml new file mode 100644 index 0000000..ab72747 --- /dev/null +++ b/charts/pleco/templates/secrets.yaml @@ -0,0 +1,9 @@ +apiVersion: v1 +kind: Secret +metadata: + name: {{ include "kubernetes.fullname" . }} + labels: + {{- include "kubernetes.labels" . | nindent 4 }} +type: Opaque +stringData: + {{- toYaml .Values.environmentVariables | nindent 2 }} \ No newline at end of file diff --git a/charts/pleco/values.yaml b/charts/pleco/values.yaml index 086fc3a..2d08a73 100644 --- a/charts/pleco/values.yaml +++ b/charts/pleco/values.yaml @@ -1,13 +1,15 @@ replicaCount: 1 image: - repository: qovery/pleco + repository: qoveryrd/pleco pullPolicy: IfNotPresent - plecoImageTag: "v0.1.4" + plecoImageTag: "v0.1.5" -pleco: - environmentVariables: {} - commandArgs: {} +environmentVariables: + LOGLEVEL: info + # AWS_ACCESS_KEY_ID: "" + # AWS_SECRET_ACCESS_KEY: "" + # AWS_DEFAULT_REGION: "" imagePullSecrets: [] nameOverride: "" @@ -25,7 +27,7 @@ serviceAccount: podAnnotations: {} podSecurityContext: {} - # fsGroup: 2000 +# fsGroup: 2000 securityContext: {} # capabilities: @@ -33,7 +35,7 @@ securityContext: {} # - ALL # readOnlyRootFilesystem: true # runAsNonRoot: true - # runAsUser: 1000 +# runAsUser: 1000 resources: limits: diff --git a/cmd/version.go b/cmd/version.go index 0caef96..652ae15 100644 --- a/cmd/version.go +++ b/cmd/version.go @@ -19,5 +19,5 @@ func init() { } func GetCurrentVersion() string { - return "0.1.4" // ci-version-check + return "0.1.5" // ci-version-check } \ No newline at end of file diff --git a/pleco/daemon.go b/pleco/daemon.go index f65d573..0b47f73 100644 --- a/pleco/daemon.go +++ b/pleco/daemon.go @@ -26,9 +26,16 @@ func StartDaemon(dryRun bool) { currentRdsSession := aws.RdsSession(*currentSession, region) for { - aws.DeleteExpiredDatabases(*currentRdsSession, "ttl", dryRun) + err = aws.DeleteExpiredDatabases(*currentRdsSession, "ttl", dryRun) + if err != nil { + log.Error(err) + } // check DocumentDB - aws.DeleteExpiredClusters(*currentRdsSession, "ttl", dryRun) + err = aws.DeleteExpiredClusters(*currentRdsSession, "ttl", dryRun) + if err != nil { + log.Error(err) + } + time.Sleep(10 * time.Second) } } \ No newline at end of file diff --git a/providers/aws/documentdb.go b/providers/aws/documentdb.go index 0a07d84..9fd82ab 100644 --- a/providers/aws/documentdb.go +++ b/providers/aws/documentdb.go @@ -121,8 +121,12 @@ func deleteCluster(svc rds.RDS, cluster documentDBCluster, dryRun bool) error { return nil } -func DeleteExpiredClusters(svc rds.RDS, tagName string, dryRun bool) { - clusters, _ := listTaggedClusters(svc, tagName) +func DeleteExpiredClusters(svc rds.RDS, tagName string, dryRun bool) error { + clusters, err := listTaggedClusters(svc, tagName) + if err != nil { + return errors.New(fmt.Sprintf("can't list DocumentDB databases: %s\n", err)) + } + for _, cluster := range clusters { if utils.CheckIfExpired(cluster.ClusterCreateTime, cluster.TTL) { err := deleteCluster(svc, cluster, dryRun) @@ -136,4 +140,6 @@ func DeleteExpiredClusters(svc rds.RDS, tagName string, dryRun bool) { cluster.DBClusterIdentifier, *svc.Config.Region) } } + + return nil } \ No newline at end of file diff --git a/providers/aws/rds.go b/providers/aws/rds.go index f04dcc6..0fb8830 100644 --- a/providers/aws/rds.go +++ b/providers/aws/rds.go @@ -1,6 +1,8 @@ package aws import ( + "errors" + "fmt" "github.com/Qovery/pleco/utils" "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" @@ -120,8 +122,12 @@ func getRDSInstanceInfos(svc rds.RDS, databaseIdentifier string) (rdsDatabase, e }, nil } -func DeleteExpiredDatabases(svc rds.RDS, tagName string, dryRun bool) { - databases, _ := listTaggedDatabases(svc, tagName) +func DeleteExpiredDatabases(svc rds.RDS, tagName string, dryRun bool) error { + databases, err := listTaggedDatabases(svc, tagName) + if err != nil { + return errors.New(fmt.Sprintf("can't list RDS databases: %s\n", err)) + } + for _, database := range databases { if utils.CheckIfExpired(database.InstanceCreateTime, database.TTL) { err := deleteDatabase(svc, database, dryRun) @@ -135,4 +141,6 @@ func DeleteExpiredDatabases(svc rds.RDS, tagName string, dryRun bool) { database.DBInstanceIdentifier, *svc.Config.Region) } } + + return nil } \ No newline at end of file