locals {
    node_problem_detector = { for k, v in var.tools.node_problem_detector : k => v if k!="enable" }
}

resource "kubernetes_namespace_v1" "tools-ns" {
  count = ( var.tools.node_problem_detector.enable )? 1 : 0
  metadata {
    annotations = local.annotations
    labels = local.common-labels
    name = var.tools.namespace
  }
}

resource "kubectl_manifest" "node_problem_detector" {
  count = var.tools.node_problem_detector.enable ? 1 : 0
  depends_on = [kubernetes_namespace_v1.tools-ns]
  yaml_body  = <<-EOF
    apiVersion: "vynil.solidite.fr/v1"
    kind: "Install"
    metadata:
      name: "node-problem-detector"
      namespace: "${var.tools.namespace}"
      labels: ${jsonencode(local.common-labels)}
    spec:
      distrib: "${var.component}"
      category: "monitor"
      component: "node-problem-detector"
      options: ${jsonencode(local.node_problem_detector)}
  EOF
}
