Skip to content

Commit

Permalink
Run tests inside the cluster
Browse files Browse the repository at this point in the history
  • Loading branch information
Arnaud Tincelin authored and Arnaud Tincelin committed Sep 9, 2021
1 parent 165e024 commit fe255dd
Show file tree
Hide file tree
Showing 5 changed files with 115 additions and 12 deletions.
54 changes: 54 additions & 0 deletions .github/kustomize/job.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
apiVersion: batch/v1
kind: Job
metadata:
name: aks-periscope
labels:
app: aks-periscope
spec:
backoffLimit: 4
template:
metadata:
labels:
app: aks-periscope
spec:
restartPolicy: Never
containers:
- name: go-test-runner
image: go-test-runner
envFrom:
- configMapRef:
name: containerlogs-config
- configMapRef:
name: kubeobjects-config
- configMapRef:
name: nodelogs-config
volumeMounts:
- name: varlog
mountPath: /var/log
- name: resolvlog
mountPath: /run/systemd/resolve
- name: etcvmlog
mountPath: /etchostlogs
- name: runner
mountPath: /runner
resources:
requests:
memory: "500Mi"
cpu: "250m"
limits:
memory: "2000Mi"
cpu: "1000m"
volumes:
- name: varlog
hostPath:
path: /var/log
- name: resolvlog
hostPath:
path: /run/systemd/resolve
- name: etcvmlog
hostPath:
path: /etc
- name: runner
hostPath:
path: /runner
type: Directory
20 changes: 20 additions & 0 deletions .github/kustomize/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization

namespace: aks-periscope

resources:
- job.yaml
- ../../deployment/namespace.yaml
- ../../deployment/cluster-role.yaml
- ../../deployment/cluster-role-binding.yaml
- ../../deployment/config-map.yaml
- ../../deployment/crd.yaml
- ../../deployment/service-account.yaml

patches:
- path: patch-command.yaml
target:
kind: Job
name: aks-periscope
version: batch/v1
35 changes: 25 additions & 10 deletions .github/workflows/ci-pipeline.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,13 @@ jobs:
nodes:
- role: control-plane
- role: worker
extraMounts:
- hostPath: ${PWD}
containerPath: /runner
- role: worker
extraMounts:
- hostPath: ${PWD}
containerPath: /runner
containerdConfigPatches:
- |-
[plugins."io.containerd.grpc.v1.cri".registry.mirrors."localhost:5000"]
Expand Down Expand Up @@ -98,23 +104,32 @@ jobs:
with:
context: .
push: true
tags: localhost:5000/periscope:foo
file: ./builder/Dockerfile
tags: localhost:5000/go-test-runner:latest
file: ./builder/Dockerfile.tests
- name: Deploy dummy helm chart for tests
run: |
helm repo add bitnami https://charts.bitnami.com/bitnami
helm repo update
helm install happy-panda bitnami/wordpress --namespace default
- name: Deploy AKS Periscope
run: |
(cd ./deployment && kustomize edit set image aksrepos.azurecr.io/staging/aks-periscope=localhost:5000/periscope:foo)
kubectl apply -f <(kustomize build ./deployment)
kubectl -n aks-periscope describe ds aks-periscope
kubectl -n aks-periscope wait po --all --for condition=ready --timeout=60s
- name: Go tests
run: go test -v -race -coverprofile=coverage.out -covermode=atomic ./...
- name: Upload coverage to Codecov
run: bash <(curl -s https://codecov.io/bash) -C $(Build.SourceVersion)
cd ./.github/kustomize
cat <<EOF >>patch-command.yaml
- op: add
path: '/spec/template/spec/containers/0/command'
value: [ "go", "test", "-v", "-coverprofile=/runner/coverage.out", "-covermode=atomic", "./..." ]
EOF
cat patch-command.yaml
kustomize edit set image go-test-runner=localhost:5000/go-test-runner:latest
kubectl apply -f <(kustomize build --load-restrictor LoadRestrictionsNone)
kubectl -n aks-periscope wait job aks-periscope --for condition=complete --timeout=120s
- name: Upload coverage to codecov
run: bash <(curl -s https://codecov.io/bash)
- name: Stop kind
run: kind delete cluster
continue-on-error: false
14 changes: 14 additions & 0 deletions builder/Dockerfile.tests
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
FROM golang:alpine AS builder

ENV GO111MODULE=on \
CGO_ENABLED=0 \
GOOS=linux \
GOARCH=amd64

WORKDIR /build

COPY go.mod .
COPY go.sum .
RUN go mod download

COPY . .
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ require (
github.com/Azure/azure-storage-blob-go v0.7.0
github.com/Azure/go-autorest/autorest/adal v0.9.14 // indirect
github.com/kr/pretty v0.2.1 // indirect
github.com/onsi/gomega v1.13.0
github.com/onsi/gomega v1.13.0 // indirect
helm.sh/helm/v3 v3.6.3
k8s.io/api v0.21.3 // indirect
k8s.io/api v0.21.3
k8s.io/apimachinery v0.21.3
k8s.io/cli-runtime v0.21.3
k8s.io/client-go v0.21.3
Expand Down

0 comments on commit fe255dd

Please sign in to comment.