Skip to content

Commit 1843ed5

Browse files
committed
Run integration tests with kind
Signed-off-by: David Gageot <[email protected]>
1 parent f2b11d5 commit 1843ed5

File tree

6 files changed

+56
-5
lines changed

6 files changed

+56
-5
lines changed

.travis.yml

+7
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,10 @@ jobs:
3434
script:
3535
- go build -o out/skaffold.exe cmd/skaffold/skaffold.go
3636
- go test -short -timeout 60s ./...
37+
- stage: integration
38+
os: linux
39+
go: "1.11.x"
40+
before_install:
41+
- curl -Lo ${HOME}/bin/kind https://github.com/kubernetes-sigs/kind/releases/download/v0.3.0/kind-linux-amd64
42+
- chmod +x ${HOME}/bin/kind
43+
script: make integration-in-kind

Makefile

+22-3
Original file line numberDiff line numberDiff line change
@@ -148,19 +148,38 @@ release-build-in-docker:
148148
clean:
149149
rm -rf $(BUILD_DIR)
150150

151-
.PHONY: integration-in-docker
152-
integration-in-docker:
151+
.PHONY: kind-cluster
152+
kind-cluster:
153+
kind get clusters | grep -q kind || kind create cluster
154+
155+
.PHONY: skaffold-builder
156+
skaffold-builder:
153157
-docker pull gcr.io/$(GCP_PROJECT)/skaffold-builder
154158
docker build \
155159
--cache-from gcr.io/$(GCP_PROJECT)/skaffold-builder \
156160
-f deploy/skaffold/Dockerfile \
157161
--target integration \
158162
-t gcr.io/$(GCP_PROJECT)/skaffold-integration .
163+
164+
.PHONY: integration-in-kind
165+
integration-in-kind: kind-cluster skaffold-builder
166+
docker exec -it kind-control-plane cat /etc/kubernetes/admin.conf > /tmp/kind-config
167+
echo '{}' > /tmp/docker-config
168+
docker run --rm \
169+
-v /var/run/docker.sock:/var/run/docker.sock \
170+
-v /tmp/kind-config:/kind-config \
171+
-v /tmp/docker-config:/root/.docker/config.json \
172+
-e REMOTE_INTEGRATION=$(REMOTE_INTEGRATION) \
173+
-e KUBECONFIG=/kind-config \
174+
gcr.io/$(GCP_PROJECT)/skaffold-integration
175+
176+
.PHONY: integration-in-docker
177+
integration-in-docker: skaffold-builder
159178
docker run --rm \
160179
-v /var/run/docker.sock:/var/run/docker.sock \
161180
-v $(HOME)/.config/gcloud:/root/.config/gcloud \
162181
-v $(GOOGLE_APPLICATION_CREDENTIALS):$(GOOGLE_APPLICATION_CREDENTIALS) \
163-
-e REMOTE_INTEGRATION=true \
182+
-e REMOTE_INTEGRATION=$(REMOTE_INTEGRATION) \
164183
-e GCP_PROJECT=$(GCP_PROJECT) \
165184
-e GKE_CLUSTER_NAME=$(GKE_CLUSTER_NAME) \
166185
-e GKE_ZONE=$(GKE_ZONE) \

cmd/skaffold/app/cmd/config/util.go

+7-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package config
1919
import (
2020
"io/ioutil"
2121
"path/filepath"
22+
"strings"
2223

2324
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/constants"
2425
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/kubernetes/context"
@@ -226,5 +227,10 @@ func GetInsecureRegistries() ([]string, error) {
226227
func isDefaultLocal(kubeContext string) bool {
227228
return kubeContext == constants.DefaultMinikubeContext ||
228229
kubeContext == constants.DefaultDockerForDesktopContext ||
229-
kubeContext == constants.DefaultDockerDesktopContext
230+
kubeContext == constants.DefaultDockerDesktopContext ||
231+
IsKindCluster(kubeContext)
232+
}
233+
234+
func IsKindCluster(kubeContext string) bool {
235+
return strings.HasSuffix(kubeContext, "@kind")
230236
}

deploy/skaffold/Dockerfile

+5
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,11 @@ COPY . .
9696
FROM builder as integration
9797
ARG VERSION
9898

99+
ENV KIND_VERSION=v0.3.0
100+
RUN curl -Lo kind https://github.com/kubernetes-sigs/kind/releases/download/${KIND_VERSION}/kind-linux-amd64 && \
101+
chmod +x kind && \
102+
mv kind /usr/local/bin/
103+
99104
RUN make out/skaffold-linux-amd64 VERSION=$VERSION && mv out/skaffold-linux-amd64 /usr/bin/skaffold
100105

101106
CMD ["make", "integration"]

hack/kokoro/presubmit.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,6 @@ export DOCKER_NAMESPACE=gcr.io/k8s-skaffold
1818
source $KOKORO_GFILE_DIR/common.sh
1919

2020
pushd $KOKORO_ARTIFACTS_DIR/github/skaffold >/dev/null
21-
make integration-in-docker
21+
REMOTE_INTEGRATION=true make integration-in-docker
2222
popd
2323

pkg/skaffold/runner/build.go

+14
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,12 @@ package runner
1919
import (
2020
"context"
2121
"io"
22+
"os/exec"
2223

24+
"github.com/GoogleContainerTools/skaffold/cmd/skaffold/app/cmd/config"
2325
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/build"
2426
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest"
27+
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/util"
2528
"github.com/pkg/errors"
2629
"github.com/sirupsen/logrus"
2730
)
@@ -53,5 +56,16 @@ func (r *SkaffoldRunner) BuildAndTest(ctx context.Context, out io.Writer, artifa
5356
return nil, errors.Wrap(err, "test failed")
5457
}
5558
}
59+
60+
// With `kind`, docker images have to be loaded with the `kind` CLI.
61+
if config.IsKindCluster(r.runCtx.KubeContext) {
62+
for _, image := range bRes {
63+
cmd := exec.CommandContext(ctx, "kind", "load", "docker-image", image.Tag)
64+
if err := util.RunCmd(cmd); err != nil {
65+
return nil, errors.Wrapf(err, "unable to load image with kind: %s", image.Tag)
66+
}
67+
}
68+
}
69+
5670
return bRes, err
5771
}

0 commit comments

Comments
 (0)