Skip to content

Commit

Permalink
Merge pull request #579 from rguske/issue-573
Browse files Browse the repository at this point in the history
Fix the error stopping behaviour for kn-pcli-tag function
  • Loading branch information
rguske authored Sep 13, 2021
2 parents 67ea1bf + 4ad0d30 commit 34df8e1
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 10 deletions.
17 changes: 14 additions & 3 deletions examples/knative/powercli/kn-pcli-tag/handler.ps1
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
Function Process-Init {
[CmdletBinding()]
param()
Write-Host "$(Get-Date) - Processing Init`n"

try {
Expand All @@ -17,23 +19,31 @@ Function Process-Init {
[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor [System.Net.SecurityProtocolType]::Tls12 -bor [System.Net.SecurityProtocolType]::Tls13

Write-Host "$(Get-Date) - Configuring PowerCLI Configuration Settings`n"
Set-PowerCLIConfiguration -InvalidCertificateAction:${VCENTER_CERTIFICATE_ACTION} -ParticipateInCeip:$true -Confirm:$false | Out-Null
Set-PowerCLIConfiguration -InvalidCertificateAction:${VCENTER_CERTIFICATE_ACTION} -ParticipateInCeip:$true -Confirm:$false

Write-Host "$(Get-Date) - Connecting to vCenter Server $VCENTER_SERVER`n"
Connect-VIServer -Server $VCENTER_SERVER -User $VCENTER_USERNAME -Password $VCENTER_PASSWORD | Out-Null

try {
Connect-VIServer -Server $VCENTER_SERVER -User $VCENTER_USERNAME -Password $VCENTER_PASSWORD
} catch {
Write-Error "$(Get-Date) - Failed to connect to vCenter Server"
throw $_
}

Write-Host "$(Get-Date) - Successfully connected to $VCENTER_SERVER`n"

Write-Host "$(Get-Date) - Init Processing Completed`n"
}

Function Process-Shutdown {
[CmdletBinding()]
param()
Write-Host "$(Get-Date) - Processing Shutdown`n"

Write-Host "$(Get-Date) - Disconnecting from vCenter Server`n"

try {
Disconnect-VIServer * -Confirm:$false | Out-Null
Disconnect-VIServer * -Confirm:$false
} catch {
Write-Error "$(Get-Date) - Failed to Disconnect from vCenter Server"
}
Expand All @@ -42,6 +52,7 @@ Function Process-Shutdown {
}

Function Process-Handler {
[CmdletBinding()]
param(
[Parameter(Position=0,Mandatory=$true)][CloudNative.CloudEvents.CloudEvent]$CloudEvent
)
Expand Down
5 changes: 5 additions & 0 deletions examples/knative/powershell/kn-ps-echo/handler.ps1
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
Function Process-Init {
[CmdletBinding()]
param()
Write-Host "$(Get-Date) - Processing Init`n"

Write-Host "$(Get-Date) - Init Processing Completed`n"
}

Function Process-Shutdown {
[CmdletBinding()]
param()
Write-Host "$(Get-Date) - Processing Shutdown`n"

Write-Host "$(Get-Date) - Shutdown Processing Completed`n"
}

Function Process-Handler {
[CmdletBinding()]
param(
[Parameter(Position=0,Mandatory=$true)][CloudNative.CloudEvents.CloudEvent]$CloudEvent
)
Expand Down
5 changes: 5 additions & 0 deletions examples/knative/powershell/kn-ps-email/handler.ps1
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
Function Process-Init {
[CmdletBinding()]
param()
Write-Host "$(Get-Date) - Processing Init`n"

Write-Host "$(Get-Date) - Init Processing Completed`n"
}

Function Process-Shutdown {
[CmdletBinding()]
param()
Write-Host "$(Get-Date) - Processing Shutdown`n"

Write-Host "$(Get-Date) - Shutdown Processing Completed`n"
}

Function Process-Handler {
[CmdletBinding()]
param(
[Parameter(Position=0,Mandatory=$true)][CloudNative.CloudEvents.CloudEvent]$CloudEvent
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
Function Process-Init {
[CmdletBinding()]
param()
Write-Host "$(Get-Date) - Processing Init`n"

Write-Host "$(Get-Date) - Init Processing Completed`n"
}

Function Process-Shutdown {
[CmdletBinding()]
param()
Write-Host "$(Get-Date) - Processing Shutdown`n"

Write-Host "$(Get-Date) - Shutdown Processing Completed`n"
}

Function Process-Handler {
[CmdletBinding()]
param(
[Parameter(Position=0,Mandatory=$true)][CloudNative.CloudEvents.CloudEvent]$CloudEvent
)
Expand Down
5 changes: 5 additions & 0 deletions examples/knative/powershell/kn-ps-slack/handler.ps1
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
Function Process-Init {
[CmdletBinding()]
param()
Write-Host "$(Get-Date) - Processing Init`n"

Write-Host "$(Get-Date) - Init Processing Completed`n"
}

Function Process-Shutdown {
[CmdletBinding()]
param()
Write-Host "$(Get-Date) - Processing Shutdown`n"

Write-Host "$(Get-Date) - Shutdown Processing Completed`n"
}

Function Process-Handler {
[CmdletBinding()]
param(
[Parameter(Position=0,Mandatory=$true)][CloudNative.CloudEvents.CloudEvent]$CloudEvent
)
Expand Down
14 changes: 7 additions & 7 deletions examples/knative/templates/server.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ $backgroundServer = Start-ThreadJob {

# Runs Shutdown function (defined in handler.ps1) to clean up connections from warm startup
try {
Process-Shutdown
Process-Shutdown -ErrorAction 'Stop'
}
catch {
Write-Error "`n$(Get-Date) - Shutdown Processing Error: $($_.Exception.ToString())"
Expand All @@ -98,7 +98,7 @@ $backgroundServer = Start-ThreadJob {

if ( $cloudEvent -ne $null ) {
try {
Process-Handler -CloudEvent $cloudEvent | Out-Null
Process-Handler -CloudEvent $cloudEvent -ErrorAction 'Stop'
$context.Response.StatusCode = [int]([System.Net.HttpStatusCode]::OK)
}
catch {
Expand Down Expand Up @@ -136,7 +136,7 @@ $backgroundServer = Start-ThreadJob {

# Runs Init function (defined in handler.ps1) which can be used to enable warm startup
try {
Process-Init
Process-Init -ErrorAction 'Stop'
}
catch {
Write-Error "$(Get-Date) - Init Processing Error: $($_.Exception.ToString())"
Expand All @@ -155,8 +155,8 @@ $killEvent = new-object 'System.Threading.AutoResetEvent' -ArgumentList $false

Start-ThreadJob {
param($killEvent, $url, $serverStopMessage)
$killEvent.WaitOne() | Out-Null
Invoke-WebRequest -Uri $url -Body $serverStopMessage | Out-Null
$killEvent.WaitOne()
Invoke-WebRequest -Uri $url -Body $serverStopMessage
} -ArgumentList $killEvent, $localUrl, $serverStopMessage

try {
Expand All @@ -171,7 +171,7 @@ try {
}
finally {
Write-Host "$(Get-Date) - PowerShell HTTP Server stop requested. Waiting for server to stop"
$killEvent.Set() | Out-Null
$killEvent.Set()
Get-Job | Wait-Job | Receive-Job
Write-Host "$(Get-Date) - PowerShell HTTP server is stopped"
}
}

0 comments on commit 34df8e1

Please sign in to comment.