Skip to content

Commit

Permalink
[nodeconfig] Fix issue with PS type mismatch
Browse files Browse the repository at this point in the history
This commit fixes an issue which would be seen when the cni config file
was created with no content. When using the -replace operator with
$null, an empty object array was returned. This caused comparison issues
with the expected config as it was comparing an array with a string.
  • Loading branch information
sebsoto committed Jan 30, 2024
1 parent 3e998b9 commit f74a819
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
5 changes: 4 additions & 1 deletion pkg/nodeconfig/payload/payload.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,10 @@ $cni_template=$cni_template.Replace("provider_address",$provider_address)
# Compare CNI config with existing file, and replace if necessary
$existing_config=""
if(Test-Path -Path CNI_CONFIG_PATH) {
` + " $existing_config=((Get-Content -Path \"CNI_CONFIG_PATH\" -Raw) -Replace \"`r\",\"\")" + `
$config_file_content=(Get-Content -Path CNI_CONFIG_PATH -Raw)
if($config_file_content -ne $null) {
` + " $existing_config=$config_file_content.Replace(\"`r\",\"\")" + `
}
}
if($existing_config -ne $cni_template){
Set-Content -Path "CNI_CONFIG_PATH" -Value $cni_template -NoNewline
Expand Down
5 changes: 4 additions & 1 deletion pkg/nodeconfig/payload/payload_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,10 @@ $cni_template=$cni_template.Replace("provider_address",$provider_address)
# Compare CNI config with existing file, and replace if necessary
$existing_config=""
if(Test-Path -Path c:\k\cni.conf) {
` + " $existing_config=((Get-Content -Path \"c:\\k\\cni.conf\" -Raw) -Replace \"`r\",\"\")" + `
$config_file_content=(Get-Content -Path c:\k\cni.conf -Raw)
if($config_file_content -ne $null) {
` + " $existing_config=$config_file_content.Replace(\"`r\",\"\")" + `
}
}
if($existing_config -ne $cni_template){
Set-Content -Path "c:\k\cni.conf" -Value $cni_template -NoNewline
Expand Down

0 comments on commit f74a819

Please sign in to comment.