Skip to content

Commit

Permalink
Merge pull request #609 from openebs/build-fixes
Browse files Browse the repository at this point in the history
Various local testing improvements
  • Loading branch information
tiagolobocastro authored Jan 8, 2025
2 parents 287d943 + 5b6db55 commit c239bc7
Show file tree
Hide file tree
Showing 13 changed files with 171 additions and 50 deletions.
18 changes: 15 additions & 3 deletions .github/workflows/build_and_push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,10 @@ jobs:
./scripts/validate-chart-version.sh --branch $BRANCH
- name: Run chart-testing lint
run: |
ct lint --config ct.yaml
run: ct lint --config ct.yaml

- name: Run golint
run: make golint

unit-tests:
runs-on: ubuntu-22.04
Expand All @@ -48,6 +50,11 @@ jobs:
go-version: 1.20.14
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 @@ -76,8 +83,13 @@ jobs:
go-version: 1.20.14
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 zfs-driver-image || exit 1;
run: make zfs-driver-image

- name: Setup zfs pools
run: |
Expand Down
18 changes: 15 additions & 3 deletions .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,10 @@ jobs:
./scripts/validate-chart-version.sh --branch $branch_name
- name: Run chart-testing lint
run: |
ct lint --config ct.yaml
run: ct lint --config ct.yaml

- name: Run golint
run: make golint

validate_codegen:
runs-on: ubuntu-22.04
Expand Down Expand Up @@ -87,6 +89,11 @@ jobs:
go-version: 1.20.14
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 @@ -115,8 +122,13 @@ jobs:
go-version: 1.20.14
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 zfs-driver-image || exit 1;
run: make zfs-driver-image

- name: Setup zfs pools
run: |
Expand Down
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@ tags
*.swo
*.swn
*.idea
*.test
*.test
/coverage.txt
/tests/bdd_coverage.txt
8 changes: 5 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ VETARGS?=-asmdecl -atomic -bool -buildtags -copylocks -methods \
EXTERNAL_TOOLS=\
golang.org/x/tools/cmd/cover@latest \
golang.org/x/lint/golint@latest \
github.com/axw/gocov/gocov@latest \
gopkg.in/matm/v1/gocov-html@latest \
github.com/axw/gocov/gocov@v1.1 \
github.com/matm/gocov-html/cmd/gocov-html@latest \
github.com/onsi/ginkgo/v2/[email protected]

# The images can be pushed to any docker/image registeries
Expand Down Expand Up @@ -86,6 +86,8 @@ clean:
@echo "--> Cleaning Directory" ;
go clean -testcache
rm -rf bin
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 @@ -210,7 +212,7 @@ zfs-driver-image: zfs-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: ci
Expand Down
4 changes: 2 additions & 2 deletions buildscripts/zfs-driver/zfs-driver.Dockerfile
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.20.14 as build
FROM golang:1.20.14 AS build

ARG BRANCH
ARG RELEASE_TAG
Expand All @@ -34,7 +34,7 @@ WORKDIR /go/src/github.com/openebs/zfs-localpv/
RUN apt-get update && apt-get install -y make git

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 Down
68 changes: 51 additions & 17 deletions ci/ci-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,34 +3,66 @@
set -e

SNAP_CLASS=deploy/sample/zfssnapclass.yaml
export OPENEBS_NAMESPACE=${OPENEBS_NAMESPACE:-openebs}
TEST_DIR="tests"

CRDS_TO_DELETE_ON_CLEANUP="zfsrestores.zfs.openebs.io zfssnapshots.zfs.openebs.io zfsvolumes.zfs.openebs.io zfsbackups.zfs.openebs.io zfsnodes.zfs.openebs.io"

cleanup() {
set +e

echo "Cleaning up test resources"

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

helm uninstall zfs-localpv -n "$OPENEBS_NAMESPACE" --wait
# shellcheck disable=SC2086
kubectl delete crds $CRDS_TO_DELETE_ON_CLEANUP
fi

set -e
# always return true
return 0
}
# trap "cleanup 2>/dev/null" EXIT
[ -n "${CLEANUP_ONLY}" ] && cleanup && exit 0
[ -n "${RESET}" ] && cleanup

# allow override
if [ -z "${KUBECONFIG}" ]
then
export KUBECONFIG="${HOME}/.kube/config"
fi


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

dumpAgentLogs() {
NR=$1
AgentPOD=$(kubectl get pods -l app=openebs-zfs-node -o jsonpath='{.items[0].metadata.name}' -n $OPENEBS_NAMESPACE)
kubectl describe po "$AgentPOD" -n $OPENEBS_NAMESPACE
AgentPOD=$(kubectl get pods -l app=openebs-zfs-node -o jsonpath='{.items[0].metadata.name}' -n "$OPENEBS_NAMESPACE")
kubectl describe po "$AgentPOD" -n "$OPENEBS_NAMESPACE"
printf "\n\n"
kubectl logs --tail="${NR}" "$AgentPOD" -n $OPENEBS_NAMESPACE -c openebs-zfs-plugin
kubectl logs --tail="${NR}" "$AgentPOD" -n "$OPENEBS_NAMESPACE" -c openebs-zfs-plugin
printf "\n\n"
}

dumpControllerLogs() {
NR=$1
ControllerPOD=$(kubectl get pods -l app=openebs-zfs-controller -o jsonpath='{.items[0].metadata.name}' -n $OPENEBS_NAMESPACE)
kubectl describe po "$ControllerPOD" -n $OPENEBS_NAMESPACE
ControllerPOD=$(kubectl get pods -l app=openebs-zfs-controller -o jsonpath='{.items[0].metadata.name}' -n "$OPENEBS_NAMESPACE")
kubectl describe po "$ControllerPOD" -n "$OPENEBS_NAMESPACE"
printf "\n\n"
kubectl logs --tail="${NR}" "$ControllerPOD" -n $OPENEBS_NAMESPACE -c openebs-zfs-plugin
kubectl logs --tail="${NR}" "$ControllerPOD" -n "$OPENEBS_NAMESPACE" -c openebs-zfs-plugin
printf "\n\n"
}


isPodReady(){
[ "$(kubectl get po "$1" -o 'jsonpath={.status.conditions[?(@.type=="Ready")].status}' -n $OPENEBS_NAMESPACE)" = 'True' ]
[ "$(kubectl get po "$1" -o 'jsonpath={.status.conditions[?(@.type=="Ready")].status}' -n "$OPENEBS_NAMESPACE")" = 'True' ]
}


Expand All @@ -46,7 +78,7 @@ waitForZFSDriver() {
interval=1
i=0
while [ "$i" -le "$period" ]; do
zfsDriver="$(kubectl get pods -l role=openebs-zfs -o 'jsonpath={.items[*].metadata.name}' -n $OPENEBS_NAMESPACE)"
zfsDriver="$(kubectl get pods -l role=openebs-zfs -o 'jsonpath={.items[*].metadata.name}' -n "$OPENEBS_NAMESPACE")"
if isDriverReady "$zfsDriver"; then
return 0
fi
Expand All @@ -69,7 +101,7 @@ runTestSuite() {

cd $TEST_DIR

kubectl get po -n $OPENEBS_NAMESPACE
kubectl get po -n "$OPENEBS_NAMESPACE"

set +e

Expand Down Expand Up @@ -102,10 +134,10 @@ runTestSuite() {
kubectl get sc --all-namespaces -oyaml

echo "get zfs volume details"
kubectl get zfsvolumes.zfs.openebs.io -n $OPENEBS_NAMESPACE -oyaml
kubectl get zfsvolumes.zfs.openebs.io -n "$OPENEBS_NAMESPACE" -oyaml

echo "get zfs snapshot details"
kubectl get zfssnapshots.zfs.openebs.io -n $OPENEBS_NAMESPACE -oyaml
kubectl get zfssnapshots.zfs.openebs.io -n "$OPENEBS_NAMESPACE" -oyaml

exit 1
fi
Expand All @@ -114,17 +146,19 @@ runTestSuite() {
runTestSuite bdd_coverage.txt "!custom-node-id"

prepareCustomNodeIdEnv() {
for node in $(kubectl get nodes -n $OPENEBS_NAMESPACE -o jsonpath='{.items[*].metadata.name}'); do
local zfsNode=$(kubectl get zfsnode -n $OPENEBS_NAMESPACE -o jsonpath="{.items[?(@.metadata.ownerReferences[0].name=='${node}')].metadata.name}")
for node in $(kubectl get nodes -n "$OPENEBS_NAMESPACE" -o jsonpath='{.items[*].metadata.name}'); do
local zfsNode
zfsNode=$(kubectl get zfsnode -n "$OPENEBS_NAMESPACE" -o jsonpath="{.items[?(@.metadata.ownerReferences[0].name=='${node}')].metadata.name}")
echo "Relabeling node ${node} with ${node}-custom-id"
kubectl label node "${node}" openebs.io/nodeid="${node}-custom-id" --overwrite

local nodeDriver=$(kubectl get pods -l name=openebs-zfs-node -o jsonpath="{.items[?(@.spec.nodeName=='${node}')].metadata.name}" -n $OPENEBS_NAMESPACE)
local nodeDriver
nodeDriver=$(kubectl get pods -l name=openebs-zfs-node -o jsonpath="{.items[?(@.spec.nodeName=='${node}')].metadata.name}" -n "$OPENEBS_NAMESPACE")
echo "Restarting ${nodeDriver} on ${node} to pick up the new node id"
kubectl delete pod "${nodeDriver}" -n $OPENEBS_NAMESPACE
kubectl delete pod "${nodeDriver}" -n "$OPENEBS_NAMESPACE"

echo "Deleting old zfsnode ${zfsNode}"
kubectl delete zfsnode "${zfsNode}" -n $OPENEBS_NAMESPACE
kubectl delete zfsnode "${zfsNode}" -n "$OPENEBS_NAMESPACE"
done
}

Expand Down
3 changes: 3 additions & 0 deletions nix/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.go/
.tmp/
/bins/
10 changes: 5 additions & 5 deletions nix/sources.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
{
"nixpkgs": {
"branch": "release-23.05",
"description": "A read-only mirror of NixOS/nixpkgs tracking the released channels. Send issues and PRs to",
"branch": "release-23.11",
"description": "Nix Packages collection & NixOS",
"homepage": "https://github.com/NixOS/nixpkgs",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "9a333eaa80901efe01df07eade2c16d183761fa3",
"sha256": "0xhqjli4m9wkzv7xhs6fr1iajdjbv7xnj0bwvwldq9s6arlwkhj3",
"rev": "205fd4226592cc83fd4c0885a3e4c9c400efabb5",
"sha256": "1f5d2g1p6nfwycpmrnnmc2xmcszp804adp16knjvdkj8nz36y1fg",
"type": "tarball",
"url": "https://github.com/NixOS/nixpkgs/archive/9a333eaa80901efe01df07eade2c16d183761fa3.tar.gz",
"url": "https://github.com/NixOS/nixpkgs/archive/205fd4226592cc83fd4c0885a3e4c9c400efabb5.tar.gz",
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
}
}
21 changes: 10 additions & 11 deletions pkg/driver/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ func (cs *controller) CreateVolume(
) (*csi.CreateVolumeResponse, error) {

var err error
var selectedNodeId string
var selectedNodeID string

if err = cs.validateVolumeCreateReq(req); err != nil {
return nil, err
Expand All @@ -459,23 +459,23 @@ func (cs *controller) CreateVolume(
if contentSource != nil && contentSource.GetSnapshot() != nil {
snapshotID := contentSource.GetSnapshot().GetSnapshotId()

selectedNodeId, err = CreateSnapClone(ctx, req, snapshotID)
selectedNodeID, err = CreateSnapClone(ctx, req, snapshotID)
} else if contentSource != nil && contentSource.GetVolume() != nil {
srcVol := contentSource.GetVolume().GetVolumeId()
selectedNodeId, err = CreateVolClone(ctx, req, srcVol)
selectedNodeID, err = CreateVolClone(ctx, req, srcVol)
} else {
selectedNodeId, err = CreateZFSVolume(ctx, req)
selectedNodeID, err = CreateZFSVolume(ctx, req)
}

if err != nil {
return nil, err
}

klog.Infof("created the volume %s/%s on node %s", pool, volName, selectedNodeId)
klog.Infof("created the volume %s/%s on node %s", pool, volName, selectedNodeID)

sendEventOrIgnore(pvcName, volName, strconv.FormatInt(int64(size), 10), analytics.VolumeProvision)

topology := map[string]string{zfs.ZFSTopologyKey: selectedNodeId}
topology := map[string]string{zfs.ZFSTopologyKey: selectedNodeID}
cntx := map[string]string{zfs.PoolNameKey: pool, zfs.OpenEBSCasTypeKey: zfs.ZFSCasTypeName}

return csipayload.NewCreateVolumeResponseBuilder().
Expand Down Expand Up @@ -906,19 +906,18 @@ func (cs *controller) GetCapacity(
poolParamSliced := strings.SplitN(poolParam, "/", 2)
if len(poolParamSliced) == 2 {
return poolParamSliced[0], poolParamSliced[1]
} else {
return poolParamSliced[0], ""
}
return poolParamSliced[0], ""
}()

var availableCapacity int64
for _, nodeName := range nodeNames {
mappedNodeId, mapErr := zfs.GetNodeID(nodeName)
mappedNodeID, mapErr := zfs.GetNodeID(nodeName)
if mapErr != nil {
klog.Warningf("Unable to find mapped node id for %s", nodeName)
mappedNodeId = nodeName
mappedNodeID = nodeName
}
v, exists, err := zfsNodesCache.GetByKey(zfs.OpenEBSNamespace + "/" + mappedNodeId)
v, exists, err := zfsNodesCache.GetByKey(zfs.OpenEBSNamespace + "/" + mappedNodeID)
if err != nil {
klog.Warning("unexpected error after querying the zfsNode informer cache")
continue
Expand Down
4 changes: 4 additions & 0 deletions pkg/zfs/volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,10 @@ func init() {
GoogleAnalyticsEnabled = os.Getenv(GoogleAnalyticsKey)
}

// GetNodeID returns the Node ID of the given K8s nodename.
// It may return an error whilst fetching the node using the k8sapi.
// If the K8s node object does contain the topology label, then the nodename
// itself is returned as the Node ID.
func GetNodeID(nodename string) (string, error) {
node, err := k8sapi.GetNode(nodename)
if err != nil {
Expand Down
Loading

0 comments on commit c239bc7

Please sign in to comment.