@@ -59,7 +59,7 @@ function Login([string]$subscription, [string]$clusterGroup, [switch]$skipPushIm
59
59
$kubeContext = (RunOrExitOnFailure kubectl config view - o json) | ConvertFrom-Json - AsHashtable
60
60
$defaultNamespace = $null
61
61
$targetContext = $kubeContext.contexts.Where ({ $_.name -eq $clusterName }) | Select - First 1
62
- if ($targetContext -ne $null -and $targetContext.PSObject.Properties.Name -match " namespace" ) {
62
+ if ($targetContext -ne $null -and $targetContext.Contains ( ' context ' ) -and $targetContext .Contains ( ' namespace' ) ) {
63
63
$defaultNamespace = $targetContext.context.namespace
64
64
}
65
65
@@ -107,7 +107,8 @@ function DeployStressTests(
107
107
[Parameter (Mandatory = $False )][string ]$MatrixDisplayNameFilter ,
108
108
[Parameter (Mandatory = $False )][array ]$MatrixFilters ,
109
109
[Parameter (Mandatory = $False )][array ]$MatrixReplace ,
110
- [Parameter (Mandatory = $False )][array ]$MatrixNonSparseParameters
110
+ [Parameter (Mandatory = $False )][array ]$MatrixNonSparseParameters ,
111
+ [Parameter (Mandatory = $False )][int ]$LockDeletionForDays
111
112
) {
112
113
if ($environment -eq ' pg' ) {
113
114
if ($clusterGroup -or $subscription ) {
@@ -168,7 +169,7 @@ function DeployStressTests(
168
169
- subscription $subscription
169
170
}
170
171
171
- if ($FailedCommands.Count -lt $pkgs.Count ) {
172
+ if ($FailedCommands.Count -lt $pkgs.Count -and ! $Template ) {
172
173
Write-Host " Releases deployed by $deployer "
173
174
Run helm list -- all- namespaces - l deployId= $deployer
174
175
}
@@ -211,12 +212,14 @@ function DeployStressPackage(
211
212
}
212
213
$imageTagBase += " /$ ( $pkg.Namespace ) /$ ( $pkg.ReleaseName ) "
213
214
214
- Write-Host " Creating namespace $ ( $pkg.Namespace ) if it does not exist..."
215
- kubectl create namespace $pkg.Namespace -- dry- run= client - o yaml | kubectl apply -f -
216
- if ($LASTEXITCODE ) {exit $LASTEXITCODE }
217
- Write-Host " Adding default resource requests to namespace/$ ( $pkg.Namespace ) "
218
- $limitRangeSpec | kubectl apply - n $pkg.Namespace -f -
219
- if ($LASTEXITCODE ) {exit $LASTEXITCODE }
215
+ if (! $Template ) {
216
+ Write-Host " Creating namespace $ ( $pkg.Namespace ) if it does not exist..."
217
+ kubectl create namespace $pkg.Namespace -- dry- run= client - o yaml | kubectl apply -f -
218
+ if ($LASTEXITCODE ) {exit $LASTEXITCODE }
219
+ Write-Host " Adding default resource requests to namespace/$ ( $pkg.Namespace ) "
220
+ $limitRangeSpec | kubectl apply - n $pkg.Namespace -f -
221
+ if ($LASTEXITCODE ) {exit $LASTEXITCODE }
222
+ }
220
223
221
224
$dockerBuildConfigs = @ ()
222
225
@@ -317,8 +320,18 @@ function DeployStressPackage(
317
320
318
321
$generatedConfigPath = Join-Path $pkg.Directory generatedValues.yaml
319
322
$subCommand = $Template ? " template" : " upgrade"
320
- $installFlag = $Template ? " " : " --install"
321
- $helmCommandArg = " helm" , $subCommand , $releaseName , $pkg.Directory , " -n" , $pkg.Namespace , $installFlag , " --set" , " stress-test-addons.env=$environment " , " --values" , $generatedConfigPath
323
+ $subCommandFlag = $Template ? " --debug" : " --install"
324
+ $helmCommandArg = " helm" , $subCommand , $releaseName , $pkg.Directory , " -n" , $pkg.Namespace , $subCommandFlag , " --values" , $generatedConfigPath , " --set" , " stress-test-addons.env=$environment "
325
+
326
+ if ($LockDeletionForDays ) {
327
+ $date = (Get-Date ).AddDays($LockDeletionForDays ).ToUniversalTime()
328
+ $isoDate = $date.ToString (" o" )
329
+ # Tell kubernetes job to run only on this specific future time. Technically it will run once per year.
330
+ $cron = " $ ( $date.Minute ) $ ( $date.Hour ) $ ( $date.Day ) $ ( $date.Month ) *"
331
+
332
+ Write-Host " PodDisruptionBudget will be set to prevent deletion until $isoDate "
333
+ $helmCommandArg += " --set" , " PodDisruptionBudgetExpiry=$ ( $isoDate ) " , " --set" , " PodDisruptionBudgetExpiryCron=$cron "
334
+ }
322
335
323
336
$result = (Run @helmCommandArg ) 2>&1 | Write-Host
324
337
@@ -342,7 +355,7 @@ function DeployStressPackage(
342
355
# Helm 3 stores release information in kubernetes secrets. The only way to add extra labels around
343
356
# specific releases (thereby enabling filtering on `helm list`) is to label the underlying secret resources.
344
357
# There is not currently support for setting these labels via the helm cli.
345
- if (! $Template ) {
358
+ if (! $Template ) {
346
359
$helmReleaseConfig = RunOrExitOnFailure kubectl get secrets `
347
360
- n $pkg.Namespace `
348
361
- l " status=deployed,name=$releaseName " `
0 commit comments