89 lines
2.1 KiB
HCL
89 lines
2.1 KiB
HCL
resource "kubernetes_namespace" "monitoring_namespace" {
|
|
metadata {
|
|
name = "monitoring"
|
|
}
|
|
}
|
|
|
|
resource "kubernetes_config_map" "slack_bot_config" {
|
|
metadata {
|
|
name = "slack-bot-hcl"
|
|
namespace = kubernetes_namespace.monitoring_namespace.id
|
|
}
|
|
data = {
|
|
"config.hcl" = <<EOF
|
|
bot_id = "${var.bot_id}"
|
|
dest_channel_id = "${var.dest_channel_id}"
|
|
webhook_id = "${var.webhook_id}"
|
|
|
|
df {
|
|
fs_name = "/dev/mapper/vg1-data--kube"
|
|
critical = "85"
|
|
}
|
|
EOF
|
|
}
|
|
}
|
|
|
|
locals {
|
|
config_volume_name = "system-bot-volume"
|
|
checked_filesystem = "host-checked-filesystem"
|
|
}
|
|
|
|
resource "kubernetes_cron_job" "slack_bot_checker" {
|
|
metadata {
|
|
name = "system-cron-bot-job"
|
|
namespace = kubernetes_namespace.monitoring_namespace.id
|
|
}
|
|
spec {
|
|
concurrency_policy = "Replace"
|
|
failed_jobs_history_limit = 5
|
|
# each day at 00:01
|
|
schedule = "1 0 * * *"
|
|
starting_deadline_seconds = 10
|
|
successful_jobs_history_limit = 10
|
|
job_template {
|
|
metadata {
|
|
name = "system-bot-job"
|
|
}
|
|
spec {
|
|
backoff_limit = 2
|
|
ttl_seconds_after_finished = 10
|
|
template {
|
|
metadata {
|
|
labels = {
|
|
app = "system-bot"
|
|
env = var.environment
|
|
}
|
|
}
|
|
spec {
|
|
volume {
|
|
name = local.checked_filesystem
|
|
host_path {
|
|
path = "/var/lib/kubernetes/volumes"
|
|
type = "Directory"
|
|
}
|
|
}
|
|
volume {
|
|
name = local.config_volume_name
|
|
config_map {
|
|
name = kubernetes_config_map.slack_bot_config.metadata.0.name
|
|
}
|
|
}
|
|
container {
|
|
name = "slackbot"
|
|
image = format("docker.registry/slackbot:%s", var.bot_version)
|
|
args = ["-config", "/conf/config.hcl"]
|
|
volume_mount {
|
|
mount_path = "/conf"
|
|
name = local.config_volume_name
|
|
}
|
|
volume_mount {
|
|
mount_path = "/host"
|
|
name = local.checked_filesystem
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
} |