diff --git a/.github/workflows/golangci-lint.yml b/.github/workflows/golangci-lint.yml index a5d572d..6a2e1ad 100644 --- a/.github/workflows/golangci-lint.yml +++ b/.github/workflows/golangci-lint.yml @@ -23,3 +23,7 @@ jobs: uses: golangci/golangci-lint-action@v3 with: version: v1.53.3 + - name: Delete git global config + if: always() + run: | + rm ~/.gitconfig diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 4c3d18f..570288f 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -10,11 +10,24 @@ on: jobs: checks: name: run - runs-on: self-hosted + runs-on: [ self-hosted, dpdk ] steps: - uses: actions/checkout@v3 with: ref: ${{ github.event.pull_request.head.sha }} + fetch-depth: 0 + - name: Download metalbond using the script + run: ./hack/rel_download.sh -dir=build -owner=onmetal -repo=metalbond -pat=${{ secrets.BOT_PAT }} + + - name: Install metalbond + run: sudo dpkg -i build/metalbond*.deb + + - name: Start metalbond + run: metalbond server --listen [::1]:4711 --http [::1]:4712 --keepalive 3 & + + - name: Run dp-service + run: docker run --rm --entrypoint ./dp_service.py --privileged -p1337:1337 --mount type=bind,source=/dev/hugepages,target=/dev/hugepages ghcr.io/onmetal/dp-service-tester --no-init & + - uses: actions/setup-go@v4 with: go-version-file: go.mod @@ -28,3 +41,12 @@ jobs: ssh-private-key: ${{ secrets.BOT_PRIVATE_KEY }} - run: ./hack/setup-git-redirect.sh - run: make test + - name: Delete git global config + if: always() + run: | + rm ~/.gitconfig + - name: Cleanup services + if: always() + run: | + killall metalbond + for i in $(docker ps -q); do docker stop $i; done diff --git a/Makefile b/Makefile index b9ec1ba..744079e 100644 --- a/Makefile +++ b/Makefile @@ -64,6 +64,10 @@ addlicense: ## Add license headers to all go files. fmt: ## Run go fmt against code. go fmt ./... +.PHONY: vet +vet: ## Run go vet against code. + go vet ./... + .PHONY: checklicense checklicense: ## Check that every file has a license header present. find . -name '*.go' -exec go run github.com/google/addlicense -check -c 'OnMetal authors' {} + @@ -73,20 +77,17 @@ lint: ## Run golangci-lint against code. golangci-lint run ./... .PHONY: check -check: manifests generate addlicense lint test +check: manifests generate fmt addlicense lint test ## Generate manifests, code, lint, add licenses, test ENVTEST_ASSETS_DIR=$(shell pwd)/testbin .PHONY: test -test: envtest manifests generate fmt checklicense ## Run tests. +test: envtest manifests generate fmt vet ## Run tests. KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) -p path)" go test -v ./... -coverprofile cover.out -ginkgo.v -ginkgo.label-filter=$(labels) -ginkgo.randomize-all -.PHONY: check -check: generate fmt addlicense lint test ## Lint and run tests. - ##@ Build .PHONY: build -build: manifests generate fmt addlicense lint ## Build the binary +build: manifests generate fmt lint ## Build the binary go build -ldflags "-X main.buildVersion=${shell git describe --tags}'" -o bin/metalnet ./main.go .PHONY: run diff --git a/controllers/suite_test.go b/controllers/suite_test.go index 6189563..c8d176c 100644 --- a/controllers/suite_test.go +++ b/controllers/suite_test.go @@ -57,7 +57,7 @@ var ( ctxGrpc context.Context dpserviceAddr string = "127.0.0.1:1337" testNode string = "testNode" - metalnetDir string = "/var/lib/metalnet" + metalnetDir string = "/tmp/var/lib/metalnet" netFnsManager *netfns.Manager conn *grpc.ClientConn dpdkProtoClient dpdkproto.DPDKonmetalClient diff --git a/hack/rel_download.sh b/hack/rel_download.sh new file mode 100755 index 0000000..3346fe9 --- /dev/null +++ b/hack/rel_download.sh @@ -0,0 +1,84 @@ +#!/bin/bash +# This script uses a Personal Access Token (PAT) to access a GitHub repository. +# It takes the following parameters in the style "-parameter=PARAMETER_VALUE": +# 1. -dir : Destination directory. A directory path (relative to the current directory) where the files will be downloaded. +# 2. -owner : Repository owner. The username of the owner of the repository on GitHub. +# 3. -repo : Repository name. The name of the repository on GitHub. +# 4. -pat : Personal Access Token (PAT). A token provided by GitHub to access the repository. +# 5. -release : (Optional) Release tag. By default, it is set to "latest". +# Example usage: +# ./hack/rel_download.sh -dir=exporter -owner=onmetal -repo=prometheus-dpdk-exporter -pat=MY_PAT + +set -e + +if [ "$#" -lt 4 ]; then + echo "Usage: $0 -dir= -owner= -repo= -pat= [-release=]" + exit 1 +fi + +# Process parameters +for i in "$@" +do +case $i in + -dir=*) + DIRECTORY="${i#*=}" + shift + ;; + -owner=*) + REPO_OWNER="${i#*=}" + shift + ;; + -repo=*) + REPO_NAME="${i#*=}" + shift + ;; + -pat=*) + PAT="${i#*=}" + shift + ;; + -release=*) + RELEASE="${i#*=}" + shift + ;; + *) + # unknown option + ;; +esac +done + +RELEASE=${RELEASE:-latest} + +if [ ! -d "$DIRECTORY" ]; then + mkdir -p "$DIRECTORY" +fi + +if [ -z "$PAT" ]; then + touch $DIRECTORY/dummy_$DIRECTORY + echo "No PAT defined. Will not download the packages" + exit 0 +fi + +# Use curl to access the GitHub API and get the asset ID. +ASSET_ID=$(curl -s -L -H "Accept: application/vnd.github+json" -H "Authorization: Bearer $PAT" -H "X-GitHub-Api-Version: 2022-11-28" https://api.github.com/repos/$REPO_OWNER/$REPO_NAME/releases/$RELEASE | jq -r '.assets[] | select (.name | contains("_amd64")) | .id') + +if [ -z "$ASSET_ID" ]; then + echo "Failed to copy the release binary to $DIRECTORY" + exit 1 +fi + +# Use curl to download the asset using the asset ID. +curl -s -L -H "Accept: application/octet-stream" -H "Authorization: Bearer $PAT" -H "X-GitHub-Api-Version: 2022-11-28" https://api.github.com/repos/$REPO_OWNER/$REPO_NAME/releases/assets/$ASSET_ID -o $DIRECTORY/$REPO_NAME.deb + +#tar -xzf $DIRECTORY/$DIRECTORY.tar.gz -C $DIRECTORY +#rm $DIRECTORY/$DIRECTORY.tar.gz +#rm -rf $DIRECTORY/LICENSE* +#rm -rf $DIRECTORY/README.md + +#if [ "$?" -eq 0 ]; then +# echo "Release binary successfully copied to $DIRECTORY" +#else +# echo "Failed to copy the release binary to $DIRECTORY" +# exit 1 +#fi + +exit 0