Skip to content

Commit 599683a

Browse files
mayastor-borsniladrih
andcommitted
chore(bors): merge pull request #555
555: ci: add script to run pytests r=niladrih a=niladrih Co-authored-by: Niladri Halder <[email protected]>
2 parents b24823e + c142995 commit 599683a

File tree

17 files changed

+360
-76
lines changed

17 files changed

+360
-76
lines changed

.github/workflows/k8s-ci.yml

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ jobs:
88
runs-on: ubuntu-latest
99
steps:
1010
- uses: actions/checkout@v4
11+
with:
12+
submodules: recursive
1113
- uses: DeterminateSystems/nix-installer-action@v11
1214
with:
1315
kvm: true
@@ -17,12 +19,22 @@ jobs:
1719
export NIX_PATH=nixpkgs=$(jq '.nixpkgs.url' nix/sources.json -r)
1820
echo "NIX_PATH=$NIX_PATH" >> $GITHUB_ENV
1921
nix-shell ./scripts/k8s/shell.nix --run "echo"
22+
- name: Build binaries and images
23+
id: build
24+
run: |
25+
TAG=$(nix-shell ./shell.nix --run './scripts/python/generate-test-tag.sh')
26+
BIN=$(mktemp -p . -d -t test-bin-XXXXXX)
27+
nix-shell ./shell.nix --run "./scripts/python/tag-chart.sh $TAG"
28+
RUSTFLAGS="-C debuginfo=0 -C strip=debuginfo" ./scripts/release.sh --tag $TAG --build-bins --build-binary-out $BIN --no-static-linking --skip-publish --debug
29+
echo "tag=$TAG" >> $GITHUB_OUTPUT
30+
echo "bin=$BIN" >> $GITHUB_OUTPUT
2031
- name: BootStrap k8s cluster
2132
run: |
2233
nix-shell ./scripts/k8s/shell.nix --run "./scripts/k8s/deployer.sh start --label"
23-
- name: Install Helm Chart
24-
run: |
25-
nix-shell ./scripts/k8s/shell.nix --run "./scripts/helm/install.sh --dep-update --wait"
34+
- name: Load images to Kind cluster
35+
run: nix-shell ./scripts/k8s/shell.nix --run "./scripts/k8s/load-images-to-kind.sh --tag ${{ steps.build.outputs.tag }} --trim-debug-suffix"
36+
- name: Run Pytests
37+
run: nix-shell ./shell.nix --run './scripts/python/test.sh'
2638
- name: The job has failed
2739
if: ${{ failure() }}
2840
run: |

.gitignore

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,5 @@ __pycache__
2222
/kubectl-plugin
2323

2424
# Pytest assets
25+
/test-bin-*
2526
tests/bdd/venv
26-
27-
# Minikube assets
28-
tests/bdd/minikube/.cleanup_config.yaml
29-
tests/bdd/minikube/.cleanup_config.yaml.lock
30-
tests/bdd/minikube/bin

default.nix

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,18 @@
1-
{ system ? null, allInOne ? true, incremental ? false, static ? false, img_tag ? "", tag ? "", img_org ? "", product_prefix ? "" }:
1+
{ system ? null
2+
, allInOne ? true
3+
, incremental ? false
4+
, static ? false
5+
, img_tag ? ""
6+
, tag ? ""
7+
, img_org ? ""
8+
, product_prefix ? ""
9+
, rustFlags ? ""
10+
}:
211
let
312
sources = import ./nix/sources.nix;
413
hostSystem = (import sources.nixpkgs { }).hostPlatform.system;
514
pkgs = import sources.nixpkgs {
6-
overlays = [ (_: _: { inherit sources; }) (import ./nix/overlay.nix { inherit allInOne incremental static img_tag tag img_org product_prefix; }) (import sources.rust-overlay) ];
15+
overlays = [ (_: _: { inherit sources; }) (import ./nix/overlay.nix { inherit allInOne incremental static img_tag tag img_org product_prefix rustFlags; }) (import sources.rust-overlay) ];
716
system = if system != null then system else hostSystem;
817
};
918
in

nix/overlay.nix

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,20 @@
1-
{ allInOne ? true, incremental ? false, static ? false, img_tag ? "", tag ? "", img_org ? "", product_prefix ? "" }:
1+
{ allInOne ? true
2+
, incremental ? false
3+
, static ? false
4+
, img_tag ? ""
5+
, tag ? ""
6+
, img_org ? ""
7+
, product_prefix ? ""
8+
, rustFlags ? ""
9+
}:
210
let
311
config = import ./config.nix;
412
img_prefix = if product_prefix == "" then config.product_prefix else product_prefix;
513
in
614
self: super: {
715
sourcer = super.callPackage ./lib/sourcer.nix { };
816
images = super.callPackage ./pkgs/images { inherit img_tag img_org img_prefix; };
9-
extensions = super.callPackage ./pkgs/extensions { inherit allInOne incremental static tag; };
17+
extensions = super.callPackage ./pkgs/extensions { inherit allInOne incremental static tag rustFlags; };
1018
openapi-generator = super.callPackage ./../dependencies/control-plane/nix/pkgs/openapi-generator { };
1119
utils = super.callPackage ./pkgs/utils { inherit incremental; };
1220
channel = import ./lib/rust.nix { pkgs = super.pkgs; };

nix/pkgs/extensions/cargo-project.nix

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
# for development and not for CI
2828
, incremental ? false
2929
, static ? false
30+
, rustFlags
3031
}:
3132
let
3233
stable_channel = {
@@ -105,6 +106,12 @@ let
105106
doCheck = false;
106107
};
107108
release_build = { "release" = true; "debug" = false; };
109+
flags =
110+
if builtins.stringLength rustFlags > 0
111+
then builtins.split " " rustFlags
112+
else if static
113+
then [ "-C" "target-feature=+crt-static" ]
114+
else [ ];
108115
in
109116
let
110117
build_with_naersk = { buildType, cargoBuildFlags }:
@@ -133,7 +140,7 @@ let
133140
export OPENSSL_LIB_DIR=${static_ssl.out}/lib
134141
export OPENSSL_INCLUDE_DIR=${static_ssl.dev}/include
135142
'';
136-
${if static then "RUSTFLAGS" else null} = [ "-C" "target-feature=+crt-static" ];
143+
${if flags == [ ] then null else "RUSTFLAGS"} = flags;
137144
cargoLock = {
138145
lockFile = ../../../Cargo.lock;
139146
};
@@ -151,7 +158,7 @@ in
151158

152159
build = { buildType, cargoBuildFlags ? [ ] }:
153160
if buildAllInOne then
154-
builder { inherit buildType; cargoBuildFlags = [ "-p rpc" "-p metrics-exporter" "-p call-home" "-p upgrade" ]; }
161+
builder { inherit buildType; cargoBuildFlags = [ "-p rpc" "-p metrics-exporter" "-p call-home" "-p upgrade" "-p kubectl-plugin" ]; }
155162
else
156163
builder { inherit buildType cargoBuildFlags; };
157164
}

nix/pkgs/extensions/default.nix

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{ stdenv, git, lib, pkgs, allInOne, incremental, static, sourcer, tag ? "" }:
1+
{ stdenv, git, lib, pkgs, allInOne, incremental, static, sourcer, tag ? "", rustFlags }:
22
let
33
versionDrv = import ../../lib/version.nix { inherit sourcer lib stdenv git tag; };
44
version = builtins.readFile "${versionDrv}";
@@ -8,7 +8,9 @@ let
88
"tag_or_long" = builtins.readFile "${versionDrv.tag_or_long}";
99
};
1010
project-builder =
11-
pkgs.callPackage ../extensions/cargo-project.nix { inherit sourcer gitVersions allInOne incremental static; };
11+
pkgs.callPackage ../extensions/cargo-project.nix {
12+
inherit sourcer gitVersions allInOne incremental static rustFlags;
13+
};
1214
installer = { pname, src, suffix ? "" }:
1315
stdenv.mkDerivation rec {
1416
inherit pname src;
@@ -70,12 +72,18 @@ let
7072
pname = "obs-callhome-stats";
7173
};
7274
};
73-
kubectl-plugin = installer {
74-
src = builder.build {
75-
inherit buildType;
76-
cargoBuildFlags = [ "--bin kubectl-mayastor" ];
75+
kubectl-plugin = rec {
76+
recurseForDerivations = true;
77+
plugin_builder = { buildType, builder, cargoBuildFlags ? [ "-p kubectl-plugin" ] }: builder.build { inherit buildType cargoBuildFlags; };
78+
plugin_installer = { pname, src }: installer { inherit pname src; };
79+
plugin = plugin_installer {
80+
src =
81+
if allInOne then
82+
plugin_builder { inherit buildType builder; cargoBuildFlags = [ "-p kubectl-plugin" ]; }
83+
else
84+
plugin_builder { inherit buildType builder; cargoBuildFlags = [ "--bin kubectl-mayastor" ]; };
85+
pname = "kubectl-mayastor";
7786
};
78-
pname = "kubectl-mayastor";
7987
};
8088
};
8189
in

scripts/helm/publish-chart-yaml.sh

Lines changed: 7 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
#!/usr/bin/env bash
22

3+
SCRIPTDIR="$(dirname "$(realpath "${BASH_SOURCE[0]:-"$0"}")")"
4+
ROOTDIR="$SCRIPTDIR/../.."
5+
6+
source "$ROOTDIR/scripts/utils/yaml.sh"
7+
source "$ROOTDIR/scripts/utils/repo.sh"
8+
39
# On a new appTag, update the Chart.yaml which is used to publish the chart to the appropriate
410
# version and appVersion.
511
# For this first iteration version and appVersion in the Chart.yaml *MUST* point to the stable
@@ -24,46 +30,12 @@ die()
2430

2531
set -euo pipefail
2632

27-
# This uses the existing remote refs for the openebs/mayastor-extensions repo to find the latest 'release/x.y' branch.
28-
# Requires a 'git fetch origin' (origin being the remote entry for openebs/mayastor-extensions) or equivalent, if not
29-
# done already.
30-
latest_release_branch() {
31-
if [ -n "$LATEST_RELEASE_BRANCH" ]; then
32-
echo "$LATEST_RELEASE_BRANCH"
33-
return 0
34-
fi
35-
36-
cd "$ROOTDIR"
37-
38-
# The latest release branch name is required for generating the helm chart version/appVersion
39-
# for the 'main' branch only.
40-
# The 'git branch' command in the below lines checks remote refs for release/x.y branch entries.
41-
# Because the 'main' branch is not a significant branch for a user/contributor, this approach towards
42-
# finding the latest release branch assumes that this script is used when the 'openebs/mayastor-extensions'
43-
# repo is present amongst git remote refs. This happens automatically when the 'openebs/mayastor-extensions'
44-
# repo is cloned, and not a user/contributor's fork.
45-
local latest_release_branch=$(git branch \
46-
--all \
47-
--list "origin/release/*.*" \
48-
--format '%(refname:short)' \
49-
--sort 'refname' \
50-
| tail -n 1)
51-
52-
if [ "$latest_release_branch" == "" ]; then
53-
latest_release_branch="origin/release/0.0"
54-
fi
55-
56-
cd - >/dev/null
57-
58-
echo "${latest_release_branch#*origin/}"
59-
}
60-
6133
helm_testing_branch_version() {
6234
local release_branch=$1
6335
local helm_kind=""
6436

6537
if [[ "$check_branch" == "helm-testing/develop" ]]; then
66-
release_branch=$(latest_release_branch)
38+
release_branch=$(latest_release_branch "origin")
6739
helm_kind="main"
6840
elif [[ "$check_branch" =~ ^helm-testing\/release\/[0-9.]+$ ]]; then
6941
release_branch="${check_branch#helm-testing/}"
@@ -203,22 +175,6 @@ index_yaml()
203175
fi
204176
}
205177

206-
# yq-go eats up blank lines
207-
# this function gets around that using diff with --ignore-blank-lines
208-
yq_ibl()
209-
{
210-
set +e
211-
diff_out=$(diff -B <(yq '.' "$2") <(yq "$1" "$2"))
212-
error=$?
213-
if [ "$error" != "0" ] && [ "$error" != "1" ]; then
214-
exit "$error"
215-
fi
216-
if [ -n "$diff_out" ]; then
217-
echo "$diff_out" | patch --quiet --no-backup-if-mismatch "$2" -
218-
fi
219-
set -euo pipefail
220-
}
221-
222178
output_yaml()
223179
{
224180
newChartVersion=$1
@@ -272,8 +228,6 @@ Examples:
272228
EOF
273229
}
274230

275-
SCRIPTDIR="$(dirname "$(realpath "${BASH_SOURCE[0]:-"$0"}")")"
276-
ROOTDIR="$SCRIPTDIR/../.."
277231
CHART_FILE=${CHART_FILE:-"$ROOTDIR/chart/Chart.yaml"}
278232
CHART_VALUES=${CHART_VALUES:-"$ROOTDIR/chart/values.yaml"}
279233
CHART_DOC=${CHART_DOC:-"$ROOTDIR/chart/doc.yaml"}

scripts/k8s/load-images-to-kind.sh

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
#!/usr/bin/env bash
2+
3+
# Print usage options for this script.
4+
print_help() {
5+
cat <<EOF
6+
Usage: $(basename "${0}") --tag <TAG>
7+
8+
Options:
9+
-h, --help Display this text.
10+
--tag <TAG> Input the container image tag.
11+
--trim-debug-suffix Remove the '-debug' suffix from image names.
12+
13+
Examples:
14+
$(basename "${0}") --tag "ribbit"
15+
EOF
16+
}
17+
18+
SCRIPT_DIR="$(dirname "$(realpath "${BASH_SOURCE[0]:-"$0"}")")"
19+
ROOT_DIR="$SCRIPT_DIR/../.."
20+
# Imports
21+
source "$ROOT_DIR/scripts/utils/log.sh"
22+
23+
set -e
24+
25+
TAG=
26+
TRIM_DEBUG_SUFFIX=0
27+
28+
while test $# -gt 0; do
29+
arg="$1"
30+
case "$arg" in
31+
--tag)
32+
test $# -lt 2 && log_fatal "missing value for the argument '$arg'"
33+
TAG=$2
34+
shift
35+
;;
36+
--tag=*)
37+
TAG=${arg#*=}
38+
;;
39+
--trim-debug-suffix)
40+
TRIM_DEBUG_SUFFIX=1
41+
;;
42+
-h* | --help*)
43+
print_help
44+
exit 0
45+
;;
46+
*)
47+
print_help
48+
log_fatal "unexpected argument '$arg'" 1
49+
;;
50+
esac
51+
shift
52+
done
53+
54+
if [ -z "$TAG" ]; then
55+
log_fatal "requires an image tag"
56+
fi
57+
58+
IMAGE_TAG="v${TAG#v}"
59+
# This list is static and is bound to fall out of date.
60+
# TODO: generate the list of container images at run time from build assets.
61+
images=("upgrade-job" "obs-callhome" "obs-callhome-stats" "metrics-exporter-io-engine")
62+
load_cmd="kind load docker-image"
63+
for image in "${images[@]}"; do
64+
if [ "$TRIM_DEBUG_SUFFIX" = 1 ]; then
65+
docker tag "openebs/mayastor-"$image"-debug":$IMAGE_TAG "openebs/mayastor-"$image:$IMAGE_TAG
66+
fi
67+
load_cmd+=" openebs/mayastor-"$image:$IMAGE_TAG
68+
done
69+
eval $load_cmd

scripts/k8s/setup-io-prereq.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ install_kernel_modules() {
5757
DISTRO="$(distro)"
5858
case "$DISTRO" in
5959
Ubuntu)
60-
$SUDO apt-get install linux-modules-extra-$(uname -r)
60+
$SUDO apt-get update && $SUDO apt-get install -y linux-modules-extra-$(uname -r)
6161
;;
6262
NixOS | *)
6363
install_kernel_modules_nsup "$DISTRO"

0 commit comments

Comments
 (0)