diff --git a/windows/cert-deployer.ps1 b/windows/cert-deployer.ps1 index 8d62e42c..75add499 100644 --- a/windows/cert-deployer.ps1 +++ b/windows/cert-deployer.ps1 @@ -3,6 +3,7 @@ $WarningPreference = 'SilentlyContinue' $VerbosePreference = 'SilentlyContinue' $DebugPreference = 'SilentlyContinue' $InformationPreference = 'SilentlyContinue' +$Utf8NoBomEncoding = New-Object System.Text.UTF8Encoding $False Import-Module -WarningAction Ignore -Name "$PSScriptRoot\utils.psm1" function Normal-Format @@ -24,7 +25,7 @@ Get-ChildItem Env: | Select-Object -Property Key,Value | Where-Object {$_.Key -c $path = "$sslCertsDir\$($key | Normal-Format).pem" if ((-not (Exist-File -Path $path)) -or ($env:FORCE_DEPLOY -eq "true")) { - $val | Out-File -NoNewline -Encoding ascii -Force -FilePath $path + [System.IO.File]::WriteAllLines($path, $val, $Utf8NoBomEncoding) } } Log-Info "Outputted PEM files for Kubernetes components" @@ -36,7 +37,7 @@ Get-ChildItem Env: | Select-Object -Property Key,Value | Where-Object {$_.Key -c $path = "$sslCertsDir\$($key | Normal-Format).yaml" if (-not (Exist-File -Path $path)) { - $val | Out-File -NoNewline -Encoding ascii -Force -FilePath $path + [System.IO.File]::WriteAllLines($path, $val, $Utf8NoBomEncoding) } } Log-Info "Outputted YAML files for Kubernetes components" \ No newline at end of file diff --git a/windows/cloud-provider.psm1 b/windows/cloud-provider.psm1 index d2f88627..b5e222a8 100644 --- a/windows/cloud-provider.psm1 +++ b/windows/cloud-provider.psm1 @@ -3,6 +3,7 @@ $WarningPreference = 'SilentlyContinue' $VerbosePreference = 'SilentlyContinue' $DebugPreference = 'SilentlyContinue' $InformationPreference = 'SilentlyContinue' +$Utf8NoBomEncoding = New-Object System.Text.UTF8Encoding $False function Complete-AzureCloudConfig { @@ -140,7 +141,8 @@ function Complete-AzureCloudConfig $azCloudConfig = $azCloudConfig | Add-Member -Force -NotePropertyMembers $azCloudConfigOverrided -PassThru # output - $azCloudConfig | ConvertTo-Json -Compress -Depth 32 | Out-File -NoNewline -Force -FilePath $CloudConfigPath + $azCloudConfigJson = $azCloudConfig | ConvertTo-Json -Compress -Depth 32 + [System.IO.File]::WriteAllLines($CloudConfigPath, $azCloudConfigJson, $Utf8NoBomEncoding) Log-Info "Completed Azure cloud configuration successfully" } catch @@ -231,7 +233,7 @@ function Get-NodeOverridedName if ($nodeName -match " ") { $nodeName = $nodeName.split(" ")[0] # take the first to be safe } - $nodeName | Out-File -NoNewline -Force -FilePath "c:\run\cloud-provider-override-hostname" + [System.IO.File]::WriteAllLines("c:\run\cloud-provider-override-hostname", $nodeName, $Utf8NoBomEncoding) Log-Info "Got overriding hostname $nodeName from metadata" } } diff --git a/windows/entrypoint.ps1 b/windows/entrypoint.ps1 index 1d3fbd27..b005f52d 100644 --- a/windows/entrypoint.ps1 +++ b/windows/entrypoint.ps1 @@ -8,6 +8,7 @@ $WarningPreference = 'SilentlyContinue' $VerbosePreference = 'SilentlyContinue' $DebugPreference = 'SilentlyContinue' $InformationPreference = 'SilentlyContinue' +$Utf8NoBomEncoding = New-Object System.Text.UTF8Encoding $False Import-Module -WarningAction Ignore -Name @( "$PSScriptRoot\utils.psm1" @@ -162,7 +163,7 @@ switch ($command) $kubeletDockerConfigB64 = $env:RKE_KUBELET_DOCKER_CONFIG if ($kubeletDockerConfigB64) { $kubeletDockerConfig = [System.Text.Encoding]::UTF8.GetString([System.Convert]::FromBase64String($kubeletDockerConfigB64)) - $kubeletDockerConfig | Out-File -NoNewline -Force -FilePath "c:\host\var\lib\kubelet\config.json" + [System.IO.File]::WriteAllLines("c:\host\var\lib\kubelet\config.json", $kubeletDockerConfig, $Utf8NoBomEncoding) } } catch{ Log-Warn "Could not put private registry Docker configuration to the host: $($_.Exception.Message)" diff --git a/windows/sidecar.ps1 b/windows/sidecar.ps1 index a2a05422..163baa9a 100644 --- a/windows/sidecar.ps1 +++ b/windows/sidecar.ps1 @@ -9,6 +9,7 @@ $WarningPreference = 'SilentlyContinue' $VerbosePreference = 'SilentlyContinue' $DebugPreference = 'SilentlyContinue' $InformationPreference = 'SilentlyContinue' +$Utf8NoBomEncoding = New-Object System.Text.UTF8Encoding $False Import-Module -WarningAction Ignore -Name @( "$PSScriptRoot\utils.psm1" @@ -199,7 +200,7 @@ if ($networkConfigObj) } } - @{ + $flannelConflist = @{ name = $cniInfo.Interface cniVersion = "0.2.0" plugins = @( @@ -211,7 +212,8 @@ if ($networkConfigObj) delegate = $cniConfDelegate } ) - } | ConvertTo-Json -Compress -Depth 32 | Out-File -NoNewline -Force -FilePath "c:\host\etc\cni\net.d\10-flannel.conflist" + } | ConvertTo-Json -Compress -Depth 32 + [System.IO.File]::WriteAllLines("c:\host\etc\cni\net.d\10-flannel.conflist", $flannelConflist, $Utf8NoBomEncoding) } @@ -220,7 +222,8 @@ if ($networkConfigObj) } # output cni informantion for kube-proxy -$cniInfo | ConvertTo-Json -Compress -Depth 32 | Out-File -NoNewline -Force -FilePath "c:\run\cni-info.json" +$cniInfoJson = $cniInfo | ConvertTo-Json -Compress -Depth 32 +[System.IO.File]::WriteAllLines("c:\run\cni-info.json", $cniInfoJson, $Utf8NoBomEncoding) # start cni management if ($networkConfigObj) @@ -255,7 +258,7 @@ if ($networkConfigObj) Log-Warn "Could not patch flannel network configration: $($_.Exception.Message)" } - @{ + $netConf = @{ Network = $clusterCIDR Backend = @{ Name = $cniInfo.Interface @@ -263,7 +266,9 @@ if ($networkConfigObj) VNI = $vni Port = $port } - } | ConvertTo-Json -Compress -Depth 32 | Out-File -NoNewline -Force -FilePath "c:\host\etc\kube-flannel\net-conf.json" + } | ConvertTo-Json -Compress -Depth 32 + + [System.IO.File]::WriteAllLines("c:\host\etc\kube-flannel\net-conf.json", $netConf, $Utf8NoBomEncoding) $flannelArgs = @( # could not use kubernetes in-cluster client, indicate kubeconfig instead