From 66b3db2c6b0039d27205d841d24b285c6ca04151 Mon Sep 17 00:00:00 2001 From: Christian Lechner Date: Mon, 31 Jul 2023 09:46:42 +0200 Subject: [PATCH] feat: add Powershell script for egress determination --- get-egress-ips/README.md | 12 +++++++--- get-egress-ips/get-egress-ips.ps1 | 38 +++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 3 deletions(-) create mode 100644 get-egress-ips/get-egress-ips.ps1 diff --git a/get-egress-ips/README.md b/get-egress-ips/README.md index 8332a759..fffe4a02 100644 --- a/get-egress-ips/README.md +++ b/get-egress-ips/README.md @@ -15,6 +15,12 @@ The script intelligently runs the curl pod in each of the different availability - On MacOS or Linux, run the following command -```shell -./get-egress-ips.sh -``` + ```shell + ./get-egress-ips.sh + ``` + +- On Windows (or MacOS or Linux if you have PowerShell installed), run the following command: + + ```pwsh + ./get-egress-ips.ps1 + ``` diff --git a/get-egress-ips/get-egress-ips.ps1 b/get-egress-ips/get-egress-ips.ps1 new file mode 100644 index 00000000..3605774c --- /dev/null +++ b/get-egress-ips/get-egress-ips.ps1 @@ -0,0 +1,38 @@ +#!/usr/bin/pwsh +$ErrorActionPreference = 'silentlycontinue' + +$ZONES = $(kubectl get nodes -o jsonpath='{.items[*].metadata.labels.topology\.kubernetes\.io/zone}').Split(" ") +$ZONES = $ZONES | Select-Object -Unique + +Write-Output "Detected zones:" +Write-Output "---------------" +foreach ($zone in $ZONES) { + Write-Output $zone +} + +foreach ($zone in $ZONES) { + $overrides = @{ + "apiVersion" = "v1" + "metadata" = @{ + "labels" = @{ + "sidecar.istio.io/inject" = "false" + } + "spec" = @{ + "nodeSelector" = @{ + "topology.kubernetes.io/zone" = $zone + } + } + } + } | ConvertTo-Json -EscapeHandling EscapeHtml -Depth 5 + + kubectl run -i --tty busybox --image=curlimages/curl --restart=Never --overrides=$overrides --rm --command -- curl 'http://ifconfig.me/ip' | Out-File -FilePath $env:TEMP/cluster_ips -Append +} + +(Get-Content $env:TEMP/cluster_ips) -replace 'pod "busybox" deleted', '' | Set-Content $env:TEMP/cluster_ips + +Write-Host +Write-Output "Detected IPs:" +Write-Output "-------------" +Get-Content $env:TEMP/cluster_ips + +Remove-Item $env:TEMP/cluster_ips \ No newline at end of file