slack-bot/manifests/common.tf

104 lines
2.5 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 = "10.32.0.152:/export/pvc-"
critical = "85"
}
EOF
}
}
locals {
config_volume_name = "system-bot-volume"
checked_filesystem = "host-checked-filesystem"
}
resource "kubernetes_persistent_volume_claim" "var_lib_kubernetes_volume_claim" {
metadata {
namespace = kubernetes_namespace.monitoring_namespace.id
name = "monitoring-slack-bot-pvc"
}
spec {
storage_class_name = "dx30-nfs"
access_modes = ["ReadWriteMany"]
resources {
requests = {
storage = "2Gi"
}
}
}
}
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
persistent_volume_claim {
claim_name = kubernetes_persistent_volume_claim.var_lib_kubernetes_volume_claim.metadata.0.name
}
}
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
}
}
}
}
}
}
}
}