Skip to content

Commit

Permalink
Move the kind and integration tests to actions (#225)
Browse files Browse the repository at this point in the history
  • Loading branch information
mattmoor authored Oct 23, 2020
1 parent 9b91035 commit d9cc0ca
Show file tree
Hide file tree
Showing 5 changed files with 228 additions and 23 deletions.
177 changes: 177 additions & 0 deletions .github/workflows/kind-e2e.yaml
Original file line number Diff line number Diff line change
@@ -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 <<EOF
apiVersion: kind.x-k8s.io/v1alpha4
kind: Cluster
# Configure registry for KinD.
containerdConfigPatches:
- |-
[plugins."io.containerd.grpc.v1.cri".registry.mirrors."$REGISTRY_NAME:$REGISTRY_PORT"]
endpoint = ["http://$REGISTRY_NAME:$REGISTRY_PORT"]
# This is needed in order to support projected volumes with service account tokens.
# See: https://kubernetes.slack.com/archives/CEKK1KTN2/p1600268272383600
kubeadmConfigPatches:
- |
apiVersion: kubeadm.k8s.io/v1beta2
kind: ClusterConfiguration
metadata:
name: config
apiServer:
extraArgs:
"service-account-issuer": "kubernetes.default.svc"
"service-account-signing-key-file": "/etc/kubernetes/pki/sa.key"
nodes:
- role: control-plane
image: kindest/node:${{ matrix.k8s-version }}@${{ matrix.kind-image-sha }}
- role: worker
image: kindest/node:${{ matrix.k8s-version }}@${{ matrix.kind-image-sha }}
EOF
- name: Create KinD Cluster
run: kind create cluster --config kind.yaml

- name: Setup local registry
run: |
# Run a registry.
docker run -d --restart=always \
-p $REGISTRY_PORT:$REGISTRY_PORT --name $REGISTRY_NAME registry:2
# Connect the registry to the KinD network.
docker network connect "kind" $REGISTRY_NAME
# Make the $REGISTRY_NAME -> 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
50 changes: 50 additions & 0 deletions .github/workflows/modules-integration-test.yaml
Original file line number Diff line number Diff line change
@@ -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
16 changes: 0 additions & 16 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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)
2 changes: 1 addition & 1 deletion cmd/ko/test/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 0 additions & 6 deletions integration_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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)"
Expand Down

0 comments on commit d9cc0ca

Please sign in to comment.