Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 30 additions & 12 deletions .github/workflows/pr-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -360,28 +360,46 @@ jobs:
& "$installDir\podman.exe" machine set --rootful
& "$installDir\podman.exe" machine start

- name: download kind (Windows)
if: matrix.install-kind == true && runner.os == 'Windows' && (matrix.requires-secret == false || needs.can-read-secret.outputs.secret-set == 'true')
shell: pwsh
run: |
$url = "https://github.com/kubernetes-sigs/kind/releases/download/v0.24.0/kind-windows-amd64"
$path = "$env:RUNNER_TEMP\kind.exe"

$maxAttempts = 3
for ($attempt = 1; $attempt -le $maxAttempts; $attempt++) {
try {
Invoke-WebRequest -Uri $url -OutFile $path
break
}
catch {
if ($attempt -eq $maxAttempts) {
throw
}
Start-Sleep -Seconds (5 * $attempt)
}
}

$expected = "6f724188289cc79395f45afae0f2b85e0d220c2b84c6ed2f5047d9d0c9a67028"
$actual = (Get-FileHash -Path $path -Algorithm SHA256).Hash.ToLower()

if ($actual -ne $expected) {
throw "SHA256 mismatch for kind.exe. Expected: $expected, Got: $actual"
}

"$env:RUNNER_TEMP" | Out-File -Append -FilePath $env:GITHUB_PATH -Encoding utf8

- name: setup kind (Windows)
if: matrix.install-kind == true && runner.os == 'Windows' && (matrix.requires-secret == false || needs.can-read-secret.outputs.secret-set == 'true')
shell: bash
env:
KIND_EXPERIMENTAL_PROVIDER: podman
DOCKER_HOST: npipe:////./pipe/podman-machine-default
run: |
curl -Lo "$RUNNER_TEMP/kind.exe" "https://github.com/kubernetes-sigs/kind/releases/download/v0.24.0/kind-windows-amd64"
expected="6f724188289cc79395f45afae0f2b85e0d220c2b84c6ed2f5047d9d0c9a67028"
actual=$(sha256sum "$RUNNER_TEMP/kind.exe" | awk '{print $1}' | sed 's/^[^a-f0-9]*//')
if [ "$actual" != "$expected" ]; then
echo "SHA256 mismatch for kind.exe! Expected: $expected, Got: $actual"
exit 1
fi
echo "kind.exe checksum verified: $actual"

export PATH="$RUNNER_TEMP:$PATH"
echo "$RUNNER_TEMP" >> "$GITHUB_PATH"

CLUSTER_NAME=$(python -c "import uuid; print(uuid.uuid4().hex)")
kind create cluster --name "$CLUSTER_NAME" --image kindest/node:v1.34.0@sha256:7416a61b42b1662ca6ca89f02028ac133a309a2a30ba309614e8ec94d976dc5a

# NOTE: skevetter/setup-kind does not work on Windows runners
- name: setup kind
if: matrix.install-kind == true && runner.os != 'Windows' && (matrix.requires-secret == false || needs.can-read-secret.outputs.secret-set == 'true')
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pre-commit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
version: latest
install-only: true

- run: go install golang.org/x/tools/cmd/goimports@latest
- run: go install golang.org/x/tools/cmd/goimports@v0.49.0

- uses: actions/cache@v5
with:
Expand Down
25 changes: 23 additions & 2 deletions pkg/ssh/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,26 @@ func buildSSHConfigLines(params addHostParams, proxyCmd string) []string {
build()
}

func sshConfigKeyword(line string) string {
trimmed := strings.TrimSpace(line)
if trimmed == "" || strings.HasPrefix(trimmed, "#") {
return ""
}

if index := strings.IndexAny(trimmed, " \t="); index >= 0 {
return trimmed[:index]
}

return trimmed
}

func isSSHSectionStart(line string) bool {
keyword := sshConfigKeyword(line)

return strings.EqualFold(keyword, "host") ||
strings.EqualFold(keyword, "match")
}

// findInsertPosition finds where to insert new SSH config entry.
func findInsertPosition(config string) (int, []string, error) {
lineNumber := 0
Expand All @@ -229,13 +249,14 @@ func findInsertPosition(config string) (int, []string, error) {
scanner := bufio.NewScanner(strings.NewReader(config))
for scanner.Scan() {
line := scanner.Text()
trimmed := strings.TrimSpace(line)

if strings.HasPrefix(strings.TrimSpace(line), "Host") && !found {
if isSSHSectionStart(line) && !found {
found = true
lineNumber = max(lineNumber-commentLines, 0)
}

if strings.HasPrefix(strings.TrimSpace(line), "#") {
if strings.HasPrefix(trimmed, "#") {
commentLines++
} else {
commentLines = 0
Expand Down
Loading
Loading