Preserve kubectl context namespace if set for active stress cluster (#3187)

Co-authored-by: Ben Broderick Phillips <bebroder@microsoft.com>
This commit is contained in:
Azure SDK Bot 2021-12-17 11:41:13 -08:00 committed by GitHub
parent 5f97ac1b3d
commit f937eae89c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -40,12 +40,19 @@ function Login([string]$subscription, [string]$clusterGroup, [switch]$pushImages
$cluster = RunOrExitOnFailure az aks list -g $clusterGroup --subscription $subscription -o json
$clusterName = ($cluster | ConvertFrom-Json).name
$kubeContext = (RunOrExitOnFailure kubectl config view -o json) | ConvertFrom-Json
$defaultNamespace = $kubeContext.contexts.Where({ $_.name -eq $clusterName }).context.namespace
RunOrExitOnFailure az aks get-credentials `
-n "$clusterName" `
-g "$clusterGroup" `
--subscription "$subscription" `
--overwrite-existing
if ($defaultNamespace) {
RunOrExitOnFailure kubectl config set-context $clusterName --namespace $defaultNamespace
}
if ($pushImages) {
$registry = RunOrExitOnFailure az acr list -g $clusterGroup --subscription $subscription -o json
$registryName = ($registry | ConvertFrom-Json).name