Skip to content

Commit f0d8d99

Browse files
authored
fix: fixed bug which was causing the incorrect image tag to be used for the initContainer<br>- renamed the input kernal_module_image_repository -> kernel_module_image_repository (#260)
1 parent d67a6a4 commit f0d8d99

File tree

10 files changed

+34
-22
lines changed

10 files changed

+34
-22
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ This module supports the provisioning of an agent to an IBM Cloud Red Hat OpenSh
2323
## Overview
2424
* [terraform-ibm-monitoring-agent](#terraform-ibm-monitoring-agent)
2525
* [Examples](./examples)
26-
* <div style="display: inline-block;"><a href="./examples/obs-agent-iks">Deploy agent in IKS cluster</a></div> <div style="display: inline-block; vertical-align: middle;"><a href="https://cloud.ibm.com/schematics/workspaces/create?workspace_name=ma-obs-agent-iks-example&repository=github.com/terraform-ibm-modules/terraform-ibm-monitoring-agent/tree/main/examples/obs-agent-iks" target="_blank"><img src="https://cloud.ibm.com/media/docs/images/icons/Deploy_to_cloud.svg" alt="Deploy to IBM Cloud button"></a></div>
27-
* <div style="display: inline-block;"><a href="./examples/obs-agent-ocp">Deploy agent in OpenShift cluster</a></div> <div style="display: inline-block; vertical-align: middle;"><a href="https://cloud.ibm.com/schematics/workspaces/create?workspace_name=ma-obs-agent-ocp-example&repository=github.com/terraform-ibm-modules/terraform-ibm-monitoring-agent/tree/main/examples/obs-agent-ocp" target="_blank"><img src="https://cloud.ibm.com/media/docs/images/icons/Deploy_to_cloud.svg" alt="Deploy to IBM Cloud button"></a></div>
26+
* <div style="display: inline-block;"><a href="./examples/obs-agent-iks">Deploy agent in IKS cluster</a></div> <div style="display: inline-block; vertical-align: middle;"><a href="https://cloud.ibm.com/schematics/workspaces/create?workspace_name=ma-obs-agent-iks-example&repository=https://github.com/terraform-ibm-modules/terraform-ibm-monitoring-agent/tree/main/examples/obs-agent-iks" target="_blank"><img src="https://cloud.ibm.com/media/docs/images/icons/Deploy_to_cloud.svg" alt="Deploy to IBM Cloud button"></a></div>
27+
* <div style="display: inline-block;"><a href="./examples/obs-agent-ocp">Deploy agent in OpenShift cluster</a></div> <div style="display: inline-block; vertical-align: middle;"><a href="https://cloud.ibm.com/schematics/workspaces/create?workspace_name=ma-obs-agent-ocp-example&repository=https://github.com/terraform-ibm-modules/terraform-ibm-monitoring-agent/tree/main/examples/obs-agent-ocp" target="_blank"><img src="https://cloud.ibm.com/media/docs/images/icons/Deploy_to_cloud.svg" alt="Deploy to IBM Cloud button"></a></div>
2828
* [Contributing](#contributing)
2929
<!-- END OVERVIEW HOOK -->
3030

@@ -141,8 +141,8 @@ No modules.
141141
| <a name="input_image_registry_namespace"></a> [image\_registry\_namespace](#input\_image\_registry\_namespace) | The namespace within the image registry to pull all images from. | `string` | `"ext/sysdig"` | no |
142142
| <a name="input_instance_region"></a> [instance\_region](#input\_instance\_region) | The region of the IBM Cloud Monitoring instance that you want to send metrics to. The region value is used to construct the ingestion and api endpoints. If you are only using the agent for security and compliance monitoring, set this to the region of your IBM Cloud Security and Compliance Center Workload Protection instance. If you have both Cloud Monitoring and Security and Compliance Center Workload Protection instances, the instances must be connected and must be in the same region to use the same agent. | `string` | n/a | yes |
143143
| <a name="input_is_vpc_cluster"></a> [is\_vpc\_cluster](#input\_is\_vpc\_cluster) | Specify true if the target cluster is a VPC cluster, false if it is a classic cluster. | `bool` | `true` | no |
144-
| <a name="input_kernal_module_image_repository"></a> [kernal\_module\_image\_repository](#input\_kernal\_module\_image\_repository) | The image repository to pull the agent kernal module initContainer image from. | `string` | `"agent-kmodule"` | no |
145-
| <a name="input_kernel_module_image_tag_digest"></a> [kernel\_module\_image\_tag\_digest](#input\_kernel\_module\_image\_tag\_digest) | The image tag or digest to use for the agent kernel module used by the initContainer. If using digest, it must be in the format of `X.Y.Z@sha256:xxxxx` | `string` | `"14.2.3@sha256:78c87643d1336efa62f4af8af80290f76097fde51c8d8204a5eb38d73363489d"` | no |
144+
| <a name="input_kernel_module_image_repository"></a> [kernel\_module\_image\_repository](#input\_kernel\_module\_image\_repository) | The image repository to pull the agent kernel module initContainer image from. | `string` | `"agent-kmodule"` | no |
145+
| <a name="input_kernel_module_image_tag_digest"></a> [kernel\_module\_image\_tag\_digest](#input\_kernel\_module\_image\_tag\_digest) | The image digest to use for the agent kernel module used by the initContainer. Must be in the format of `X.Y.Z@sha256:xxxxx` | `string` | `"14.2.3@sha256:78c87643d1336efa62f4af8af80290f76097fde51c8d8204a5eb38d73363489d"` | no |
146146
| <a name="input_max_surge"></a> [max\_surge](#input\_max\_surge) | The number of pods that can be created above the desired amount of daemonset pods during an update. If `max_surge` is set to null, the `max_surge` setting is ignored. The variable accepts absolute number or percentage value(e.g., '1' or '10%'). | `string` | `null` | no |
147147
| <a name="input_max_unavailable"></a> [max\_unavailable](#input\_max\_unavailable) | The maximum number of pods that can be unavailable during a DaemonSet rolling update. Accepts absolute number or percentage (e.g., '1' or '10%'). | `string` | `"1"` | no |
148148
| <a name="input_metrics_filter"></a> [metrics\_filter](#input\_metrics\_filter) | To filter custom metrics you can specify which metrics to include and exclude. For more info, 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 |

ibm_catalog.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,7 @@
397397
"key": "cluster_shield_requests_memory"
398398
},
399399
{
400-
"key": "kernal_module_image_repository"
400+
"key": "kernel_module_image_repository"
401401
},
402402
{
403403
"key": "kernel_module_image_tag_digest"

main.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,8 +181,8 @@ resource "helm_release" "cloud_monitoring_agent" {
181181
"image":
182182
"repository": ${var.agent_image_repository}
183183
"kmoduleImage":
184-
"repository": ${var.kernal_module_image_repository}
185-
"tag": ${var.kernel_module_image_tag_digest}
184+
"repository": ${var.kernel_module_image_repository}
185+
"digest": ${var.kernel_module_image_tag_digest}
186186
"image":
187187
"registry": ${var.image_registry_base_url}
188188
"tag": ${var.agent_image_tag_digest}

scripts/confirm-rollout-status.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,6 @@ set -e
55
daemonset=$1
66
namespace=$2
77

8+
echo "Waiting for daemonset ${daemonset} to roll out in namespace ${namespace}..."
89
kubectl rollout status ds "${daemonset}" -n "${namespace}" --timeout 30m
10+
echo "Daemonset ${daemonset} successfully rolled out"

solutions/fully-configurable/main.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ module "monitoring_agent" {
5656
agent_image_repository = var.agent_image_repository
5757
agent_image_tag_digest = var.agent_image_tag_digest
5858
kernel_module_image_tag_digest = var.kernel_module_image_tag_digest
59-
kernal_module_image_repository = var.kernal_module_image_repository
59+
kernel_module_image_repository = var.kernel_module_image_repository
6060
agent_limits_cpu = var.agent_limits_cpu
6161
agent_limits_memory = var.agent_limits_memory
6262
agent_requests_cpu = var.agent_requests_cpu

solutions/fully-configurable/variables.tf

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -220,15 +220,15 @@ variable "agent_image_tag_digest" {
220220
}
221221

222222
variable "kernel_module_image_tag_digest" {
223-
description = "The image tag or digest to use for the agent kernel module used by the initContainer. If using digest, it must be in the format of `X.Y.Z@sha256:xxxxx`"
223+
description = "The image digest to use for the agent kernel module used by the initContainer. Must be in the format of `X.Y.Z@sha256:xxxxx`"
224224
type = string
225225
# This version is automatically managed by renovate automation - do not remove the datasource comment on next line
226226
default = "14.2.3@sha256:78c87643d1336efa62f4af8af80290f76097fde51c8d8204a5eb38d73363489d" # datasource: icr.io/ext/sysdig/agent-kmodule
227227
nullable = false
228228
}
229229

230-
variable "kernal_module_image_repository" {
231-
description = "The image repository to pull the agent kernal module initContainer image from."
230+
variable "kernel_module_image_repository" {
231+
description = "The image repository to pull the agent kernel module initContainer image from."
232232
type = string
233233
default = "agent-kmodule"
234234
nullable = false

tests/other_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
package test
33

44
import (
5-
"math/rand/v2"
65
"testing"
76

87
"github.com/stretchr/testify/assert"
@@ -18,7 +17,7 @@ func TestRunAgentVpcOcp(t *testing.T) {
1817
TerraformDir: terraformDirMonitoringAgentROKS,
1918
Prefix: "obs-agent-ocp",
2019
ResourceGroup: resourceGroup,
21-
Region: validRegions[rand.IntN(len(validRegions))],
20+
Region: validRegions[randInt(len(validRegions))],
2221
IgnoreUpdates: testhelper.Exemptions{ // Ignore for consistency check
2322
List: IgnoreUpdates,
2423
},

tests/pr_test.go

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22
package test
33

44
import (
5+
"crypto/rand"
56
"fmt"
67
"log"
7-
"math/rand/v2"
8+
"math/big"
89
"os"
910
"strings"
1011
"testing"
@@ -27,6 +28,7 @@ const fullyConfigurableSolutionDir = "solutions/fully-configurable"
2728
const fullyConfigurableSolutionKubeconfigDir = "solutions/fully-configurable/kubeconfig"
2829
const terraformDirMonitoringAgentIKS = "examples/obs-agent-iks"
2930
const terraformDirMonitoringAgentROKS = "examples/obs-agent-ocp"
31+
3032
const terraformVersion = "terraform_v1.12.2" // This should match the version in the ibm_catalog.json
3133
// Define a struct with fields that match the structure of the YAML data
3234
const yamlLocation = "../common-dev-assets/common-go-assets/common-permanent-resources.yaml"
@@ -54,6 +56,15 @@ var IgnoreUpdates = []string{
5456
// workaround for https://github.com/terraform-ibm-modules/terraform-ibm-scc-workload-protection/issues/243
5557
var IgnoreAdds = []string{"module.scc_wp.restapi_object.cspm"}
5658

59+
// randInt returns a cryptographically secure random integer in the range [0, max)
60+
func randInt(max int) int {
61+
n, err := rand.Int(rand.Reader, big.NewInt(int64(max)))
62+
if err != nil {
63+
log.Fatal(err)
64+
}
65+
return int(n.Int64())
66+
}
67+
5768
// TestMain will be run before any parallel tests, used to set up a shared InfoService object to track region usage
5869
// for multiple tests
5970
func TestMain(m *testing.M) {
@@ -71,7 +82,7 @@ func TestMain(m *testing.M) {
7182
func TestFullyConfigurableSolution(t *testing.T) {
7283
t.Parallel()
7384

74-
var region = validRegions[rand.IntN(len(validRegions))]
85+
var region = validRegions[randInt(len(validRegions))]
7586
// ------------------------------------------------------------------------------------------------------
7687
// Deploy OCP Cluster and Monitoring instance since it is needed to deploy agent
7788
// ------------------------------------------------------------------------------------------------------
@@ -156,7 +167,7 @@ func TestFullyConfigurableSolution(t *testing.T) {
156167
func TestFullyConfigurableUpgradeSolution(t *testing.T) {
157168
t.Parallel()
158169

159-
var region = validRegions[rand.IntN(len(validRegions))]
170+
var region = validRegions[randInt(len(validRegions))]
160171

161172
// ------------------------------------------------------------------------------------------------------
162173
// Deploy OCP Cluster and Monitoring instance since it is needed to deploy agent
@@ -247,7 +258,7 @@ func TestRunAgentVpcKubernetes(t *testing.T) {
247258
Testing: t,
248259
TerraformDir: terraformDirMonitoringAgentIKS,
249260
Prefix: "obs-agent-vpc-iks",
250-
Region: validRegions[rand.IntN(len(validRegions))],
261+
Region: validRegions[randInt(len(validRegions))],
251262
ResourceGroup: resourceGroup,
252263
IgnoreUpdates: testhelper.Exemptions{ // Ignore for consistency check
253264
List: IgnoreUpdates,
@@ -269,7 +280,7 @@ func TestRunAgentClassicKubernetes(t *testing.T) {
269280
Testing: t,
270281
TerraformDir: terraformDirMonitoringAgentIKS,
271282
Prefix: "obs-agent-iks",
272-
Region: validRegions[rand.IntN(len(validRegions))],
283+
Region: validRegions[randInt(len(validRegions))],
273284
ResourceGroup: resourceGroup,
274285
IgnoreUpdates: testhelper.Exemptions{ // Ignore for consistency check
275286
List: IgnoreUpdates,

variables.tf

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -196,15 +196,15 @@ variable "agent_image_tag_digest" {
196196
}
197197

198198
variable "kernel_module_image_tag_digest" {
199-
description = "The image tag or digest to use for the agent kernel module used by the initContainer. If using digest, it must be in the format of `X.Y.Z@sha256:xxxxx`"
199+
description = "The image digest to use for the agent kernel module used by the initContainer. Must be in the format of `X.Y.Z@sha256:xxxxx`"
200200
type = string
201201
# This version is automatically managed by renovate automation - do not remove the datasource comment on next line
202202
default = "14.2.3@sha256:78c87643d1336efa62f4af8af80290f76097fde51c8d8204a5eb38d73363489d" # datasource: icr.io/ext/sysdig/agent-kmodule
203203
nullable = false
204204
}
205205

206-
variable "kernal_module_image_repository" {
207-
description = "The image repository to pull the agent kernal module initContainer image from."
206+
variable "kernel_module_image_repository" {
207+
description = "The image repository to pull the agent kernel module initContainer image from."
208208
type = string
209209
default = "agent-kmodule"
210210
nullable = false

0 commit comments

Comments
 (0)