Skip to content

Commit 747c3fd

Browse files
azure-sdkbenbp
andauthored
Sync eng/common directory with azure-sdk-tools for PR 7002 (Azure#21610)
* Add LockDeletionForDays parameter to set PodDisruptionBudget and cleanup job * Use matrix for parallel tests. PDB improvements+docs. * Fix kubectl namespace context preservation on login --------- Co-authored-by: Ben Broderick Phillips <[email protected]>
1 parent 0a1ed18 commit 747c3fd

File tree

2 files changed

+29
-13
lines changed

2 files changed

+29
-13
lines changed

eng/common/scripts/stress-testing/deploy-stress-tests.ps1

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,10 @@ param(
3131
[Parameter(Mandatory=$False)][string]$MatrixDisplayNameFilter,
3232
[Parameter(Mandatory=$False)][array]$MatrixFilters,
3333
[Parameter(Mandatory=$False)][array]$MatrixReplace,
34-
[Parameter(Mandatory=$False)][array]$MatrixNonSparseParameters
34+
[Parameter(Mandatory=$False)][array]$MatrixNonSparseParameters,
35+
36+
# Prevent kubernetes from deleting nodes or rebalancing pods related to this test for N days
37+
[Parameter(Mandatory=$False)][ValidateRange(1, 14)][int]$LockDeletionForDays
3538
)
3639

3740
. $PSScriptRoot/stress-test-deployment-lib.ps1

eng/common/scripts/stress-testing/stress-test-deployment-lib.ps1

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ function Login([string]$subscription, [string]$clusterGroup, [switch]$skipPushIm
5959
$kubeContext = (RunOrExitOnFailure kubectl config view -o json) | ConvertFrom-Json -AsHashtable
6060
$defaultNamespace = $null
6161
$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')) {
6363
$defaultNamespace = $targetContext.context.namespace
6464
}
6565

@@ -107,7 +107,8 @@ function DeployStressTests(
107107
[Parameter(Mandatory=$False)][string]$MatrixDisplayNameFilter,
108108
[Parameter(Mandatory=$False)][array]$MatrixFilters,
109109
[Parameter(Mandatory=$False)][array]$MatrixReplace,
110-
[Parameter(Mandatory=$False)][array]$MatrixNonSparseParameters
110+
[Parameter(Mandatory=$False)][array]$MatrixNonSparseParameters,
111+
[Parameter(Mandatory=$False)][int]$LockDeletionForDays
111112
) {
112113
if ($environment -eq 'pg') {
113114
if ($clusterGroup -or $subscription) {
@@ -168,7 +169,7 @@ function DeployStressTests(
168169
-subscription $subscription
169170
}
170171

171-
if ($FailedCommands.Count -lt $pkgs.Count) {
172+
if ($FailedCommands.Count -lt $pkgs.Count -and !$Template) {
172173
Write-Host "Releases deployed by $deployer"
173174
Run helm list --all-namespaces -l deployId=$deployer
174175
}
@@ -211,12 +212,14 @@ function DeployStressPackage(
211212
}
212213
$imageTagBase += "/$($pkg.Namespace)/$($pkg.ReleaseName)"
213214

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+
}
220223

221224
$dockerBuildConfigs = @()
222225

@@ -317,8 +320,18 @@ function DeployStressPackage(
317320

318321
$generatedConfigPath = Join-Path $pkg.Directory generatedValues.yaml
319322
$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+
}
322335

323336
$result = (Run @helmCommandArg) 2>&1 | Write-Host
324337

@@ -342,7 +355,7 @@ function DeployStressPackage(
342355
# Helm 3 stores release information in kubernetes secrets. The only way to add extra labels around
343356
# specific releases (thereby enabling filtering on `helm list`) is to label the underlying secret resources.
344357
# There is not currently support for setting these labels via the helm cli.
345-
if(!$Template) {
358+
if (!$Template) {
346359
$helmReleaseConfig = RunOrExitOnFailure kubectl get secrets `
347360
-n $pkg.Namespace `
348361
-l "status=deployed,name=$releaseName" `

0 commit comments

Comments
 (0)