Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OCPBUGS-28575: Fix issue with PS type mismatch #2051

Merged
merged 1 commit into from
Jan 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't an existing file without content throw an error?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is not the case

PS C:\Users\Administrator> rm /k/cni/config/cni.conf; New-Item /k/cni/config/cni.conf -type file


    Directory: C:\k\cni\config


Mode                LastWriteTime         Length Name
----                -------------         ------ ----
-a----        1/30/2024   5:23 PM              0 cni.conf


PS C:\Users\Administrator> cat /k/cni/config/cni.conf
PS C:\Users\Administrator> $foo=(cat /k/cni/config/cni.conf)
PS C:\Users\Administrator> $foo
PS C:\Users\Administrator> $foo.gettype()
You cannot call a method on a null-valued expression. 
At line:1 char:1
+ $foo.gettype()
+ ~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull

if($config_file_content -ne $null) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should it also check for non empty?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you're asking if it should check if the file is empty, thats what this is doing
$config_file_content will be $null if /k/cni/config/cni.conf is empty

` + " $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