From d79b7d1a9ab436fa02cd6eb89f7ba5ad237c02e0 Mon Sep 17 00:00:00 2001 From: Matt Moore Date: Fri, 23 Oct 2020 08:32:21 -0700 Subject: [PATCH] Move the kind and integration tests to actions --- .github/workflows/kind-e2e.yaml | 177 ++++++++++++++++++ .../workflows/modules-integration-test.yaml | 50 +++++ .travis.yml | 16 -- cmd/ko/test/main.go | 2 +- integration_test.sh | 6 - 5 files changed, 228 insertions(+), 23 deletions(-) create mode 100644 .github/workflows/kind-e2e.yaml create mode 100644 .github/workflows/modules-integration-test.yaml diff --git a/.github/workflows/kind-e2e.yaml b/.github/workflows/kind-e2e.yaml new file mode 100644 index 0000000000..27407c5d90 --- /dev/null +++ b/.github/workflows/kind-e2e.yaml @@ -0,0 +1,177 @@ +name: KinD e2e tests + +on: + pull_request: + branches: [ 'master' ] + +defaults: + run: + shell: bash + working-directory: ./src/github.com/google/ko + +jobs: + + e2e-tests: + name: e2e tests + runs-on: ubuntu-latest + strategy: + fail-fast: false # Keep running if one leg fails. + matrix: + k8s-version: + - v1.17.11 + - v1.18.8 + - v1.19.1 + + include: + # Map between K8s and KinD versions. + # This is attempting to make it a bit clearer what's being tested. + # See: https://github.com/kubernetes-sigs/kind/releases/tag/v0.9.0 + - k8s-version: v1.17.11 + kind-version: v0.9.0 + kind-image-sha: sha256:5240a7a2c34bf241afb54ac05669f8a46661912eab05705d660971eeb12f6555 + - k8s-version: v1.18.8 + kind-version: v0.9.0 + kind-image-sha: sha256:f4bcc97a0ad6e7abaf3f643d890add7efe6ee4ab90baeb374b4f41a4c95567eb + - k8s-version: v1.19.1 + kind-version: v0.9.0 + kind-image-sha: sha256:98cf5288864662e37115e362b23e4369c8c4a408f99cbc06e58ac30ddc721600 + + env: + GOPATH: ${{ github.workspace }} + GO111MODULE: off + # https://github.com/google/go-containerregistry/pull/125 allows insecure registry for + # '*.local' hostnames. This works both for `ko` and our own tag-to-digest resolution logic, + # thus allowing us to test without bypassing tag-to-digest resolution. + REGISTRY_NAME: registry.local + REGISTRY_PORT: 5000 + KO_DOCKER_REPO: registry.local:5000/knative + + steps: + - name: Set up Go 1.15.x + uses: actions/setup-go@v2 + with: + go-version: 1.15.x + + - name: Check out code onto GOPATH + uses: actions/checkout@v2 + with: + path: ./src/github.com/google/ko + + - name: Install ko + run: go install ./cmd/ko + + - name: Install KinD + run: | + set -x + + # Disable swap otherwise memory enforcement doesn't work + # See: https://kubernetes.slack.com/archives/CEKK1KTN2/p1600009955324200 + sudo swapoff -a + sudo rm -f /swapfile + + curl -Lo ./kind https://github.com/kubernetes-sigs/kind/releases/download/${{ matrix.kind-version }}/kind-$(uname)-amd64 + chmod +x ./kind + sudo mv kind /usr/local/bin + + - name: Configure KinD Cluster + run: | + set -x + + # KinD configuration. + cat > kind.yaml < 127.0.0.1, to tell `ko` to publish to + # local reigstry, even when pushing $REGISTRY_NAME:$REGISTRY_PORT/some/image + sudo echo "127.0.0.1 $REGISTRY_NAME" | sudo tee -a /etc/hosts + + - name: Wait for ready nodes + run: | + kubectl wait --for=condition=Ready nodes --all + + - name: Run Smoke Test + run: | + # Test with kind load + KO_DOCKER_REPO=kind.local ko apply --platform=all -f ./cmd/ko/test + kubectl wait --timeout=10s --for=condition=Ready pod/kodata + kubectl delete pod kodata + + # Test with registry + ko apply --platform=all -f ./cmd/ko/test + kubectl wait --timeout=60s --for=condition=Ready pod/kodata + kubectl delete pod kodata + + - name: Collect pod diagnostics + if: ${{ failure() }} + env: + SYSTEM_NAMESPACE: default + run: | + kubectl -n${SYSTEM_NAMESPACE} get pods + + echo '::group:: describe' + kubectl -n${SYSTEM_NAMESPACE} describe pods + echo '::endgroup::' + + for x in $(kubectl get pods -n${SYSTEM_NAMESPACE} -oname); do + echo "::group:: describe $x" + kubectl -n${SYSTEM_NAMESPACE} describe $x + echo '::endgroup::' + + echo "::group:: $x logs" + kubectl -n${SYSTEM_NAMESPACE} logs $x --all-containers + echo '::endgroup::' + done + + - name: Collect node diagnostics + if: ${{ failure() }} + run: | + kubectl get nodes + + echo '::group:: describe' + kubectl describe nodes + echo '::endgroup::' + + for x in $(kubectl get nodes -oname); do + echo "::group:: describe $x" + kubectl describe $x + echo '::endgroup::' + done diff --git a/.github/workflows/modules-integration-test.yaml b/.github/workflows/modules-integration-test.yaml new file mode 100644 index 0000000000..737431e21b --- /dev/null +++ b/.github/workflows/modules-integration-test.yaml @@ -0,0 +1,50 @@ +# Copyright 2020 The Knative Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# This file is automagically synced here from github.com/knative-sandbox/.github +# repo by knobots: https://github.com/mattmoor/knobots and will be overwritten. + +name: Integration Test + +on: + + pull_request: + branches: [ 'master' ] + +jobs: + + test: + name: Module Tests + strategy: + matrix: + go-version: [1.14.x, 1.15.x] + platform: [ubuntu-latest] + + runs-on: ${{ matrix.platform }} + + steps: + + - name: Set up Go ${{ matrix.go-version }} + uses: actions/setup-go@v2 + with: + go-version: ${{ matrix.go-version }} + id: go + + - name: Check out code + uses: actions/checkout@v2 + + - name: Test + env: + GOPATH: does not matter + run: ./integration_test.sh diff --git a/.travis.yml b/.travis.yml index 4e2dfd7779..12186d9a5e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -17,21 +17,5 @@ git: install: true # skipping the default go dependencies install step -before_script: - # Download and install kubectl - - curl -LO https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl && chmod +x kubectl && sudo mv kubectl /usr/local/bin/ - # Download and install KinD - - curl -Lo ./kind https://github.com/kubernetes-sigs/kind/releases/download/v0.8.1/kind-$(uname)-amd64 && chmod +x ./kind && sudo mv kind /usr/local/bin/ - # Create a new Kubernetes cluster using KinD - - kind create cluster - script: - # Verify that all source files are correctly formatted. - - find . -name "*.go" | grep -v vendor/ | xargs gofmt -d -e -l - - - go clean -i - - go test -v -race -coverprofile=coverage.txt -covermode=atomic ./... - bash integration_test.sh -# TODO: Set up coverage. -#after_success: -# - bash <(curl -s https://codecov.io/bash) diff --git a/cmd/ko/test/main.go b/cmd/ko/test/main.go index 70b2a34389..4832b53e10 100644 --- a/cmd/ko/test/main.go +++ b/cmd/ko/test/main.go @@ -32,7 +32,7 @@ func main() { } log.Print(string(bytes)) - file = filepath.Join(dp, "refs/heads/master") + file = filepath.Join(dp, "HEAD") bytes, err = ioutil.ReadFile(file) if err != nil { log.Fatalf("Error reading %q: %v", file, err) diff --git a/integration_test.sh b/integration_test.sh index a3e1312b51..e0e15aa9de 100755 --- a/integration_test.sh +++ b/integration_test.sh @@ -9,12 +9,6 @@ pushd "$ROOT_DIR" ROOT_DIR="$(pwd)" -echo "Running smoke test." -go install ./cmd/ko -# Travis runs this against a kind cluster so properly use the kind publisher. -KO_DOCKER_REPO=kind.local ko apply --platform=all -f ./cmd/ko/test -kubectl wait --timeout=10s --for=condition=Ready pod/kodata - echo "Moving GOPATH into /tmp/ to test modules behavior." export ORIGINAL_GOPATH="$GOPATH" export GOPATH="$(mktemp -d)"