Skip to content

Commit

Permalink
test: integration test for defaultNamespace config
Browse files Browse the repository at this point in the history
  • Loading branch information
renzodavid9 committed Dec 13, 2022
1 parent ce99fd0 commit 81dd6e4
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 0 deletions.
29 changes: 29 additions & 0 deletions integration/run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -582,3 +582,32 @@ func TestRunNoOptFlags(t *testing.T) {
WaitForLogs(t, out, test.targetLog)
})
}

func TestRunKubectlDefaultNamespace(t *testing.T) {
tests := []struct {
description string
namespaceToCreate string
projectDir string
podName string
envVariable string
}{
{
description: "run with defaultNamespace when namespace exists in cluster",
namespaceToCreate: "namespace-test",
projectDir: "testdata/kubectl-with-default-namespace",
podName: "getting-started",
envVariable: "ENV1",
},
}

for _, test := range tests {
testutil.Run(t, test.description, func(t *testutil.T) {
MarkIntegrationTest(t.T, CanRunWithoutGcp)
ns, client := SetupNamespace(t.T)
t.SetEnvs(map[string]string{test.envVariable: ns.Name})
skaffold.Run().InDir(test.projectDir).RunOrFail(t.T)
pod := client.GetPod(test.podName)
t.CheckNotNil(pod)
})
}
}
14 changes: 14 additions & 0 deletions integration/testdata/kubectl-with-default-namespace/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
FROM golang:1.18 as builder
WORKDIR /code
COPY main.go .
COPY go.mod .
# `skaffold debug` sets SKAFFOLD_GO_GCFLAGS to disable compiler optimizations
ARG SKAFFOLD_GO_GCFLAGS
RUN go build -gcflags="${SKAFFOLD_GO_GCFLAGS}" -trimpath -o /app main.go

FROM alpine:3
# Define GOTRACEBACK to mark this container as using the Go language runtime
# for `skaffold debug` (https://skaffold.dev/docs/workflows/debug/).
ENV GOTRACEBACK=single
CMD ["./app"]
COPY --from=builder /app .
3 changes: 3 additions & 0 deletions integration/testdata/kubectl-with-default-namespace/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module github.com/GoogleContainerTools/skaffold/examples/cross-platform-builds

go 1.18
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
apiVersion: v1
kind: Pod
metadata:
name: getting-started
spec:
containers:
- name: getting-started
image: skaffold-example
15 changes: 15 additions & 0 deletions integration/testdata/kubectl-with-default-namespace/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package main

import (
"fmt"
"runtime"
"time"
)

func main() {
for {
fmt.Printf("Hello world! Running on %s/%s\n", runtime.GOOS, runtime.GOARCH)

time.Sleep(time.Second * 1)
}
}
17 changes: 17 additions & 0 deletions integration/testdata/kubectl-with-default-namespace/skaffold.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
apiVersion: skaffold/v4beta1
kind: Config

build:
artifacts:
- image: skaffold-example
context: .
docker:
dockerfile: Dockerfile

manifests:
rawYaml:
- k8s-*

deploy:
kubectl:
defaultNamespace: "{{.ENV1}}"

0 comments on commit 81dd6e4

Please sign in to comment.