Skip to content

Commit a20bf01

Browse files
Jordan-Williams2Jordan-Williams2
authored andcommitted
feat: add features to new DA helm chart
1 parent cfbd5ae commit a20bf01

File tree

10 files changed

+122
-80
lines changed

10 files changed

+122
-80
lines changed

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,15 +103,16 @@ No modules.
103103
| Name | Description | Type | Default | Required |
104104
|------|-------------|------|---------|:--------:|
105105
| <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 |
106-
| <a name="input_access_key_secret"></a> [access\_key\_secret](#input\_access\_key\_secret) | The name of the secret which will store the access key. | `string` | `"sysdig-agent"` | no |
107-
| <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. | `bool` | `true` | no |
106+
| <a name="input_access_key_secret"></a> [access\_key\_secret](#input\_access\_key\_secret) | The name of a Kubernetes/Openshift secret containing an access-key entry. | `string` | `null` | no |
107+
| <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. | `bool` | `false` | no |
108108
| <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 |
109109
| <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.1@sha256:14860d181a8b712c4150bb59e3ba0ff4be08959e2c45376b32c8eb7ff70461f9"` | no |
110110
| <a name="input_agent_limits_cpu"></a> [agent\_limits\_cpu](#input\_agent\_limits\_cpu) | Specifies the CPU limit for the agent. | `string` | `"1"` | no |
111111
| <a name="input_agent_limits_memory"></a> [agent\_limits\_memory](#input\_agent\_limits\_memory) | Specifies the memory limit for the agent. | `string` | `"1024Mi"` | no |
112112
| <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 |
113113
| <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 |
114-
| <a name="input_agent_tags"></a> [agent\_tags](#input\_agent\_tags) | List of tags to associate to all matrics that the agent collects. NOTE: Use the 'add\_cluster\_name' variable to add the cluster name as a tag. | `list(string)` | `[]` | no |
114+
| <a name="input_agent_tags"></a> [agent\_tags](#input\_agent\_tags) | Map of tags to associate to all matrics that the agent collects. NOTE: Use the 'add\_cluster\_name' variable to add the cluster name as a tag, e.g `ibm-containers-kubernetes-cluster-name: cluster_name`. | `map(string)` | `{}` | no |
115+
| <a name="input_blacklisted_ports"></a> [blacklisted\_ports](#input\_blacklisted\_ports) | To blacklist ports, include the ports you wish to block network traffic and metrics from network ports. See https://cloud.ibm.com/docs/monitoring?topic=monitoring-change_kube_agent#change_kube_agent_block_ports. | `list(number)` | `[]` | no |
115116
| <a name="input_chart"></a> [chart](#input\_chart) | The name of the Helm chart to deploy. | `string` | `"sysdig-deploy"` | no |
116117
| <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 |
117118
| <a name="input_chart_version"></a> [chart\_version](#input\_chart\_version) | The version of the Cloud Monitoring agent helm chart to deploy. | `string` | `"1.84.2"` | no |

examples/obs-agent-ocp/main.tf

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,20 @@ resource "ibm_is_vpc" "vpc" {
2626
tags = var.resource_tags
2727
}
2828

29+
resource "ibm_is_public_gateway" "gateway" {
30+
name = "${var.prefix}-gateway-1"
31+
vpc = ibm_is_vpc.vpc.id
32+
resource_group = module.resource_group.resource_group_id
33+
zone = "${var.region}-1"
34+
}
35+
2936
resource "ibm_is_subnet" "subnet_zone_1" {
3037
name = "${var.prefix}-subnet-1"
3138
vpc = ibm_is_vpc.vpc.id
3239
resource_group = module.resource_group.resource_group_id
3340
zone = "${var.region}-1"
3441
total_ipv4_address_count = 256
42+
public_gateway = ibm_is_public_gateway.gateway.id
3543
}
3644

3745
########################################################################################################################
@@ -99,14 +107,14 @@ module "cloud_monitoring" {
99107
# Monitoring Agents
100108
##############################################################################
101109

102-
module "monitoring_agents" {
103-
source = "../.."
104-
cluster_id = module.ocp_base.cluster_id
105-
cluster_resource_group_id = module.resource_group.resource_group_id
106-
# 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" }]
111-
cloud_monitoring_instance_region = var.region
112-
}
110+
# module "monitoring_agents" {
111+
# source = "../.."
112+
# cluster_id = module.ocp_base.cluster_id
113+
# cluster_resource_group_id = module.resource_group.resource_group_id
114+
# # Monitoring agent
115+
# access_key = module.cloud_monitoring.access_key
116+
# # 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
117+
# metrics_filter = [{ type = "exclude", name = "metricA.*" }, { type = "include", name = "metricB.*" }]
118+
# container_filter = [{ type = "exclude", parameter = "kubernetes.namespace.name", name = "kube-system" }]
119+
# cloud_monitoring_instance_region = var.region
120+
# }

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" {

ibm_catalog.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,9 @@
195195
}
196196
]
197197
},
198+
{
199+
"key": "blacklisted_ports"
200+
},
198201
{
199202
"key": "metrics_filter"
200203
},

main.tf

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ data "ibm_container_cluster_config" "cluster_config" {
3030
locals {
3131
# LOCALS
3232
cluster_name = var.is_vpc_cluster ? data.ibm_container_vpc_cluster.cluster[0].resource_name : data.ibm_container_cluster.cluster[0].resource_name # Not publically documented in provider. See https://github.com/IBM-Cloud/terraform-provider-ibm/issues/4485
33-
agent_tags = var.add_cluster_name ? concat(["ibm.containers-kubernetes.cluster.name:${local.cluster_name}"], var.agent_tags) : var.agent_tags
3433
collector_host = var.cloud_monitoring_instance_endpoint_type == "private" ? "ingest.private.${var.cloud_monitoring_instance_region}.monitoring.cloud.ibm.com" : "ingest.${var.cloud_monitoring_instance_region}.monitoring.cloud.ibm.com"
3534
}
3635

@@ -71,15 +70,13 @@ resource "helm_release" "cloud_monitoring_agent" {
7170
type = "string"
7271
value = var.access_key
7372
}
74-
set {
75-
name = "global.sysdig.accessKeySecret"
76-
type = "string"
77-
value = var.access_key_secret
78-
}
79-
set {
80-
name = "global.sysdig.tags"
81-
type = "string"
82-
value = join("\\,", local.agent_tags)
73+
dynamic "set" {
74+
for_each = var.access_key_secret != null && var.access_key_secret != "" ? [1] : []
75+
content {
76+
name = "global.sysdig.accessKeySecret"
77+
type = "string"
78+
value = var.access_key_secret
79+
}
8380
}
8481
set {
8582
name = "global.clusterConfig.name"
@@ -139,21 +136,24 @@ resource "helm_release" "cloud_monitoring_agent" {
139136
}
140137

141138
values = [
142-
yamlencode(
143-
{
144-
metrics_filter = var.metrics_filter
145-
}
146-
),
147-
yamlencode(
148-
{
149-
tolerations = var.tolerations
150-
}
151-
),
152-
yamlencode(
153-
{
154-
container_filter = var.container_filter
139+
yamlencode({
140+
agent = {
141+
sysdig = {
142+
settings = {
143+
blacklisted_ports = var.blacklisted_ports
144+
metrics_filter = var.metrics_filter
145+
tolerations = var.tolerations
146+
container_filter = var.container_filter
147+
}
148+
tags = merge(
149+
var.agent_tags,
150+
var.add_cluster_name ? {
151+
"ibm-containers-kubernetes-cluster-name" = local.cluster_name
152+
} : {}
153+
)
154+
}
155155
}
156-
)
156+
})
157157
]
158158

159159
provisioner "local-exec" {

solutions/fully-configurable/main.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ module "monitoring_agent" {
2525
access_key_secret = var.access_key_secret
2626
agent_tags = var.agent_tags
2727
add_cluster_name = var.add_cluster_name
28+
blacklisted_ports = var.blacklisted_ports
2829
metrics_filter = var.metrics_filter
2930
cloud_monitoring_instance_region = var.cloud_monitoring_instance_region
3031
tolerations = var.tolerations

solutions/fully-configurable/variables.tf

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ variable "cluster_resource_group_id" {
2323
variable "cluster_config_endpoint_type" {
2424
description = "Specify the type of endpoint to use to access the cluster configuration. Possible values: `default`, `private`, `vpe`, `link`. The `default` value uses the default endpoint of the cluster."
2525
type = string
26-
default = "private"
27-
nullable = false # use default if null is passed in
26+
default = "private" # Use 'private' for VPC clusters, 'default' for classic clusters
27+
nullable = false # use default if null is passed in
2828
}
2929

3030
variable "is_vpc_cluster" {
@@ -58,9 +58,9 @@ variable "access_key" {
5858

5959
variable "access_key_secret" {
6060
type = string
61-
description = "The name of the secret which will store the access key."
62-
default = "sysdig-agent"
63-
nullable = false
61+
description = "The name of a Kubernetes/Openshift secret containing an access-key entry."
62+
default = null
63+
nullable = true
6464
}
6565

6666
variable "cloud_monitoring_instance_region" {
@@ -75,25 +75,29 @@ variable "cloud_monitoring_instance_endpoint_type" {
7575
default = "private"
7676
}
7777

78+
variable "blacklisted_ports" {
79+
type = list(number)
80+
description = "To blacklist ports, include the ports you wish to block network traffic and metrics from network ports. See https://cloud.ibm.com/docs/monitoring?topic=monitoring-change_kube_agent#change_kube_agent_block_ports."
81+
default = []
82+
}
83+
7884
variable "metrics_filter" {
7985
type = list(object({
80-
type = string
81-
name = string
86+
include = optional(string)
87+
exclude = optional(string)
8288
}))
8389
description = "To filter on custom metrics, specify the IBM Cloud Monitoring metrics to include or exclude. [Learn more](https://cloud.ibm.com/docs/monitoring?topic=monitoring-change_kube_agent#change_kube_agent_inc_exc_metrics) and [here](https://github.com/terraform-ibm-modules/terraform-ibm-monitoring-agent/tree/main/solutions/fully-configurable/DA-types.md)."
84-
default = [] # [{ type = "exclude", name = "metricA.*" }, { type = "include", name = "metricB.*" }]
90+
default = [{ exclude = "all" }]
91+
validation {
92+
condition = length(var.metrics_filter) == 0 || can(regex("^(include|exclude)$", var.metrics_filter[0].include)) || can(regex("^(include|exclude)$", var.metrics_filter[0].exclude))
93+
error_message = "Invalid input for `metrics_filter`. Valid options for 'include' and 'exclude' are: `include` and `exclude`. If empty, no metrics are included or excluded."
94+
}
8595
}
8696

8797
variable "agent_tags" {
88-
type = list(string)
89-
description = "List of tags to associate to all matrics that the agent collects. NOTE: Use the 'add_cluster_name' variable to add the cluster name as a tag."
90-
default = []
91-
nullable = false
92-
93-
validation {
94-
condition = alltrue([for tags in var.agent_tags : !can(regex("\\s", tags))])
95-
error_message = "The cloud monitoring agent tags must not contain any spaces."
96-
}
98+
description = "Map of tags to associate to all matrics that the agent collects. NOTE: Use the 'add_cluster_name' variable to add the cluster name as a tag, e.g `ibm-containers-kubernetes-cluster-name: cluster_name`."
99+
type = map(string)
100+
default = {}
97101
}
98102

99103
variable "add_cluster_name" {

variables.tf

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,9 @@ variable "access_key" {
6666

6767
variable "access_key_secret" {
6868
type = string
69-
description = "The name of the secret which will store the access key."
70-
default = "sysdig-agent"
71-
nullable = false
69+
description = "The name of a Kubernetes/Openshift secret containing an access-key entry."
70+
default = null
71+
nullable = true
7272
}
7373

7474
variable "cloud_monitoring_instance_region" {
@@ -87,16 +87,22 @@ variable "cloud_monitoring_instance_endpoint_type" {
8787
}
8888
}
8989

90+
variable "blacklisted_ports" {
91+
type = list(number)
92+
description = "To blacklist ports, include the ports you wish to block network traffic and metrics from network ports. See https://cloud.ibm.com/docs/monitoring?topic=monitoring-change_kube_agent#change_kube_agent_block_ports."
93+
default = []
94+
}
95+
9096
variable "metrics_filter" {
9197
type = list(object({
92-
type = string
93-
name = string
98+
include = optional(string)
99+
exclude = optional(string)
94100
}))
95101
description = "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."
96102
default = []
97103
validation {
98-
condition = alltrue([for filter in var.metrics_filter : can(regex("^(include|exclude)$", filter.type)) && filter.name != ""])
99-
error_message = "The specified `type` for the `metrics_filter` is not valid. Specify either `include` or `exclude`. The `name` field cannot be empty."
104+
condition = length(var.metrics_filter) == 0 || can(regex("^(include|exclude)$", var.metrics_filter[0].include)) || can(regex("^(include|exclude)$", var.metrics_filter[0].exclude))
105+
error_message = "Invalid input for `metrics_filter`. Valid options for 'include' and 'exclude' are: `include` and `exclude`. If empty, no metrics are included or excluded."
100106
}
101107
}
102108

@@ -115,21 +121,15 @@ variable "container_filter" {
115121
}
116122

117123
variable "agent_tags" {
118-
type = list(string)
119-
description = "List of tags to associate to all matrics that the agent collects. NOTE: Use the 'add_cluster_name' variable to add the cluster name as a tag."
120-
default = []
121-
nullable = false
122-
123-
validation {
124-
condition = alltrue([for tags in var.agent_tags : !can(regex("\\s", tags))])
125-
error_message = "The cloud monitoring agent tags must not contain any spaces."
126-
}
124+
description = "Map of tags to associate to all matrics that the agent collects. NOTE: Use the 'add_cluster_name' variable to add the cluster name as a tag, e.g `ibm-containers-kubernetes-cluster-name: cluster_name`."
125+
type = map(string)
126+
default = {}
127127
}
128128

129129
variable "add_cluster_name" {
130130
type = bool
131131
description = "If true, configure the cloud monitoring agent to attach a tag containing the cluster name to all metric data."
132-
default = true
132+
default = false
133133
}
134134

135135
variable "name" {

0 commit comments

Comments
 (0)