diff --git a/windows/setup_k8s.ps1 b/windows/setup_k8s.ps1 index 1ee846e..f603b9f 100644 --- a/windows/setup_k8s.ps1 +++ b/windows/setup_k8s.ps1 @@ -7,11 +7,22 @@ $kubectlVersion = "v1.32.0" Write-Host "Starting kubernetes setup..." -if (-not (Test-Path -Path "anon.conf" -PathType Leaf)) { - Write-Host "Please download anon.conf from the AMD OSSCI confluence site to get started" +# Exit early if KUBECONFIG is not set to a valid path +$kubeconfigPath = [System.Environment]::GetEnvironmentVariable('KUBECONFIG') +if ( -not $kubeconfigPath) { + Write-Host "KUBECONFIG is not set or empty. Exiting" + Write-Host "Please download the authentication file from the AMD OSSCI confluence site and set KUBECONFIG env variable to the file path" Write-Host "You will need this auth file to access the k8s cluster" exit 1 } +elseif ( -not (Test-Path -Path $kubeconfigPath)) { + Write-Host "File $kubeconfigPath does not exit. Exiting" + Write-Host "Plese make sure the KUBECONFIG env variable is correctly set to the authentication file path" + exit 1 +} +else { + Write-Host "KUBECONFIG is set to: $kubeconfigPath" +} Write-Host "Downloading kubectl..." curl.exe -LO "https://dl.k8s.io/release/$kubectlVersion/bin/windows/amd64/kubectl.exe" @@ -31,11 +42,23 @@ if ($calculatedHash -eq $expectedHash) { } # Requires elevated powershell -Write-Host "Adding current directory to PATH..." -[System.Environment]::SetEnvironmentVariable( - "Path", - [System.Environment]::GetEnvironmentVariable("Path", [System.EnvironmentVariableTarget]::Machine) + ";$PWD", - [System.EnvironmentVariableTarget]::Machine -) +# Check if the current directory is already present in PATH +$path = [System.Environment]::GetEnvironmentVariable("PATH", [System.EnvironmentVariableTarget]::Machine) + +if ($path -split ';' -contains $PWD) { + Write-Host "The current directory $PWD is already in the PATH." +} else { + Write-Host "The current directory $PWD is not in the PATH. Adding..." + + [System.Environment]::SetEnvironmentVariable( + "Path", + $path + ";$PWD", + [System.EnvironmentVariableTarget]::Machine + ) + + # Also modify the current context + $env:Path = $path + ";$PWD" +} Write-Host "Setup completed successfully!" +Write-Host "If you want to run jobs from a different elevated powershell session, make sure to set the KUBECONFIG env variable again."