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

build: a number of fixes on Makefile and nix-shell #360

Merged
merged 6 commits into from
Jan 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
12 changes: 11 additions & 1 deletion .github/workflows/build_and_push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ jobs:
go-version: 1.19.9
cache: false

- name: Set go env
run: |
echo "GOPATH=$(go env GOPATH)" >> $GITHUB_ENV
echo "GOCACHE=$(go env GOCACHE)" >> $GITHUB_ENV

- name: Unit test
run: make test

Expand Down Expand Up @@ -77,6 +82,11 @@ jobs:
go-version: 1.19.9
cache: false

- name: Set go env
run: |
echo "GOPATH=$(go env GOPATH)" >> $GITHUB_ENV
echo "GOCACHE=$(go env GOCACHE)" >> $GITHUB_ENV

- name: Setup Minikube-Kubernetes
uses: medyagh/setup-minikube@latest
with:
Expand All @@ -99,7 +109,7 @@ jobs:
run: ./ci/ci-test.sh

- name: Upload Coverage Report
uses: codecov/codecov-action@v4
uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }}
file: ./tests/bdd_coverage.txt
Expand Down
19 changes: 17 additions & 2 deletions .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ jobs:
go-version: 1.19.9
cache: false

- name: Set go env
run: |
echo "GOPATH=$(go env GOPATH)" >> $GITHUB_ENV
echo "GOCACHE=$(go env GOCACHE)" >> $GITHUB_ENV
- name: Lint Check
uses: golangci/golangci-lint-action@v4
with:
Expand Down Expand Up @@ -71,6 +76,11 @@ jobs:
go-version: 1.19.9
cache: false

- name: Set go env
run: |
echo "GOPATH=$(go env GOPATH)" >> $GITHUB_ENV
echo "GOCACHE=$(go env GOCACHE)" >> $GITHUB_ENV
- name: Unit test
run: make test

Expand Down Expand Up @@ -99,8 +109,13 @@ jobs:
go-version: 1.19.9
cache: false

- name: Set go env
run: |
echo "GOPATH=$(go env GOPATH)" >> $GITHUB_ENV
echo "GOCACHE=$(go env GOCACHE)" >> $GITHUB_ENV
- name: Build images locally
run: make lvm-driver-image || exit 1;
run: make lvm-driver-image

- name: Setup Minikube-Kubernetes
uses: medyagh/setup-minikube@latest
Expand All @@ -125,7 +140,7 @@ jobs:
run: ./ci/ci-test.sh

- name: Upload Coverage Report
uses: codecov/codecov-action@v4
uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }}
file: ./tests/bdd_coverage.txt
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ tags
*.idea
*.test
coverage.txt
/tests/bdd_coverage.txt
25 changes: 12 additions & 13 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ VETARGS?=-asmdecl -atomic -bool -buildtags -copylocks -methods \
EXTERNAL_TOOLS=\
golang.org/x/tools/cmd/cover \
golang.org/x/lint/golint \
github.com/axw/gocov/gocov \
github.com/axw/gocov/gocov@v1.1 \
github.com/matm/gocov-html/cmd/gocov-html \
github.com/onsi/ginkgo/ginkgo \
github.com/onsi/gomega/...
github.com/onsi/gomega/...@v1.35

# The images can be pushed to any docker/image registeries
# like docker hub, quay. The registries are specified in
Expand Down Expand Up @@ -86,6 +86,9 @@ clean:
@echo "--> Cleaning Directory" ;
go clean -testcache
rm -rf bin
CLEANUP_ONLY=1 ./ci/ci-test.sh
chmod -R u+w ${GOPATH}/bin/${CSI_DRIVER} 2>/dev/null || true
chmod -R u+w ${GOPATH}/pkg/* 2>/dev/null || true
rm -rf ${GOPATH}/bin/${CSI_DRIVER}
rm -rf ${GOPATH}/pkg/*

Expand Down Expand Up @@ -119,7 +122,10 @@ verify-deps: deps
bootstrap: controller-gen install-golangci-lint
@for tool in $(EXTERNAL_TOOLS) ; do \
echo "+ Installing $$tool" ; \
cd && GO111MODULE=on go install $$tool@latest; \
if ! echo $$tool | grep "@"; then \
tool=$$tool@latest ; \
fi ; \
GO111MODULE=on go install $$tool; \
done

## golangci-lint tool used to check linting tools in codebase
Expand All @@ -130,11 +136,11 @@ bootstrap: controller-gen install-golangci-lint
## Install golangci-lint only if tool doesn't exist in system
.PHONY: install-golangci-lint
install-golangci-lint:
$(if $(shell which golangci-lint), echo "golangci-lint already exist in system", (curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sudo sh -s -- -b "${GOPATH}/bin" v1.56.2))
$(if $(shell which golangci-lint), echo "golangci-lint already exist in system", (curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b "${GOPATH}/bin" v1.56.2))

.PHONY: controller-gen
controller-gen:
TMP_DIR=$(shell mktemp -d) && cd $$TMP_DIR && go mod init tmp && go install sigs.k8s.io/controller-tools/cmd/[email protected] && rm -rf $$TMP_DIR;
@go install -mod=mod sigs.k8s.io/controller-tools/cmd/[email protected]

# SRC_PKG is the path of code files
SRC_PKG := github.com/openebs/lvm-localpv/pkg
Expand Down Expand Up @@ -222,16 +228,9 @@ lvm-driver-image: lvm-driver
@echo "+ Generating ${CSI_DRIVER} image"
@echo "--------------------------------"
@cp bin/${CSI_DRIVER}/${CSI_DRIVER} buildscripts/${CSI_DRIVER}/
cd buildscripts/${CSI_DRIVER} && sudo docker build -t ${IMAGE_ORG}/${CSI_DRIVER}:${IMAGE_TAG} ${DBUILD_ARGS} . && sudo docker tag ${IMAGE_ORG}/${CSI_DRIVER}:${IMAGE_TAG} quay.io/${IMAGE_ORG}/${CSI_DRIVER}:${IMAGE_TAG}
cd buildscripts/${CSI_DRIVER} && docker build -t ${IMAGE_ORG}/${CSI_DRIVER}:${IMAGE_TAG} ${DBUILD_ARGS} . && docker tag ${IMAGE_ORG}/${CSI_DRIVER}:${IMAGE_TAG} quay.io/${IMAGE_ORG}/${CSI_DRIVER}:${IMAGE_TAG}
@rm buildscripts/${CSI_DRIVER}/${CSI_DRIVER}

.PHONY: ansible-runner-image
ansible-runner-image:
@echo "------------------"
@echo "--> Build ansible-runner image for lvm-localpv e2e-tests"
@echo "------------------"
sudo docker build . -f e2e-tests/Dockerfile -t ${IMAGE_ORG}/lvm-localpv-e2e:ci

.PHONY: ci
ci:
@echo "--> Running ci test";
Expand Down
53 changes: 30 additions & 23 deletions buildscripts/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ DIR="$( cd -P "$( dirname "$SOURCE" )/../" && pwd )"
cd "$DIR"

# Get the git commit
if [ -f $GOPATH/src/github.com/openebs/lvm-localpv/GITCOMMIT ];
if [ -f "$GOPATH"/src/github.com/openebs/lvm-localpv/GITCOMMIT ];
then
GIT_COMMIT="$(cat $GOPATH/src/github.com/openebs/lvm-localpv/GITCOMMIT)"
GIT_COMMIT="$(cat "$GOPATH"/src/github.com/openebs/lvm-localpv/GITCOMMIT)"
else
GIT_COMMIT="$(git rev-parse HEAD)"
fi
Expand All @@ -38,9 +38,9 @@ if [[ -n "$RELEASE_TAG" ]] && [[ $RELEASE_TAG != *"RC"* ]]; then
fi

CURRENT_BRANCH=""
if [ -z ${BRANCH} ];
if [ -z "${BRANCH}" ];
then
CURRENT_BRANCH=$(git branch | grep \* | cut -d ' ' -f2)
CURRENT_BRANCH=$(git branch --show-current)
else
CURRENT_BRANCH=${BRANCH}
fi
Expand All @@ -49,19 +49,18 @@ fi
if [ -n "$RELEASE_TAG" ]; then
VERSION="$RELEASE_TAG"
else
BUILDDATE=`date +%m-%d-%Y`
BUILDDATE=$(date +%m-%d-%Y)
SHORT_COMMIT="$(git rev-parse --short HEAD)"
VERSION="$CURRENT_BRANCH-$SHORT_COMMIT:$BUILDDATE"
fi

echo -e "\nbuilding the LVM Driver version :- $VERSION\n"

VERSION_META="$(cat $PWD/BUILDMETA)"
VERSION_META="$(cat "$PWD"/BUILDMETA)"

# Determine the arch/os combos we're building for
UNAME=$(uname)
ARCH=$(uname -m)
if [ "$UNAME" != "Linux" -a "$UNAME" != "Darwin" ] ; then
if [ "$UNAME" != "Linux" ] && [ "$UNAME" != "Darwin" ] ; then
echo "Sorry, this OS is not supported yet."
exit 1
fi
Expand All @@ -80,8 +79,8 @@ fi

# Delete the old dir
echo "==> Removing old directory..."
rm -rf bin/${PNAME}/*
mkdir -p bin/${PNAME}/
rm -rf bin/"${PNAME}"/*
mkdir -p bin/"${PNAME}"/

XC_OS=$(go env GOOS)
XC_ARCH=$(go env GOARCH)
Expand All @@ -91,17 +90,23 @@ echo "==> Building ${CTLNAME} using $(go version)... "

GOOS="${XC_OS}"
GOARCH="${XC_ARCH}"
output_name="bin/${PNAME}/"$GOOS"_"$GOARCH"/"$CTLNAME
output_name=bin/"$PNAME"/"$GOOS"_"$GOARCH"/"$CTLNAME"

if [ $GOOS = "windows" ]; then
if [ "$GOOS" = "windows" ]; then
output_name+='.exe'
fi
env GOOS=$GOOS GOARCH=$GOARCH go build -ldflags \

if command -v musl-gcc; then
CC="musl-gcc"
fi

env CC="$CC" GOOS="$GOOS" GOARCH="$GOARCH" go build -ldflags \
"-X github.com/openebs/lvm-localpv/pkg/version.GitCommit=${GIT_COMMIT} \
-X main.CtlName='${CTLNAME}' \
-linkmode external -extldflags -static \
-X github.com/openebs/lvm-localpv/pkg/version.Version=${VERSION} \
-X github.com/openebs/lvm-localpv/pkg/version.VersionMeta=${VERSION_META}"\
-o $output_name\
-X github.com/openebs/lvm-localpv/pkg/version.VersionMeta=${VERSION_META}" \
-o "$output_name" \
./cmd

echo ""
Expand All @@ -110,24 +115,26 @@ echo ""
GOPATH=${GOPATH:-$(go env GOPATH)}
case $(uname) in
CYGWIN*)
GOPATH="$(cygpath $GOPATH)"
GOPATH="$(cygpath "$GOPATH")"
;;
esac
OLDIFS=$IFS
IFS=: MAIN_GOPATH=($GOPATH)
IFS=:
read -r -a SPLIT_GOPATHS <<< "$GOPATH"
IFS=$OLDIFS
MAIN_GOPATH=${SPLIT_GOPATHS[0]}

# Create the gopath bin if not already available
mkdir -p ${MAIN_GOPATH}/bin/
mkdir -p "${MAIN_GOPATH}"/bin/

# Copy our OS/Arch to the bin/ directory
DEV_PLATFORM="./bin/${PNAME}/$(go env GOOS)_$(go env GOARCH)"
for F in $(find ${DEV_PLATFORM} -mindepth 1 -maxdepth 1 -type f); do
cp ${F} bin/${PNAME}/
cp ${F} ${MAIN_GOPATH}/bin/
done
find "${DEV_PLATFORM}" -mindepth 1 -maxdepth 1 -type f \
-exec cp {} "bin/${PNAME}/" \; \
-exec cp {} "${MAIN_GOPATH}/bin/" \;


# Done!
echo
echo "==> Results:"
ls -hl bin/${PNAME}/
ls -hl bin/"${PNAME}"/
8 changes: 4 additions & 4 deletions buildscripts/lvm-driver/Dockerfile.buildx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

FROM golang:1.19.9 as build
FROM golang:1.19.9-alpine AS build

ARG BRANCH
ARG RELEASE_TAG
Expand All @@ -31,10 +31,10 @@ ENV GO111MODULE=on \

WORKDIR /go/src/github.com/openebs/lvm-localpv/

RUN apt-get update && apt-get install -y make git
RUN apk add make git bash gcc musl-dev

COPY go.mod go.sum ./
# Get dependancies - will also be cached if we won't change mod/sum
# Get dependencies - will also be cached if we won't change mod/sum
RUN go mod download

COPY . .
Expand All @@ -44,7 +44,7 @@ RUN make buildx.csi-driver
FROM alpine:3.18.4
RUN apk add --no-cache lvm2 lvm2-extra util-linux device-mapper
RUN apk add --no-cache btrfs-progs xfsprogs xfsprogs-extra e2fsprogs e2fsprogs-extra
RUN apk add --no-cache ca-certificates libc6-compat
RUN apk add --no-cache ca-certificates

ARG DBUILD_DATE
ARG DBUILD_REPO_URL
Expand Down
34 changes: 26 additions & 8 deletions ci/ci-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
set -e

SNAP_CLASS="$(realpath deploy/sample/lvmsnapclass.yaml)"
export OPENEBS_NAMESPACE=${OPENEBS_NAMESPACE:-openebs}

export TEST_DIR="tests"

Expand All @@ -19,7 +20,7 @@ CRDS_TO_DELETE_ON_CLEANUP="lvmnodes.local.openebs.io lvmsnapshots.local.openebs.

# Clean up generated resources for successive tests.
cleanup_loopdev() {
sudo losetup -l | grep '(deleted)' | awk '{print $1}' \
losetup -l | grep '(deleted)' | awk '{print $1}' \
| while IFS= read -r disk
do
sudo losetup -d "${disk}"
Expand All @@ -35,24 +36,41 @@ cleanup_foreign_lvmvg() {
cleanup_loopdev
}

# Clean up loop devices and vgs created by the ginkgo lvm_utils.go
cleanup_ginkgo_loop_lvm() {
for device in $(losetup -l -J | jq -r '.loopdevices[]|select(."back-file" | startswith("/tmp/openebs_lvm_localpv_disk_"))' | jq -r '.name'); do
echo "Found stale loop device: $device"

sudo "$(which vgremove)" -y --select="pv_name=$device" || :
sudo losetup -d "$device" 2>/dev/null || :
done
}

cleanup() {
set +e

echo "Cleaning up test resources"

cleanup_foreign_lvmvg
cleanup_ginkgo_loop_lvm

if kubectl get nodes 2>/dev/null; then
kubectl delete pvc -n "$OPENEBS_NAMESPACE" lvmpv-pvc
kubectl delete -f "${SNAP_CLASS}"

kubectl delete pvc -n "$OPENEBS_NAMESPACE" lvmpv-pvc
kubectl delete -f "${SNAP_CLASS}"
kubectl delete pvc -n "$OPENEBS_NAMESPACE" lvmpv-pvc
kubectl delete -f "${SNAP_CLASS}"

helm uninstall lvm-localpv -n "$OPENEBS_NAMESPACE" || true
kubectl delete crds "$CRDS_TO_DELETE_ON_CLEANUP"
helm uninstall lvm-localpv -n "$OPENEBS_NAMESPACE" || true
# shellcheck disable=SC2086
kubectl delete crds $CRDS_TO_DELETE_ON_CLEANUP
fi
# always return true
return 0
}
# trap "cleanup 2>/dev/null" EXIT
[ -n "${CLEANUP_ONLY}" ] && cleanup 2>/dev/null && exit 0
[ -n "${RESET}" ] && cleanup 2>/dev/null
[ -n "${CLEANUP_ONLY}" ] && cleanup && exit 0
[ -n "${RESET}" ] && cleanup


# setup a foreign lvm to test
Expand All @@ -72,7 +90,7 @@ sudo sed -i '/^[^#]*thin_pool_autoextend_percent/ s/= .*/= 20/' /etc/lvm/lvm.con

# Prepare env for running BDD tests
# Minikube is already running
helm install lvm-localpv ./deploy/helm/charts -n "$OPENEBS_NAMESPACE" --create-namespace --set lvmPlugin.pullPolicy=Never --set analytics.enabled=false
helm install lvm-localpv ./deploy/helm/charts -n "$OPENEBS_NAMESPACE" --create-namespace --set lvmPlugin.image.pullPolicy=Never --set analytics.enabled=false
kubectl apply -f "${SNAP_CLASS}"

dumpAgentLogs() {
Expand Down
1 change: 1 addition & 0 deletions nix/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
.go/
.tmp/
/bins/
Loading
Loading