Skip to content
Draft
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
20 changes: 20 additions & 0 deletions .github/workflows/integration-linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,26 @@ jobs:
distribution: 'temurin'
java-version: ${{ matrix.java }}

- name: Clean up disk space
run: |
echo "--- Disk space before cleanup ---"
df -h
sudo rm -rf /usr/share/dotnet
sudo rm -rf /usr/local/lib/android
sudo rm -rf /opt/ghc
sudo rm -rf /usr/share/swift
sudo rm -rf /usr/local/.ghcup
sudo rm -rf /usr/share/code
sudo rm -rf /usr/share/miniconda
sudo rm -rf /usr/share/az_deps
# Remove unused Docker images, containers, networks, and build cache
# The '|| true' prevents the workflow from failing if no items are found to prune.
docker system prune -a --force || true
docker builder prune -a --force || true

echo "--- Disk space after cleanup ---"
df -h

# Retrieve build locations with `go env`
# <https://markphelps.me/posts/speed-up-your-go-builds-with-actions-cache/>
- id: go-cache-paths
Expand Down
67 changes: 46 additions & 21 deletions integration/run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -345,12 +345,13 @@ func TestRunRenderOnly(t *testing.T) {

func TestRunGCPOnly(t *testing.T) {
tests := []struct {
description string
dir string
args []string
deployments []string
pods []string
skipCrossPlatform bool
description string
dir string
args []string
deployments []string
pods []string
skipCrossPlatform bool
requiresKanikoSecret bool
}{
{
description: "Google Cloud Build",
Expand Down Expand Up @@ -378,27 +379,32 @@ func TestRunGCPOnly(t *testing.T) {
dir: "examples/gcb-kaniko",
pods: []string{"getting-started-kaniko"},
// building machines on gcb are linux/amd64, kaniko doesn't support cross-platform builds.
skipCrossPlatform: true,
skipCrossPlatform: true,
requiresKanikoSecret: true,
},
{
description: "kaniko",
dir: "examples/kaniko",
pods: []string{"getting-started-kaniko"},
description: "kaniko",
dir: "examples/kaniko",
pods: []string{"getting-started-kaniko"},
requiresKanikoSecret: true,
},
{
description: "kaniko with target",
dir: "testdata/kaniko-target",
pods: []string{"getting-started-kaniko"},
description: "kaniko with target",
dir: "testdata/kaniko-target",
pods: []string{"getting-started-kaniko"},
requiresKanikoSecret: true,
},
{
description: "kaniko with sub folder",
dir: "testdata/kaniko-sub-folder",
pods: []string{"getting-started-kaniko"},
description: "kaniko with sub folder",
dir: "testdata/kaniko-sub-folder",
pods: []string{"getting-started-kaniko"},
requiresKanikoSecret: true,
},
{
description: "kaniko microservices",
dir: "testdata/kaniko-microservices",
deployments: []string{"leeroy-app", "leeroy-web"},
description: "kaniko microservices",
dir: "testdata/kaniko-microservices",
deployments: []string{"leeroy-app", "leeroy-web"},
requiresKanikoSecret: true,
},
{
description: "jib in googlecloudbuild",
Expand All @@ -421,22 +427,41 @@ func TestRunGCPOnly(t *testing.T) {
skipCrossPlatform: true,
},
}

keyPath := os.Getenv("GOOGLE_APPLICATION_CREDENTIALS")
for _, test := range tests {
if (os.Getenv("GKE_CLUSTER_NAME") == "integration-tests-arm" || os.Getenv("GKE_CLUSTER_NAME") == "integration-tests-hybrid") && test.skipCrossPlatform {
continue
}
t.Run(test.description, func(t *testing.T) {
MarkIntegrationTest(t, NeedsGcp)
ns, client := SetupNamespace(t)
if test.requiresKanikoSecret {
// Copy the secret from 'default' to the new random namespace
// This prevents Skaffold from trying to auto-create it
client.CreateSecretFrom("default", "e2esecret")
}

env := []string{}
// If we're running a Kaniko test and have a GCP key available,
// pass it to Skaffold so it can create the required secret in the dynamic namespace.
if test.requiresKanikoSecret && keyPath != "" {
// This environment variable tells Skaffold to fill in the
// build.cluster.pullSecretPath field dynamically.
env = append(env, fmt.Sprintf("SKAFFOLD_PULL_SECRET_PATH=%s", keyPath))
// Ensure the child process can also find the key on disk
env = append(env, fmt.Sprintf("GOOGLE_APPLICATION_CREDENTIALS=%s", keyPath))
}

test.args = append(test.args, "--tag", uuid.New().String())

skaffold.Run(test.args...).InDir(test.dir).InNs(ns.Name).RunOrFail(t)
// Use .WithEnv(env) to pass the credentials path
skaffold.Run(test.args...).InDir(test.dir).InNs(ns.Name).WithEnv(env).RunOrFail(t)

client.WaitForPodsReady(test.pods...)
client.WaitForDeploymentsToStabilize(test.deployments...)

skaffold.Delete().InDir(test.dir).InNs(ns.Name).RunOrFail(t)
skaffold.Delete().InDir(test.dir).InNs(ns.Name).WithEnv(env).RunOrFail(t)
})
}
}
Expand Down
11 changes: 10 additions & 1 deletion pkg/skaffold/build/cluster/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,19 @@ func NewBuilder(bCtx BuilderContext, buildCfg *latest.ClusterDetails) (*Builder,
return nil, fmt.Errorf("parsing timeout: %w", err)
}

// 1. Create the CLI first.
kubectlcli := kubectl.NewCLI(bCtx, buildCfg.Namespace)

// 2. Synchronize the buildCfg.Namespace with the CLI's resolved namespace.
// This ensures that b.Namespace (used in secret.go) matches the CLI flag.
if buildCfg.Namespace == "" || bCtx.GetKubeNamespace() != "" {
buildCfg.Namespace = kubectlcli.Namespace
}

return &Builder{
ClusterDetails: buildCfg,
cfg: bCtx,
kubectlcli: kubectl.NewCLI(bCtx, ""),
kubectlcli: kubectlcli,
mode: bCtx.Mode(),
timeout: timeout,
artifactStore: bCtx.ArtifactStore(),
Expand Down
Loading