fix: kube binding checked filesystem and posix formating for df command

This commit is contained in:
RouxAntoine 2021-03-23 22:13:39 +01:00
parent 58a7dcd52c
commit dee08b808b
Signed by: antoine
GPG Key ID: 098FB66FC0475E70
3 changed files with 15 additions and 2 deletions

View File

@ -39,7 +39,7 @@ RUN export GOARCH=$TARGETARCH; \
export CGO_ENABLED=0; \
go build -o bin/bot-$GOOS-$GOARCH cmd/main.go
FROM scratch
FROM alpine:3.12.4
USER appuser:appuser

View File

@ -25,6 +25,7 @@ EOF
locals {
config_volume_name = "system-bot-volume"
checked_filesystem = "host-checked-filesystem"
}
resource "kubernetes_cron_job" "slack_bot_checker" {
@ -54,6 +55,13 @@ resource "kubernetes_cron_job" "slack_bot_checker" {
}
}
spec {
volume {
name = local.checked_filesystem
host_path {
path = "/var/lib/kubernetes/volumes"
type = "Directory"
}
}
volume {
name = local.config_volume_name
config_map {
@ -68,6 +76,10 @@ resource "kubernetes_cron_job" "slack_bot_checker" {
mount_path = "/conf"
name = local.config_volume_name
}
volume_mount {
mount_path = "/host"
name = local.checked_filesystem
}
}
}
}

View File

@ -37,7 +37,7 @@ func NewDfChecker() *DfChecker {
return &DfChecker{
CliChecker: CliChecker{
alertingMessage: dfMessage,
command: []string{"bash", "-c", "df | grep -v 'auto_home'"},
command: []string{"sh", "-c", "df -P | grep -v 'auto_home'"},
},
pourcentRegexMatcher: regexp.MustCompile(`(?P<value>.*)%`),
}
@ -60,6 +60,7 @@ func (dc *DfChecker) Parse(stdout string) interface{} {
}
valueIndex := dc.pourcentRegexMatcher.SubexpIndex("value")
log.Printf("df column : %+v\n", cleanedColumns)
v, err := strconv.Atoi(dc.pourcentRegexMatcher.FindStringSubmatch(cleanedColumns[4])[valueIndex])
if err != nil {
v = -1