Skip to content

Commit

Permalink
fix: kubernetes chart + dockerfile now using go 1.15 + adding more de…
Browse files Browse the repository at this point in the history
…bug logs
  • Loading branch information
deimosfr committed Nov 13, 2020
1 parent e5c7aa0 commit 54d4ed5
Show file tree
Hide file tree
Showing 9 changed files with 80 additions and 35 deletions.
14 changes: 7 additions & 7 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]
RUN apt-get update && apt-get install -y ca-certificates && apt-get clean
COPY --from=build /pleco.bin /usr/bin/pleco
CMD ["pleco", "start"]
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.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
37 changes: 25 additions & 12 deletions charts/pleco/templates/deployment.yaml
Original file line number Diff line number Diff line change
@@ -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 }}
9 changes: 9 additions & 0 deletions charts/pleco/templates/secrets.yaml
Original file line number Diff line number Diff line change
@@ -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 }}
16 changes: 9 additions & 7 deletions charts/pleco/values.yaml
Original file line number Diff line number Diff line change
@@ -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: ""
Expand All @@ -25,15 +27,15 @@ serviceAccount:
podAnnotations: {}

podSecurityContext: {}
# fsGroup: 2000
# fsGroup: 2000

securityContext: {}
# capabilities:
# drop:
# - ALL
# readOnlyRootFilesystem: true
# runAsNonRoot: true
# runAsUser: 1000
# runAsUser: 1000

resources:
limits:
Expand Down
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.4" // ci-version-check
return "0.1.5" // ci-version-check
}
11 changes: 9 additions & 2 deletions pleco/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
10 changes: 8 additions & 2 deletions providers/aws/documentdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -136,4 +140,6 @@ func DeleteExpiredClusters(svc rds.RDS, tagName string, dryRun bool) {
cluster.DBClusterIdentifier, *svc.Config.Region)
}
}

return nil
}
12 changes: 10 additions & 2 deletions providers/aws/rds.go
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -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)
Expand All @@ -135,4 +141,6 @@ func DeleteExpiredDatabases(svc rds.RDS, tagName string, dryRun bool) {
database.DBInstanceIdentifier, *svc.Config.Region)
}
}

return nil
}

0 comments on commit 54d4ed5

Please sign in to comment.