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
24 changes: 6 additions & 18 deletions .github/workflows/pr-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1073,35 +1073,23 @@ jobs:

- name: cache kind.exe (Windows)
if: matrix.install-kind == true && runner.os == 'Windows' && (matrix.requires-secret == false || needs.can-read-secret.outputs.secret-set == 'true')
id: kind-cache-windows
uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
with:
path: ${{ runner.temp }}/kind.exe
key: ${{ runner.os }}-${{ runner.arch }}-kind-v0.33.0

- 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
shell: pwsh
env:
KIND_EXPERIMENTAL_PROVIDER: podman
DOCKER_HOST: npipe:////./pipe/podman-machine-default
run: |
if [ "${{ steps.kind-cache-windows.outputs.cache-hit }}" != "true" ]; then
curl -Lo "$RUNNER_TEMP/kind.exe" "https://github.com/kubernetes-sigs/kind/releases/download/v0.33.0/kind-windows-amd64"
expected="4b22adaa135368c5a465d56bbd8e520cbea87272a06ca00b6078e7b81515c9fc"
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"
fi

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.36.4@sha256:099e049362a1526b2db71494e1947aae99bd16290d7c895f2b7ea312e3cbfaed
& "$env:RUNNER_TEMP\devsy-ci-podman\devsy-ci-podman.exe" install-kind `
--url "https://github.com/kubernetes-sigs/kind/releases/download/v0.33.0/kind-windows-amd64" `
--sha256 "4b22adaa135368c5a465d56bbd8e520cbea87272a06ca00b6078e7b81515c9fc" `
--kind-path "$env:RUNNER_TEMP\kind.exe" `
--image "kindest/node:v1.36.4@sha256:099e049362a1526b2db71494e1947aae99bd16290d7c895f2b7ea312e3cbfaed"

# NOTE: skevetter/setup-kind does not work on Windows runners
- name: setup kind
Expand Down
11 changes: 8 additions & 3 deletions hack/podman_ci/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func installPodmanMSI(
if err != nil {
return fmt.Errorf("read podman MSI: %w", err)
}
if err := verifyMSIChecksum(msi, cfg.SHA256); err != nil {
if err := verifyChecksum("podman MSI", msi, cfg.SHA256); err != nil {
return err
}
deps.Log.Printf("Podman MSI checksum verified: %s", installSum(msi))
Expand Down Expand Up @@ -114,10 +114,15 @@ func installSum(data []byte) string {
return hex.EncodeToString(sum[:])
}

func verifyMSIChecksum(data []byte, expected string) error {
func verifyChecksum(artifact string, data []byte, expected string) error {
actual := installSum(data)
if !strings.EqualFold(actual, expected) {
return fmt.Errorf("SHA256 mismatch for podman MSI! Expected: %s, Got: %s", expected, actual)
return fmt.Errorf(
"SHA256 mismatch for %s! Expected: %s, Got: %s",
artifact,
expected,
actual,
)
}
return nil
}
Expand Down
103 changes: 103 additions & 0 deletions hack/podman_ci/kind.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
package main

import (
"context"
"crypto/rand"
"encoding/hex"
"fmt"
"os"
"os/exec"
"path/filepath"

"github.com/spf13/cobra"
)

const (
commandInstallKind = "install-kind"
kindClusterNameSize = 16
)

type ClusterNamer func() (string, error)

type ClusterCreator func(ctx context.Context, kindPath, name, image string) error

type KindConfig struct {
URL string
SHA256 string
KindPath string
Image string
GitHubPath string
}

func newInstallKindCommand() *cobra.Command {
var cfg KindConfig
cmd := &cobra.Command{
Use: commandInstallKind,
Short: "Install a verified kind binary and create a cluster with a random name",
RunE: func(*cobra.Command, []string) error {
deps := Dependencies{
Log: newLogger(),
Files: osFileSystem{},
Download: downloadFile,
NewClusterName: newClusterName,
CreateCluster: createKindCluster,
}
return classifyOperationalError(installKind(context.Background(), deps, cfg))
},
}
cmd.Flags().StringVar(&cfg.URL, "url", "", "kind download URL")
cmd.Flags().StringVar(&cfg.SHA256, "sha256", "", "expected SHA256 of the kind binary")
cmd.Flags().StringVar(&cfg.KindPath, "kind-path", "", "local path for the kind binary")
cmd.Flags().StringVar(&cfg.Image, "image", "", "kind node image")
cmd.Flags().
StringVar(&cfg.GitHubPath, "github-path", os.Getenv("GITHUB_PATH"), "file to append the kind directory to")
for _, name := range []string{"url", "sha256", "kind-path", "image"} {
_ = cmd.MarkFlagRequired(name)
}
return cmd
}

func installKind(ctx context.Context, deps Dependencies, cfg KindConfig) error {
if _, statErr := deps.Files.Stat(cfg.KindPath); statErr != nil {
if err := deps.Download(ctx, cfg.URL, cfg.KindPath); err != nil {
return fmt.Errorf("download kind: %w", err)
}
}
data, err := deps.Files.ReadFile(cfg.KindPath)
if err != nil {
return fmt.Errorf("read kind: %w", err)
}
if err := verifyChecksum("kind.exe", data, cfg.SHA256); err != nil {
return err
}
deps.Log.Printf("kind.exe checksum verified: %s", installSum(data))

if err := appendGitHubPath(deps.Files, cfg.GitHubPath, filepath.Dir(cfg.KindPath)); err != nil {
return err
}

name, err := deps.NewClusterName()
if err != nil {
return fmt.Errorf("generate kind cluster name: %w", err)
}
deps.Log.Printf("creating kind cluster %s", name)
if err := deps.CreateCluster(ctx, cfg.KindPath, name, cfg.Image); err != nil {
return fmt.Errorf("kind create cluster: %w", err)
}
return nil
}

func newClusterName() (string, error) {
b := make([]byte, kindClusterNameSize)
if _, err := rand.Read(b); err != nil {
return "", err
}
return hex.EncodeToString(b), nil
}

func createKindCluster(ctx context.Context, kindPath, name, image string) error {
cmd := exec.CommandContext(ctx, kindPath, "create", "cluster", "--name", name, "--image", image)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
return cmd.Run()
}
Loading
Loading