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; \ export CGO_ENABLED=0; \
go build -o bin/bot-$GOOS-$GOARCH cmd/main.go go build -o bin/bot-$GOOS-$GOARCH cmd/main.go
FROM scratch FROM alpine:3.12.4
USER appuser:appuser USER appuser:appuser

View File

@ -25,6 +25,7 @@ EOF
locals { locals {
config_volume_name = "system-bot-volume" config_volume_name = "system-bot-volume"
checked_filesystem = "host-checked-filesystem"
} }
resource "kubernetes_cron_job" "slack_bot_checker" { resource "kubernetes_cron_job" "slack_bot_checker" {
@ -54,6 +55,13 @@ resource "kubernetes_cron_job" "slack_bot_checker" {
} }
} }
spec { spec {
volume {
name = local.checked_filesystem
host_path {
path = "/var/lib/kubernetes/volumes"
type = "Directory"
}
}
volume { volume {
name = local.config_volume_name name = local.config_volume_name
config_map { config_map {
@ -68,6 +76,10 @@ resource "kubernetes_cron_job" "slack_bot_checker" {
mount_path = "/conf" mount_path = "/conf"
name = local.config_volume_name 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{ return &DfChecker{
CliChecker: CliChecker{ CliChecker: CliChecker{
alertingMessage: dfMessage, 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>.*)%`), pourcentRegexMatcher: regexp.MustCompile(`(?P<value>.*)%`),
} }
@ -60,6 +60,7 @@ func (dc *DfChecker) Parse(stdout string) interface{} {
} }
valueIndex := dc.pourcentRegexMatcher.SubexpIndex("value") valueIndex := dc.pourcentRegexMatcher.SubexpIndex("value")
log.Printf("df column : %+v\n", cleanedColumns)
v, err := strconv.Atoi(dc.pourcentRegexMatcher.FindStringSubmatch(cleanedColumns[4])[valueIndex]) v, err := strconv.Atoi(dc.pourcentRegexMatcher.FindStringSubmatch(cleanedColumns[4])[valueIndex])
if err != nil { if err != nil {
v = -1 v = -1