Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run k8s sanity also on macos and windows #39

Draft
wants to merge 21 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
114 changes: 102 additions & 12 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@ env:
TEST_VERBOSITY: 2

jobs:
license-check:
name: License check
license-checks:
name: License checks
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: License check
run: make license_check
- name: Run checks
run: make license-checks

unit-tests:
name: Unit tests (${{ matrix.python-version }}/${{ matrix.os }})
Expand Down Expand Up @@ -116,7 +116,7 @@ jobs:
TEST_STACK_VERSION: ${{ matrix.stack-version }}
run: |
mkdir ~/elastic-stack-cache
docker compose pull -q
make stack-pull
docker save -o ~/elastic-stack-cache/elasticsearch-${{ matrix.stack-version }}.tar \
docker.elastic.co/elasticsearch/elasticsearch:${{ matrix.stack-version }}
docker save -o ~/elastic-stack-cache/kibana-${{ matrix.stack-version }}.tar \
Expand All @@ -125,26 +125,116 @@ jobs:
- name: Start Elastic Stack ${{ matrix.stack-version }}
env:
TEST_STACK_VERSION: ${{ matrix.stack-version }}
run: make up
run: make stack-up

- name: Run online tests
env:
TEST_SCHEMA_URI: ${{ matrix.schema-uri }}
TEST_DETECTION_RULES_URI: ${{ matrix.detection-rules-uri }}
TEST_SIGNALS_QUERIES: ${{ matrix.signals_queries }}
TEST_SIGNALS_RULES: ${{ matrix.signals_rules }}
run: make online_tests
run: make online-tests

- name: Stop Elastic Stack ${{ matrix.stack-version }}
run: make down
run: make stack-down

docker-sanity:
name: Docker image sanity
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Setup Python
uses: actions/setup-python@v2
with:
python-version: "3.8"

- name: Install dependencies
run: make prereq

- name: Build image
run: make docker-build

- name: Run sanity checks
run: make docker-sanity

package-sanity:
name: Python package sanity
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Setup Python
uses: actions/setup-python@v2
with:
python-version: "3.8"

- name: Install dependencies
run: make prereq

- name: Build package
run: make pkg-build

- name: Install package
run: make pkg-install

- name: Try package
run: make pkg-try

kubernetes-sanity:
name: Kubernetes sanity
runs-on: ${{ matrix.os }}
needs:
- docker-sanity

strategy:
fail-fast: false
matrix:
os: ["ubuntu-latest", "macos-latest", "windows-latest"]

steps:
- name: Checkout code
uses: actions/checkout@v1

- name: Setup Go
uses: actions/setup-go@v3
with:
go-version: ">=1.16"

- name: Install Kind
run: |
go install sigs.k8s.io/kind@latest
kind version

- name: Build image
run: make docker-build

- name: Create cluster
run: |
make kind-up
kubectl get nodes -o wide
kubectl get pods -o wide
kubectl get services -o wide

- name: Run sanity checks
run: make sanity-checks

- name: Destroy Kind cluster
run: make kind-down

publish:
name: Publish
runs-on: ubuntu-latest
needs:
- license-check
- license-checks
- unit-tests
- online-tests
- kubernetes-sanity
- package-sanity
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags')

steps:
Expand All @@ -160,13 +250,13 @@ jobs:
run: make prereq

- name: Build package
run: make pkg_build
run: make pkg-build

- name: Install package
run: make pkg_install
run: make pkg-install

- name: Try package
run: make pkg_try
run: make pkg-try

- name: Publish to TestPyPI
uses: pypa/[email protected]
Expand Down
32 changes: 32 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# syntax=docker/dockerfile:1

# Licensed to Elasticsearch B.V. under one or more contributor
# license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright
# ownership. Elasticsearch B.V. licenses this file to you 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.

FROM python:alpine
WORKDIR /app

COPY requirements.txt requirements.txt
RUN pip3 install --user -r requirements.txt

COPY etc etc
COPY geneve geneve

EXPOSE 5000

ENV FLASK_APP=geneve/webapi.py
CMD [ "python3", "-m" , "flask", "run", "--host=0.0.0.0", "-p 5000" ]
64 changes: 53 additions & 11 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,34 +16,76 @@ lint:
tests: tests/*.py
$(PYTHON) -m pytest -raP tests/test_*.py

online_tests: tests/*.py
online-tests: tests/*.py
$(PYTHON) -m pytest -raP tests/test_emitter_*.py

up:
docker compose up --wait --quiet-pull
sanity-checks:
for n in `seq 30`; do \
curl -s --fail http://localhost:30000/api/v1/version && exit 0 || sleep 1; \
done; exit 1

down:
docker compose down
stack-pull:
cd tests && docker compose pull -q

license_check:
stack-up:
cd tests && docker compose up --wait --quiet-pull

stack-down:
cd tests && docker compose down

docker-build:
-docker image rm geneve
docker build -q -t geneve .

docker-run:
docker run -p 127.0.0.1:30000:5000 --rm --name geneve geneve

docker-sanity: GENEVE_VERSION=$(shell $(PYTHON) -c "import geneve; print(geneve.version)")
docker-sanity:
docker run -p 127.0.0.1:30000:5000 --rm --name geneve-test -d geneve
[ "`$(MAKE) -s sanity-checks`" = '{"version":"$(GENEVE_VERSION)"}' ] || \
(docker container stop geneve-test; exit 1)
docker container stop geneve-test

docker-push: GENEVE_VERSION=$(shell $(PYTHON) -c "import geneve; print(geneve.version)")
docker-push:
docker tag geneve:latest $(DOCKER_REGISTRY)/geneve:latest
docker tag geneve:latest $(DOCKER_REGISTRY)/geneve:$(GENEVE_VERSION)
docker push -q $(DOCKER_REGISTRY)/geneve:latest
docker push -q $(DOCKER_REGISTRY)/geneve:$(GENEVE_VERSION)
docker image rm $(DOCKER_REGISTRY)/geneve:latest $(DOCKER_REGISTRY)/geneve:$(GENEVE_VERSION)

kind-up:
kind create cluster --config=etc/kind-config.yml
kind load docker-image geneve
kubectl apply -f etc/pods/geneve.yml
kubectl apply -f etc/services/geneve.yml

kind-down:
kind delete cluster

license-checks:
bash scripts/license_check.sh

run:
$(PYTHON) -m geneve --version
$(PYTHON) -m geneve --help
$(PYTHON) -m geneve

pkg_build:
flask:
FLASK_APP=geneve/webapi.py $(PYTHON) -m flask run

pkg-build:
$(PYTHON) -m build

pkg_install:
pkg-install:
$(PYTHON) -m pip install --force-reinstall dist/geneve-*.whl

pkg_try:
pkg-try:
geneve --version
geneve --help
geneve

package: pkg_build pkg_install pkg_try
package: pkg-build pkg-install pkg-try

.PHONY: lint tests online_tests run up down
.PHONY: lint tests online-tests run flask stack-up stack-down license-checks package docker docker-sanity
9 changes: 9 additions & 0 deletions etc/kind-config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
apiVersion: kind.x-k8s.io/v1alpha4
kind: Cluster
nodes:
- role: control-plane
extraPortMappings:
- containerPort: 30000
hostPort: 30000
- role: worker
- role: worker
11 changes: 11 additions & 0 deletions etc/pods/geneve.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
apiVersion: v1
kind: Pod
metadata:
name: geneve
labels:
app: geneve
spec:
containers:
- name: geneve
image: geneve
imagePullPolicy: Never
11 changes: 11 additions & 0 deletions etc/services/geneve.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
apiVersion: v1
kind: Service
metadata:
name: geneve
spec:
type: NodePort
selector:
app: geneve
ports:
- port: 5000
nodePort: 30000
Loading