Skip to content

Commit a8ef0e1

Browse files
[fix] Add min function to the dc name substring functionparameters to avoid template deployment failure for shorter names (#951)
This pr adds min function to the dc name substrings so that the template deployment does not fail for shorter(than 44/64) string lengths. I was testing onboarding a cluster with a short name testsohambicep and caught this bug. This fixes current failure for shorter strings: Getting this error from selected code : {"code": "InvalidTemplate", "message": "Deployment template validation failed: 'The template variable 'dceName' is not valid: Unable to evaluate the template language function 'substring'. The index and length parameters must refer to a location within the string. The index parameter: '0', the length parameter: '44', the length of the string parameter: '28'. Please see https://aka.ms/arm-function-substring for usage details.. Please see https://aka.ms/arm-functions for usage details.'.", "additionalInfo": [{"type": "TemplateViolation", "info": {"lineNumber": 55, "linePosition": 132, "path": "properties.template.variables.dceName"}}]} [comment]: # (Note that your PR title should follow the conventional commit format: https://conventionalcommits.org/en/v1.0.0/#summary) # PR Description [comment]: # (The below checklist is for PRs adding new features. If a box is not checked, add a reason why it's not needed.) # New Feature Checklist - [ ] List telemetry added about the feature. - [ ] Link to the one-pager about the feature. - [ ] List any tasks necessary for release (3P docs, AKS RP chart changes, etc.) after merging the PR. - [ ] Attach results of scale and perf testing. [comment]: # (The below checklist is for code changes. Not all boxes necessarily need to be checked. Build, doc, and template changes do not need to fill out the checklist.) # Tests Checklist - [ ] Have end-to-end Ginkgo tests been run on your cluster and passed? To bootstrap your cluster to run the tests, follow [these instructions](/otelcollector/test/README.md#bootstrap-a-dev-cluster-to-run-ginkgo-tests). - Labels used when running the tests on your cluster: - [ ] `operator` - [ ] `windows` - [ ] `arm64` - [ ] `arc-extension` - [ ] `fips` - [ ] Have new tests been added? For features, have tests been added for this feature? For fixes, is there a test that could have caught this issue and could validate that the fix works? - [ ] Is a new scrape job needed? - [ ] The scrape job was added to the folder [test-cluster-yamls](/otelcollector/test/test-cluster-yamls/) in the correct configmap or as a CR. - [ ] Was a new test label added? - [ ] A string constant for the label was added to [constants.go](/otelcollector/test/utils/constants.go). - [ ] The label and description was added to the [test README](/otelcollector/test/README.md). - [ ] The label was added to this [PR checklist](/.github/pull_request_template). - [ ] The label was added as needed to [testkube-test-crs.yaml](/otelcollector/test/testkube/testkube-test-crs.yaml). - [ ] Are additional API server permissions needed for the new tests? - [ ] These permissions have been added to [api-server-permissions.yaml](/otelcollector/test/testkube/api-server-permissions.yaml). - [ ] Was a new test suite (a new folder under `/tests`) added? - [ ] The new test suite is included in [testkube-test-crs.yaml](/otelcollector/test/testkube/testkube-test-crs.yaml).
1 parent 2e3dfb5 commit a8ef0e1

File tree

5 files changed

+11
-9
lines changed

5 files changed

+11
-9
lines changed

.trivyignore

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33

44
# =========== CRITICAL ================
55
CVE-2024-24790
6+
CVE-2024-5535
7+
CVE-2024-41110
68

79
# =========== HIGH ================
810
# HIGH - otelcollector

AddonArmTemplate/FullAzureMonitorMetricsProfile.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@
5252
"clusterSubscriptionId": "[split(parameters('clusterResourceId'),'/')[2]]",
5353
"clusterResourceGroup": "[split(parameters('clusterResourceId'),'/')[4]]",
5454
"clusterName": "[split(parameters('clusterResourceId'),'/')[8]]",
55-
"dceName": "[substring(Concat('MSProm', '-', parameters('azureMonitorWorkspaceLocation'), '-', variables('clusterName')), 0, 44)]",
56-
"dcrName": "[substring(Concat('MSProm', '-', parameters('azureMonitorWorkspaceLocation'), '-', variables('clusterName')), 0, 64)]",
55+
"dceName": "[substring(concat('MSProm', '-', parameters('azureMonitorWorkspaceLocation'), '-', variables('clusterName')), 0, min(44, length(concat('MSProm', '-', parameters('azureMonitorWorkspaceLocation'), '-', variables('clusterName')))))]",
56+
"dcrName": "[substring(concat('MSProm', '-', parameters('azureMonitorWorkspaceLocation'), '-', variables('clusterName')), 0, min(64, length(concat('MSProm', '-', parameters('azureMonitorWorkspaceLocation'), '-', variables('clusterName')))))]",
5757
"dcraName": "[Concat('MSProm', '-', parameters('clusterLocation'), '-', variables('clusterName'))]",
5858
"nodeRecordingRuleGroup": "NodeRecordingRulesRuleGroup-",
5959
"nodeRecordingRuleGroupName": "[concat(variables('nodeRecordingRuleGroup'), variables('clusterName'))]",

AddonBicepTemplate/FullAzureMonitorMetricsProfile.bicep

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ var azureMonitorWorkspaceSubscriptionId = split(azureMonitorWorkspaceResourceId,
1717
var clusterSubscriptionId = split(clusterResourceId, '/')[2]
1818
var clusterResourceGroup = split(clusterResourceId, '/')[4]
1919
var clusterName = split(clusterResourceId, '/')[8]
20-
var dceName = substring('MSProm-${azureMonitorWorkspaceLocation}-${clusterName}', 0, 44)
21-
var dcrName = substring('MSProm-${azureMonitorWorkspaceLocation}-${clusterName}', 0, 64)
20+
var dceName = substring('MSProm-${azureMonitorWorkspaceLocation}-${clusterName}', 0, min(44, length('MSProm-${azureMonitorWorkspaceLocation}-${clusterName}')))
21+
var dcrName = substring('MSProm-${azureMonitorWorkspaceLocation}-${clusterName}', 0, min(64, length('MSProm-${azureMonitorWorkspaceLocation}-${clusterName}')))
2222
var dcraName = 'MSProm-${clusterLocation}-${clusterName}'
2323
var nodeRecordingRuleGroupPrefix = 'NodeRecordingRulesRuleGroup-'
2424
var nodeRecordingRuleGroupName = '${nodeRecordingRuleGroupPrefix}${clusterName}'

AddonPolicyTemplate/AddonPolicyMetricsProfile.rules.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@
5151
"clusterSubscriptionId": "[split(parameters('clusterResourceId'),'/')[2]]",
5252
"clusterResourceGroup": "[split(parameters('clusterResourceId'),'/')[4]]",
5353
"clusterName": "[split(parameters('clusterResourceId'),'/')[8]]",
54-
"dceName": "[substring(Concat('MSProm', '-', parameters('azureMonitorWorkspaceLocation'), '-', variables('clusterName')), 0, 44)]",
55-
"dcrName": "[substring(Concat('MSProm', '-', parameters('azureMonitorWorkspaceLocation'), '-', variables('clusterName')), 0, 64)]",
54+
"dceName": "[substring(concat('MSProm', '-', parameters('azureMonitorWorkspaceLocation'), '-', variables('clusterName')), 0, min(44, length(concat('MSProm', '-', parameters('azureMonitorWorkspaceLocation'), '-', variables('clusterName')))))]",
55+
"dcrName": "[substring(concat('MSProm', '-', parameters('azureMonitorWorkspaceLocation'), '-', variables('clusterName')), 0, min(64, length(concat('MSProm', '-', parameters('azureMonitorWorkspaceLocation'), '-', variables('clusterName')))))]",
5656
"dcraName": "[Concat('MSProm', '-', parameters('clusterLocation'), '-', variables('clusterName'))]",
5757
"nodeRecordingRuleGroup": "NodeRecordingRulesRuleGroup-",
5858
"nodeRecordingRuleGroupName": "[concat(variables('nodeRecordingRuleGroup'), variables('clusterName'))]",
@@ -548,4 +548,4 @@
548548
}
549549
}
550550
}
551-
}
551+
}

AddonTerraformTemplate/main.tf

+2-2
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,14 @@ resource "azurerm_monitor_workspace" "amw" {
4242
}
4343

4444
resource "azurerm_monitor_data_collection_endpoint" "dce" {
45-
name = substr("MSProm-${azurerm_resource_group.rg.location}-${var.cluster_name}", 0, 44)
45+
name = substr("MSProm-${azurerm_resource_group.rg.location}-${var.cluster_name}", 0, min(44, length("MSProm-${azurerm_resource_group.rg.location}-${var.cluster_name}")))
4646
resource_group_name = azurerm_resource_group.rg.name
4747
location = azurerm_resource_group.rg.location
4848
kind = "Linux"
4949
}
5050

5151
resource "azurerm_monitor_data_collection_rule" "dcr" {
52-
name = substr("MSProm-${azurerm_resource_group.rg.location}-${var.cluster_name}", 0, 64)
52+
name = substr("MSProm-${azurerm_resource_group.rg.location}-${var.cluster_name}", 0, min(64, length("MSProm-${azurerm_resource_group.rg.location}-${var.cluster_name}")))
5353
resource_group_name = azurerm_resource_group.rg.name
5454
location = azurerm_resource_group.rg.location
5555
data_collection_endpoint_id = azurerm_monitor_data_collection_endpoint.dce.id

0 commit comments

Comments
 (0)