Skip to content

Commit 0d835ff

Browse files
authored
feat: added the ability to set resource limits<br>- added the ability to add tags<br>- added the ability to pass blacklisted ports<br>- added the ability to use existing kube secret for access key<br>- schema update for metrics_filter<br>- fixed bug where tolerations were not working (#74)
1 parent f1b9ebb commit 0d835ff

File tree

18 files changed

+321
-47
lines changed

18 files changed

+321
-47
lines changed

README.md

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ You need the following permissions to run this module.
8383
|------|---------|
8484
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.9.0 |
8585
| <a name="requirement_helm"></a> [helm](#requirement\_helm) | >= 2.15.0, <3.0.0 |
86-
| <a name="requirement_ibm"></a> [ibm](#requirement\_ibm) | >= 1.76.1, <2.0.0 |
86+
| <a name="requirement_ibm"></a> [ibm](#requirement\_ibm) | >= 1.79.0, <2.0.0 |
8787

8888
### Modules
8989

@@ -102,9 +102,16 @@ No modules.
102102

103103
| Name | Description | Type | Default | Required |
104104
|------|-------------|------|---------|:--------:|
105-
| <a name="input_access_key"></a> [access\_key](#input\_access\_key) | Access key used by the IBM Cloud Monitoring agent to communicate with the instance | `string` | n/a | yes |
105+
| <a name="input_access_key"></a> [access\_key](#input\_access\_key) | Access key used by the IBM Cloud Monitoring agent to communicate with the instance. Either `access_key` or `existing_access_key_secret_name` is required. This value will be stored on a new secret on the cluster if passed. | `string` | `null` | no |
106+
| <a name="input_add_cluster_name"></a> [add\_cluster\_name](#input\_add\_cluster\_name) | If true, configure the cloud monitoring agent to attach a tag containing the cluster name to all metric data. This tag is added in the format `ibm-containers-kubernetes-cluster-name: cluster_name`. | `bool` | `true` | no |
106107
| <a name="input_agent_image_repository"></a> [agent\_image\_repository](#input\_agent\_image\_repository) | The image repository to pull the Cloud Monitoring agent image from. | `string` | `"agent-slim"` | no |
107108
| <a name="input_agent_image_tag_digest"></a> [agent\_image\_tag\_digest](#input\_agent\_image\_tag\_digest) | The image tag digest to use for the Cloud Monitoring agent. | `string` | `"13.9.2@sha256:0dcdb6d70bab60dae4bf5f70c338f2feb9daeba514f1b8ad513ed24724c2a04d"` | no |
109+
| <a name="input_agent_limits_cpu"></a> [agent\_limits\_cpu](#input\_agent\_limits\_cpu) | Specifies the CPU limit for the agent. | `string` | `"1"` | no |
110+
| <a name="input_agent_limits_memory"></a> [agent\_limits\_memory](#input\_agent\_limits\_memory) | Specifies the memory limit for the agent. | `string` | `"1024Mi"` | no |
111+
| <a name="input_agent_requests_cpu"></a> [agent\_requests\_cpu](#input\_agent\_requests\_cpu) | Specifies the CPU requested to run in a node for the agent. | `string` | `"1"` | no |
112+
| <a name="input_agent_requests_memory"></a> [agent\_requests\_memory](#input\_agent\_requests\_memory) | Specifies the memory requested to run in a node for the agent. | `string` | `"1024Mi"` | no |
113+
| <a name="input_agent_tags"></a> [agent\_tags](#input\_agent\_tags) | Map of tags to associate to all metrics that the agent collects. NOTE: Use the `add_cluster_name` boolean variable to add the cluster name as a tag, e.g `{'environment': 'production'}.` | `map(string)` | `{}` | no |
114+
| <a name="input_blacklisted_ports"></a> [blacklisted\_ports](#input\_blacklisted\_ports) | To block network traffic and metrics from network ports, pass the list of ports from which you want to filter out any data. [Learn more](https://cloud.ibm.com/docs/monitoring?topic=monitoring-change_kube_agent#change_kube_agent_block_ports). | `list(number)` | `[]` | no |
108115
| <a name="input_chart"></a> [chart](#input\_chart) | The name of the Helm chart to deploy. | `string` | `"sysdig-deploy"` | no |
109116
| <a name="input_chart_location"></a> [chart\_location](#input\_chart\_location) | The location of the Cloud Monitoring agent helm chart. | `string` | `"https://charts.sysdig.com"` | no |
110117
| <a name="input_chart_version"></a> [chart\_version](#input\_chart\_version) | The version of the Cloud Monitoring agent helm chart to deploy. | `string` | `"1.85.1"` | no |
@@ -114,12 +121,13 @@ No modules.
114121
| <a name="input_cluster_id"></a> [cluster\_id](#input\_cluster\_id) | The ID of the cluster you wish to deploy the agent in | `string` | n/a | yes |
115122
| <a name="input_cluster_resource_group_id"></a> [cluster\_resource\_group\_id](#input\_cluster\_resource\_group\_id) | The Resource Group ID of the cluster | `string` | n/a | yes |
116123
| <a name="input_container_filter"></a> [container\_filter](#input\_container\_filter) | To filter custom containers, specify which containers to include or exclude from metrics collection for the cloud monitoring agent. See https://cloud.ibm.com/docs/monitoring?topic=monitoring-change_kube_agent#change_kube_agent_filter_data. | <pre>list(object({<br/> type = string<br/> parameter = string<br/> name = string<br/> }))</pre> | `[]` | no |
124+
| <a name="input_existing_access_key_secret_name"></a> [existing\_access\_key\_secret\_name](#input\_existing\_access\_key\_secret\_name) | An alternative to using the Sysdig Agent `access_key`. Specify the name of a Kubernetes secret containing an access-key entry. Either `access_key` or `existing_access_key_secret_name` is required. | `string` | `null` | no |
117125
| <a name="input_image_registry_base_url"></a> [image\_registry\_base\_url](#input\_image\_registry\_base\_url) | The image registry base URL to pull the Cloud Monitoring agent images from. For example `icr.io`, `quay.io`, etc. | `string` | `"icr.io"` | no |
118126
| <a name="input_image_registry_namespace"></a> [image\_registry\_namespace](#input\_image\_registry\_namespace) | The namespace within the image registry to pull the Cloud Monitoring agent images from. | `string` | `"ext/sysdig"` | no |
119127
| <a name="input_is_vpc_cluster"></a> [is\_vpc\_cluster](#input\_is\_vpc\_cluster) | Specify true if the target cluster for the monitoring agent is a VPC cluster, false if it is a classic cluster. | `bool` | `true` | no |
120128
| <a name="input_kernal_module_image_repository"></a> [kernal\_module\_image\_repository](#input\_kernal\_module\_image\_repository) | The image repository to pull the Cloud Monitoring agent kernal module initContainer image from. | `string` | `"agent-kmodule"` | no |
121129
| <a name="input_kernel_module_image_tag_digest"></a> [kernel\_module\_image\_tag\_digest](#input\_kernel\_module\_image\_tag\_digest) | The image tag digest to use for the Cloud Monitoring agent kernel module used by the initContainer. | `string` | `"13.9.2@sha256:a6b301f24557c5e14ab5abe62577340e7ab33ce11f33cfcd4797296d1603184a"` | no |
122-
| <a name="input_metrics_filter"></a> [metrics\_filter](#input\_metrics\_filter) | To filter custom metrics, specify the Cloud Monitoring metrics to include or to exclude. See https://cloud.ibm.com/docs/monitoring?topic=monitoring-change_kube_agent#change_kube_agent_inc_exc_metrics. | <pre>list(object({<br/> type = string<br/> name = string<br/> }))</pre> | `[]` | no |
130+
| <a name="input_metrics_filter"></a> [metrics\_filter](#input\_metrics\_filter) | To filter custom metrics, specify the Cloud Monitoring metrics to include or to exclude. See https://cloud.ibm.com/docs/monitoring?topic=monitoring-change_kube_agent#change_kube_agent_inc_exc_metrics. | <pre>list(object({<br/> include = optional(string)<br/> exclude = optional(string)<br/> }))</pre> | `[]` | no |
123131
| <a name="input_name"></a> [name](#input\_name) | Cloud Monitoring agent name. Used for naming all kubernetes and helm resources on the cluster. | `string` | `"sysdig-agent"` | no |
124132
| <a name="input_namespace"></a> [namespace](#input\_namespace) | Namespace where to deploy the Cloud Monitoring agent. Default value is 'ibm-observe' | `string` | `"ibm-observe"` | no |
125133
| <a name="input_tolerations"></a> [tolerations](#input\_tolerations) | List of tolerations to apply to Cloud Monitoring agent. | <pre>list(object({<br/> key = optional(string)<br/> operator = optional(string)<br/> value = optional(string)<br/> effect = optional(string)<br/> tolerationSeconds = optional(number)<br/> }))</pre> | <pre>[<br/> {<br/> "operator": "Exists"<br/> },<br/> {<br/> "effect": "NoSchedule",<br/> "key": "node-role.kubernetes.io/master",<br/> "operator": "Exists"<br/> }<br/>]</pre> | no |

examples/obs-agent-iks/main.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ locals {
6262

6363
module "ocp_base" {
6464
source = "terraform-ibm-modules/base-ocp-vpc/ibm"
65-
version = "3.49.1"
65+
version = "3.49.2"
6666
resource_group_id = module.resource_group.resource_group_id
6767
region = var.region
6868
tags = var.resource_tags

examples/obs-agent-iks/version.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ terraform {
66
required_providers {
77
ibm = {
88
source = "ibm-cloud/ibm"
9-
version = "1.78.2"
9+
version = "1.79.0"
1010
}
1111
helm = {
1212
source = "hashicorp/helm"

examples/obs-agent-ocp/main.tf

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ locals {
6262

6363
module "ocp_base" {
6464
source = "terraform-ibm-modules/base-ocp-vpc/ibm"
65-
version = "3.49.1"
65+
version = "3.49.2"
6666
resource_group_id = module.resource_group.resource_group_id
6767
region = var.region
6868
tags = var.resource_tags
@@ -104,9 +104,10 @@ module "monitoring_agents" {
104104
cluster_id = module.ocp_base.cluster_id
105105
cluster_resource_group_id = module.resource_group.resource_group_id
106106
# Monitoring agent
107-
access_key = module.cloud_monitoring.access_key
108-
# example of how to include / exclude metrics - more info https://cloud.ibm.com/docs/monitoring?topic=monitoring-change_kube_agent#change_kube_agent_log_metrics
109-
metrics_filter = [{ type = "exclude", name = "metricA.*" }, { type = "include", name = "metricB.*" }]
110-
container_filter = [{ type = "exclude", parameter = "kubernetes.namespace.name", name = "kube-system" }]
107+
access_key = module.cloud_monitoring.access_key
111108
cloud_monitoring_instance_region = var.region
109+
# example of how to include / exclude metrics - more info https://cloud.ibm.com/docs/monitoring?topic=monitoring-change_kube_agent#change_kube_agent_log_metrics
110+
metrics_filter = [{ exclude = "metricA.*" }, { include = "metricB.*" }]
111+
container_filter = [{ type = "exclude", parameter = "kubernetes.namespace.name", name = "kube-system" }]
112+
blacklisted_ports = [22, 2379, 3306]
112113
}

examples/obs-agent-ocp/outputs.tf

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,35 @@
22
# Outputs
33
##############################################################################
44

5-
#output "myoutput" {
6-
# description = "Description of my output"
7-
# value = "value"
8-
# depends_on = [<some resource>]
9-
#}
5+
output "region" {
6+
description = "The region where the resources are deployed."
7+
value = var.region
8+
}
9+
10+
output "cloud_monitoring_name" {
11+
description = "The name of the IBM Cloud Monitoring instance."
12+
value = module.cloud_monitoring.name
13+
}
14+
15+
output "cloud_monitoring_access_key" {
16+
description = "The access key that is used by the IBM Cloud Monitoring agent to communicate with the instance."
17+
value = module.cloud_monitoring.access_key
18+
sensitive = true
19+
}
20+
21+
output "cluster_name" {
22+
description = "The name of the OpenShift cluster."
23+
value = module.ocp_base.cluster_name
24+
}
25+
26+
output "cluster_id" {
27+
description = "The ID of the OpenShift cluster."
28+
value = module.ocp_base.cluster_id
29+
}
30+
31+
output "cluster_resource_group_id" {
32+
description = "The resource group ID of the cluster."
33+
value = module.resource_group.resource_group_id
34+
}
1035

1136
##############################################################################

examples/obs-agent-ocp/variables.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ variable "ibmcloud_api_key" {
77
variable "prefix" {
88
type = string
99
description = "A prefix for the name of all resources that are created by this example"
10-
default = "obs-agent-ocp"
10+
default = "mon-agent"
1111
}
1212

1313
variable "resource_group" {
@@ -31,7 +31,7 @@ variable "access_tags" {
3131
variable "region" {
3232
type = string
3333
description = "The region where the resources are created."
34-
default = "au-syd"
34+
default = "us-south"
3535
}
3636

3737
variable "ocp_version" {

examples/obs-agent-ocp/version.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ terraform {
66
required_providers {
77
ibm = {
88
source = "ibm-cloud/ibm"
9-
version = ">= 1.71.0"
9+
version = ">= 1.79.0"
1010
}
1111
helm = {
1212
source = "hashicorp/helm"

ibm_catalog.json

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,27 @@
158158
{
159159
"key": "namespace"
160160
},
161+
{
162+
"key": "existing_access_key_secret_name"
163+
},
164+
{
165+
"key": "add_cluster_name"
166+
},
167+
{
168+
"key": "agent_tags"
169+
},
170+
{
171+
"key": "agent_requests_cpu"
172+
},
173+
{
174+
"key": "agent_limits_cpu"
175+
},
176+
{
177+
"key": "agent_requests_memory"
178+
},
179+
{
180+
"key": "agent_limits_memory"
181+
},
161182
{
162183
"key": "tolerations"
163184
},
@@ -174,6 +195,9 @@
174195
}
175196
]
176197
},
198+
{
199+
"key": "blacklisted_ports"
200+
},
177201
{
178202
"key": "metrics_filter"
179203
},

main.tf

Lines changed: 56 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,21 @@ resource "helm_release" "cloud_monitoring_agent" {
6565
name = "agent.slim.enabled"
6666
value = true
6767
}
68-
set {
69-
name = "global.sysdig.accessKey"
70-
type = "string"
71-
value = var.access_key
68+
dynamic "set_sensitive" {
69+
for_each = var.access_key != null && var.access_key != "" ? [1] : []
70+
content {
71+
name = "global.sysdig.accessKey"
72+
type = "string"
73+
value = var.access_key
74+
}
75+
}
76+
dynamic "set" {
77+
for_each = var.existing_access_key_secret_name != null && var.existing_access_key_secret_name != "" ? [1] : []
78+
content {
79+
name = "global.sysdig.accessKeySecret"
80+
type = "string"
81+
value = var.existing_access_key_secret_name
82+
}
7283
}
7384
set {
7485
name = "global.clusterConfig.name"
@@ -95,6 +106,26 @@ resource "helm_release" "cloud_monitoring_agent" {
95106
type = "string"
96107
value = var.agent_image_tag_digest
97108
}
109+
set {
110+
name = "agent.resources.requests.cpu"
111+
type = "string"
112+
value = var.agent_requests_cpu
113+
}
114+
set {
115+
name = "agent.resources.requests.memory"
116+
type = "string"
117+
value = var.agent_requests_memory
118+
}
119+
set {
120+
name = "agent.resources.limits.cpu"
121+
type = "string"
122+
value = var.agent_limits_cpu
123+
}
124+
set {
125+
name = "agent.resources.limits.memory"
126+
type = "string"
127+
value = var.agent_limits_memory
128+
}
98129
set {
99130
name = "agent.slim.kmoduleImage.digest"
100131
type = "string"
@@ -107,13 +138,27 @@ resource "helm_release" "cloud_monitoring_agent" {
107138
value = false
108139
}
109140

110-
values = [yamlencode({
111-
metrics_filter = var.metrics_filter
112-
}), yamlencode({
113-
tolerations = var.tolerations
114-
}), yamlencode({
115-
container_filter = var.container_filter
116-
})]
141+
# Values to be passed to the agent config map, e.g `kubectl describe configmap sysdig-agent -n ibm-observe`
142+
values = [
143+
yamlencode({
144+
agent = {
145+
sysdig = {
146+
settings = {
147+
blacklisted_ports = var.blacklisted_ports
148+
metrics_filter = var.metrics_filter
149+
container_filter = var.container_filter
150+
}
151+
tags = merge(
152+
var.agent_tags,
153+
var.add_cluster_name ? {
154+
"ibm-containers-kubernetes-cluster-name" = local.cluster_name
155+
} : {}
156+
)
157+
},
158+
tolerations = var.tolerations
159+
}
160+
})
161+
]
117162

118163
provisioner "local-exec" {
119164
command = "${path.module}/scripts/confirm-rollout-status.sh ${var.name} ${var.namespace}"

reference-architecture/deployable-architecture-monitoring-agent.svg

Lines changed: 1 addition & 1 deletion
Loading

0 commit comments

Comments
 (0)