Skip to content

Commit

Permalink
Merge pull request #18 from PrimalPimmy/test
Browse files Browse the repository at this point in the history
(Enhancement) Ginkgo test framework for k8tls
  • Loading branch information
nyrahul committed Aug 29, 2023
2 parents 16c912b + 6254327 commit 2abaed3
Show file tree
Hide file tree
Showing 13 changed files with 788 additions and 2 deletions.
6 changes: 4 additions & 2 deletions .github/workflows/ci-docker-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ on:
branches: [ "main" ]
paths:
- "src/**"
- "k8s/**"
- ".github/workflows/ci-docker-release.yml"
release:
types: [published]
jobs:
Expand Down Expand Up @@ -34,14 +36,14 @@ jobs:
with:
context: .
push: true
tags: kubearmor/kubetls:latest
tags: kubearmor/k8tls:latest

- name: Build and push version
if: startsWith(github.ref, 'refs/tags/v')
uses: docker/build-push-action@v4
with:
context: .
push: true
tags: kubearmor/kubetls:${{ github.ref_name}}
tags: kubearmor/k8tls:${{ github.ref_name}}


61 changes: 61 additions & 0 deletions .github/workflows/ci-test-ginkgo.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
name: ci-test-ginkgo

on:
push:
branches: [main]
paths:
- "src/**"
- "tests/**"
- ".github/workflows/ci-test-ginkgo.yml"

pull_request:
branches: [main]
paths:
- "src/**"
- "tests/**"
- ".github/workflows/ci-test-ginkgo.yml"

jobs:
build:
name: Auto-testing Framework
runs-on: ubuntu-latest
env:
RUNTIME: containerd
steps:
- uses: actions/checkout@v3

- uses: actions/setup-go@v4
with:
go-version: "v1.20"

- name: Create k3s cluster
run: ./.github/workflows/scripts/install_k3s.sh

- name: Test connectivity
run: kubectl get pods -A

- name: Deploy wordpress-mysql
run: |
kubectl apply -f ./tests/res/wordpress-mysql-dep.yaml
kubectl wait --for=condition=ready --timeout=15m -n wordpress-mysql pod -l app=wordpress
- name: Building k8tls
run: make build

- name: Deploy k8tls
run: |
docker save kubearmor/k8tls:latest | sudo k3s ctr images import -
kubectl apply -f ./tests/res/test-k8tls.yaml
sleep 10
- name: Check k8tls is completed
run: kubectl get pods -A

- name: Test k8tls using Ginkgo
run: |
# mkdir /tmp/k8tls
go install -mod=mod github.com/onsi/ginkgo/v2/ginkgo
make
working-directory: ./tests
timeout-minutes: 30

9 changes: 9 additions & 0 deletions .github/workflows/scripts/install_k3s.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
curl -sfL https://get.k3s.io | K3S_KUBECONFIG_MODE="644" INSTALL_K3S_EXEC="--disable=traefik" sh -
[[ $? != 0 ]] && echo "Failed to install k3s" && exit 1
mkdir -p ~/.kube && cp /etc/rancher/k3s/k3s.yaml ~/.kube/config

until kubectl wait --for=condition=ready --timeout=15m -n kube-system pod -l k8s-app=metrics-server
do
[[ $? != 0 ]] && echo "Checking for metrics-server"
sleep 5
done
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# gingko test tmp file
**/*.test
11 changes: 11 additions & 0 deletions tests/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# SPDX-License-Identifier: Apache-2.0
# Copyright 2022 Authors of KubeArmor

.PHONY: build
build:
@go mod tidy
@ginkgo --vv --flake-attempts=10 --timeout=10m

.PHONY: test
test:
@ginkgo -r
89 changes: 89 additions & 0 deletions tests/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
module ginkgo

go 1.20

require (
github.com/onsi/ginkgo/v2 v2.11.0
github.com/onsi/gomega v1.27.10
)

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/emicklei/go-restful/v3 v3.10.2 // indirect
github.com/evanphx/json-patch v5.6.0+incompatible // indirect
github.com/go-errors/errors v1.4.2 // indirect
github.com/go-logr/logr v1.2.4 // indirect
github.com/go-openapi/jsonpointer v0.19.6 // indirect
github.com/go-openapi/jsonreference v0.20.2 // indirect
github.com/go-openapi/swag v0.22.3 // indirect
github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/google/btree v1.1.2 // indirect
github.com/google/gnostic v0.6.9 // indirect
github.com/google/go-cmp v0.5.9 // indirect
github.com/google/gofuzz v1.2.0 // indirect
github.com/google/pprof v0.0.0-20230728192033-2ba5b33183c6 // indirect
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/gregjones/httpcache v0.0.0-20190611155906-901d90724c79 // indirect
github.com/imdario/mergo v0.3.15 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/kr/pretty v0.3.1 // indirect
github.com/kubearmor/KubeArmor/pkg/KubeArmorController v0.0.0-20230519075515-e8b45043a53d // indirect
github.com/kubearmor/KubeArmor/protobuf v0.0.0-20230519075515-e8b45043a53d // indirect
github.com/kubearmor/KubeArmor/tests v0.0.0-20230808073138-46a1e116bcd7 // indirect
github.com/kubearmor/kubearmor-client v0.13.1 // indirect
github.com/liggitt/tabwriter v0.0.0-20181228230101-89fcab3d43de // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.18 // indirect
github.com/moby/spdystream v0.2.0 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/monochromegane/go-gitignore v0.0.0-20200626010858-205db1a8cc00 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/peterbourgon/diskv v2.0.1+incompatible // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/rogpeppe/go-internal v1.10.0 // indirect
github.com/rs/zerolog v1.29.1 // indirect
github.com/sirupsen/logrus v1.9.2 // indirect
github.com/spf13/cobra v1.7.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/stretchr/testify v1.8.4 // indirect
github.com/xlab/treeprint v1.2.0 // indirect
go.starlark.net v0.0.0-20230302034142-4b1e35fe2254 // indirect
golang.org/x/exp v0.0.0-20230519143937-03e91628a987 // indirect
golang.org/x/net v0.14.0 // indirect
golang.org/x/oauth2 v0.8.0 // indirect
golang.org/x/sys v0.11.0 // indirect
golang.org/x/term v0.11.0 // indirect
golang.org/x/text v0.12.0 // indirect
golang.org/x/time v0.3.0 // indirect
golang.org/x/tools v0.12.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/genproto v0.0.0-20230410155749-daa745c078e1 // indirect
google.golang.org/grpc v1.55.0 // indirect
google.golang.org/protobuf v1.31.0 // indirect
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
k8s.io/api v0.27.2 // indirect
k8s.io/apiextensions-apiserver v0.27.2 // indirect
k8s.io/apimachinery v0.27.2 // indirect
k8s.io/cli-runtime v0.27.2 // indirect
k8s.io/client-go v0.27.2 // indirect
k8s.io/klog/v2 v2.100.1 // indirect
k8s.io/kube-openapi v0.0.0-20230515203736-54b630e78af5 // indirect
k8s.io/kubectl v0.27.2 // indirect
k8s.io/utils v0.0.0-20230505201702-9f6742963106 // indirect
sigs.k8s.io/controller-runtime v0.14.6 // indirect
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
sigs.k8s.io/kustomize/api v0.13.2 // indirect
sigs.k8s.io/kustomize/kyaml v0.14.1 // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.2.3 // indirect
sigs.k8s.io/yaml v1.3.0 // indirect
)
Loading

0 comments on commit 2abaed3

Please sign in to comment.