-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9f4ad7b
commit a345167
Showing
6 changed files
with
253 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<!-- BEGIN_TF_DOCS --> | ||
## Requirements | ||
|
||
| Name | Version | | ||
|------|---------| | ||
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.0 | | ||
| <a name="requirement_kubectl"></a> [kubectl](#requirement\_kubectl) | >=1.14.0 | | ||
| <a name="requirement_kubernetes"></a> [kubernetes](#requirement\_kubernetes) | >= 2.21.1 | | ||
|
||
## Providers | ||
|
||
| Name | Version | | ||
|------|---------| | ||
| <a name="provider_kubectl"></a> [kubectl](#provider\_kubectl) | 1.14.0 | | ||
| <a name="provider_kubernetes"></a> [kubernetes](#provider\_kubernetes) | 2.33.0 | | ||
|
||
## Modules | ||
|
||
No modules. | ||
|
||
## Resources | ||
|
||
| Name | Type | | ||
|------|------| | ||
| [kubectl_manifest.windows_exporter](https://registry.terraform.io/providers/gavinbunney/kubectl/latest/docs/resources/manifest) | resource | | ||
| [kubernetes_config_map.windows_exporter_config](https://registry.terraform.io/providers/hashicorp/kubernetes/latest/docs/resources/config_map) | resource | | ||
| [kubernetes_service.windows_exporter](https://registry.terraform.io/providers/hashicorp/kubernetes/latest/docs/resources/service) | resource | | ||
|
||
## Inputs | ||
|
||
| Name | Description | Type | Default | Required | | ||
|------|-------------|------|---------|:--------:| | ||
| <a name="input_docker_image"></a> [docker\_image](#input\_docker\_image) | Docker image for windows exporter | <pre>object({<br> image = string<br> tag = string<br> image_pull_secrets = string<br> })</pre> | n/a | yes | | ||
| <a name="input_namespace"></a> [namespace](#input\_namespace) | Namespace of ArmoniK monitoring | `string` | n/a | yes | | ||
| <a name="input_node_selector"></a> [node\_selector](#input\_node\_selector) | Node selector for windows exporter | `any` | `{}` | no | | ||
|
||
## Outputs | ||
|
||
No outputs. | ||
<!-- END_TF_DOCS --> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
locals { | ||
tolerations = [ | ||
for key, value in var.node_selector : { | ||
key = key | ||
operator = "Equal" | ||
value = value | ||
effect = "NoSchedule" | ||
} | ||
] | ||
|
||
node_selector = { | ||
for key, value in var.node_selector : key => value | ||
} | ||
} |
163 changes: 163 additions & 0 deletions
163
monitoring/onpremise/exporters/windows-exporter/main.tf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,163 @@ | ||
# Define the YAML configuration as a file current version of kubernetes provider doesn't support windowsOptions; and there is a bug in the provider with the option: https://github.com/hashicorp/terraform-provider-kubernetes/issues/2575 | ||
|
||
resource "kubectl_manifest" "windows_exporter" { | ||
yaml_body = yamlencode({ | ||
apiVersion = "apps/v1" | ||
kind = "DaemonSet" | ||
metadata = { | ||
name = "windows-exporter" | ||
namespace = var.namespace | ||
labels = { | ||
app = "armonik" | ||
type = "monitoring" | ||
service = "windows-exporter" | ||
} | ||
} | ||
spec = { | ||
selector = { | ||
matchLabels = { | ||
app = "armonik" | ||
type = "monitoring" | ||
service = "windows-exporter" | ||
} | ||
} | ||
template = { | ||
metadata = { | ||
labels = { | ||
app = "armonik" | ||
type = "monitoring" | ||
service = "windows-exporter" | ||
} | ||
annotations = { | ||
"prometheus.io/scrape" = "true" | ||
"prometheus.io/scheme" = "http" | ||
"prometheus.io/path" = "/metrics" | ||
"prometheus.io/port" = "9182" | ||
"prometheus.io/input" = "windows-exporter" | ||
} | ||
} | ||
spec = { | ||
securityContext = { | ||
windowsOptions = { | ||
hostProcess = true | ||
runAsUserName = "NT AUTHORITY\\system" | ||
} | ||
} | ||
hostNetwork = true | ||
initContainers = [ | ||
{ | ||
name = "configure-firewall" | ||
image = "mcr.microsoft.com/windows/nanoserver:ltsc2022" | ||
command = ["powershell"] | ||
args = ["New-NetFirewallRule", "-DisplayName", "'windows-exporter'", "-Direction", "inbound", "-Profile", "Any", "-Action", "Allow", "-LocalPort", "9182", "-Protocol", "TCP"] | ||
} | ||
] | ||
containers = [ | ||
{ | ||
name = "windows-exporter" | ||
image = "${var.docker_image.image}:${var.docker_image.tag}" | ||
args = ["--config.file=%CONTAINER_SANDBOX_MOUNT_POINT%/config.yml"] | ||
ports = [ | ||
{ | ||
containerPort = 9182 | ||
hostPort = 9182 | ||
name = "http" | ||
} | ||
] | ||
volumeMounts = [ | ||
{ | ||
name = "windows-exporter-config" | ||
mountPath = "/config.yml" | ||
subPath = "config.yml" | ||
} | ||
] | ||
} | ||
] | ||
nodeSelector = merge( | ||
{ | ||
"kubernetes.io/os" = "windows" | ||
"kubernetes.io/arch" = "amd64" | ||
}, | ||
local.node_selector | ||
) | ||
tolerations = concat( | ||
[ | ||
{ | ||
key = "kubernetes.io/arch" | ||
operator = "Equal" | ||
value = "amd64" | ||
effect = "NoSchedule" | ||
}, | ||
{ | ||
key = "kubernetes.io/os" | ||
operator = "Equal" | ||
value = "windows" | ||
effect = "NoSchedule" | ||
} | ||
], | ||
local.tolerations | ||
) | ||
volumes = [ | ||
{ | ||
name = "windows-exporter-config" | ||
configMap = { | ||
name = "windows-exporter-config" | ||
} | ||
} | ||
] | ||
} | ||
} | ||
} | ||
}) | ||
} | ||
|
||
# windows-exporter config map | ||
resource "kubernetes_config_map" "windows_exporter_config" { | ||
metadata { | ||
name = "windows-exporter-config" | ||
namespace = var.namespace | ||
labels = { | ||
app = "armonik" | ||
type = "monitoring" | ||
service = "windows-exporter" | ||
} | ||
} | ||
|
||
data = { | ||
"config.yml" = <<-EOT | ||
collectors: | ||
enabled: cpu_info,container,logical_disk,memory,net,os | ||
collector: | ||
service: | ||
services-where: "Name='containerd' or Name='kubelet'" | ||
EOT | ||
} | ||
} | ||
|
||
# windows-exporter service | ||
resource "kubernetes_service" "windows_exporter" { | ||
metadata { | ||
name = "windows-exporter" | ||
namespace = var.namespace | ||
labels = { | ||
app = "armonik" | ||
type = "monitoring" | ||
service = "windows-exporter" | ||
} | ||
} | ||
|
||
spec { | ||
selector = { | ||
app = "armonik" | ||
type = "monitoring" | ||
service = "windows-exporter" | ||
} | ||
|
||
port { | ||
name = "http" | ||
protocol = "TCP" | ||
port = 9182 | ||
target_port = 9182 | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# default outputs |
22 changes: 22 additions & 0 deletions
22
monitoring/onpremise/exporters/windows-exporter/variables.tf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# Namespace | ||
variable "namespace" { | ||
description = "Namespace of ArmoniK monitoring" | ||
type = string | ||
} | ||
|
||
# Docker image | ||
variable "docker_image" { | ||
description = "Docker image for windows exporter" | ||
type = object({ | ||
image = string | ||
tag = string | ||
image_pull_secrets = string | ||
}) | ||
} | ||
|
||
# Node selector | ||
variable "node_selector" { | ||
description = "Node selector for windows exporter" | ||
type = any | ||
default = {} | ||
} |
13 changes: 13 additions & 0 deletions
13
monitoring/onpremise/exporters/windows-exporter/versions.tf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
terraform { | ||
required_version = ">= 1.0" | ||
required_providers { | ||
kubernetes = { | ||
source = "hashicorp/kubernetes" | ||
version = ">= 2.21.1" | ||
} | ||
kubectl = { | ||
source = "gavinbunney/kubectl" | ||
version = ">=1.14.0" | ||
} | ||
} | ||
} |