Trying to configure a PreStop Hook which should run a script in a windows container. Observed that the prestop hook is not executing the script in OpenShift Windows Container. This is a Powershell script which moves logs to volume
Tried specifying basic hello world to the console, that is also not working.
Tried increasing terminationGracePeriodSeconds
to 1001
, had no luck with that approach.
My YAML file has a Prestop hook (see below), wonder if a Windows Container in OpenShift has any limitations with PreStop Hook processes?
lifecycle:
preStop:
exec:
command:
- 'C:\Windows\System32\WindowsPowerShell\v1.0\Powershell.exe'
- '-File'
- 'C:\pathtoscriptinrepo\appscript.ps1'
I tried several ways by specifying cmd
also but it does not work.
Below is the Powershell script that is executed:
$sourcePath ="C:/somefolder/logs"
$destinationPath = "C:/Data/appname/PROD "
# Get all .log files in the source folder
$files = Get-ChildItem -Path $sourcePath -Filter "*.log"
# Move each .log file to the destination folder
foreach ($file in $files) {
$destination = Join-Path -Path $destinationPath -ChildPath $file.Name
Move-Item -Path $file.FullName -Destination $destination
Write-Host "Moved file: $($file.Name)"
}
Found that the moving of files to a volume using a Popwershell script in PreStop is not working. Any ideas or solutions ?
The service account for the Persistent Volume Claim has Full permissions
Was able to fix this.
Observed that the Powershell Move-Item
command does not work during PreStop executions.
Replacing it with Copy-Item
command within the Powershell script resolved the issue, it was able to move the files.
It appears that during PreStop process, the Powershell Move-Item
does not work and execution is prevented, it maybe that Windows will lock few files that are in use and causing the above.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With