Skip to content

Commit

Permalink
ci(nightly): add prometheus kind test
Browse files Browse the repository at this point in the history
Signed-off-by: Alexei Dodon <[email protected]>
  • Loading branch information
adodon2go committed Oct 17, 2023
1 parent 7f6534a commit 372f80b
Show file tree
Hide file tree
Showing 5 changed files with 127 additions and 129 deletions.
134 changes: 5 additions & 129 deletions .github/workflows/nightly.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: 'Nightly jobs'
on:
schedule:
- cron: '30 1 * * *'
pull_request:
branches: [main]
workflow_dispatch:

permissions: read-all
Expand All @@ -13,7 +13,7 @@ permissions: read-all
# task scheduler will start a restore all blobs process at zot startup, after it finishes all blobs should be restored to their original state (have content)
jobs:
dedupe:
name: Dedupe/restore blobs
name: Kind Prometheus test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
Expand All @@ -24,8 +24,6 @@ jobs:
- name: Install dependencies
run: |
cd $GITHUB_WORKSPACE
go install github.com/swaggo/swag/cmd/[email protected]
go mod download
sudo apt-get update
sudo apt-get install libgpgme-dev libassuan-dev libbtrfs-dev libdevmapper-dev pkg-config rpm uidmap
# install skopeo
Expand All @@ -40,127 +38,5 @@ jobs:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ github.token }}
- name: Install localstack
run: |
pip install --upgrade pyopenssl
pip install localstack==2.3.1 awscli-local[ver1] # install LocalStack cli and awslocal
docker pull ghcr.io/project-zot/ci-images/localstack:2.3.1 # Make sure to pull the latest version of the image
localstack start -d # Start LocalStack in the background
echo "Waiting for LocalStack startup..." # Wait 30 seconds for the LocalStack container
localstack wait -t 30 # to become ready before timing out
echo "Startup complete"
- name: Run blackbox nightly dedupe tests
run: |
# test restoring s3 blobs after cache is deleted
# test deduping filesystem blobs after switching dedupe to enable
make run-blackbox-dedupe-nightly
env:
AWS_ACCESS_KEY_ID: fake
AWS_SECRET_ACCESS_KEY: fake
- uses: ./.github/actions/teardown-localstack

sync:
name: Sync harness
runs-on: ubuntu-latest
steps:
- name: Check out source code
uses: actions/checkout@v4
- uses: ./.github/actions/clean-runner
- uses: actions/setup-go@v3
with:
go-version: 1.20.x
- name: Install dependencies
run: |
cd $GITHUB_WORKSPACE
go install github.com/swaggo/swag/cmd/[email protected]
go mod download
- name: Run sync harness
run: |
make run-blackbox-sync-nightly
gc-referrers-stress-s3:
name: GC(with referrers) on S3(localstack) with short interval
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/clean-runner
- uses: actions/setup-go@v4
with:
cache: false
go-version: 1.20.x
- uses: ./.github/actions/setup-localstack

- name: Run zb
id: bench
run: |
make binary
make bench
./bin/zot-linux-amd64 serve test/gc-stress/config-gc-referrers-bench-s3-localstack.json &
sleep 10
bin/zb-linux-amd64 -c 10 -n 100 -o ci-cd http://localhost:8080 --skip-cleanup
killall -r zot-*
# clean zot storage
sudo rm -rf /tmp/zot
env:
AWS_ACCESS_KEY_ID: fake
AWS_SECRET_ACCESS_KEY: fake
continue-on-error: true

- name: Check on failures
if: steps.bench.outcome != 'success'
run: |
cat /tmp/gc-referrers-bench-s3.log
exit 1
- uses: ./.github/actions/teardown-localstack

gc-stress-s3:
name: GC(without referrers) on S3(localstack) with short interval
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/clean-runner
- uses: actions/setup-go@v4
with:
cache: false
go-version: 1.20.x
- uses: ./.github/actions/setup-localstack

- name: Run zb
id: bench
run: |
make binary
make bench
./bin/zot-linux-amd64 serve test/gc-stress/config-gc-bench-s3-localstack.json &
sleep 10
bin/zb-linux-amd64 -c 10 -n 100 -o ci-cd http://localhost:8080 --skip-cleanup
killall -r zot-*
# clean zot storage
sudo rm -rf /tmp/zot
env:
AWS_ACCESS_KEY_ID: fake
AWS_SECRET_ACCESS_KEY: fake
continue-on-error: true

- name: Check on failures
if: steps.bench.outcome != 'success'
run: |
cat /tmp/gc-bench-s3.log
exit 1
- uses: ./.github/actions/teardown-localstack

docker-image:
name: Build docker image (for users still using Docker environments)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/clean-runner
- name: Check out source code
uses: actions/checkout@v4
- name: Build image
run: |
make docker-image
- name: Run tests
run: ./examples/kind/kind-ci.sh
8 changes: 8 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@ jobs:
key: ${{ runner.os }}-go-mod-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-mod-
- name: Install RAMDISK
run: |
lscpu
free --giga -h -t
sudo mkdir -p /tmp/ramdisk
sudo chmod 777 /tmp/ramdisk
sudo mount -t tmpfs -o size=6G tmpfs /tmp/ramdisk
- name: Install go dependencies
if: steps.cache-go-dependencies.outputs.cache-hit != 'true'
run: |
Expand All @@ -44,6 +51,7 @@ jobs:
cd $GITHUB_WORKSPACE
make test-minimal
env:
TMPDIR: /tmp/ramdisk
S3MOCK_ENDPOINT: localhost:4566
DYNAMODBMOCK_ENDPOINT: http://localhost:4566
AWS_ACCESS_KEY_ID: fake
Expand Down
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ test-extended: test-prereq

.PHONY: test-minimal
test-minimal: test-prereq
echo "TMPDIR=$(TMPDIR)"
go test -failfast -tags containers_image_openpgp -trimpath -race -cover -coverpkg ./... -coverprofile=coverage-minimal.txt -covermode=atomic ./...
rm -rf /tmp/getter*; rm -rf /tmp/trivy*

Expand Down
105 changes: 105 additions & 0 deletions examples/kind/kind-ci.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
#!/bin/sh
set -o errexit

# Reference: https://kind.sigs.k8s.io/docs/user/local-registry/

# set no_proxy if applicable
if [ ! -z "${no_proxy}" ]; then
echo "Updating no_proxy env var";
export no_proxy=${no_proxy},kind-registry;
export NO_PROXY=${no_proxy};
fi

# create registry container unless it already exists
reg_name='kind-registry'
reg_port='5001'
if [ "$(docker inspect -f '{{.State.Running}}' "${reg_name}" 2>/dev/null || true)" != 'true' ]; then
docker run \
-d --restart=always -p "127.0.0.1:${reg_port}:5000" --name "${reg_name}" \
ghcr.io/project-zot/zot-minimal-linux-amd64:latest
fi

CLUSTER_NAME=kind
## Delete the cluster if it already exist
kind get clusters | grep ${CLUSTER_NAME} && kind delete cluster --name ${CLUSTER_NAME}

# create a cluster with the local registry enabled in containerd
cat <<EOF | kind create cluster --config=-
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
containerdConfigPatches:
- |-
[plugins."io.containerd.grpc.v1.cri".registry.mirrors."localhost:${reg_port}"]
endpoint = ["http://${reg_name}:5000"]
EOF

# connect the registry to the cluster network if not already connected
if [ "$(docker inspect -f='{{json .NetworkSettings.Networks.kind}}' "${reg_name}")" = 'null' ]; then
docker network connect "kind" "${reg_name}"
fi

# https://github.com/kubernetes/enhancements/tree/master/keps/sig-cluster-lifecycle/generic/1755-communicating-a-local-registry
#
# document the local registry
cat <<EOF | kubectl apply -f -
apiVersion: v1
kind: ConfigMap
metadata:
name: local-registry-hosting
namespace: kube-public
data:
localRegistryHosting.v1: |
host: "localhost:${reg_port}"
help: "https://kind.sigs.k8s.io/docs/user/local-registry/"
EOF

## Deploy prometheus operator
kubectl create -f examples/metrics/kubernetes/prometheus/bundle.yaml

## Deploy the Kubernetes objects for RBAC, prometheus CRD and deploy the service
kubectl apply -f examples/metrics/kubernetes/prometheus/prom_rbac.yaml
kubectl apply -f examples/metrics/kubernetes/prometheus/prometheus.yaml
kubectl apply -f examples/metrics/kubernetes/prometheus/prom_service.yaml

make oci-image
# copy the image
skopeo copy --format=oci --dest-tls-verify=false oci:oci docker://localhost:5001/zot-build:latest

# deploy the image
kubectl apply -f examples/metrics/kubernetes/zot-extended/deployment.yaml
kubectl patch deployment/zot-extended --patch-file examples/metrics/kubernetes/zot-extended/patch-deployment.yaml
kubectl apply -f examples/metrics/kubernetes/zot-extended/service.yaml
kubectl apply -f examples/metrics/kubernetes/zot-extended/servicemonitor.yaml

# check for availability
echo "Waiting for deployment/zot-extended to be ready ..."
kubectl wait deployment -n default zot-extended --for condition=Available=True --timeout=90s
kubectl wait deployment -n default prometheus-operator --for condition=Available=True --timeout=90s

kubectl port-forward svc/prometheus 9090 --address='0.0.0.0' &
echo "Kind cluster status before sleep:"
kubectl get pods -A
sleep 20
echo "Kind cluster status:"
kubectl get pods -A
echo "zot-extended logs:"
kubectl logs -l app=zot-extended --tail=-1


containername=`curl -s http://localhost:9090/api/v1/query?query=up | jq '.data.result[].metric.container'`
echo "containername=${containername}"
if [ "${containername}" != '"zot-extended"' ]; then
exit 1
fi

containerup=`curl -s http://localhost:9090/api/v1/query?query=up | jq '.data.result[].value[1]'`
echo "containerup=${containerup}"
if [ "${containerup}" != '"1"' ]; then
exit 1
fi

zotinfo=`curl -s http://localhost:9090/api/v1/query?query=zot_info | jq '.data.result[].value[1]'`
echo "zotinfo=${zotinfo}"
if [ "${zotinfo}" != '"0"' ]; then
exit 1
fi
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
spec:
template:
spec:
containers:
- name: zot-extended
image: localhost:5001/zot-build:latest
command: ["/usr/local/bin/zot-linux-amd64"]

0 comments on commit 372f80b

Please sign in to comment.